Skip to main content

Secrets Management

Add secrets to a vault​

This section describes how you can create, update and delete vaults and vault secrets.

A vault can contain multiple secret collections. Each secret collection contains multiple key/value maps.

The vault controls to which sites its constituent secret collections are distributed to.

Create a new vault​

Create a vault named operations and distribute the vault to all sites the tenant has access to.

supctl create strongbox vaults <<EOF
name: operations
distribute:
to: all
EOF

Please see here for more distribution options.

Create a key value map in a vault​

Store username and password in a key/value map named credentials in the operations vault and give access to any image.

supctl create strongbox vaults operations secrets<<EOF
name: credentials
allow-application-access:
- "*"
data:
username: the-user
password: the-password
EOF

Data that contains newlines or non-string characters, i.e. binary data can instead be stored as base64 encoded data in the base64-data parameter.

supctl create strongbox vaults operations secrets<<EOF
name: credentials-b64
allow-application-access:
- "*"
base64-data:
username: dGhlLXVzZXItMg==
password: dGhlIHBhc3N3b3Jk
EOF

And there may even be a mix of plain-text and base64 data.

supctl create strongbox vaults operations secrets<<EOF
name: credentials-mixed
allow-application-access:
- "*"
data:
username: the-user
password: the-password
base64-data:
username: dGhlLXVzZXItMg==
password: dGhlIHBhc3N3b3Jk
EOF

If a base64 encoded value is mounted as a file from an app then the decoded value will appear as content in the file. If the same key appears in both data and base64-data then the base64-data will prevail, in the case above the base64 version of username and password will be used.

Update secrets in a vault​

Update the password in the credentials key/value map.

supctl merge strongbox vaults operations secrets credentials<<EOF
data:
password: the-new-password
EOF

Delete a secret from a vault​

supctl delete strongbox vaults operations secrets credentials

This will delete the entire secret. It is also possible to delete a specific secret version using a query parameter, ie

supctl -q version=2 delete strongbox vaults operations secrets credentials

This will delete version 2 of the secret. This operation can be undone suing the undelete action.

Undelete a secret version from a vault​

supctl do strongbox vaults operations secrets credentials undelete

This will restore the latest version of the secret to the vault. A specific version can be un-deleted using a version argument, ie

supctl -q version=2 do strongbox vaults operations secrets credentials undelete

Remove a secret from a vault​

supctl do strongbox vaults operations secrets credentials destroy

A secret can be completely removed using the destroy action. If all versions of a secret has been destroyed then the entire secret is removed.

Delete a vault​

supctl delete strongbox vaults operations

Control distribution of secrets​

Distribute a vault to all sites​

To distribute a vault to to all sites a tenant has access to

supctl create strongbox vaults <<EOF
name: global-vault
distribute:
to: all
EOF

Distribute a vault to select sites​

supctl create strongbox vaults <<EOF
name: credentials-stockholm-sergel
distribute:
sites:
- stockholm-sergel
- helsingborg-bergakungen
EOF

Distribute a vault to the same sites as an application is deployed​

supctl create config strongbox vault <<EOF
name: popcorn-credentials
distribute:
deployments:
- popcorn-deployment
EOF

popcorn-deployemnt is the name of the application deployment (not the name of the application).

Application configuration​

tip

Use the ${SYS_SITE} variable, this variable will expand to the site name when deployed.

name: site-secrets
services:
- name: site-service
containers:
- name: alpine
image: docker/alpine
cmd: ["sleep", "infinity"]
mounts:
- volume-name: credentials
mount-path: /credentials
volumes:
- name: credentials
vault-secret-ref:
vault: credentials-${SYS_SITE}
secret: credentials

mode: replicated
replicas: 1

This will expand credentials-${SYS_SITE} to e.g. credentials-stockholm-sergel in the Stockholm site.

Don't distribute secrets​

Some secrets does not need to be distributed to any sites, e.g. registry credentials, to store secrets in the Control Tower only

supctl create strongbox vaults <<EOF
name: my-vault
distribute:
to: none
EOF

Control which container can access a key/value map​

