Get started with Secrets
Store a secret, let deployed apps read it, read it back yourself, and delete it again, in about ten minutes.
Replace STRIPE_API_KEY with a name of your own, 5b8c1d2e-3f4a-4b6c-8d7e-9f0a1b2c3d4e with the id the create returns, and 1a2b3c4d-5e6f-4a7b-8c9d-0e1f2a3b4c5d with the id of one of your KMS keys.
Prerequisites
- Permission for
secrets:CreateSecret,secrets:GrantSecret,secrets:GetSecretValueandsecrets:DeleteSecret. In the console, alsosecrets:ListSecretsto open Secrets; without it the page says "You do not have permission to list secrets." The panel's Last read needssecrets:GetSecretAccessLog; without it the section says "The access log needs secrets:GetSecretAccessLog." - An enabled KMS key. A new organization has one, named
default. For the CLI and the API, find its id withdcloud kms keys list(kms:ListKeys).
Step 1: Create a secret
- Open Secrets, then choose Create secret.
- For Name, enter STRIPE_API_KEY.
- For Value, paste the value.
- Leave Environment at Default, so every environment gets this value.
- Choose Create secret.
The secret appears in the list, version v1. The console encrypts it under your default key unless
you choose another under Key and rotation.
dcloud secrets secrets create --name STRIPE_API_KEY \
--key-id 1a2b3c4d-5e6f-4a7b-8c9d-0e1f2a3b4c5d --value 'sk_test_EXAMPLE'POST /secrets/api/secrets
{ "name": "STRIPE_API_KEY", "keyId": "1a2b3c4d-5e6f-4a7b-8c9d-0e1f2a3b4c5d", "value": "sk_test_EXAMPLE" }The answer carries the secret's id, never its value.
Step 2: Let deployed apps read it
A deployment reads a secret only while the deploy consumer holds a grant on it, and a workflow
only with an actions grant. Binding the secret to an app's variable grants deploy by itself;
this step grants it ahead of time, the way you would for any consumer.
- In the list, choose the secret. Its panel opens.
- Under Consumers, on the
deployrow, choose Grant.
dcloud secrets secrets grant 5b8c1d2e-3f4a-4b6c-8d7e-9f0a1b2c3d4e --consumer deployPOST /secrets/api/secrets/5b8c1d2e-3f4a-4b6c-8d7e-9f0a1b2c3d4e/grants
{ "consumer": "deploy" }An app that binds the secret on its Environment page now gets it at each rollout; see Set environment variables.
Step 3: Read the value back
- In the secret's panel, under Value, choose Reveal value.
- The value arrives masked. Show it or copy it with the buttons beside it.
Closing the panel forgets the value.
dcloud secrets secrets get-value 5b8c1d2e-3f4a-4b6c-8d7e-9f0a1b2c3d4eGET /secrets/api/secrets/5b8c1d2e-3f4a-4b6c-8d7e-9f0a1b2c3d4e/valueThe read is written to the secret's access log with the version you got. The panel's Last read shows it.
Clean up
- In the secret's panel, under Danger zone, choose Delete secret.
- Enter the secret's name, then choose Delete secret.
dcloud secrets secrets delete 5b8c1d2e-3f4a-4b6c-8d7e-9f0a1b2c3d4eDELETE /secrets/api/secrets/5b8c1d2e-3f4a-4b6c-8d7e-9f0a1b2c3d4eThe secret, its versions, its grants and its access log are deleted.