生成gossamer配置文件和aws别名
goss-config-gen的Python项目详细描述
薄纱/AWS别名生成器
生成Gossamer和aws别名 基于单个配置文件。
要求
安装
安装最新版本的Gossamer
确保将gossamer保存到的路径位于
$PATH
中。linux/mac:
添加到
.bashrc
(Linux)或.bash_profile
(Mac)中:export PATH=$PATH:<add the path to the folder containing the Gossamer binary>
Windows:
https://helpdeskgeek.com/windows-10/add-windows-path-environment-variable/
安装goss config gen
pip install goss-config-gen
在
.bash_profile
的底部添加以下内容:# Generated aliases if [ -f $HOME/gossamer/goss-generated-aliases.sh ]; then . $HOME/gossamer/goss-generated-aliases.sh fi
配置
配置文件可以手动指定为参数--config-file
或-c
,也可以使用
GOSS_GEN_CONFIG
环境变量。它默认为$HOME/goss-config.json
这里是
默认情况下需要存储配置文件。有一个sample configuration file可用
让你开始根据需要自定义值。
OutputDirectory
将要写入文件的输出目录。
此参数是可选的,默认为$HOME/gossamer
。
OutputFile
包含所有生成别名的输出文件
此参数是可选的,默认为goss-generated-aliases.sh
。
RoleAliases
别名到角色的映射。
此参数是可选的,允许创建映射到一个或多个角色的别名。
"RoleAliases":{"all":["path/role1","path/role2]}
例如,如果您试图在使用上述方法的所有帐户中承担角色path/role1
和path/role2
配置时,生成的别名将是goss-all
。除了这些别名之外,默认情况下,每个
将创建角色名的规范化版本(/
替换为-
)。
GossamerPath
gossamer可执行文件的路径。默认为/usr/local/bin/gossamer
AWSCredentialsPath
AWS凭据文件的路径。默认为$HOME/.aws/credentials
AWSCLIPath
aws cli可执行文件的路径。默认为/usr/local/bin/aws
BaseProfile
具有可以假定角色的凭据的基本配置文件此配置文件应该已经在 AWS凭据文件。默认为“默认”
Accounts
包含帐户信息的对象列表。此参数是必需的。
下面是每个对象支持的字段的概述
Field | Description | Required | Defaults |
---|---|---|---|
Id | Account ID | Yes | |
Name | Account Name | Yes | |
Alias | String to use in the generated alias (i.e. if this is ^{ | No | Value of the "Name" field |
Region | AWS region | Yes | |
Role | Role name, including path, to assume | Yes |
用法
运行
goss-config-gen
:goss-config-gen
重新启动终端
使用生成的别名之一。例如,如果您的
Alias
之一设置为a
,则将生成名为goss-a
的别名别名的用法如下:goss-a [enter your MFA code here]
如果已经有多个gossamer角色文件,则可以通过以下方式生成goss-config-gen
配置文件
将这些角色文件传递到goss-config-gen
。
例如,如果您有以下角色文件:
role-file-1
{"Roles":[{"AccountName":"acct-a","Region":"us-east-1","RoleArn":"arn:aws:iam::123456789012:role/path/role1"},{"AccountName":"acct-b","Region":"us-east-1","Role":"arn:aws:iam::987654321098:role/path/role1"}]}
role-file-2
{"Roles":[{"AccountName":"acct-c","Region":"us-east-1","Role":"arn:aws:iam::123456789012:role/cs/role2"},{"AccountName":"acct-d","Region":"us-east-1","Role":"arn:aws:iam::111111111111:role/cs/role2"}]}
运行以下命令生成配置文件:
goss-config-gen \
--config-file <path-where-config-file-will-be-saved> \
--import-file <path-to-role-file-1> \
--import-file <path-to-role-file-2>
注意:参数--config-file
是可选的,仅当配置文件应保存到自定义位置时才需要。
它将生成以下配置文件,可用于后续
{"Accounts":[{"Id":"123456789012","Name":"acct-a","Region":"us-east-1","Role":"path/role1"},{"Id":"987654321098","Name":"acct-b","Region":"us-east-1","Role":"path/role1"},{"Id":"123456789012","Name":"acct-c","Region":"us-east-1","Role":"path/role2"},{"Id":"111111111111","Name":"acct-d","Region":"us-east-1","Role":"path/role2"}]}
现在要用新的配置文件生成别名,只需像平常一样运行goss-config-gen
:
goss-config-gen --config-file <path-to-config-file>
注意:同样,--config-file
参数是可选的,只有当配置文件存储在自定义位置时才需要。
样本
sample configuration file将生成以下别名:
goss-a goss-b goss-c goss-d goss-e goss-acct-f aws-a aws-b aws-c aws-d aws-e aws-acct-f awsi-a awsi-b awsi-c awsi-d awsi-e awsi-acct-f