Google Cloud Tutorial · Identity and Access · Lesson 7 of 27

Cloud IAM: Principals, Roles and Policies

How Google Cloud decides who can do what: principals, roles, allow policies, conditions and deny policies.

Members can save this page, take notes and track progress. See membership · Sign in

The pieces

  • Principals: Google accounts, groups, service accounts, Cloud Identity domains, and federated identities.
  • Permissions: single actions such as storage.objects.get.
  • Roles: collections of permissions. Basic roles (Owner, Editor, Viewer) are very broad; predefined roles are per service (roles/storage.objectViewer); custom roles hold exactly the permissions you choose.
  • Allow policies: attached to a resource (organisation, folder, project, or a single bucket), binding principals to roles, optionally with a condition (only objects with a prefix, only until a date).
  • Deny policies: block permissions for principals regardless of any allow.

How a request is checked

  1. Is there a deny rule for this principal and permission anywhere up the hierarchy? Then denied.
  2. Otherwise, does any allow policy on the resource or its ancestors grant a role containing the permission (with its condition true)? Then allowed.
  3. Otherwise denied.
Evaluating allow and deny policiesTry it yourself
ROLES = {
    "roles/storage.objectViewer": {"storage.objects.get", "storage.objects.list"},
    "roles/storage.objectAdmin": {"storage.objects.get", "storage.objects.list", "storage.objects.create",
                                  "storage.objects.delete"},
}
allow = [("group:[email protected]", "roles/storage.objectViewer"),
         ("group:[email protected]", "roles/storage.objectAdmin")]
deny = [("group:[email protected]", "storage.objects.delete")]

def check(principal, permission):
    if (principal, permission) in deny:
        return "DENIED by deny policy"
    if any(p == principal and permission in ROLES[r] for p, r in allow):
        return "allowed"
    return "denied (no role grants it)"

for who, perm in [("group:[email protected]", "storage.objects.get"),
                  ("group:[email protected]", "storage.objects.create"),
                  ("group:[email protected]", "storage.objects.delete")]:
    print(f"{who:26} {perm:24} {check(who, perm)}")

Output

group:[email protected]    storage.objects.get      allowed
group:[email protected]    storage.objects.create   denied (no role grants it)
group:[email protected]         storage.objects.delete   allowed

Good habits

Grant roles to groups, not people; use predefined roles over basic ones; grant at the lowest level that works; review the IAM Recommender, which suggests removing permissions that haven't been used.

Test yourself

Why should you avoid granting the basic Editor role?

  1. It can't be removed
  2. It grants broad write permissions across almost every service
  3. It only works for service accounts
  4. It costs extra
Show answer

Answer: It grants broad write permissions across almost every service

Basic roles predate fine-grained IAM and include thousands of permissions.

Last reviewed · By the ByteCamel team · How we write content

Was this page helpful?

Report a mistake