Configuring permissions for access to a secret created by Yandex Connection Manager for a Yandex Managed Service for PostgreSQL user
You can get a Managed Service for PostgreSQL user's password from the Yandex Lockbox secret. You can do it via the Yandex Cloud CLI. Do it by permitting the service account you are using to log in to the Yandex Cloud CLI to access the user's secret. You can get the secret-related information you need to configure the permissions from the Connection Manager connection.
To configure permissions for access to a user's secret:
- Create the required infrastructure and configure permissions for access to the user's secret.
- Get the user password from the secret.
If you no longer need the resources you created, delete them.
Getting started
Sign up for Yandex Cloud and create a billing account:
- Navigate to the management console
and log in to Yandex Cloud or create a new account. - On the Yandex Cloud Billing
page, make sure you have a billing account linked and it has theACTIVEorTRIAL_ACTIVEstatus. If you do not have a billing account, create one and link a cloud to it.
If you have an active billing account, you can create or select a folder for your infrastructure on the cloud page
Learn more about clouds and folders here.
Required paid resources
- Managed Service for PostgreSQL cluster, which includes the use of computing resources allocated to hosts, storage and backup size (see Managed Service for PostgreSQL pricing).
- Public IP addresses if public access is enabled for cluster hosts (see Virtual Private Cloud pricing).
Connection Manager and the secrets created with it are free of charge.
Configure permissions for access to a Managed Service for PostgreSQL user's secret
-
If you do not have Terraform yet, install it.
-
Get the authentication credentials. You can add them to environment variables or specify them later in the provider configuration file.
-
Configure and initialize a provider. There is no need to create a provider configuration file manually, you can download it
.Warning
Requires Yandex provider version
0.160.0or higher. If the provider version is not explicitly specified in the configuration, Terraform will automatically download the latest compatible version. -
Place the configuration file in a separate working directory and specify the parameter values. If you did not add the authentication credentials to environment variables, specify them in the configuration file.
-
Download the conn-man-secret-access.tf
configuration file to the same working directory.This file describes:
- Managed Service for PostgreSQL cluster.
- Setting up service account permissions to access the Managed Service for PostgreSQL user's secret.
- Getting connection ID and secret ID.
-
Specify the following in the configuration file:
network_id: Network ID for the cluster.subnet_id: Subnet ID in theru-central1-aavailability zone for the cluster.pg_cluster_version: PostgreSQL version.pg_cluster_name: Cluster name.pg_cluster_db: Cluster database name.pg_cluster_username: Cluster username.pg_cluster_password: User password.lockbox_sa_id: ID of the service account for which access to the secret will be configured.
-
Validate your Terraform configuration files using this command:
terraform validateTerraform will display any configuration errors detected in your files.
-
Create the required infrastructure:
-
Run this command to view the planned changes:
terraform planIf you described the configuration correctly, the terminal will display a list of the resources to update and their parameters. This is a verification step that does not apply changes to your resources.
-
If everything looks correct, apply the changes:
-
Run this command:
terraform apply -
Confirm updating the resources.
-
Wait for the operation to complete.
-
All the required resources will be created in the specified folder. You can check resource availability and their settings in the management console
. -
-
After you apply the configuration, Terraform will output the connection and secret IDs.
Here is an example of the command output:
Outputs: connection_id = "a59v09bb8907********" connection_info = "e6q2rjghh9bc********"Save the
connection_infosecret ID for later to get the user password.
Get the user password from the Yandex Lockbox secret
-
Authenticate to the Yandex Cloud CLI as a service account using an authorized key.
-
Get the user password from the secret and save it to the
PASSWORDvariable:CLIPASSWORD=$(yc lockbox payload get <secret_ID> \ --format json \ | jq -r '.entries[] | select(.key=="postgresql_password") | .text_value') -
To view the saved password, run this command:
echo "$PASSWORD"
Delete the resources you created
Some resources are not free of charge. Delete the resources you no longer need to avoid paying for them:
-
In the terminal window, go to the directory containing the infrastructure plan.
Warning
Make sure the directory has no Terraform manifests with the resources you want to keep. Terraform deletes all resources that were created using the manifests in the current directory.
-
Delete resources:
-
Run this command:
terraform destroy -
Confirm deleting the resources and wait for the operation to complete.
All the resources described in the Terraform manifests will be deleted.
-