gmo/credstash

一个用于使用AWS KMS和DynamoDB在云中管理秘密的实用程序

v1.0.0 2016-04-18 16:05 UTC

This package is not auto-updated.

Last update: 2024-09-12 00:56:06 UTC


README

这是原始CredStash(用Python编写)的PHP版本。加密和DynamoDB存储与Python版本兼容,因此两者可以并行工作。此外,还有一个可选的CLI工具,详情如下。

有关CredStash是什么、如何工作以及如何设置的更多信息,请参阅他们的README或运行此工具而不带任何参数。

安装

$ composer require gmo/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 

由于与Symfony的Console应用程序的标准命令/参数的兼容性,CLI工具与Python版本兼容,有一些差异。

版本参数

Python版本使用-v--version来指定要putget的版本。这里使用的是-c--cred-version,因为Symfony使用它来指定控制台工具的版本。

列表命令

Python版本的list命令在这里被重命名为info。Symfony有一个列表命令,用于列出可用的命令。

除了这两个差异之外,它们完全相同。

更多信息可以在他们的README中找到,或者通过在不带任何参数的情况下运行此工具。可以使用标准的help命令或-h/--help参数查看每个命令的详细信息。