Skip to content

Set version limit for Secrets Manager

The Secrets Manager allows you to securely store and manage different versions of your sensitive data (Secrets). This is particularly useful for tracking changes and reverting to older states if needed. You can define the number of versions to retain at two levels:

  • Instance Level: Here, you set a global limit for all secrets within your current Secrets Manager instance.
  • Secret Level: Here, you can set specific limits for individual secrets that differ from the instance-wide setting. The default version limit on instances is unlimited (Value = 0). The default version limit on secrets is set to inherit the instances limit. It can be overwritten. The secrets limit always overrules the instances limit (unless 0/inherit is set).

To set environment variables, you need to log in with an secrets manager user. The following environment variables can be set:

Terminal window
export VAULT\_TOKEN=$(vault token lookup --format=json | jq -r.data.id) export VAULT\_ADDR="https://prod.sm.eu01.stackit.cloud" export INSTANCE\_ID='The ID of your secrets manager instance' export SECRET='The path of the secret you want to change'

This setting will apply by default to all created secrets in your instance.

Terminal window
curl --header "X-Vault-Token: $VAULT\_TOKEN" \\ --header "Content-Type: application/json" \\ --request POST \\ --data '{"max\_versions":100}' \\ $VAULT\_ADDR/v1/$INSTANCE\_ID/config
Terminal window
curl --header "X-Vault-Token: $VAULT\_TOKEN" \\ --request GET \\ $VAULT\_ADDR/v1/$INSTANCE\_ID/config

This setting allows you to define different version limits for specific, individual secrets. This is useful when certain secrets require a longer or shorter history than others.

Setting the version limit can be done either via a PATCH or PUT/POST request.
The PUT/POST overwrites other configurations and custom metadata on the secret level. A PATCH request would just update the version limit, keeping the other configurations.

Terminal window
curl --header "X-Vault-Token: $VAULT\_TOKEN" \\ --header "Content-Type: application/json" \\ --request POST \\ --data '{"max\_versions": 50}' \\ $VAULT\_ADDR/v1/$INSTANCE\_ID/metadata/$SECRET
Terminal window
curl --header "X-Vault-Token: $VAULT\_TOKEN" \\ --header "Content-Type: application/merge-patch+json" \\ --request PATCH \\ --data '{"max\_versions": 50}' \\ $VAULT\_ADDR/v1/$INSTANCE\_ID/metadata/$SECRET
Terminal window
curl --header "X-Vault-Token: $VAULT\_TOKEN" \\ --request GET \\ $VAULT\_ADDR/v1/$INSTANCE\_ID/metadata/$SECRET