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 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 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
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.
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, 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.
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 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 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
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.
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, 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.
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.
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 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 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.