Learn to Code
All tracks
Learn to Code

Free lessons from scratch to pro — every language, databases and DevOps.

AboutContactPrivacy PolicyTerms of Use

Your progress is saved in this browser. © 2026 Learn to Code

CL
Cloud (AWS, GCP, Azure)
0/12 completed
Beginner
What is cloud computing?AWS, Google Cloud and Azure comparedAccounts, billing alerts and the CLI
Intermediate
Identity and access (IAM)Virtual machinesObject storageNetworking: VPCs, subnets and load balancersManaged databases
Advanced
Serverless: functions, queues and eventsContainers in the cloud
Pro
Infrastructure as codeCost control, security and reliability
Tracks / Cloud (AWS, GCP, Azure) / Intermediate

Identity and access (IAM)

IAM (Identity and Access Management) decides who can do what to which resources. It's the most important security system in any cloud: leaked or over-powerful credentials cause more cloud breaches than anything else. This lesson covers the building blocks, how to write a policy, and the habits that keep accounts safe.

The building blocks

Concept AWS Google Cloud Azure
A person IAM user, or (better) an IAM Identity Center user Google account / Workspace user Entra ID user
A group of people IAM group Google group Entra group
An identity for software Role (assumed temporarily) Service account Managed identity / service principal
A set of permissions Policy (JSON document) Role (a list of permissions) Role definition
Granting it Attach the policy to a user, group or role IAM binding: member + role on a resource Role assignment: principal + role + scope

The principle is the same everywhere: give identities only the permissions they need, on only the resources they need, for only as long as they need them. That's called least privilege.

Policies (AWS)

An AWS policy is a JSON document of statements. Each says Allow or Deny these actions on these resources, optionally under some conditions:

read-reports-policy.json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "ListTheBucket",
      "Effect": "Allow",
      "Action": "s3:ListBucket",
      "Resource": "arn:aws:s3:::acme-reports"
    },
    {
      "Sid": "ReadReports",
      "Effect": "Allow",
      "Action": "s3:GetObject",
      "Resource": "arn:aws:s3:::acme-reports/finance/*"
    },
    {
      "Sid": "OnlyFromTheOffice",
      "Effect": "Deny",
      "Action": "s3:*",
      "Resource": "*",
      "Condition": { "NotIpAddress": { "aws:SourceIp": "203.0.113.0/24" } }
    }
  ]
}
Part Meaning
Effect Allow or Deny
Action API operations, service:Operation. Wildcards work: s3:Get*
Resource Which things, by ARN (Amazon Resource Name)
Condition Extra rules: source IP, time, MFA used, tags, encryption…

Evaluation rules: everything starts denied; an Allow grants access; an explicit Deny always wins. That's why the third statement blocks all S3 access from outside the office network, whatever other policies say.

An ARN names any AWS resource uniquely: arn:aws:s3:::acme-reports/finance/q3.pdf, arn:aws:iam::123456789012:role/app-server.

Creating users, groups and policies

bash
aws iam create-group --group-name analysts --query "Group.Arn" --output text
aws iam create-policy --policy-name ReadFinanceReports --policy-document file://read-reports-policy.json \
  --query "Policy.Arn" --output text
aws iam attach-group-policy --group-name analysts --policy-arn arn:aws:iam::123456789012:policy/ReadFinanceReports
aws iam create-user --user-name asha --query "User.Arn" --output text
aws iam add-user-to-group --user-name asha --group-name analysts
echo "--- asha's groups and their policies:"
aws iam list-groups-for-user --user-name asha --query "Groups[].GroupName" --output text
aws iam list-attached-group-policies --group-name analysts --query "AttachedPolicies[].PolicyName" --output text
Output
arn:aws:iam::123456789012:group/analysts
arn:aws:iam::123456789012:policy/ReadFinanceReports
arn:aws:iam::123456789012:user/asha
--- asha's groups and their policies:
analysts
ReadFinanceReports

Attach policies to groups, and put people in groups. When someone changes team, you move them to another group instead of editing a dozen individual permissions.

💡 For people, AWS recommends IAM Identity Center (single sign-on) rather than IAM users: people log in through the browser and get temporary credentials, and there are no long-lived passwords or keys to leak. IAM users with access keys are mostly a legacy pattern now.

Roles: permissions for software

Your code needs credentials too, for example an app server that reads from S3. Never put access keys in code or config files. Give the server a role instead: it receives short-lived credentials automatically, and they rotate by themselves.

A role has two policies:

  1. A trust policy: who may use (assume) the role.
  2. Permission policies: what the role can do.
