stonewaves / credstash
源自 https://github.com/gmo/credstash。一个使用 AWS KMS 和 DynamoDB 管理云中机密的实用工具
1.0.4
2019-11-26 15:42 UTC
Requires
- php: ^5.5.9 || ^7.0
- ext-openssl: *
- aws/aws-sdk-php: 3.121.1
- symfony/polyfill-php56: ^1.0
- webmozart/path-util: ^2.3
Requires (Dev)
- symfony/console: ^2.7 || ^3.0
- symfony/yaml: ^2.7 || ^3.0
This package is auto-updated.
Last update: 2024-09-27 02:04:18 UTC
README
这是 CredStash(用 Python 编写)的 PHP 版本。加密和 DynamoDB 存储与 Python 版本兼容,因此两者可以并行工作。还有一个可选的 CLI 工具,详情见下文。
关于 CredStash 是什么,它是如何工作的,以及如何设置的更多信息,可以阅读他们的 README。
安装
$ composer require stonewaves/credstash
PHP 使用
创建 CredStash 实例
创建 CredStash 最简单的方法是使用 AWS SDK 对象
<?php use CredStash\CredStash; $sdk = new Aws\Sdk(); // config omitted $credStash = CredStash::createFromSdk($sdk);
获取单个机密
// Get secret for "foo" credential $secret = $credStash->get('foo'); // Including context parameters $secret = $credStash->get('foo', ['env' => 'prod']); // By default, the latest version is used, // but a specific version can be passed in. $secret = $credStash->get('foo', [], 2);
获取多个机密
// Get latest version of all secrets $secrets = $credStash->getAll(); // ['foo' => 'secret', 'bar' => 'another secret']; // Including context parameters $secrets = $credStash->getAll(['env' => 'prod']); // Get specific version for all secrets $secrets = $credStash->getAll([], 2); // Get all secrets matching pattern $secrets = $credStash->search('ssl.*'); // matches "ssl.foo" and "ssl.bar" // This version also allows "?" and "[]" patterns. $secrets = $credStash->search('s?l'); // matches "ssl" and "sdl" $secrets = $credStash->search('gr[ae]y'); // matches "gray" and "grey" // Context and version can specified here as well $secrets = $credStash->search($pattern, $context, $version);
放置机密
// Put secret into store at the next highest version $credStash->put('foo', 'secret'); // Including context parameters $credStash->put('foo', 'secret', ['env' => 'prod']); // Put secret into store at a specified version $credStash->put('foo', 'secret', [], 2);
删除机密
$credStash->delete('foo');
列出凭据及其最新版本
$credentials = $credStash->listCredentials(); // ['foo' => '000000000000000002', 'bar' => '000000000000000003']; // As you can see versions are padded to ensure sorting is consistent // They can be optionally converted to integers though // with the by passing false to the $pad parameter. $credentials = $credStash->listCredentials(false); // ['foo' => 2, 'bar' => 3];
CLI 使用
注意: CLI 工具需要手动安装 Symfony 的 Console Component,因为这是一个可选的依赖项。
$ composer require symfony/console
CLI 工具与 Python 版本兼容,但由于与 Symfony 的 Console 应用程序的命令/参数的兼容性,存在一些差异。
版本参数
Python 版本使用 -v
或 --version
来指定 put
或 get
的版本。这里使用 -c
或 --cred-version
,因为 Symfony 使用它来指定 控制台工具 的版本。
列表命令
Python 版本的 list
命令在此处重命名为 info
。Symfony 有一个列出可用命令的列表命令。
除了这两个差异之外,它们完全相同。
更多信息可以在他们的 README 中找到或通过运行此工具而不带任何参数。每个命令的详细信息可以通过标准 help
命令或 -h
/--help
参数查看。