To allow a container in an application to auto-mount a vault secret as a virtual file, or as en environment variable, it must be listed in the allow-application-access parameter. It is possible to use * to allow all applications to mount the secret, but this is strongly discouraged for production use. Each application, service, and container should instead be explicitly listed.

Allow auto-mounting of secret from the alpine container in the srv service in the app application.

name: credentials
allow-application-access:
- "app.srv.alpine"
data:
username: the-user
password: the-password

Allow another tenant access​

It is also possible to share a secret with another tenant. This is useful when, for example, auto generating mTLS certifictates for a share MQTT service. An image started by another tenant may access a secret, provided that the allow-application-access setting allows it and allow-tenant-access is configured to permit the tenant to access the secret. See [Tenant Secret Sharing]https://docs.avassa.io/how-to/tenant-secret-sharing

Add secrets to a versioned vault​

By default only a single version of a secret is stored in a vault. This can be changed by setting the max-versions parameter when creating a vault, or changed for an existing vault using the merge (PATCH) operation.

Allowing multiple version makes it possible to rollback a change for example, using the delete operation.

Create a new versioned vault​

Create a versioned vault named popcorn-systems and distribute the vault to all sites the tenant has access to. The vault will hold at most 10 old version of each map it stores. Check-and-set (CAS) is configured to allow cooperative locking, ie, to prevent unintentional overwrite.

supctl create strongbox vaults <<EOF
name: popcorn-systems
max-versions: 10
cas-required: true
distribute:
to: all
EOF

Create a key value map in a versioned vault​

Store username and password in a key/value map named db-user in the popcorn-systems versioned vault. Since CAS is required version is set to 0 to indicate that the value should be created.

supctl -q version=0 create strongbox vaults popcorn-systems secrets<<EOF
name: db-user
data:
username: the-db-user
password: the-db-password
EOF

Add a new version of the key value map​

To update an existing value the current version must be supplied since the cas-required options was set for the vault.

supctl -q version=1 merge strongbox vaults popcorn-systems secrets db-user<<EOF
data:
password: the-new-db-password
EOF

Access the current version​

Read the current version

supctl show strongbox vaults popcorn-systems secrets db-user
name: db-user
data:
password: the-new-db-password
username: the-db-user
dict:
password: the-new-db-password
username: the-db-user
creation-time: 2021-08-23T12:35:05.429330Z
version: 2
metadata:
current-version: 2
modified-time: 2021-08-23T12:35:05.429331Z
creation-time: 2021-08-23T12:33:26.480139Z
oldest-version: 1

Access an old version​

Show the first version of the db-user map.

supctl -q version=1 show strongbox vaults popcorn-systems secrets db-user
name: db-user
data:
password: the-db-password
username: the-db-user
dict:
password: the-db-password
username: the-db-user
creation-time: 2021-08-23T12:33:26.480139Z
version: 1
metadata:
current-version: 2
modified-time: 2021-08-23T12:35:05.429331Z
creation-time: 2021-08-23T12:33:26.480139Z
oldest-version: 1

Delete an old version​

It is possible to delete certain versions of a key value map, as well as the entire map. Deleting a version makes it temporarily unavailable.

Delete version 1 of the map.

supctl -q version=1 delete strongbox vaults popcorn-systems secrets db-user

or

supctl do strongbox vaults popcorn-systems secrets db-user delete --versions 1

Delete the latest version (version 3) of the key value map.

supctl do strongbox vaults popcorn-systems secrets db-user delete

Un-delete a key value map from a versioned vault​

To un-delete the previously deleted versions 1 and 2 of the db-user map.

supctl do strongbox vaults popcorn-systems secrets db-user undelete --versions 1 2

Destroy a key value map in a versioned vault​

Permanently remove a version of the key value map.

supctl do strongbox vaults popcorn-systems secrets db-user destroy --versions 1

Permanently remove the entire key value map.

supctl do strongbox vaults popcorn-systems secrets db-user destroy

Delete a versioned vault​

Remove the entire versioned vault.

supctl delete strongbox vaults popcorn-systems