ENع
←IAM
Lesson 06 · The cloud

Identity and access management

10 min11 steps5 questionsBeginner
About this lesson

Every request to a cloud service is checked twice: who is asking (authentication), and are they allowed to do this (authorization)? Follow one person, Alice, as she signs in with multi-factor authentication and sends three requests to cloud storage. Her JSON policy allows one, an explicit Deny blocks the second, and the third is denied by default. Then see why least privilege matters and how programs use roles with temporary credentials instead of passwords.

You'll learn to

Tick what you feel confident about. These self-checks do not affect your lesson score.

Fig 6 · Interactive
01 / 11

Who, and what may they do?

In the cloud, every request, such as "read this file", is checked. Identity and access management (IAM) asks two questions: who is asking (authentication), and are they allowed to do this (authorization)?

every request to a cloud service is checked

  1. authentication  who is asking?
  2. authorization   may they do this, to that?

IAM = identity and access management
Loading figure…
or ← →
Read the lesson step by step
  1. Who, and what may they do?

    In the cloud, every request, such as "read this file", is checked. Identity and access management (IAM) asks two questions: who is asking (authentication), and are they allowed to do this (authorization)?

    every request to a cloud service is checked
    
      1. authentication  who is asking?
      2. authorization   may they do this, to that?
    
    IAM = identity and access management
  2. Identities

    An identity that can send requests is called a principal. It can be a person or a program. Alice is an IAM user: an identity for one person. The app server is a program; we give it an identity at the end.

    principal = who or what sends a request
    
      Alice        an IAM user (one person)
      app server   a program (a role, step 10)
    
    no identity, no access
  3. Prove who you are

    Alice signs in with her password plus a one-time code from her phone. Using two kinds of proof is multi-factor authentication (MFA). She gets credentials that prove who she is. Nobody has said yet what she may do.

    authentication: who is asking?
    
      something she knows   password
      something she has     phone code (MFA)
    
    → credentials: later requests are signed with them
    still unknown: what she is allowed to do
  4. Permissions are written down

    What Alice may do is written in a policy: a JSON document attached to her. Each statement has an Effect (Allow or Deny), an Action (what can be done) and a Resource (to what). Hers has two statements.

    a policy = a list of statements
    
      Effect    Allow or Deny
      Action    s3:GetObject = read a file
                s3:DeleteObject = delete a file
      Resource  arn:aws:s3:::photos/*
                = anything in the photos bucket
                "*" = anything at all
  5. Request 1: allowed

    Alice asks to read photos/cat.jpg (the action s3:GetObject). Her credentials pass the "who?" check. Then her policy is checked: statement 1 allows reading anything in photos and nothing denies it, so she gets the file.

    request  s3:GetObject  photos/cat.jpg
    
      who?      Alice ✓
      Deny?     statement 2: DeleteObject ≠ GetObject
      Allow?    statement 1: matches ✓
    
    → ALLOW (explicit allow)
  6. Request 2: explicit deny

    Next she tries to delete the same photo (s3:DeleteObject). Statement 2 denies that action on every resource ("*"). An explicit Deny always wins, even over an Allow, so the request is refused and nothing is deleted.

    request  s3:DeleteObject  photos/cat.jpg
    
      who?      Alice ✓
      Deny?     statement 2: matches ✗
    
    → DENY (explicit deny)
    a Deny beats any Allow
  7. Request 3: denied by default

    Then she asks to read payroll/pay.csv (s3:GetObject). No statement allows reading the payroll bucket. In IAM everything starts denied: unless a policy allows an action, the answer is no. This is called an implicit deny.

    request  s3:GetObject  payroll/pay.csv
    
      who?      Alice ✓
      Deny?     no statement matches
      Allow?    photos/* does not match payroll/…
    
    → DENY (implicit deny: the default)
  8. The rule, in order

    The check follows one rule. First, if any statement denies the request, deny. Otherwise, if a statement allows it, allow. Otherwise, deny. A tiny Python version of that rule gives the same three answers.

    from fnmatch import fnmatchcase as match
    
    def allowed(policy, action, resource):
        hits = [s["Effect"] for s in policy["Statement"]
                if match(action, s["Action"])
                and match(resource, s["Resource"])]
        if "Deny" in hits:
            return False          # 1. explicit deny wins
        return "Allow" in hits    # 2. allow, else 3. deny
    
    allowed(policy, "s3:GetObject", "…photos/cat.jpg")  # True
    allowed(policy, "s3:DeleteObject", "…photos/cat.jpg")  # False
    allowed(policy, "s3:GetObject", "…payroll/pay.csv")  # False
  9. Least privilege

    Alice can read photos, but cannot delete them or open payroll. Giving each identity only the permissions its job needs, and nothing more, is called least privilege. If her password ever leaks, the damage stays small.

    least privilege: only what the job needs
    
      photos   read    ✓
      photos   delete  ✗
      payroll  read    ✗
    
    start from nothing, add what is needed
  10. Roles for programs

    The app server must read photos too, but a password stored on a server can be stolen. Instead it uses a role: an identity with a policy but no password. AWS gives it temporary credentials that expire and are renewed automatically.

    role = an identity with permissions, no password
    
      app server takes on the role
      → temporary credentials (they expire)
      AssumeRole default: 3600 s = 1 hour
      on a server: renewed automatically
    
    request  s3:GetObject  photos/… → ALLOW
  11. Same idea in every cloud

    Google Cloud and Microsoft Azure use other names: roles are granted to principals in an allow policy, or by a role assignment. The idea is the same everywhere: prove who you are, then check what you are allowed to do.

              who            what they may do
      AWS     IAM user/role  policy statements
      Google  principal      role in an allow policy
      Azure   principal      role assignment (RBAC)
    
    1. authenticate   2. authorize   every request

Quiz Unlocks after the last step.