Secrets and ENV Values
You can store ENV values used by a container (within a workload) within Control Plane at the following levels:
- Workload Container
- GVC
For your "review apps," it is convenient to have simple ENVs stored in plain text in your source code. You will want to
keep some ENVs, like the Rails' SECRET_KEY_BASE
, out of your source code. For staging and production apps, you will
set these values directly at the GVC or workload levels, so none of these ENV values are committed to the source code.
For storing ENVs in the source code, we can use a level of indirection so that you can store an ENV value in your source
code like cpln://secret/my-app-review-env-secrets.SECRET_KEY_BASE
and then have the secret value stored at the org
level, which applies to your GVCs mapped to that org.
For setting up secrets, you'll need:
- Org-level Secret: This is where the values will be stored.
- GVC Identity: An identity that must be associated with each workload that requires access to the secret.
- Org-level Policy: A policy that binds the identity to the secret, granting the necessary permissions for the workload to access the secret.
You can do this during the initial app setup, like this:
- Add the template for
app
to.controlplane/templates
- Ensure that the
app
template is listed insetup_app_templates
for the app in.controlplane/controlplane.yml
- Run
cpflow setup-app -a $APP_NAME
- The secrets, secrets policy and identity will be automatically created, along with the proper binding
- In the Control Plane console, upper left "Manage Org" menu, click on "Secrets"
- Find the created secret (it will be in the
$APP_PREFIX-secrets
format) and add the secret env vars there - Use
cpln://secret/...
in the app to access the secret env vars (e.g.,cpln://secret/$APP_PREFIX-secrets.SOME_VAR
)
Here are the manual steps for reference. We recommend that you follow the steps above:
- In the upper left of the Control Plane console, "Manage Org" menu, click on "Secrets"
- Create a secret with
Secret Type: Dictionary
(e.g.,my-secrets
) and add the secret env vars there - In the upper left "Manage GVC" menu, click on "Identities"
- Create an identity (e.g.,
my-identity
) - Navigate to the workload that you want to associate with the identity created
- Click "Identity" on the left menu and select the identity created
- In the lower left "Access Control" menu, click on "Policies"
- Create a policy with
Target Kind: Secret
and add a binding with thereveal
permission for the identity created - Use
cpln://secret/...
in the app to access the secret env vars (e.g.,cpln://secret/my-secrets.SOME_VAR
)