为SSO账户和角色构建AWS CLI配置配置文件
项目描述
AWS SSO Config Builder
目录
概要
此工具生成AWS CLI配置块,用于与AWS IAM身份中心(以前称为AWS SSO)一起使用
为什么
...有人会用这个吗?
如果他们
- 通过AWS SSO访问大量或不断变化的账户和角色
- 尚未设置生成和维护其命名配置文件的工具
- 这类工具有一些,我记得aws-sso-util特别如此
- 想要自动生成/重新生成模板化块,而不干扰手动定义的部分
...我发布了这个吗?
- 在https://github.com/99designs/aws-vault/pull/1088合并后,我想更新我用来更新我的AWS CLI配置的脚本
- Cog在我开始做这些事情时并没有出现在我的雷达上,但它正是我想用来维护我frankenconfig中更干净的部分的
- 我想找个借口来尝试Hatch
...关注aws-vault?
从用户体验的角度来看,最大的好处是当使用我的aws-vault配置文件时,它们只需工作即可
- 如果没有活跃的SSO会话,它会自动打开浏览器登录,无需手动输入
aws sso login
- 如果会话凭证缺失或已过期,aws-vault会在后台刷新它们,而不会终止正在运行的命令
但说到底,我之所以使用aws-vault,很大程度上是出于习惯。如果你还没有使用它,我并不打算向你推销。
安装
到活动Python环境
pip install aws-sso-config-builder
使用Pipx
pipx install aws-sso-config-builder
与Cog一起使用Pipx
对支持与Cog的使用很有用。
pipx install cogapp
pipx inject cogapp aws-sso-config-builder
使用方法
根据您的AWS SSO登录权限,生成AWS CLI sso-session
和profile
块。
可以作为CLI工具或从Python使用。
CLI
使用默认值快速入门
generate-sso-profiles -s my-sso-directory-name
这将生成sso-session
和profile
块
更多选项
Usage: generate-sso-profiles [OPTIONS]
Options:
-s, --sso-directories TEXT SSO directory names, which will be used:
- To define "sso-session" config blocks
- To build an SSO start URL [required]
-t, --profile-template TEXT An AWS CLI profile block template with
{placeholders} for profile values
Supported placeholder variables:
- profile_name
- account_name
- account_id
- role_name
- sso_session
...and any other "key" provided in --extra-
vars
-e, --extra-vars TEXT Custom variables in the form "key=value" that
can be referenced with {placeholders} in a
profile template.
-r, --regex-replacements TEXT Regex replacements to perform on generated
profile names, in the form
'pattern,replacement'
--help Show this message and exit.
Python
使用默认值快速入门
from aws_sso_config_builder.gen_config import generate_config_blocks
print(generate_config_blocks(sso_directories=["my-sso-directory-name"]))
与Cog一起使用
使用Cog动态生成或替换~/.aws/config
文件中特定部分的特定内容,无需手动维护块。
此调用指定
- 自定义配置文件模板,包括
- 用于与aws-vault一起使用的
credential_process
配置文件 - 为每个配置文件定义的附加设置
- 用于与aws-vault一起使用的
- 一些正则表达式替换来调整生成的配置文件名称
将此Cog块添加到新的或现有的~/.aws/config
文件中
# [[[cog
# import cog
# from aws_sso_config_builder.gen_config import generate_config_blocks
#
# cog.outl(generate_config_blocks(
# sso_directories=["home", "work"],
# profile_template="""
# [profile {profile_name}-sso]
# sso_session = {sso_session}
# sso_account_id = {account_id}
# sso_role_name = {role_name}
# output = json
# region = us-east-2
#
# [profile {profile_name}]
# credential_process = {aws_vault_path} exec --json {profile_name}-sso
# output = json
# region = us-east-2
# """,
# regex_replacements={
# "Production": "prod",
# "Sandbox": "sbx"
# },
# aws_vault_path="/home/aj/go/bin/aws-vault",
# ))
# ]]]
# [[[end]]]
然后运行
cog -r ~/.aws/config
请注意,这取决于Cog和aws-sso-config-builder是否安装在同一Python环境中。请参阅上方的与Cog一起使用Pipx进行安装。
附加功能
Fish便捷函数
这些可能特定于我的环境,但分享它们是因为其他人可能也会觉得它们有用。
我使用一个fish便捷函数(asp)来搜索或切换AWS配置文件。我相当确信它在某个时刻受到了oh-my-zsh的aws插件中同名函数的启发。
使用无参数的asp
调用会打开fzf搜索可用配置文件。但该命令也支持使用此完成脚本的tab补全。
许可证
aws-sso-config-builder
遵循MIT许可。
项目详情
下载文件
下载适合您平台的项目文件。如果您不确定选择哪个,请了解有关安装包的更多信息。
源分布
aws_sso_config_builder-0.0.4.tar.gz (18.1 kB 查看哈希值)
构建分布
关闭
aws_sso_config_builder-0.0.4.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | e290956796787590b7b8aca0d2c6498e5f66cc509dc79f4dd6596675dde50a6f |
|
MD5 | 8eafb2d258a8c1a25c1aeac116b4a718 |
|
BLAKE2b-256 | de8f28f6f261a58424a7c995a91d6a86617e279287247e531a0a90ce48464a36 |
关闭
哈希值 用于 aws_sso_config_builder-0.0.4-py3-none-any.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 14810b3240a41288e8795b68c31823b1fd0a688fc80110f5453673ac42e48c86 |
|
MD5 | 3002251c2bd64a9cce879c2b8f45a595 |
|
BLAKE2b-256 | 0b283b3f1f745627bd7dcaea12e3d5bd25966745e7c3970598cf91c10667224c |