Getting information about a secret, its contents, and access rights
You can get detailed information about a secret and secret contents and view access rights to a secret.
Getting information about a secret
- In the management console
, select the folder the secret belongs to. - In the list of services, select Lockbox.
- In the left-hand menu, select Secrets.
- Click the name of the secret you need.
If you do not have the Yandex Cloud CLI installed yet, install and initialize it.
By default, the CLI uses the folder specified when creating the profile. To change the default folder, use the yc config set folder-id <folder_ID>
command. You can also set a different folder for any specific command using the --folder-name
or --folder-id
parameter.
-
View the description of the CLI command to get information about a secret:
yc lockbox secret get --help
-
Get information about a secret by specifying its name or ID:
yc lockbox secret get <secret_name>
Result:
id: e6qi98vtdva1******** folder_id: b1go79qlt1tp******** created_at: "2023-11-03T15:28:18.909Z" name: test-secret kms_key_id: abj765aos682******** status: ACTIVE current_version: id: e6q7nvojsgmk******** secret_id: e6qi98vtdva1******** created_at: "2023-11-03T15:28:18.909Z" status: ACTIVE payload_entry_keys: - example-key
With Terraform
Terraform is distributed under the Business Source License
For more information about the provider resources, see the documentation on the Terraform
If you do not have Terraform yet, install it and configure its Yandex Cloud provider.
To get information about a secret using Terraform:
-
Add the
data
andoutput
sections to the Terraform configuration file:data "yandex_lockbox_secret" "my_secret" { secret_id = "<secret_ID>" } output "current_version" { value = data.yandex_lockbox_secret.my_secret.current_version }
Where:
data "yandex_lockbox_secret"
: Description of the secret as a data source:secret_id
: Secret ID.
output "current_version"
: Output variable that contains information about the current secret version:value
: Returned value.
You can replace
current_version
with any other parameter to get the information you need. For more information about theyandex_lockbox_secret
data source parameters, see the relevant provider documentation . -
Create resources:
-
In the terminal, go to the directory where you edited the configuration file.
-
Make sure the configuration file is correct using this command:
terraform validate
If the configuration is correct, you will get this message:
Success! The configuration is valid.
-
Run this command:
terraform plan
You will see a detailed list of resources. No changes will be made at this step. Terraform will show any errors found in your configuration.
-
Apply the changes:
terraform apply
-
Type
yes
and press Enter to confirm the changes.
Terraform will create the required resources and display the output variable values in the terminal. To check the results, run:
terraform output
Result:
current_version = tolist([ { "created_at" = "2024-03-27T02:45:05Z" "description" = "" "destroy_at" = "" "id" = "e6qo5a6imnm0********" "payload_entry_keys" = tolist([ "key", ]) "secret_id" = "e6qnva6ntl66********" "status" = "ACTIVE" }, ])
-
To get information about a secret, use the get REST API method for the Secret resource or the SecretService/Get gRPC API call.
Getting the contents of a secret
- In the management console
, select the folder the secret belongs to. - In the list of services, select Lockbox.
- In the left-hand menu, select Secrets.
- Click the name of the secret you need.
- Under Versions, click the secret version you need.
If you do not have the Yandex Cloud CLI installed yet, install and initialize it.
By default, the CLI uses the folder specified when creating the profile. To change the default folder, use the yc config set folder-id <folder_ID>
command. You can also set a different folder for any specific command using the --folder-name
or --folder-id
parameter.
-
See the description of the CLI command to get the contents of a secret:
yc lockbox payload get --help
-
Get the contents of a secret by specifying its name or ID:
yc lockbox payload get <secret_name_or_ID>
Result:
version_id: e6q7nvojsgmk******** entries: - key: example-key text_value: example-value
If a file is used as the confidential value, the returned secret content will be Base64 encoded
. To decode the file, use the Linux base64 utility:base64 --decode <path_to_file> > output.txt
With Terraform
Terraform is distributed under the Business Source License
For more information about the provider resources, see the documentation on the Terraform
If you do not have Terraform yet, install it and configure its Yandex Cloud provider.
To get the contents of the secret using Terraform:
-
Add the
data
andoutput
sections to the Terraform configuration file:data "yandex_lockbox_secret_version" "my_secret_version" { secret_id = "<secret_ID>" version_id = "<version_ID>" } output "my_secret_entries" { value = data.yandex_lockbox_secret_version.my_secret_version.entries }
Where:
data "yandex_lockbox_secret_version"
: Description of the secret as a data source:secret_id
: Secret ID.version_id
: Secret version ID. This is an optional parameter. Defaults to the current secret version.
output "my_secret_entries"
: Output variable which stores the contents of the secret:value
: Returned value.
For more information about the
yandex_lockbox_secret_version
data source parameters, see the provider documentation . -
Create resources:
-
In the terminal, go to the directory where you edited the configuration file.
-
Make sure the configuration file is correct using this command:
terraform validate
If the configuration is correct, you will get this message:
Success! The configuration is valid.
-
Run this command:
terraform plan
You will see a detailed list of resources. No changes will be made at this step. Terraform will show any errors found in your configuration.
-
Apply the changes:
terraform apply
-
Type
yes
and press Enter to confirm the changes.
Terraform will create the required resources and display the output variable values in the terminal. To check the results, run:
terraform output
Result:
my_secret_entries = [ { key = "example-key" text_value = "example-value" }, { key = "example-key" text_value = "example-value" }, ]
-
To get the secret contents, use the get REST API method for the Payload resource or the PayloadService/Get gRPC API call.
If a file is used as the confidential value, the returned secret content will be Base64 encoded
Viewing permissions to a secret
- In the management console
, select the folder the secret belongs to. - In the list of services, select Lockbox.
- In the left-hand menu, select Secrets.
- Click the name of the secret you need.
- In the left-hand panel, select
Access bindings.
If you do not have the Yandex Cloud CLI installed yet, install and initialize it.
By default, the CLI uses the folder specified when creating the profile. To change the default folder, use the yc config set folder-id <folder_ID>
command. You can also set a different folder for any specific command using the --folder-name
or --folder-id
parameter.
-
See the description of the CLI command to view access permissions to a secret:
yc lockbox secret list-access-bindings --help
-
View access permissions to a secret by specifying its name or ID:
yc lockbox secret list-access-bindings <secret_name_or_ID>
Result:
+---------+---------------+----------------------+ | ROLE ID | SUBJECT TYPE | SUBJECT ID | +---------+---------------+----------------------+ | viewer | federatedUser | ajej2i98kcjd******** | +---------+---------------+----------------------+
To view access permissions to a secret, use the ListAccessBindings REST API method for the Secret resource or the SecretService/ListAccessBindings gRPC API call.