使用加密凭据文件中的访问密钥调用aws cli
aws-profile-gpg的Python项目详细描述
AWS配置文件gpg
使用IAM Access Keys从GPG加密凭据文件调用aws-cli的脚本。
这个脚本的灵感来自于github上的各种aws-profile包装器,以及保持凭证加密的愿望。
优点
一。您的秘密访问密钥在磁盘上的静止位置加密,因此如果有人访问了您的计算机,他们仍然无法访问您的AWS凭据
2.您可以将加密的凭据安全地存储在Dropbox或服务器上,以便可以从多台计算机访问相同的配置和凭据文件
三。由于脚本的工作方式是解密凭据文件并将AWS_ACCESS_KEY_ID
和AWS_SECRET_ACCESS_KEY
添加到进程环境中,因此您可以将其与使用这些环境变量的其他应用程序一起使用,例如Terraform
四。如果使用OpenGPG card如Yubikey作为私钥,它将有效地充当访问密钥的硬件mfa设备
详细信息和用例在下面的用法中概述。
先决条件
本指南假设您熟悉GPG,并且能够加密凭据文件。如果您不熟悉gpg,有很多good tutorials online。
安装
使用自制
brew bundle
或
brew tap firstlookmedia/firstlookmedia
brew install aws-profile-gpg
使用pypi
pip install aws-profile-gpg
用法
pip install aws-profile-gpg
基本用法
usage: aws-profile-gpg [-h] [-v] command [command ...]
positional arguments:
command command passed to aws cli
optional arguments:
-h, --help show this help message and exit
-v, --verbose verbose output
使用默认配置
aws-profile-gpg aws s3 ls
指定aws配置文件
AWS_PROFILE=iam_leet \
aws-profile-gpg aws s3 ls
指定备用凭据文件
AWS_ENCRYPTED_CREDENTIALS_FILE=/path/to/shared/aws/credentials.asc \
aws-profile-gpg aws s3 ls
指定替代配置文件
AWS_CONFIG_FILE=/path/to/shared/aws/config \
aws-profile-gpg aws s3 ls
在Dropbox中存储配置和凭据文件
AWS_CONFIG_FILE=${HOME}/Dropbox/etc/aws/config \
AWS_ENCRYPTED_CREDENTIALS_FILE=${HOME}/Dropbox/aws/credentials.gpg \
aws-profile-gpg aws s3 ls
与terraform一起使用
AWS_PROFILE=terraform \
aws-profile-gpg terraform -plan
环境变量
aws_profile_gpg_主页
- 指向
aws-profile-gpg
目录的路径;用于定位virtualenv和python脚本 - 默认为
/usr/local/opt/aws-profile-gpg
- 指向
AWS加密的凭据文件
- GPG加密凭据文件的路径
- 支持纯
.gpg
和ascii铠装.asc
文件 - 默认为
~/.aws/credentials.gpg
aws配置文件
- 见AWS Command Line Interface
- 默认为
~/.aws/config
- 注意:如果更改此设置,则必须在自定义配置文件中定义所有配置文件
AWS默认配置文件
- 见AWS Command Line Interface
- 默认为
default
注释
创建bash快捷方式
创建bash函数有助于快速调用不同的配置文件:
$ vim ~/.bash_profile
# optional
export AWS_ENCRYPTED_CREDENTIALS_FILE="${HOME}/Dropbox/aws/credentials.gpg"
export AWS_CONFIG_FILE="${HOME}/Dropbox/aws/config"
function aws-leet {
AWS_PROFILE=iam_leet \
aws-profile-gpg \
aws \
$@
}
function aws-terraform {
AWS_PROFILE=terraform \
aws-profile-gpg \
aws \
$@
}
然后您可以运行:
$ source ~/.bash_profile
$ aws-leet iam get-user
{
"User": {
"Path": "/",
"UserName": "iam.leet",
"UserId": "AID35DF67GHFEK3",
"Arn": "arn:aws:iam::737415635305:user/iam.leet",
"CreateDate": "1970-01-01T00:00:00Z",
"PasswordLastUsed": "2000-01-01T00:00:01Z"
}
}
在配置文件中指定配置文件
使用的AWS_PROFILE
必须在AWS_CONFIG_FILE
文件中定义,例如
$ cat ~/.aws/config
[profile default]
region=us-east-1
[profile iam_leet]
region=us-east-1
这也适用于default
配置文件。
如果尝试使用未定义的配置文件,将看到以下错误:
Profile not found in config; profile=iam_leet
相关链接
github上
aws-profile
的各种版本GNU隐私保护(GPG)
俾格麦
两个目录