Skip to content

IAM / Task

Assign and revoke roles

Updated · 3 min read

Grant a built-in role to a user or service account org-wide or for one project, and revoke it again at exactly the scope it was granted.

On this page5 sections

Assign a role to give a user or service account access, and revoke it to take that access away. A change takes effect on the principal’s next request. To give a person access by email instead of by user ID, invite them.

Before you begin

Assign a role

  1. Find the URN of the role you want to assign.

    terminal
    origin iam list-roles --org-id <org-id>

    For the permissions of each role, see Built-in roles.

  2. Assign the role. Omit --project-id for an org-wide grant.

    terminal
    origin iam assign-role --org-id <org-id> \
      --principal user:<user-id> \
      --role-urn urn:origin:cloud:iam::::tc/role/roles/viewer

    To limit the grant to one project, add --project-id <project-id>. A project-scoped grant applies only to resources in that project; it never allows IAM operations. See Role assignments and scopes.

  3. Verify the grant. The output lists every principal with its role URNs.

    terminal
    origin iam list-members --org-id <org-id>

Assigning a role the principal already holds at the same scope succeeds and changes nothing. A role URN that isn’t in the built-in catalog is refused with BAD_REQUEST. A role with permissions you don’t hold yourself at that scope is refused with FORBIDDEN, and so is revoking one.

Revoke a role

  1. Find the role URN of the grant in the roleUrns of the principal in list-members. It’s the same URN that list-roles shows for the role, for example urn:origin:cloud:iam::::tc/role/roles/owner, except for a grant created together with the organization, which carries the organization ID inside its URN. Copy the URN from list-members or from origin iam principal-grants --org-id <org-id> --principal <principal> rather than typing it.

    terminal
    origin iam list-members --org-id <org-id>
  2. Revoke the role at the same scope it was assigned with. Omit --project-id for an org-wide grant, or pass the same project for a project-scoped one.

    terminal
    origin iam revoke-role --org-id <org-id> \
      --principal user:<user-id> \
      --role-urn urn:origin:cloud:iam::::tc/role/roles/viewer
  3. Optionally, run list-members again to check that the role URN is gone from the principal.

If the principal holds no grant of that role at that scope, the platform refuses with NOT_FOUND and changes nothing. Check the scope: an org-wide grant isn’t revoked by a request that names a project, and the reverse.

If revoking would leave the organization without an org-wide owner, the platform refuses with CONFLICT. Assign roles/owner org-wide to someone else first. See The last owner is protected.

To take away every role a principal holds in the organization at once, remove the member instead.

Using the API

The assignRole and revokeRole mutations take the same input. Omit projectId for an org-wide grant.

GraphQL
mutation {
  iam {
    assignRole(input: {
      orgId: "<org-id>"
      principal: "user:<user-id>"
      roleUrn: "urn:origin:cloud:iam::::tc/role/roles/viewer"
    })
  }
}