ec2-trust.json
{
  "Version": "2012-10-17",
  "Statement": [{
    "Effect": "Allow",
    "Principal": { "Service": "ec2.amazonaws.com" },
    "Action": "sts:AssumeRole"
  }]
}
bash
aws iam create-role --role-name report-reader --assume-role-policy-document file://ec2-trust.json --query "Role.Arn" --output text
aws iam attach-role-policy --role-name report-reader --policy-arn arn:aws:iam::123456789012:policy/ReadFinanceReports
aws iam create-instance-profile --instance-profile-name report-reader --query "InstanceProfile.Arn" --output text
aws iam add-role-to-instance-profile --instance-profile-name report-reader --role-name report-reader
echo "--- assuming the role gives temporary credentials:"
aws sts assume-role --role-arn arn:aws:iam::123456789012:role/report-reader --role-session-name demo \
  --query "Credentials.{KeyStartsWith: AccessKeyId, Expires: Expiration}" --output json | sed -E 's/"(ASIA|AKIA)[A-Z0-9]+"/"\1…"/; s/"[0-9T:.+-]{19,}[^"]*"/"<in one hour>"/'
Output
arn:aws:iam::123456789012:role/report-reader
arn:aws:iam::123456789012:instance-profile/report-reader
--- assuming the role gives temporary credentials:
{
    "KeyStartsWith": "ASIA…",
    "Expires": "<in one hour>"
}

An instance profile attaches the role to an EC2 virtual machine. Software on that VM then gets the role's temporary credentials automatically from the instance metadata service, and the AWS SDKs find them with no configuration. The same idea exists everywhere: Lambda functions, containers on ECS/EKS, and GitHub Actions (with OpenID Connect) can all use roles instead of stored keys.

On Google Cloud, attach a service account to a VM or Cloud Run service. On Azure, enable a managed identity on the resource and give it a role assignment.

Google Cloud and Azure

The same grant on the other clouds: allow a user to read objects in one bucket.

bash
# Google Cloud: an IAM binding on the bucket
gcloud storage buckets add-iam-policy-binding gs://acme-reports \
  --member="user:asha@example.com" --role="roles/storage.objectViewer"

# Azure: a role assignment scoped to a storage account
az role assignment create --assignee asha@example.com \
  --role "Storage Blob Data Reader" \
  --scope "/subscriptions/<sub-id>/resourceGroups/data-rg/providers/Microsoft.Storage/storageAccounts/acmereports"

Both clouds favour predefined roles (roles/storage.objectViewer, "Storage Blob Data Reader") over writing your own, and grant them at a scope: organization → folder/management group → project/subscription → resource group → single resource. Grant at the lowest scope that works.

Checking what's allowed

Before deploying a policy, test it. The policy simulator answers "would this request be allowed?":

bash
aws iam simulate-custom-policy --policy-input-list file://read-reports-policy.json \
  --action-names s3:GetObject s3:PutObject \
  --resource-arns "arn:aws:s3:::acme-reports/finance/q3.pdf" \
  --context-entries "ContextKeyName=aws:SourceIp,ContextKeyValues=203.0.113.10,ContextKeyType=ip" \
  --query "EvaluationResults[].[EvalActionName, EvalDecision]" --output text

Example output on a real AWS account:

s3:GetObject	allowed
s3:PutObject	implicitDeny

Reading is allowed; writing is denied by default because no statement allows it. (implicitDeny means "nothing allowed it"; explicitDeny means a Deny statement matched.) IAM Access Analyzer goes further: it finds resources shared with outside accounts and suggests least-privilege policies from your actual usage.

Security habits

Do Don't
MFA for every human, especially admins Share logins between people
Single sign-on with temporary credentials Long-lived access keys on laptops
Roles / service accounts / managed identities for software Access keys in code, .env files committed to Git, or Docker images
Least privilege, at the narrowest scope "Action": "*", "Resource": "*" because it was quicker
Separate accounts/projects for prod and dev Testing in production
Review access regularly; remove what's unused Leave ex-employees' access active
Turn on audit logs (CloudTrail, Cloud Audit Logs, Azure Activity Log) Have no record of who did what

If a key ever leaks (for example pushed to GitHub, where bots find it within minutes), deactivate it immediately, then check the audit logs for what it was used for.

Clean up

bash
aws iam remove-user-from-group --user-name asha --group-name analysts
aws iam delete-user --user-name asha
aws iam list-users --query "length(Users)"
Output
0

Practice

  1. Write a policy that lets a group read and write objects under uploads/ in one bucket, and nothing else.
  2. Add a condition so the policy only works when the user signed in with MFA (aws:MultiFactorAuthPresent).
  3. Use simulate-custom-policy to check your policy allows s3:PutObject on uploads/a.png but not on admin/a.png.
  4. Explain why a role is safer than an access key for an app running on a VM.
✎ Check your understanding

1.In AWS policy evaluation, what happens when one policy allows an action and another explicitly denies it?

2.How should an application on a VM get cloud credentials?

3.What does "least privilege" mean?

4.An access key was pushed to a public GitHub repository. What's the first step?

← Accounts, billing alerts and the CLI