Secret version management
With secret version management, you can:
- Create a new user secret version.
- Create a new generated secret version.
- Get information about a version.
- Create a version based on an existing version.
- Roll back to a particular version.
- Schedule a version for deletion.
Creating a new user secret version
-
In the management console
, select the folder the secret belongs to. -
In the list of services, select Lockbox.
-
Click the name of the secret you need.
-
Under Versions, click Add version.
-
Add the following parameters:
- (Optional) Description: Version description.
- Key: Non-secret name you will use to identify a value.
- Value: Explicitly represented secret data.
You can create multiple key-value pairs per version.
-
Click Add version.
Terraform
For more information about the provider resources, see the documentation on the Terraform
If you change the configuration files, Terraform automatically detects which part of your configuration is already deployed, and what should be added or removed.
If you don't have Terraform, install it and configure the Yandex Cloud provider.
-
In the configuration file, describe the parameters of the resources you want to create:
resource "yandex_lockbox_secret_version_hashed" "my_version" { secret_id = "<secret_ID>" key_1 = "<secret_1_key>" text_value_1 = "<secret_1_value>" key_2 = "<secret_2_key>" text_value_2 = "<secret_2_value>" }
Where:
secret_id
: ID of the secret you are creating a version for.- (Optional)
description
: Any comment on the secret version. key_N
: Secret key. Non-secret name you will use to identify a value.text_value_N
: Explicitly represented secret data.
The
key_N/text_value_N
pairs are numbered sequentially from 1 to 10 (10 pairs are supported). If only one pair is required, usekey_1/text_value_1
.Note
We recommend using
yandex_lockbox_secret_version_hashed
: it stores values in Terraform state in hashed format. We continue supportingyandex_lockbox_secret_version
.For more information about
yandex_lockbox_secret_version_hashed
, see the relevant provider documentation . -
Create resources:
-
In the terminal, change to the folder where you edited the configuration file.
-
Make sure the configuration file is correct using the command:
terraform validate
If the configuration is correct, the following message is returned:
Success! The configuration is valid.
-
Run the command:
terraform plan
The terminal will display a list of resources with parameters. No changes are made at this step. If the configuration contains errors, Terraform will point them out.
-
Apply the configuration changes:
terraform apply
-
Confirm the changes: type
yes
in the terminal and press Enter.
-
This creates a new version of the specified secret. You can check the new version and its settings using the management console
yc lockbox secret list-versions <secret_ID>
To create a new secret version, use the addVersion REST API method for the Secret resource or the SecretService/AddVersion gRPC API call.
Creating a new generated secret version
- In the management console
, select the folder the secret belongs to. - In the list of services, select Lockbox.
- Click the name of the secret you need.
- Under Versions, click Add version.
- (Optional) Add Description of the version.
- (Optional) To change other parameters, click Edit secret and specify:
-
Secret type: You can either leave the generated type or select the user type.
-
Key and Automatic generation options, for the generated secret type.
-
Key and Value, for the user secret type.
You can create multiple key-value pairs per version.
-
- Click Add version or Save.
Getting information about a version
- In the management console
, select the folder the secret belongs to. - In the list of services, select Lockbox.
- Click the name of the secret you need.
- Under Versions, you will see a list of all secret versions with information about them.
- Click a version to see the details about its key-value pairs.
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
-
View the description of the CLI command to view secret versions:
yc lockbox secret list-version --help
-
Run this command:
yc lockbox secret list-version <secret_name>
It will return information about all versions of the secret, key names included. Secret version values will not be displayed.
To get information about a version, use the listVersions REST API method for the Secret resource or the SecretService/ListVersions gRPC API call.
Creating a version based on an existing version
- In the management console
, select the folder the secret belongs to. - In the list of services, select Lockbox.
- Click the name of the secret you need.
- Under Versions, next to the appropriate version, click
. - Select Create a new version from this one.
- Edit or add the following parameters:
- (Optional) Description: Version description.
- Key: Non-secret name you will use to identify a value.
- For a user secret, Value: Secret data in an explicit form.
You can create multiple key-value pairs per version. - For a generated secret, you can change the key and the value parameters. To do this, click Edit secret and specify new parameters.
- Click Add version.
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
-
View the description of the CLI command to create a new secret version:
yc lockbox secret add-version --help
-
Run this command:
yc lockbox secret add-version <secret_name> \ --description <secret_version_description> \ --payload "<array_with_secret_version_contents>" \ --base-version-id <existing_secret_version_ID>
Where:
<secret_name>
: Name of the secret to create a version for.--description
: Description of the new secret version (optional).--payload
: Contents of the new secret version as a YAML or JSON array.--base-version-id
: ID of the secret version used to create a new secret. If this parameter is not specified, the new version will be created based on the current version.
Result:
id: e6qor8pe3ju7******** secret_id: e6qkkp3k29jf******** created_at: "2024-04-25T13:49:26.621Z" status: ACTIVE payload_entry_keys: - secret-key1 - secret-key2
To create a version based on an existing version, use the addVersion REST API method for the Secret resource or the SecretService/AddVersion gRPC API call.
Changing the current version
- In the management console
, select the folder the secret belongs to. - In the list of services, select Lockbox.
- Click the name of the secret you need.
- Under Versions, next to the appropriate version, click
. - Select Set as current version.
- Click Set as current version.
To change the current version, use the addVersion REST API method for the Secret resource or the SecretService/AddVersion gRPC API call and specify the required version.
Scheduling a version for deletion
- In the management console
, select the folder the secret belongs to. - In the list of services, select Lockbox.
- Click the name of the secret you need.
- Under Versions, next to the appropriate version, click
. - Select Schedule destruction.
- Enter the deletion pending period.
- Click Schedule.
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
-
See the description of the CLI command to schedule version deletion:
yc lockbox secret schedule-version-destruction --help
-
Schedule a version for deletion by specifying the secret name, version ID, and the deletion pending period. For example, 1 week:
168h
:yc lockbox secret schedule-version-destruction <secret_name> \ --version-id <version_ID> \ --pending-period 168h
Result:
id: e6qor8pe3ju7******** secret_id: e6qkkp3k29jf******** created_at: "2023-11-08T13:14:34.676Z" destroy_at: "2023-11-15T17:06:28.795Z" status: SCHEDULED_FOR_DESTRUCTION payload_entry_keys: - secret-key
To schedule the removal of a version, remove the resource description for that version from the configuration file. You cannot use Terraform to set time to deletion, it will be set by default: 7 days.
To schedule a version for deletion, use the scheduleVersionDestruction REST API method for the Secret resource or the SecretService/ScheduleVersionDestruction gRPC API call.