Managing access to a Managed Service for PostgreSQL cluster
You can assign a user or service account a role that grants access to a specific cluster.
Thus, you can granularly assign different roles for particular clusters to different users and service accounts.
Getting a list of roles assigned for a cluster
If you do not have the Yandex Cloud CLI yet, install and initialize it.
The folder used by default is the one specified when creating the CLI profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also specify a different folder for any command using --folder-name or --folder-id.
If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.
-
To get a list of clusters in the default folder, run this command:
yc managed-postgresql cluster list -
To get a list of roles assigned for the cluster, run this command:
yc managed-postgresql cluster list-access-bindings <cluster_name_or_ID>
-
Get an IAM token for API authentication and put it into an environment variable:
export IAM_TOKEN="<IAM_token>" -
Call the Cluster.ListAccessBindings method, e.g., via the following cURL
request:curl \ --request GET \ --header "Authorization: Bearer $IAM_TOKEN" \ --header "Content-Type: application/json" \ --url 'https://mdb.api.cloud.yandex.net/managed-postgresql/v1/clusters/<cluster_ID>:listAccessBindings' -
View the server response to make sure your request was successful.
-
Get an IAM token for API authentication and put it into an environment variable:
export IAM_TOKEN="<IAM_token>" -
Clone the cloudapi
repository:cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapiBelow, we assume that the repository contents reside in the
~/cloudapi/directory. -
Call the ClusterService.ListAccessBindings method, e.g., via the following gRPCurl
request:grpcurl \ -format json \ -import-path ~/cloudapi/ \ -import-path ~/cloudapi/third_party/googleapis/ \ -proto ~/cloudapi/yandex/cloud/mdb/postgresql/v1/cluster_service.proto \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d '{ "resource_id": "<cluster_ID>" }' \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.postgresql.v1.ClusterService.ListAccessBindings -
Check the server response to make sure your request was successful.
Assigning a role
If you do not have the Yandex Cloud CLI yet, install and initialize it.
The folder used by default is the one specified when creating the CLI profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also specify a different folder for any command using --folder-name or --folder-id.
If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.
-
View the description of the CLI command for assigning a role for a cluster:
yc managed-postgresql cluster add-access-binding --help -
Use this command to assign a role:
yc managed-postgresql cluster add-access-binding <cluster_name_or_ID> \ --role <role> \ --subject <subject_type>:<subject_ID>Where:
-
--role: Role, e.g.,managed-postgresql.editor. -
--subject: Subject getting the role.Here is an example:
serviceAccount:aje6p030************userAccount:aje8tj79************system:allAuthenticatedUsers
Subject designations
To indicate a subject, use the
--subjectparameter in<subject_type>:<ID>format. For some subject types, the Yandex Cloud CLI provides separate parameters instead of--subject, where you only need to specify the subject name or ID without the type. Possible subject designations and matching CLI parameters:Subject type
Subject designation
Yandex Cloud CLI parameter
userAccountuserAccount:<user_ID>--user-account-idor--user-yandex-loginserviceAccountserviceAccount:<service_account_ID>--service-account-idor--service-account-namefederatedUserfederatedUser:<user_ID>--user-account-idgroupgroup:<group_ID>--group-memberssystemsystem:allAuthenticatedUsers(
All authenticated usersgroup)--all-authenticated-userssystem:allUsers(
All usersgroup)—
system:group:organization:<organization_ID>:users(
All users in organization Xgroup)--organization-userssystem:group:federation:<federation_ID>:users(
All users in federation Ngroup)--federation-userssystem:group:userpool:<pool_ID>:users(
All users in userpool Pgroup)—
-
-
To view a list of roles assigned for the cluster, run this command:
yc managed-postgresql cluster list-access-bindings <cluster_name_or_ID>
Note
To assign roles for a Managed Service for PostgreSQL cluster, use the yandex_mdb_postgresql_cluster_iam_binding resource with the members parameter.
-
Open the current configuration file with the Managed Service for PostgreSQL cluster description.
To learn how to create this file, see Creating a PostgreSQL cluster.
-
Add a resource description:
resource "yandex_mdb_postgresql_cluster_iam_binding" "<local_resource_name>" { cluster_id = "<cluster_ID>" role = "<role>" members = ["<subject_type>:<subject_ID>"] }Where:
-
cluster_id: Cluster ID. -
role: Role, e.g.,managed-postgresql.editor. -
members: Array of designations of subjects getting the role.Here is an example:
serviceAccount:${yandex_iam_service_account.mpg_sa.id}userAccount:ajerq94v************system:allAuthenticatedUsers
Subject designations
To indicate a subject, use a combination of its type and unique ID, i.e.,
<subject_type>:<ID>. Here is how you can designate a subject:Subject type
Subject designation
userAccountuserAccount:<user_ID>serviceAccountserviceAccount:<service_account_ID>federatedUserfederatedUser:<user_ID>groupgroup:<group_ID>systemsystem:allAuthenticatedUsers(
All authenticated usersgroup)system:allUsers(
All usersgroup)system:group:organization:<organization_ID>:users(
All users in organization Xgroup)system:group:federation:<federation_ID>:users(
All users in federation Ngroup)system:group:userpool:<pool_ID>:users(
All users in userpool Pgroup)
-
-
Make sure the configuration files are correct.
-
In the command line, navigate to the directory that contains the current Terraform configuration files defining the infrastructure.
-
Run this command:
terraform validateTerraform will show any errors found in your configuration files.
-
-
Confirm resource changes.
-
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.
-
For more information, see this Terraform provider guide.
-
-
To view a list of roles assigned for the cluster, run this CLI command:
yc managed-postgresql cluster list-access-bindings <cluster_name_or_ID>
-
Get an IAM token for API authentication and put it into an environment variable:
export IAM_TOKEN="<IAM_token>" -
Call the Cluster.UpdateAccessBindings method, e.g., via the following cURL
request:curl \ --request PATCH \ --header "Authorization: Bearer $IAM_TOKEN" \ --header "Content-Type: application/json" \ --url 'https://mdb.api.cloud.yandex.net/managed-postgresql/v1/clusters/<cluster_ID>:updateAccessBindings' \ --data '{ "access_binding_deltas": [ { "action": "ADD", "access_binding": { "role_id": "<role>", "subject": { "id": "<subject_ID>", "type": "<subject_type>" } } } ] }'Where:
-
access_binding_deltas.roleId: Role, e.g.,managed-postgresql.editor. -
access_binding_deltas.subject.id: ID of the subject the role is assigned to. -
access_binding_deltas.subject.type: Type of subject the role is assigned to.Subject designations
To indicate a subject, use a combination of its type and unique ID in the
subject.typeandsubject.idfields of the request. Here are possible combinations:subject.type
subject.id
userAccount<user_ID>serviceAccount<service_account_ID>federatedUser<user_ID>group<group_ID>systemallAuthenticatedUsers(
All authenticated usersgroup)allUsers(
All usersgroup)group:organization:<organization_ID>:users(
All users in organization Xgroup)group:federation:<federation_ID>:users(
All users in federation Ngroup)group:userpool:<pool_ID>:users(
All users in userpool Pgroup)
-
-
Check the server response to make sure your request was successful.
-
Get an IAM token for API authentication and put it into an environment variable:
export IAM_TOKEN="<IAM_token>" -
Clone the cloudapi
repository:cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapiBelow, we assume that the repository contents reside in the
~/cloudapi/directory. -
Call the ClusterService.UpdateAccessBindings method, e.g., via the following gRPCurl
request:grpcurl \ -format json \ -import-path ~/cloudapi/ \ -import-path ~/cloudapi/third_party/googleapis/ \ -proto ~/cloudapi/yandex/cloud/mdb/postgresql/v1/cluster_service.proto \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d '{ "resource_id": "<cluster_ID>", "access_binding_deltas": [ { "action": "ADD", "access_binding": { "role_id": "<role>", "subject": { "id": "<subject_ID>", "type": "<subject_type>" } } } ] }' \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.postgresql.v1.ClusterService.UpdateAccessBindingsWhere:
-
resource_id: Cluster ID. -
access_binding_deltas.roleId: Role, e.g.,managed-postgresql.editor. -
access_binding_deltas.subject.id: ID of the subject the role is assigned to. -
access_binding_deltas.subject.type: Type of subject the role is assigned to.Subject designations
To indicate a subject, use a combination of its type and unique ID in the
subject.typeandsubject.idfields of the request. Here are possible combinations:subject.type
subject.id
userAccount<user_ID>serviceAccount<service_account_ID>federatedUser<user_ID>group<group_ID>systemallAuthenticatedUsers(
All authenticated usersgroup)allUsers(
All usersgroup)group:organization:<organization_ID>:users(
All users in organization Xgroup)group:federation:<federation_ID>:users(
All users in federation Ngroup)group:userpool:<pool_ID>:users(
All users in userpool Pgroup)
-
-
Check the server response to make sure your request was successful.
Assigning multiple roles
If you do not have the Yandex Cloud CLI yet, install and initialize it.
The folder used by default is the one specified when creating the CLI profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also specify a different folder for any command using --folder-name or --folder-id.
If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.
Alert
The set-access-bindings command deletes all roles assigned for the cluster and assigns new ones.
-
To view a list of roles assigned for the cluster, run this command:
yc managed-postgresql cluster list-access-bindings <cluster_name_or_ID> -
View the description of the CLI command for assigning roles for a cluster:
yc managed-postgresql cluster set-access-bindings --help -
To assign roles, run this command:
yc managed-postgresql cluster set-access-bindings <cluster_name_or_ID> \ --access-binding role=<role>,subject=<subject_type>:<subject_1_ID> \ --access-binding role=<role>,subject=<subject_type>:<subject_2_ID>Where
--access-bindingassigns a role to a subject. You can assign multiple roles at once by describing each of them in a separate--access-bindingparameter.-
role: Role, e.g.,managed-postgresql.editor. -
subject: Subject getting the role.Here is an example:
serviceAccount:aje6p030************userAccount:aje8tj79************system:allAuthenticatedUsers
Subject designations
To indicate a subject, use the
--subjectparameter in<subject_type>:<ID>format. For some subject types, the Yandex Cloud CLI provides separate parameters instead of--subject, where you only need to specify the subject name or ID without the type. Possible subject designations and matching CLI parameters:Subject type
Subject designation
Yandex Cloud CLI parameter
userAccountuserAccount:<user_ID>--user-account-idor--user-yandex-loginserviceAccountserviceAccount:<service_account_ID>--service-account-idor--service-account-namefederatedUserfederatedUser:<user_ID>--user-account-idgroupgroup:<group_ID>--group-memberssystemsystem:allAuthenticatedUsers(
All authenticated usersgroup)--all-authenticated-userssystem:allUsers(
All usersgroup)—
system:group:organization:<organization_ID>:users(
All users in organization Xgroup)--organization-userssystem:group:federation:<federation_ID>:users(
All users in federation Ngroup)--federation-userssystem:group:userpool:<pool_ID>:users(
All users in userpool Pgroup)—
-
Note
To assign roles for a Managed Service for PostgreSQL cluster, use the yandex_mdb_postgresql_cluster_iam_binding resource with the members parameter.
-
Open the current Terraform configuration file with the infrastructure plan.
To learn how to create this file, see Creating a cluster.
-
Add resource descriptions:
resource "yandex_mdb_postgresql_cluster_iam_binding" "<resource_1_local_name>" { cluster_id = "<cluster_ID>" role = "<role_1>" members = ["<subject_type>:<subject_ID>"] } resource "yandex_mdb_postgresql_cluster_iam_binding" "<resource_2_local_name>" { cluster_id = "<cluster_ID>" role = "<role_2>" members = ["<subject_type>:<subject_ID>"] }Where:
-
cluster_id: Cluster ID. -
role: Role, e.g.,managed-postgresql.editor. -
members: Array of types and IDs of subjects getting the role, in<subject_type>:<subject_ID>format.Here is an example:
serviceAccount:${yandex_iam_service_account.mpg_sa.id}userAccount:ajerq94v************system:allAuthenticatedUsers
Subject designations
To indicate a subject, use a combination of its type and unique ID, i.e.,
<subject_type>:<ID>. Here is how you can designate a subject:Subject type
Subject designation
userAccountuserAccount:<user_ID>serviceAccountserviceAccount:<service_account_ID>federatedUserfederatedUser:<user_ID>groupgroup:<group_ID>systemsystem:allAuthenticatedUsers(
All authenticated usersgroup)system:allUsers(
All usersgroup)system:group:organization:<organization_ID>:users(
All users in organization Xgroup)system:group:federation:<federation_ID>:users(
All users in federation Ngroup)system:group:userpool:<pool_ID>:users(
All users in userpool Pgroup)
-
-
Make sure the configuration files are correct.
-
In the command line, navigate to the directory that contains the current Terraform configuration files defining the infrastructure.
-
Run this command:
terraform validateTerraform will show any errors found in your configuration files.
-
-
Confirm resource changes.
-
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.
-
For more information, see this Terraform provider guide.
-
-
To view a list of roles assigned for the cluster, run this CLI command:
yc managed-postgresql cluster list-access-bindings <cluster_name_or_ID>
Alert
The setAccessBindings method overwrites access permissions for the resource. All roles previously assigned for this resource will be deleted.
-
Get an IAM token for API authentication and put it into an environment variable:
export IAM_TOKEN="<IAM_token>" -
Call the Cluster.SetAccessBindings method, e.g., via the following cURL
request:curl \ --request POST \ --header "Authorization: Bearer $IAM_TOKEN" \ --header "Content-Type: application/json" \ --url 'https://mdb.api.cloud.yandex.net/managed-postgresql/v1/clusters/<cluster_ID>:setAccessBindings' \ --data '{ "accessBindings": [ { "roleId": "<role>", "subject": { "id": "<subject_1_ID>", "type": "<subject_type>" } }, { "roleId": "<role>", "subject": { "id": "<subject_2_ID>", "type": "<subject_type>" } }, ... { "roleId": "<role>", "subject": { "id": "<subject_N_ID>", "type": "<subject_type>" } } ] }'Where:
-
accessBindings.roleId: Role, e.g.,managed-postgresql.editor. -
accessBindings.subject.id: ID of the subject the role is assigned to. -
accessBindings.subject.type: Type of subject the role is assigned to.Subject designations
To indicate a subject, use a combination of its type and unique ID in the
subject.typeandsubject.idfields of the request. Here are possible combinations:subject.type
subject.id
userAccount<user_ID>serviceAccount<service_account_ID>federatedUser<user_ID>group<group_ID>systemallAuthenticatedUsers(
All authenticated usersgroup)allUsers(
All usersgroup)group:organization:<organization_ID>:users(
All users in organization Xgroup)group:federation:<federation_ID>:users(
All users in federation Ngroup)group:userpool:<pool_ID>:users(
All users in userpool Pgroup)
-
-
Check the server response to make sure your request was successful.
Alert
The ClusterService.SetAccessBindings method completely overwrites access permissions for the resource. All roles previously assigned for this resource will be deleted.
-
Get an IAM token for API authentication and put it into an environment variable:
export IAM_TOKEN="<IAM_token>" -
Clone the cloudapi
repository:cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapiBelow, we assume that the repository contents reside in the
~/cloudapi/directory. -
Call the ClusterService.SetAccessBindings method, e.g., via the following gRPCurl
request:grpcurl \ -format json \ -import-path ~/cloudapi/ \ -import-path ~/cloudapi/third_party/googleapis/ \ -proto ~/cloudapi/yandex/cloud/mdb/postgresql/v1/cluster_service.proto \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d '{ "resource_id": "<cluster_ID>", "accessBindings": [ { "roleId": "<role>", "subject": { "id": "<subject_1_ID>", "type": "<subject_type>" } }, { "roleId": "<role>", "subject": { "id": "<subject_2_ID>", "type": "<subject_type>" } }, ... { "roleId": "<role>", "subject": { "id": "<subject_N_ID>", "type": "<subject_type>" } } ] }' \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.postgresql.v1.ClusterService.SetAccessBindingsWhere:
-
resource_id: Cluster ID. -
accessBindings.roleId: Role, e.g.,managed-postgresql.editor. -
accessBindings.subject.id: ID of the subject the role is assigned to. -
accessBindings.subject.type: Type of subject the role is assigned to.Subject designations
To indicate a subject, use a combination of its type and unique ID in the
subject.typeandsubject.idfields of the request. Here are possible combinations:subject.type
subject.id
userAccount<user_ID>serviceAccount<service_account_ID>federatedUser<user_ID>group<group_ID>systemallAuthenticatedUsers(
All authenticated usersgroup)allUsers(
All usersgroup)group:organization:<organization_ID>:users(
All users in organization Xgroup)group:federation:<federation_ID>:users(
All users in federation Ngroup)group:userpool:<pool_ID>:users(
All users in userpool Pgroup)
-
-
Check the server response to make sure your request was successful.
Revoking a role
If you do not have the Yandex Cloud CLI yet, install and initialize it.
The folder used by default is the one specified when creating the CLI profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also specify a different folder for any command using --folder-name or --folder-id.
If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.
-
To view a list of roles assigned for the cluster, run this command:
yc managed-postgresql cluster list-access-bindings <cluster_name_or_ID> -
View the description of the CLI command for revoking a role for a cluster:
yc managed-postgresql cluster remove-access-binding --help -
To revoke a role, run this command:
yc managed-postgresql cluster remove-access-binding <cluster_name_or_ID> \ --role <role> \ --subject <subject_type>:<subject_ID>Where:
-
--role: Role being revoked, e.g.,managed-postgresql.editor. -
--subject: Subject to revoke the role from.Here is an example:
serviceAccount:aje6p030************userAccount:aje8tj79************system:allAuthenticatedUsers
Subject designations
To indicate a subject, use the
--subjectparameter in<subject_type>:<ID>format. For some subject types, the Yandex Cloud CLI provides separate parameters instead of--subject, where you only need to specify the subject name or ID without the type. Possible subject designations and matching CLI parameters:Subject type
Subject designation
Yandex Cloud CLI parameter
userAccountuserAccount:<user_ID>--user-account-idor--user-yandex-loginserviceAccountserviceAccount:<service_account_ID>--service-account-idor--service-account-namefederatedUserfederatedUser:<user_ID>--user-account-idgroupgroup:<group_ID>--group-memberssystemsystem:allAuthenticatedUsers(
All authenticated usersgroup)--all-authenticated-userssystem:allUsers(
All usersgroup)—
system:group:organization:<organization_ID>:users(
All users in organization Xgroup)--organization-userssystem:group:federation:<federation_ID>:users(
All users in federation Ngroup)--federation-userssystem:group:userpool:<pool_ID>:users(
All users in userpool Pgroup)—
-
Note
To revoke roles for a Managed Service for PostgreSQL cluster, use the yandex_mdb_postgresql_cluster_iam_binding resource with the members parameter.
-
Open the current Terraform configuration file with the infrastructure plan.
To learn how to create this file, see Creating a cluster.
-
Find the description of the resource with the role you want to revoke and delete this description:
resource "yandex_mdb_postgresql_cluster_iam_binding" "<local_resource_name>" { cluster_id = "<cluster_ID>" role = "<role>" members = ["<subject_type>:<subject_ID>"] } -
Make sure the configuration files are correct.
-
In the command line, navigate to the directory that contains the current Terraform configuration files defining the infrastructure.
-
Run this command:
terraform validateTerraform will show any errors found in your configuration files.
-
-
Confirm resource changes.
-
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.
-
For more information, see this Terraform provider guide.
-
-
To view a list of roles assigned for the cluster, run this CLI command:
yc managed-postgresql cluster list-access-bindings <cluster_name_or_ID>
-
Get an IAM token for API authentication and put it into an environment variable:
export IAM_TOKEN="<IAM_token>" -
Call the Cluster.UpdateAccessBindings method, e.g., via the following cURL
request:curl \ --request PATCH \ --header "Authorization: Bearer $IAM_TOKEN" \ --header "Content-Type: application/json" \ --url 'https://mdb.api.cloud.yandex.net/managed-postgresql/v1/clusters/<cluster_ID>:updateAccessBindings' \ --data '{ "access_binding_deltas": [ { "action": "REMOVE", "access_binding": { "role_id": "<role>", "subject": { "id": "<subject_ID>", "type": "<subject_type>" } } } ] }'Where:
-
access_binding_deltas.roleId: Role being revoked, e.g.,managed-postgresql.editor. -
access_binding_deltas.subject.id: ID of the subject to revoke the role from. -
access_binding_deltas.subject.type: Subject type to revoke a role from.Subject designations
To indicate a subject, use a combination of its type and unique ID in the
subject.typeandsubject.idfields of the request. Here are possible combinations:subject.type
subject.id
userAccount<user_ID>serviceAccount<service_account_ID>federatedUser<user_ID>group<group_ID>systemallAuthenticatedUsers(
All authenticated usersgroup)allUsers(
All usersgroup)group:organization:<organization_ID>:users(
All users in organization Xgroup)group:federation:<federation_ID>:users(
All users in federation Ngroup)group:userpool:<pool_ID>:users(
All users in userpool Pgroup)
-
-
Check the server response to make sure your request was successful.
-
Get an IAM token for API authentication and put it into an environment variable:
export IAM_TOKEN="<IAM_token>" -
Clone the cloudapi
repository:cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapiBelow, we assume that the repository contents reside in the
~/cloudapi/directory. -
Call the ClusterService.UpdateAccessBindings method, e.g., via the following gRPCurl
request:grpcurl \ -format json \ -import-path ~/cloudapi/ \ -import-path ~/cloudapi/third_party/googleapis/ \ -proto ~/cloudapi/yandex/cloud/mdb/postgresql/v1/cluster_service.proto \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d '{ "resource_id": "<cluster_ID>", "access_binding_deltas": [ { "action": "REMOVE", "access_binding": { "role_id": "<role>", "subject": { "id": "<subject_ID>", "type": "<subject_type>" } } } ] }' \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.postgresql.v1.ClusterService.UpdateAccessBindingsWhere:
-
resource_id: Cluster ID. -
access_binding_deltas.roleId: Role being revoked, e.g.,managed-postgresql.editor. -
access_binding_deltas.subject.id: ID of the subject to revoke the role from. -
access_binding_deltas.subject.type: Subject type to revoke a role from.Subject designations
To indicate a subject, use a combination of its type and unique ID in the
subject.typeandsubject.idfields of the request. Here are possible combinations:subject.type
subject.id
userAccount<user_ID>serviceAccount<service_account_ID>federatedUser<user_ID>group<group_ID>systemallAuthenticatedUsers(
All authenticated usersgroup)allUsers(
All usersgroup)group:organization:<organization_ID>:users(
All users in organization Xgroup)group:federation:<federation_ID>:users(
All users in federation Ngroup)group:userpool:<pool_ID>:users(
All users in userpool Pgroup)
-
-
Check the server response to make sure your request was successful.
Examples
Granting cluster management access to a service account
For a service account to be able to view the info of all Managed Service for PostgreSQL clusters in the folder but modify the resources in one particular cluster alone, give it the managed-postgresql.viewer role for the folder and the managed-postgresql.editor role for that cluster:
-
Assign the role for the folder:
yc resource-manager folder add-access-binding <folder_name_or_ID> \ --role managed-postgresql.viewer \ --subject=serviceAccount:<service_account_ID> -
Assign the roles for the cluster:
yc managed-postgresql cluster add-access-bindings <cluster_name_or_ID> \ --access-binding role=managed-postgresql.editor,subject=serviceAccount:<service_account_ID> -
Check the list of roles assigned for the cluster:
yc managed-postgresql cluster list-access-bindings <cluster_name_or_ID>
-
Open the current Terraform configuration file with the infrastructure plan.
To learn how to create this file, see Creating a cluster.
-
Add resource descriptions:
resource "yandex_resourcemanager_folder_iam_member" "mpg-viewer-account-iam" { folder_id = "<folder_ID>" role = "managed-postgresql.viewer" member = "serviceAccount:<service_account_ID>" } resource "yandex_mdb_postgresql_cluster_iam_binding" "mpg-cluster-api-editor" { cluster_id = "<cluster_ID>" role = "managed-postgresql.editor" members = ["serviceAccount:<service_account_ID>"] } -
Make sure the configuration files are correct.
-
In the command line, navigate to the directory that contains the current Terraform configuration files defining the infrastructure.
-
Run this command:
terraform validateTerraform will show any errors found in your configuration files.
-
-
Confirm resource changes.
-
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.
-
-
-
Get an IAM token for API authentication and put it into an environment variable:
export IAM_TOKEN="<IAM_token>" -
Assign the role for the folder:
curl \ --request POST \ --header "Authorization: Bearer $IAM_TOKEN" \ --header "Content-Type: application/json" \ --url 'https://resource-manager.api.cloud.yandex.net/resource-manager/v1/folders/<folder_ID>:updateAccessBindings' \ --data '{ "access_binding_deltas": [ { "action": "ADD", "access_binding": { "role_id": "managed-postgresql.viewer", "subject": { "id": "<service_account_ID>", "type": "serviceAccount" } } } ] }'access_binding_deltas.subject.id: ID of the service account the role is assigned to. -
Call the Cluster.UpdateAccessBindings method, e.g., via the following cURL
request:curl \ --request PATCH \ --header "Authorization: Bearer $IAM_TOKEN" \ --header "Content-Type: application/json" \ --url 'https://mdb.api.cloud.yandex.net/managed-postgresql/v1/clusters/<cluster_ID>:updateAccessBindings' \ --data '{ "access_binding_deltas": [ { "action": "ADD", "access_binding": { "role_id": "managed-postgresql.editor", "subject": { "id": "<service_account_ID>", "type": "serviceAccount" } } } ] }'access_binding_deltas.subject.id: ID of the service account the role is assigned to. -
Check the list of roles assigned for the folder:
curl \ --request GET \ --header "Authorization: Bearer $IAM_TOKEN" \ --header "Content-Type: application/json" \ --url 'https://resource-manager.api.cloud.yandex.net/resource-manager/v1/folders/<folder_ID>:updateAccessBindings' -
Check the list of roles assigned for the cluster:
curl \ --request GET \ --header "Authorization: Bearer $IAM_TOKEN" \ --header "Content-Type: application/json" \ --url 'https://mdb.api.cloud.yandex.net/managed-postgresql/v1/clusters/<cluster_ID>:listAccessBindings'
-
Get an IAM token for API authentication and put it into an environment variable:
export IAM_TOKEN="<IAM_token>" -
Clone the cloudapi
repository:cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapiBelow, we assume that the repository contents reside in the
~/cloudapi/directory. -
Assign the role for the folder:
grpcurl \ -format json \ -import-path ~/cloudapi/ \ -import-path ~/cloudapi/third_party/googleapis/ \ -proto ~/cloudapi/yandex/cloud/resourcemanager/v1/folder_service.proto \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d '{ "resource_id": "<cluster_ID>", "access_binding_deltas": [ { "action": "ADD", "access_binding": { "role_id": "managed-postgresql.viewer", "subject": { "id": "<service_account_ID>", "type": "serviceAccount" } } } ] }' \ resource-manager.api.cloud.yandex.net:443 \ yandex.cloud.resourcemanager.v1.FolderService.UpdateAccessBindingsaccess_binding_deltas.subject.id: ID of the service account the role is assigned to. -
Assign the role for the cluster:
grpcurl \ -format json \ -import-path ~/cloudapi/ \ -import-path ~/cloudapi/third_party/googleapis/ \ -proto ~/cloudapi/yandex/cloud/mdb/postgresql/v1/cluster_service.proto \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d '{ "resource_id": "<cluster_ID>", "access_binding_deltas": [ { "action": "ADD", "access_binding": { "role_id": "managed-postgresql.editor", "subject": { "id": "<service_account_ID>", "type": "serviceAccount" } } } ] }' \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.postgresql.v1.ClusterService.UpdateAccessBindingsaccess_binding_deltas.subject.id: ID of the service account the role is assigned to. -
Check the list of roles assigned for the folder:
grpcurl \ -format json \ -import-path ~/cloudapi/ \ -import-path ~/cloudapi/third_party/googleapis/ \ -proto ~/cloudapi/yandex/cloud/resourcemanager/v1/folder_service.proto \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d '{ "resource_id": "<folder_ID>" }' \ resource-manager.api.cloud.yandex.net:443 \ yandex.cloud.resourcemanager.v1.FolderService.ListAccessBindings -
Check the list of roles assigned for the cluster:
grpcurl \ -format json \ -import-path ~/cloudapi/ \ -import-path ~/cloudapi/third_party/googleapis/ \ -proto ~/cloudapi/yandex/cloud/mdb/postgresql/v1/cluster_service.proto \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d '{ "resource_id": "<cluster_ID>" }' \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.postgresql.v1.ClusterService.ListAccessBindings