部署密钥库的Humilis层
项目描述
这是一个 humilis 插件,实现了 secrets-vault 层。该层由一个加密的DynamoDB表组成,为同一humilis环境中的Lambda函数提供密钥。密钥的加密和解密由AWS KMS服务处理。
安装
从 PyPI
pip install humilis-secrets-vault
安装开发版本
pip install git+https://github.com/InnovativeTravel/humilis-secrets-vault
如何使用它?
只需将此层添加到您的 humilis 环境,并使用层参数 associated_processors 指定包含需要访问密钥库中密钥的Lambda函数的层。例如,以下环境部署了一个处理Kinesis流事件的Lambda函数。Lambda处理器被授权访问同一环境中的密钥库
--- myenvironment: description: An environment with a Lambda processor to filter events in a Kinesis stream. layers: - layer: streams layer_type: streams streams: - name: InputStream shard_count: 1 - layer: event-processor layer_type: kinesis-processor dependencies: ["streams"] input: {layer: streams, stream: InputStream} - layer: secrets-vault layer_type: secrets-vault # We specify that the Lambda function in the event-processor layer # should have access to the secrets in the vault. associated_processors: ["event-processor"]
密钥库层期望包含Lambda处理器(s)的层公开一个层输出 LambdaFunctionArn,其中包含应该有权访问密钥库中密钥的Lambda函数的ARN。如上例中的 kinesis-processor 类型层满足此要求,因此它们将直接工作。
检索密钥
从Lambda函数中检索密钥的最简单方法是将软件包 lambdautils 作为依赖项包含。
然后您可以在Lambda代码中轻松检索库中的密钥,如下所示
import lambdautils.utils as utils # Assuming that you are deploying this Lambda with humilis the line below # will indicate humilis to preprocess this function with Jinja2 before # producing the Lambda deployment package. # preprocessor:jinja2 # During deployment, humilis will replace here the name of the humilis # environment and deployment stage. ENVIRONMENT = "{{_env.name}}" STAGE = "{{_env.stage}}" plaintext = utils.get_secret( "my_secret_key", environment=ENVIRONMENT, stage=STAGE)
存储密钥
您可以使用 humilis 从命令行将密钥存储在库中
humilis set-secret --stage [STAGE] [ENVIRONMENT_FILE] [SECRET_KEY] [SECRET_VALUE]
开发
假设您已安装 virtualenv
make develop
配置humilis
.env/bin/humilis configure --local
测试
您可以使用以下方法测试秘密保险库的部署:
make create
然后您可以运行集成测试套件(待定)
make testi
完成后,不要忘记删除测试部署
make delete
更多信息
请参阅 humilis 文档。
联系方式
如果您有任何问题、错误报告、建议等,请在本GitHub项目页面上创建问题。
许可证
本软件遵循MIT许可证。
请参阅许可证文件。
© 2016 German Gomez-Herrero,Find Hotel 及其他。