可以使用AWS加密SDK对多个AWS KMS区域中使用的加密/解密秘密的命令行工具。
mrcrypt的Python项目详细描述
mrcrypt:多区域加密
mrcrypt是一个命令行工具,它加密符合aws的秘密 加密sdk的message format 用于信封加密。从v2.0开始,mrcrypt现在包装aws-encryption-sdk-cli。
有关aws encryption sdk的更多信息,请参见 https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/introduction.html。
安装
您可以使用pip:
安装mrcrypt的最新版本pip install mrcrypt
快速启动
加密用于3个区域的文件(注意:密钥别名必须存在于指定区域中):
mrcrypt encrypt -r us-east-1 us-west-2 eu-west-1 -- alias/master-key secrets.txt
解密文件:
mrcrypt decrypt secrets.txt.encrypted
用法
usage: mrcrypt [-h] [-p PROFILE] [-v] [-q] [-o OUTFILE] {encrypt,decrypt} ... Multi Region Encryption. A tool for managing secrets across multiple AWS regions. positional arguments: {encrypt,decrypt} optional arguments: -h, --help show this help message and exit -p PROFILE, --profile PROFILE The profile to use -v, --verbose More verbose output (ignored if --quiet) -q, --quiet Quiet all output -o OUTFILE, --outfile OUTFILE The file to write the results to (use "-" to write to stdout
encrypt和decrypt命令都可以在 目录递归。
命名配置文件
如果您的~/.aws/credentials文件中有多个命名配置文件, 可以使用-p参数指定一个。
mrcrypt -p my_profile encrypt alias/master-key secrets.txt
加密上下文
可以指定encryption context 使用-e参数。此标志接受没有空格的json对象:
# encrypt mrcrypt -e '{"key":"value","key2":"value2"}' encrypt alias/master-key secrets.txt # decrypt mrcrypt -e '{"key":"value","key2":"value2"}' decrypt secrets.txt.encrypted
输出文件名
如果要指定输出文件名,可以使用-o 争论。
- ::
- 加密“file.txt”将输出写入“encrypted file.txt” mrcrypt-o encrypted-file.txt加密别名/master key file.txt
要写入stdout,可以使用-
- ::
- 加密“file.txt”将输出写入stdout mrcrypt-o-加密别名/主密钥文件.txt
当未指定输出文件名参数时,mrcrypt将使用输入 文件名作为基础并添加后缀。加密时,这个后缀是.encrypted 解密时这个后缀是.decrypted。
加密
usage: mrcrypt encrypt [-h] [-r REGIONS [REGIONS ...]] [-e ENCRYPTION_CONTEXT] key_id filename Encrypts a file or directory recursively positional arguments: key_id An identifier for a customer master key. filename The file or directory to encrypt. Use "-" to read from stdin optional arguments: -h, --help show this help message and exit -r REGIONS [REGIONS ...], --regions REGIONS [REGIONS ...] A list of regions to encrypt with KMS. End the list with -- -e ENCRYPTION_CONTEXT, --encryption_context ENCRYPTION_CONTEXT An encryption context to use
示例:用密钥别名加密secrets.txt。 alias/master-key在区域us-east-1和us-west-2:
mrcrypt encrypt -r us-east-1 us-west-2 -- alias/master-key secrets.txt
^ {STR 1 } $注:在此示例中,密钥别名{TT10} $均存在于 us-east-1,和us-west-2区域。
解密
usage: mrcrypt decrypt [-h] filename Decrypts a file positional arguments: filename The file or directory to decrypt. Use "-" to read from stdin optional arguments: -h, --help show this help message and exit
示例:解密secrets.txt.encrypted:
mrcrypt decrypt secrets.txt.encrypted
注意:解密目录时要小心。如果目录 包含未加密的文件,将失败。
测试
如果安装了tox,那么运行mrcrypt的测试很容易。简单地 在项目的根目录下运行tox。
如果您有带KMS密钥的AWS帐户,则可以使用运行集成测试
AWS_ENCRYPTION_SDK_PYTHON_INTEGRATION_TEST_AWS_KMS_KEY_ID=<my-key-arn> tox -e py{27,34,35,36}-{local,integ}
有关在v2.0之前使用mrcrypt创建的文件的说明
在v2.0发布后,mrcrypt开始包装 aws-encryption-sdk-cli。包装 aws encryption sdk cli意味着mrcrypt现在完全符合aws 加密sdk的message format和使用 加密文件时压缩的点。在v2.0之前,mrcrypt没有使用压缩点,并且 虽然仍然安全,但它会导致与其他aws加密sdk实现的兼容性问题。 更新2.0以前版本的mrcrypt加密文件,并提高与aws加密的兼容性 sdk,只需使用mrcrypt的最新版本对文件进行解密和重新加密。