Setting up cloud access permissions
Warning
Even if an operation with resources pertaining to Yandex Cloud services is allowed by a role, it may still be blocked if the organization, cloud, or folder is subject to an access policy prohibiting this operation.
To grant a user access to cloud resources, assign the user a role for the cloud.
Assigning a role for a cloud
- In the management console
, select a cloud. - Go to the Access bindings tab.
- Click Configure access.
- In the window that opens, select User accounts.
- Select a user from the list or search by user.
- Click
Add role and select the role from the list or use the search bar. - Click Save.
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 a description of the command to assign a role for a cloud:
yc resource-manager cloud add-access-binding --help -
Get a list of available clouds:
yc resource-manager cloud listResult:
+----------------------+----------+ | ID | NAME | +----------------------+----------+ | b1gg8sgd16g7******** | my-cloud | +----------------------+----------+ -
Get a list of available roles:
yc iam role listResult:
+--------------------------------+-------------+ | ID | DESCRIPTION | +--------------------------------+-------------+ | admin | | | compute.images.user | | | editor | | | ... | | +--------------------------------+-------------+ -
Find out the user ID from the login or email address.
yc iam user-account get test-userResult:
id: gfei8n54hmfh******** yandex_passport_user_account: login: test-user default_email: test-user@yandex.ru -
Assign the user a role for the cloud. In the subject, specify the
userAccounttype and user ID:yc resource-manager cloud add-access-binding my-cloud \ --role editor \ --subject userAccount:<user_ID>Where:
-
--role: ID of the role you need to assign, e.g.,resource-manager.clouds.owner. -
--subject: Subject getting the role.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 the corresponding 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 assign a role to a service account, user group, or system group instead of a user, see these examples.
If you do not have Terraform yet, install it and configure the Yandex Cloud provider.
To manage infrastructure using Terraform under a service account or user accounts (a Yandex account, a federated account, or a local user), authenticate using the appropriate method.
-
Describe the roles you are assigning in the configuration file:
Here is an example of the configuration file structure:
data "yandex_resourcemanager_cloud" "project1" { name = "Project 1" } resource "yandex_resourcemanager_cloud_iam_member" "editor" { cloud_id = "${data.yandex_resourcemanager_cloud.project1.id}" role = "<role>" member = "userAccount:<user_ID>" }Where:
-
cloud_id: Cloud ID. You can get a list of available clouds using the CLI command:yc resource-manager cloud list. This is a required setting. -
role: Role you need to assign. You can get a list of roles using the CLI command:yc iam role list. In oneyandex_resourcemanager_cloud_iam_memberresource, only one role can be assigned. This is a required setting. -
member: Subject getting the role. This is a required setting.Subject designations
To indicate a subject, use a combination of its type and unique ID, i.e.,
<subject_type>:<ID>. 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)
For more on the properties of the
yandex_resourcemanager_cloud_iam_memberin Terraform, see this provider guide. -
-
Create the resources:
-
In the terminal, navigate to the configuration file directory.
-
Make sure the configuration is correct using this command:
terraform validateIf the configuration is valid, you will get this message:
Success! The configuration is valid. -
Run this command:
terraform planYou will see a list of resources and their properties. No changes will be made at this step. Terraform will show any errors in the configuration.
-
Apply the configuration changes:
terraform apply -
Type
yesand press Enter to confirm the changes.
This will assign access permissions for the cloud.
-
Use the updateAccessBindings REST API method for the Cloud resource or the CloudService/UpdateAccessBindings gRPC API call.
You will need the cloud ID and the ID of the user who is assigned the role for the cloud.
-
Find out the cloud ID using the list REST API method:
curl \ --header "Authorization: Bearer <IAM_token>" \ https://resource-manager.api.cloud.yandex.net/resource-manager/v1/cloudsResult:
{ "clouds": [ { "id": "b1gg8sgd16g7********", "createdAt": "2018-09-23T12:14:45Z", "name": "cloud-b1gg8sgd16g7qc" } ] } -
Find out the user ID by login using the getByLogin REST API method:
curl \ --header "Authorization: Bearer <IAM_token>" \ https://iam.api.cloud.yandex.net/iam/v1/yandexPassportUserAccounts:byLogin?login=test-userResult:
{ "id": "gfei8n54hmfh********", "yandexPassportUserAccount": { "login": "test-user", "defaultEmail": "test-user@yandex.ru" } } -
Assign the user a role for the cloud. In the
actionproperty, enterADDand specify theuserAccounttype and user ID undersubject.curl \ --request POST \ --header 'Content-Type: application/json' \ --header "Authorization: Bearer <IAM_token>" \ --data '{ "accessBindingDeltas": [ { "action": "ADD", "accessBinding": { "roleId": "<role>", "subject": { "id": "<user_ID>", "type": "userAccount" } } } ] }' \ https://resource-manager.api.cloud.yandex.net/resource-manager/v1/clouds/<cloud_ID>:updateAccessBindingsWhere:
-
roleId: Role. -
subject: Subject getting the role.Subject designations
To indicate a subject, use a combination of its type and unique ID in the
subject.typeandsubject.idfields of the request. 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)
-
Assigning multiple roles
- In the management console
, select a cloud. - Click the Access bindings tab.
- Click Assign bindings.
- In the Configure access bindings window, click Select user.
- Select a user from the list or search for a user.
- Click Add role.
- Select a role in the cloud.
- Use the Add role button to add another role.
- Click Save.
The add-access-binding command allows you to add only one role. You can assign multiple roles using the set-access-bindings command.
Alert
The set-access-bindings command for assigning multiple roles completely rewrites access permissions for the resource. All current resource roles will be deleted.
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.
-
Make sure the resource has no important roles assigned before proceeding:
yc resource-manager cloud list-access-bindings <cloud_name_or_ID> -
To assign a role, run this command:
yc resource-manager cloud set-access-bindings <cloud_name_or_ID> \ --access-binding role=<role>,subject=<subject_type>:<subject_ID>Where:
-
role: ID of the role you need to assign. -
subject: Subject getting the role.Subject designations
To indicate a subject, use a combination of its type and unique ID, i.e.,
<subject_type>:<ID>. 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)
Provide a separate
--access-bindingparameter for each role. Here is an example:yc resource-manager cloud set-access-bindings my-cloud \ --access-binding role=editor,subject=userAccount:gfei8n54hmfh******** \ --access-binding role=viewer,subject=userAccount:helj89sfj80a******** -
To assign a role to a service account, user group, or system group instead of a user, see these examples.
If you do not have Terraform yet, install it and configure the Yandex Cloud provider.
To manage infrastructure using Terraform under a service account or user accounts (a Yandex account, a federated account, or a local user), authenticate using the appropriate method.
-
Describe the cloud access permission parameters in the configuration file.
Here is an example of the configuration file structure:
data "yandex_resourcemanager_cloud" "project1" { name = "Project 1" } resource "yandex_resourcemanager_cloud_iam_member" "member1" { cloud_id = "${data.yandex_resourcemanager_cloud.project1.id}" role = "<role_1>" member = "userAccount:<user_ID>" } resource "yandex_resourcemanager_cloud_iam_member" "member2" { cloud_id = "${data.yandex_resourcemanager_cloud.project1.id}" role = "<role_2>" member = "userAccount:<user_ID>" }Where:
-
cloud_id: Cloud ID. You can get a list of available clouds using the CLI command:yc resource-manager cloud list. This is a required setting. -
role: Role you need to assign. You can get a list of roles using the CLI command:yc iam role list. In oneyandex_resourcemanager_cloud_iam_memberresource, only one role can be assigned. This is a required setting. -
member: Subject getting the role. This is a required setting.Subject designations
To indicate a subject, use a combination of its type and unique ID, i.e.,
<subject_type>:<ID>. 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)
-
-
Create the resources:
-
In the terminal, navigate to the configuration file directory.
-
Make sure the configuration is correct using this command:
terraform validateIf the configuration is valid, you will get this message:
Success! The configuration is valid. -
Run this command:
terraform planYou will see a list of resources and their properties. No changes will be made at this step. Terraform will show any errors in the configuration.
-
Apply the configuration changes:
terraform apply -
Type
yesand press Enter to confirm the changes.
This will assign access permissions for the cloud.
-
Assign roles to the users:
curl \
--request POST \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer <IAM_token>" \
--data '{
"accessBindingDeltas": [
{
"action": "ADD",
"accessBinding": {
"roleId": "<role_1>",
"subject": {
"id": "<user_ID>",
"type": "userAccount"
}
}
},
{
"action": "ADD",
"accessBinding": {
"roleId": "<role_2>",
"subject": {
"id": "<user_ID>",
"type": "userAccount"
}
}
}
]
}' \
https://resource-manager.api.cloud.yandex.net/resource-manager/v1/clouds/<cloud_ID>:updateAccessBindings
Where:
-
roleId: Role. -
subject: Subject getting the role.Subject designations
To indicate a subject, use a combination of its type and unique ID in the
subject.typeandsubject.idfields of the request. 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)
You can also assign roles using the setAccessBindings REST API method for the Cloud resource or the CloudService/SetAccessBindings gRPC API call.
Alert
The setAccessBindings method for assigning multiple roles completely rewrites access permissions for the resource. All current resource roles will be deleted.
Cloud access for service accounts
A service account can be assigned roles for any cloud and folder within the organization it belongs to.
Allow the test-sa service account to manage my-cloud and its resources:
You assign roles to a service account the same way as to a user account.
To assign a service account a role for a cloud:
- In the management console
, on the left, select a cloud. - Go to the Access bindings tab.
- Click Configure access.
- In the window that opens, select Service accounts.
- Select a service account from the list or use the search.
- Click
Add role and select a role. - Click Save.
-
Find out the ID of the service account you want to assign the role to. To do this, get a list of available service accounts:
yc iam service-account listResult:
+----------------------+----------+------------------+ | ID | NAME | DESCRIPTION | +----------------------+----------+------------------+ | ajebqtreob2d******** | test-sa | test-description | +----------------------+----------+------------------+ -
Assign the role to the service account using its ID:
yc resource-manager cloud add-access-binding my-cloud \ --role <role> \ --service-account-id <service_account_ID>Where:
--role: ID of the role you need to assign, e.g.,resource-manager.clouds.owner.--service-account-id: Service account ID. You can also use the--service-account-nameparameter and specify the service account name instead of the ID.
If you do not have Terraform yet, install it and configure the Yandex Cloud provider.
To manage infrastructure using Terraform under a service account or user accounts (a Yandex account, a federated account, or a local user), authenticate using the appropriate method.
-
In the configuration file, describe the resources you want to create:
Here is an example of the configuration file structure:
resource "yandex_resourcemanager_cloud_iam_member" "editor" { cloud_id = "<cloud_ID>" role = "<role>" member = "serviceAccount:<service_account_ID>" }Where:
-
cloud_id: Cloud ID. This is a required setting. -
role: Role. You can find the description of the roles in the Yandex Identity and Access Management documentation in the Yandex Cloud role reference. This is a required setting. -
member: Subject getting the role. For a service account, specifyserviceAccount:<service_account_ID>. This is a required setting.Subject designations
To indicate a subject, use a combination of its type and unique ID, i.e.,
<subject_type>:<ID>. 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)
-
-
Create the resources:
-
In the terminal, navigate to the configuration file directory.
-
Make sure the configuration is correct using this command:
terraform validateIf the configuration is valid, you will get this message:
Success! The configuration is valid. -
Run this command:
terraform planYou will see a list of resources and their properties. No changes will be made at this step. Terraform will show any errors in the configuration.
-
Apply the configuration changes:
terraform apply -
Type
yesand press Enter to confirm the changes.
This will assign access permissions for the cloud.
-
-
Find out the ID of the service account you want to assign the role to. To do this, get a list of available service accounts:
curl \ --header "Authorization: Bearer <IAM_token>" \ https://iam.api.cloud.yandex.net/iam/v1/serviceAccounts?folderId=<folder_ID>Result:
{ "serviceAccounts": [ { "id": "ajebqtreob2d********", "folderId": "b1gvmob95yys********", "createdAt": "2018-10-18T13:42:40Z", "name": "test-sa", "description": "test-description" } ] } -
Assign the role for the cloud to the service account. In the
subjectproperty, specify theserviceAccounttype and the service account ID. In the request URL, specify the cloud ID as the resource:curl \ --request POST \ --header 'Content-Type: application/json' \ --header "Authorization: Bearer <IAM_token>" \ --data '{ "accessBindingDeltas": [ { "action": "ADD", "accessBinding": { "roleId": "<role>", "subject": { "id": "<service_account_ID>", "type": "serviceAccount" } } } ] }' \ https://resource-manager.api.cloud.yandex.net/resource-manager/v1/clouds/<cloud_ID>:updateAccessBindingsWhere:
-
roleId: Role. -
subject: Subject getting the role.Subject designations
To indicate a subject, use a combination of its type and unique ID in the
subject.typeandsubject.idfields of the request. 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)
-