You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+54-25
Original file line number
Diff line number
Diff line change
@@ -21,6 +21,8 @@ Whenever you want to store/share a credential, such as a database password, you
21
21
22
22
When you want to fetch the credential, for example as part of the bootstrap process on your web-server, you simply do `credstash get [credential-name]`. For example, `export DB_PASSWORD=$(credstash get myapp.db.prod)`. When you run `get`, credstash will go and fetch the encrypted credential and the wrapped encryption key from the credential store (DynamoDB). It will then send the wrapped encryption key to KMS, where it is decrypted with the master key. credstash then uses the decrypted data encryption key to decrypt the credential. The credential is printed to `stdout`, so you can use it in scripts or assign environment variables to it.
23
23
24
+
Optionally you can include any number of [Encryption Context](http://docs.aws.amazon.com/kms/latest/developerguide/encrypt-context.html) key value pairs to associate with the credential. The exact set of encryption context key value pairs that were associated with the credential when it was `put` in DynamoDB must be provided in the `get` request to successfully decrypt the credential. These encryption context key value pairs are useful to provide auditing context to the encryption and decryption operations in your CloudTrail logs. They are also useful for constraining access to a given credstash stored credential by using KMS Key Policy conditions and KMS Grant conditions. Doing so allows you to, for example, make sure that your database servers and web-servers can read the web-server DB user password but your database servers can not read your web-servers TLS/SSL certificate's private key. A `put` request with encryption context would look like `credstash put myapp.db.prod supersecretpassword1234 app.tier=db environment=prod`. In order for your web-servers to read that same credential they would execute a `get` call like `export DB_PASSWORD=$(credstash get myapp.db.prod environment=prod app.tier=db)`
25
+
24
26
Credentials stored in the credential-store are versioned and immutable. That is, if you `put` a credential called `foo` with a version of `1` and a value of `bar`, then foo version 1 will always have a value of bar, and there is no way in `credstash` to change its value (although you could go fiddle with the bits in DDB, but you shouldn't do that). Credential rotation is handed through versions. Suppose you do `credstash put foo bar`, and then decide later to rotate `foo`, you can put version 2 of `foo` by doing `credstash put foo baz -v `. The next time you do `credstash get foo`, it will return `baz`. You can get specific credential versions as well (with the same `-v` flag). You can fetch a list of all credentials in the credential-store and their versions with the `list` command.
25
27
26
28
## Dependencies
@@ -64,43 +66,70 @@ Once credentials are in place, run `credstash setup`. This will create the DDB t
parser.add_argument("action", type=str, choices=["delete", "get", "list", "put", "setup"], help="Put, Get, or Delete a credential from the store, list credentials and their versions, or setup the credential store")
159
-
parser.add_argument("credential", type=str, help="the name of the credential to store/get", nargs='?')
160
-
parser.add_argument("value", type=str, help="the value of the credential to put (ignored if action is 'get')", nargs='?', default="")
182
+
parsers['super'].add_argument("-r", "--region", help="the AWS region in which to operate. If a region is not specified, credstash will use the value of the AWS_DEFAULT_REGION env variable, or if that is not set, us-east-1")
183
+
parsers['super'].add_argument("-t", "--table", default="credential-store", help="DynamoDB table to use for credential storage")
184
+
subparsers=parsers['super'].add_subparsers(help='Try commands like "{name} get -h" or "{name} put --help" to get each sub command\'s options'.format(name=os.path.basename(__file__)))
185
+
186
+
action='delete'
187
+
parsers[action] =subparsers.add_parser(action, help='Delete a credential from the store')
188
+
parsers[action].add_argument("credential", type=str, help="the name of the credential to delete")
189
+
parsers[action].set_defaults(action=action)
190
+
191
+
action='get'
192
+
parsers[action] =subparsers.add_parser(action, help='Get a credential from the store')
193
+
parsers[action].add_argument("credential", type=str, help="the name of the credential to get")
194
+
parsers[action].add_argument("context", type=is_key_value_pair, action=KeyValueToDictionary, nargs='*', help="encryption context key/value pairs associated with the credential in the form of \"key=value\"")
195
+
parsers[action].add_argument("-k", "--key", default="alias/credstash", help="the KMS key-id of the master key to use. See the README for more information. Defaults to alias/credstash")
196
+
parsers[action].add_argument("-n", "--noline", action="store_true", help="Don't append newline to returned value (useful in scripts or with binary files)")
197
+
parsers[action].add_argument("-v", "--version", default="", help="Get a specific version of the credential (defaults to the latest version).")
198
+
parsers[action].set_defaults(action=action)
199
+
200
+
action='list'
201
+
parsers[action] =subparsers.add_parser(action, help='list credentials and their versions')
202
+
parsers[action].set_defaults(action=action)
161
203
162
-
parser.add_argument("-i", "--infile", default="", help="store the contents of `infile` rather than provide a value on the command line")
163
-
parser.add_argument("-k", "--key", default="alias/credstash", help="the KMS key-id of the master key to use. See the README for more information. Defaults to alias/credstash")
164
-
parser.add_argument("-n", "--noline", action="store_true", help="Don't append newline to returned value (useful in scripts or with binary files)")
165
-
parser.add_argument("-r", "--region", help="the AWS region in which to operate. If a region is not specified, credstash will use the value of the AWS_DEFAULT_REGION env variable, or if that is not set, us-east-1")
166
-
parser.add_argument("-t", "--table", default="credential-store", help="DynamoDB table to use for credential storage")
167
-
parser.add_argument("-v", "--version", default="", help="If doing a `put`, put a specific version of the credential (update the credential; defaults to version `1`). If doing a `get`, get a specific version of the credential (defaults to the latest version).")
204
+
action='put'
205
+
parsers[action] =subparsers.add_parser(action, help='Put a credential into the store')
206
+
parsers[action].add_argument("credential", type=str, help="the name of the credential to store")
207
+
parsers[action].add_argument("value", type=str, help="the value of the credential to store", default="")
208
+
parsers[action].add_argument("context", type=is_key_value_pair, action=KeyValueToDictionary, nargs='*', help="encryption context key/value pairs associated with the credential in the form of \"key=value\"")
209
+
parsers[action].add_argument("-i", "--infile", default="", help="store the contents of `infile` rather than provide a value on the command line")
210
+
parsers[action].add_argument("-k", "--key", default="alias/credstash", help="the KMS key-id of the master key to use. See the README for more information. Defaults to alias/credstash")
211
+
parsers[action].add_argument("-v", "--version", default="", help="Put a specific version of the credential (update the credential; defaults to version `1`).")
212
+
parsers[action].set_defaults(action=action)
168
213
214
+
action='setup'
215
+
parsers[action] =subparsers.add_parser(action, help='setup the credential store')
0 commit comments