Skip to content

Manage role bindings

This guide shows you how to grant, revoke, list, and test fine-grained IAM access using role bindings.

Before you manage role bindings, you’ll need:

List predefined roles before you grant access. The response includes each role’s scope and permissions.

Terminal window
evroc iam rolebinding roles

You can also use the rb shortcut instead of rolebinding.

Use the role’s id value when granting access, for example /iam/roles/computeOperator.

For descriptions of each predefined role and permission, see permissions and roles.

Grant a role to a principal in a project with the assign command. This creates the principal’s role binding if it doesn’t already exist.

Terminal window
evroc config set-project my-project
evroc iam rb assign \
--principal /iam/users/5a9bb4ea-a79f-4918-9b62-a983b576799e \
--role /iam/roles/projectOwner

The principal receives the role on every applicable resource in my-project.

Note: Assigning a role is idempotent. If the principal already has that role in the scope, the request replaces the role’s resource list. Also, the assign API creates the actual RoleBinding resource for you, with a friendly name like u-<user-id>.

Add resources to limit a role to specific resource FQIDs.

Terminal window
evroc iam rb assign \
--principal /iam/users/5a9bb4ea-a79f-4918-9b62-a983b576799e \
--role /iam/roles/projectOwner \
--resource /compute/projects/my-project/regions/se-sto/virtualMachines/my-vm

Use exact resource FQIDs for individual resources. Use * to match one path segment, such as all VMs in one region.

Grant organization-level roles on an organization scope.

Terminal window
evroc iam rb assign \
--principal /iam/users/5a9bb4ea-a79f-4918-9b62-a983b576799e \
--role /iam/roles/organizationOwner \
--organization

Organization roles govern organization-level IAM operations. They don’t grant access to resources inside projects.

List all role bindings in the current project:

Terminal window
evroc iam rb list

List all role bindings in the current organization:

Terminal window
evroc iam rb list --organization

Use the metadata.id value from the response when you need to get, patch, or delete a specific role binding.

Terminal window
evroc iam rb get u-5a9bb4ea-a79f-4918-9b62-a983b576799e

A role binding’s metadata.id is derived from the principal it binds, so a principal has at most one role binding per project or organization:

Principal metadata.id
/iam/users/{userId} u-{userId}
/iam/projects/{projectId}/serviceAccounts/{serviceAccountId} sa-{projectId}.{serviceAccountId}

In API version v1beta2, the server enforces this format: metadata.id is required when you create a role binding and must match the form above. A mismatch is rejected, and the error names the ID that was expected:

metadata.name must be u-5a9bb4ea-a79f-4918-9b62-a983b576799e, got my-binding

In v1beta1, the id is recommended but not enforced — any value is accepted. New integrations should use v1beta2.

The CLI derives the ID for you. If you call the REST API directly, provide the correct metadata.id.

Creating a second role binding for a principal that already has one in the same project or organization fails, because both resolve to the same ID. Add the role to the existing binding with evroc iam rb assign instead.

v1beta1 is deprecated; new integrations should use v1beta2. The only difference is the id enforcement described above — everything else is identical. Existing role bindings are handled for you; no action needed.

If you manage role bindings with the evroc Terraform provider, upgrade to v0.9.0 or later — it handles the transition transparently.

Remove one role from a principal with the revoke endpoint.

Terminal window
evroc iam rb revoke \
--principal /iam/users/5a9bb4ea-a79f-4918-9b62-a983b576799e \
--role /iam/roles/computeOperator

Revoking a role is idempotent. If the principal doesn’t have the role, the request still succeeds. If no roles remain in the role binding, it is deleted.

Delete the whole role binding to revoke every role it grants to the principal in that scope.

Terminal window
evroc iam rb delete rb-name

Warning: Deleting a role binding revokes every role in that binding for the principal on the selected scope.

To get all role bindings for you, across all projects and organizations:

Terminal window
evroc iam rb list-me

Use testPermissions to check whether the authenticated caller has specific permissions on specific resources. This is useful when you need to tailor an application UI to the caller’s access.

Terminal window
TOKEN=$(evroc iam get-access-token)
curl -X POST \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"checks": [
{
"permission": "compute.virtualMachines.start",
"resource": "/compute/projects/my-project/regions/se-sto/virtualMachines/my-vm"
},
{
"permission": "iam.roleBindings.read",
"resource": "/iam/projects/my-project"
}
]
}' \
https://api.evroc.com/iam/v1beta1/testPermissions

The response returns one result for each check, in the same order as the request.

{
"results": [
{
"permission": "compute.virtualMachines.start",
"resource": "/compute/projects/my-project/regions/se-sto/virtualMachines/my-vm",
"allowed": true
},
{
"permission": "iam.roleBindings.read",
"resource": "/iam/projects/my-project",
"allowed": false
}
]
}

Use checkAccess to evaluate another principal’s access.

Terminal window
TOKEN=$(evroc iam get-access-token)
curl -X POST \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"principal": "/iam/projects/my-project/serviceAccounts/ci-robot",
"checks": [
{
"permission": "compute.virtualMachines.start",
"resource": "/compute/projects/my-project/regions/se-sto/virtualMachines/my-vm"
}
]
}' \
https://api.evroc.com/iam/v1beta1/checkAccess

You need permission to read role bindings on the scope to inspect another principal. If you don’t have that permission, the request returns 404 so the scope’s existence isn’t revealed.