Skip to Content
Cloud Engineering Academy
1. Cloud Computing & AWS Fundamentals

IAM fundamentals

Read and write IAM policies, explain users, groups, roles and temporary credentials, and scope a least-privilege policy for the Module 1 lab.

beginnerโฑ 1 h 30 min๐ŸŸข FreeCLF-C02SAA-C03SCS-C03

Assumes: .NET 10 LTS ยท AWS SDK for .NET v4 (AWSSDK.IdentityManagement 4.1.x) ยท AWS CLI v2 ยท Region us-east-1. Verified against official sources on 2026-11-17.

Learning objectives

By the end of this lesson you can:

  • Name the kinds of principal in AWS (root user, IAM user, IAM role, role session, Identity Center user) and say which ones a bank lets humans use.
  • Explain the difference between authentication (who are you?) and authorization (are you allowed to do this?), and where each happens in AWS.
  • Read an IAM policy line by line: Version, Statement, Sid, Effect, Action, Resource, Condition and, in resource-based policies, Principal.
  • Predict whether a request is allowed, using the three core rules: default deny, explicit allow, explicit deny wins, plus the idea of permission caps (SCPs, permissions boundaries, session policies).
  • Explain how roles and AWS STS turn a sign-in into temporary credentials, and read an ARN.
  • Write a least-privilege policy for the Module 1 lab, validate it with IAM Access Analyzer, and test it with the IAM policy simulator.

Prerequisites

  • AWS accounts and Organizations โ€” you should know what an account and an SCP are
  • Secure your AWS account โ€” your root user is locked down and you sign in through IAM Identity Center
  • Tools: AWS CLI v2 with the learn-sandbox SSO profile; .NET 10 SDK for the optional C# snippet

Why this matters in banking

Picture a Harbourline Bank developer who needs to upload monthly statement files to one S3 bucket. The quickest fix is to attach AdministratorAccess to their role "for now". Six months later a dependency in their build pipeline is compromised. The attacker inherits administrator rights and copies every bucket in the account, including a data-platform bucket full of (fictional) customer transactions. The post-incident review asks three questions: Who could do what? Why did they have that much access? Where is the evidence?

Every one of those questions is an IAM question. Regulators and auditors expect a bank to show least privilege (people and systems have only the access they need), segregation of duties (no single person can both make and approve a change) and traceability (every action maps to a named identity). IAM is the AWS service that expresses all of that. If you can read and reason about IAM policies, you can answer an auditor; if you cannot, every other AWS skill is built on sand.

The idea in plain language

IAM (Identity and Access Management) answers one question for every single request sent to AWS: is this caller allowed to do this action, on this resource, right now?

  • An identity (also called a principal) is the "who": a person or a piece of software.
  • A policy is a JSON document that lists what is allowed or denied.
  • Every API call โ€” from the console, the CLI or your C# code โ€” is signed with credentials. AWS works out which principal signed it (authentication), then evaluates every policy that applies (authorization). If nothing explicitly allows the request, it is denied.

Analogy: IAM is Harbourline Bank's keycard system. Your badge proves who you are (authentication). Each door has a reader that checks a rulebook: "badges in the Payments team may open the Payments floor between 07:00 and 19:00" (authorization). Some rules come from head office and override everything: "nobody enters the vault room on a weekend" (an explicit deny). Visitors do not get a permanent badge; they get a day pass from reception that stops working at 18:00 (a role session with temporary credentials).

The principals you will meet

PrincipalWhat it isCredentialsWho should use it at a bank
Root userThe identity created with the account (email + password)Password, MFA; access keys are possible but must never existNobody day to day. Break-glass only
IAM userA long-lived identity defined inside one accountConsole password and/or access keys (long-lived)Almost never. Legacy integrations that cannot use roles, and even then reluctantly
IAM groupA collection of IAM users that share policiesNone โ€” a group is not a principal and cannot sign requestsOnly where IAM users still exist
IAM roleAn identity with permissions but no permanent credentials; something must assume itTemporary credentials from STS (15 minutes to 12 hours)Applications, AWS services (Lambda, ECS tasks), CI/CD pipelines, cross-account access, and humans via federation
Role sessionThe result of assuming a role: a temporary principalAccess key ID + secret + session token, with an expiryThis is what actually signs your requests
IAM Identity Center userA workforce identity in Identity Center (or synced from Entra ID / Okta)Browser sign-in + MFA; becomes a role session in each accountAll humans. This is what you set up in Module 0

The key insight: when you sign in through IAM Identity Center and pick SandboxAdmin in the sandbox account, you are not an IAM user in that account. You are a session of a role called something like AWSReservedSSO_SandboxAdmin_0123abcd. Run aws sts get-caller-identity --profile learn-sandbox and you will see an assumed-role ARN โ€” proof that you are using temporary credentials.

What problem the AWS service solves

IAM exists so that one AWS account can be shared by many people and many programs without sharing a password, and so that every action can be limited and traced.

What IAM gives you:

  • Fine-grained authorization on more than 400 services, down to individual actions (s3:PutObject vs s3:DeleteObject), individual resources (one bucket, one prefix) and conditions (only over TLS, only from one Region, only with MFA).
  • Temporary credentials through AWS STS, so nothing has to store a long-lived secret.
  • Federation with corporate directories through IAM Identity Center or SAML/OIDC.
  • Analysis tools: IAM Access Analyzer (policy validation, external-access findings, policy generation, unused-access findings) and the IAM policy simulator.
  • No charge. IAM itself, roles, users and policies cost nothing.

Limitations and sharp edges (verified against the IAM quotas page on 2026-11-17):

LimitValue
Size of one customer managed policy6,144 characters (whitespace not counted)
Inline policy total per role / user / group10,240 / 2,048 / 5,120 characters
Managed policies attached per role20 by default, can be raised to 25
Managed policies attached per user10 by default, can be raised to 20
Roles per account1,000 by default, can be raised to 10,000
Role session duration15 minutes to 12 hours (role setting decides the maximum; default 1 hour)

Other sharp edges:

  • IAM is eventually consistent. A change you just made can take a few seconds to apply everywhere. Do not put IAM changes on the hot path of an application.
  • Policy language is strict but silent. A typo in an action name (s3:PutObjects) does not fail when you save the policy in every tool; it simply never matches. Validate policies with Access Analyzer.
  • Wildcards are seductive. "Action": "s3:*" includes s3:DeleteBucket and s3:PutBucketPolicy. Read the action list for each service in the Service Authorization Reference.

Microsoft / Azure comparison

You know (Microsoft/Azure)AWS equivalentWhat's different
Entra ID userIAM Identity Center user (workforce)AWS IAM users also exist but are per-account and long-lived; humans should use Identity Center
Entra ID security groupIdentity Center group (or IAM group)Groups are not principals; you cannot put a group in a resource policy
Azure RBAC role definition (Storage Blob Data Contributor)IAM policy (AWS managed or customer managed)IAM policies are JSON with Allow/Deny statements; Azure role definitions list allowed actions and NotActions
Azure RBAC role assignment at a scopeAttaching a policy to a role, user or group; resource scope is inside the policy (Resource)In Azure the scope lives on the assignment; in AWS the scope lives in the policy document
Managed identity (system/user-assigned)IAM role assumed by a service (Lambda execution role, ECS task role, EC2 instance profile)Same idea: no secret in code. The SDK picks up the role automatically
Service principal with client secretIAM user with access keysBoth are long-lived secrets; both are discouraged. Prefer roles + OIDC federation (GitHub Actions, Module 9)
Storage account access policy / container ACLS3 bucket policy (resource-based policy)Resource policies name a Principal and can grant cross-account access
Azure Policy deny / management group guardrailsSCPs and RCPs in AWS OrganizationsThey cap permissions; they never grant
PIM eligible assignmentSeparate permission set or role with short sessionJust-in-time elevation needs extra tooling in AWS
DefaultAzureCredential token from Entra IDSTS temporary credentials from a role sessionAWS credentials are an access key + secret + session token, signed with SigV4

Architecture

From sign-in to an authorized API call

How AWS decides: policy evaluation for a request in one account

This is the simplified view you need for CLF-C02 and most SAA-C03 questions. The full logic in the policy evaluation logic page has extra rules โ€” for example, for some cross-account requests both the caller's account and the resource owner's account must allow the request, and resource policies naming a role session can allow access even without an identity-policy allow. Module 5 covers those cases.

Security-boundary view: an SCP is set by the organisation (outside the account) and caps every principal in the account except service-linked roles. A permissions boundary is set by an account administrator on one role or user to cap what it can ever be given. A session policy is passed when a session is created and caps that one session. None of these three ever grants anything; they only take away.

Policy anatomy

An identity-based policy

Identity-based policies attach to a user, group or role and describe what that identity may do.

example-identity-policy.json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "ReadStatementsOverTlsOnly",
      "Effect": "Allow",
      "Action": ["s3:GetObject"],
      "Resource": "arn:aws:s3:::hl-m01-statements-111122223333-a1b2c3/statements/*",
      "Condition": {
        "Bool": { "aws:SecureTransport": "true" }
      }
    }
  ]
}
ElementMeaning
VersionThe policy-language version. Always 2012-10-17; older versions lack features such as policy variables
StatementA list of rules. A policy can have one or many
SidAn optional label for humans and for tools. Use it to explain intent
EffectAllow or Deny
ActionWhich API actions, as service-prefix:ActionName. Wildcards allowed (s3:Get*)
ResourceWhich resources, as ARNs. Wildcards allowed
ConditionOptional extra tests on the request context: Region, TLS, tags, MFA age, source VPC, time

A resource-based policy

Resource-based policies attach to a resource (an S3 bucket, a KMS key, an SQS queue, a Lambda function) and must say who they apply to, with Principal. This is the TLS-only bucket policy the Module 1 lab puts on its bucket:

bucket-policy-tls-only.json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "DenyInsecureTransport",
      "Effect": "Deny",
      "Principal": "*",
      "Action": "s3:*",
      "Resource": [
        "arn:aws:s3:::hl-m01-statements-111122223333-a1b2c3",
        "arn:aws:s3:::hl-m01-statements-111122223333-a1b2c3/*"
      ],
      "Condition": {
        "Bool": { "aws:SecureTransport": "false" }
      }
    }
  ]
}

Notice that it only denies. It does not grant anyone access; it just guarantees that, whoever is allowed in by their identity policy, they can only arrive over HTTPS.

Managed vs inline

TypeWho maintains itReusable?When to use
AWS managed (arn:aws:iam::aws:policy/ReadOnlyAccess)AWS; can change when services add actionsYes, in every accountStarting points and job-function policies; often broader than you need
Customer managed (arn:aws:iam::111122223333:policy/hl-m01-statement-lab)You; versioned (up to 5 versions)Yes, within your accountThe normal choice for least privilege
InlineYou; embedded in one identityNoA strict one-to-one relationship you want deleted with the identity

Reading an ARN

An Amazon Resource Name identifies anything in AWS. The general shape is arn:partition:service:region:account-id:resource.

ARNPartitionServiceRegionAccountResource
arn:aws:s3:::hl-m01-statements-111122223333-a1b2c3awss3(empty โ€” bucket names are global)(empty)bucket name
arn:aws:iam::111122223333:role/hl-m01-readerawsiam(empty โ€” IAM is global)111122223333role path and name
arn:aws:sts::111122223333:assumed-role/AWSReservedSSO_SandboxAdmin_0123abcd/alex.learnerawssts(empty)111122223333role session
arn:aws:kms:eu-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890abawskmseu-west-2111122223333key ID

Other partitions exist (aws-cn for China, aws-us-gov for GovCloud). Account IDs here are AWS's documentation placeholders.

Roles and AWS STS

A role has two policies:

  1. A trust policy (a resource-based policy on the role) that says who may assume it, e.g. the Lambda service, another account, or a GitHub OIDC provider.
  2. One or more permission policies that say what the session may do.

When a trusted principal calls sts:AssumeRole (or a service does it on its behalf), STS returns temporary credentials. The SDK refreshes them automatically. Identity Center does exactly this for you behind the access portal.

trust-policy-lambda.json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": { "Service": "lambda.amazonaws.com" },
      "Action": "sts:AssumeRole"
    }
  ]
}

Why humans use Identity Center, not IAM users

  • No long-lived keys on laptops. IAM user access keys never expire unless you rotate them; leaked keys are the most common AWS breach pattern. Identity Center gives sessions of 1โ€“12 hours.
  • One identity, many accounts. Banks run dozens or hundreds of accounts. IAM users exist in one account each; Identity Center users get access to many accounts through permission sets.
  • Joiners, movers, leavers. When the identity source (for example Entra ID) disables a leaver, their AWS access stops. IAM users would have to be found and deleted in every account.
  • MFA in one place. Identity Center enforces MFA at sign-in for every account and role.

The IAM security best practices page puts federation with temporary credentials for humans at the top of its list.

Step-by-step implementation

You will write a least-privilege policy for the Module 1 lab app (labs/m01-hello-aws), validate it and test it โ€” without changing your own permissions.

List exactly what the app does

The lab's statement-demo command creates a bucket, tags it, turns on default encryption, blocks public access, attaches the TLS-only bucket policy, uploads statements/ACC-0000012345/2026-10.csv, lists objects, deletes the object, removes the bucket. cleanup lists your buckets and reads their tags to find leftovers. Each step maps to one IAM action:

SDK call (AWSSDK.S3 v4)IAM actionResource
ListBucketsAsyncs3:ListAllMyBuckets* (account level)
PutBucketAsyncs3:CreateBucketbucket
PutBucketTaggingAsync / GetBucketTaggingAsyncs3:PutBucketTagging / s3:GetBucketTaggingbucket
PutBucketEncryptionAsyncs3:PutEncryptionConfigurationbucket
PutPublicAccessBlockAsyncs3:PutBucketPublicAccessBlockbucket
PutBucketPolicyAsyncs3:PutBucketPolicybucket
PutObjectAsyncs3:PutObjectobject (bucket/*)
ListObjectsV2Asyncs3:ListBucketbucket
DeleteObjectAsyncs3:DeleteObjectobject
DeleteBucketAsyncs3:DeleteBucketbucket
GetCallerIdentityAsync (STS)none โ€” every principal may call itโ€”

Notice that the API name and the IAM action name are not always the same: ListObjectsV2 is authorized by s3:ListBucket, PutBucketEncryption by s3:PutEncryptionConfiguration, ListBuckets by s3:ListAllMyBuckets. Always check the S3 actions table.

Write the policy

Save the policy from the Complete code section as hl-m01-statement-lab-policy.json. It has three statements: one account-level list action, one set of bucket actions limited to bucket names starting with hl-m01-statements-, and one set of object actions limited to objects inside those buckets.

Validate the grammar with IAM Access Analyzer

Run aws accessanalyzer validate-policy (see AWS CLI). It reports errors (invalid JSON or actions), security warnings (for example iam:PassRole with *), warnings and suggestions. Policy validation is free.

Simulate the policy

Use aws iam simulate-custom-policy to ask "would this policy allow s3:PutObject on my statement object? Would it allow s3:DeleteBucket on somebody else's bucket?" You should see allowed for the first and implicitDeny for the second.

(Optional) Create it as a customer managed policy

If you want to keep it, create it in the sandbox account with the CLI, Terraform or CDK. In Module 5 you will attach it to a narrow Identity Center permission set and run the lab with that instead of SandboxAdmin.

AWS Console instructions

  • Create a policy: Console โ†’ IAM โ†’ Policies โ†’ Create policy โ†’ JSON tab. Paste the policy. The editor runs Access Analyzer policy validation as you type and lists findings under the editor. Choose Next, name it hl-m01-statement-lab, add the tags Project=cea-lab, Lab=m01-hello-aws, Environment=learn, Owner=<your-name>, then Create policy.
  • See what a role can do: IAM โ†’ Roles โ†’ search AWSReservedSSO โ†’ open the SandboxAdmin role โ†’ Permissions tab. You will see the AWS managed AdministratorAccess policy. You cannot edit this role directly โ€” Identity Center owns it; change the permission set instead.
  • Policy simulator: IAM โ†’ Policies โ†’ open your policy โ†’ Simulate opens the IAM policy simulator in a new tab. Pick service Amazon S3, actions PutObject and DeleteBucket, enter a resource ARN and choose Run simulation.
  • Access Analyzer: IAM โ†’ Access analyzer (left menu). Here you create analyzers and see findings. External access analyzers are free; unused access and internal access analyzers are paid (see Cost and cleanup).
  • Last accessed data: IAM โ†’ Roles โ†’ a role โ†’ Last Accessed tab shows which services the role actually used. This is the cheapest way to spot unused permissions.

AWS CLI

# 1. Who am I? Shows an "assumed-role" ARN when you use Identity Center. Needs no permissions.
aws sts get-caller-identity --profile learn-sandbox

# 2. Check the policy for errors and risky patterns (free).
#    --policy-type IDENTITY_POLICY because it will attach to a role/permission set.
aws accessanalyzer validate-policy `
  --policy-type IDENTITY_POLICY `
  --policy-document file://hl-m01-statement-lab-policy.json `
  --query "findings[].[findingType,issueCode,findingDetails]" --output table `
  --profile learn-sandbox

# 3. Simulate the policy WITHOUT attaching it to anyone.
#    Expect PutObject -> allowed, DeleteBucket on another bucket -> implicitDeny.
aws iam simulate-custom-policy `
  --policy-input-list file://hl-m01-statement-lab-policy.json `
  --action-names s3:PutObject s3:DeleteObject `
  --resource-arns "arn:aws:s3:::hl-m01-statements-111122223333-a1b2c3/statements/ACC-0000012345/2026-10.csv" `
  --query "EvaluationResults[].[EvalActionName,EvalDecision]" --output table `
  --profile learn-sandbox

aws iam simulate-custom-policy `
  --policy-input-list file://hl-m01-statement-lab-policy.json `
  --action-names s3:DeleteBucket `
  --resource-arns "arn:aws:s3:::hl-prod-payments-archive" `
  --query "EvaluationResults[].[EvalActionName,EvalDecision]" --output table `
  --profile learn-sandbox

# 4. Simulate what YOUR current role can do (all attached policies, real principal).
#    Replace the ARN with the role ARN (not the assumed-role ARN) from IAM -> Roles.
aws iam simulate-principal-policy `
  --policy-source-arn "arn:aws:iam::111122223333:role/aws-reserved/sso.amazonaws.com/AWSReservedSSO_SandboxAdmin_0123abcd" `
  --action-names s3:CreateBucket iam:CreateUser `
  --query "EvaluationResults[].[EvalActionName,EvalDecision]" --output table `
  --profile learn-sandbox

# 5. Optional: create the policy as a customer managed policy, tagged.
aws iam create-policy `
  --policy-name hl-m01-statement-lab `
  --policy-document file://hl-m01-statement-lab-policy.json `
  --tags Key=Project,Value=cea-lab Key=Lab,Value=m01-hello-aws Key=Environment,Value=learn Key=Owner,Value=alex `
  --profile learn-sandbox

Line notes:

  • PowerShell uses the backtick ` to continue a line; in CloudShell (bash) use \.
  • simulate-custom-policy evaluates only the policy you pass in; it ignores SCPs and your real role. simulate-principal-policy uses the real role's attached policies and, where applicable, Organizations policies โš  VERIFY (the simulator documents that it includes SCPs affecting the principal, but not resource-control policies).
  • Simulation results are allowed, explicitDeny or implicitDeny.

Infrastructure as Code

Both versions create the same customer managed policy, tagged per course conventions. Neither attaches it to anything.

iam-policy.tf
terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 6.0"
    }
  }
}

provider "aws" {
  region  = "us-east-1"
  profile = "learn-sandbox"

  default_tags {
    tags = {
      Project     = "cea-lab"
      Lab         = "m01-hello-aws"
      Environment = "learn"
      Owner       = "alex"
    }
  }
}

data "aws_iam_policy_document" "statement_lab" {
  statement {
    sid       = "ListMyBuckets"
    actions   = ["s3:ListAllMyBuckets"]
    resources = ["*"]
  }

  statement {
    sid = "ManageLabBuckets"
    actions = [
      "s3:CreateBucket",
      "s3:DeleteBucket",
      "s3:ListBucket",
      "s3:GetBucketTagging",
      "s3:PutBucketTagging",
      "s3:PutEncryptionConfiguration",
      "s3:GetEncryptionConfiguration",
      "s3:PutBucketPublicAccessBlock",
      "s3:GetBucketPublicAccessBlock",
      "s3:PutBucketPolicy",
      "s3:GetBucketPolicy",
      "s3:DeleteBucketPolicy",
    ]
    resources = ["arn:aws:s3:::hl-m01-statements-*"]
  }

  statement {
    sid       = "ManageLabStatementObjects"
    actions   = ["s3:PutObject", "s3:GetObject", "s3:DeleteObject"]
    resources = ["arn:aws:s3:::hl-m01-statements-*/*"]
  }
}

resource "aws_iam_policy" "statement_lab" {
  name        = "hl-m01-statement-lab"
  description = "Least-privilege policy for the Module 1 hello-aws lab"
  policy      = data.aws_iam_policy_document.statement_lab.json
}

output "policy_arn" {
  value = aws_iam_policy.statement_lab.arn
}

Run terraform init, terraform plan, terraform apply; remove with terraform destroy.

Complete code

The least-privilege policy for the Module 1 lab:

hl-m01-statement-lab-policy.json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "ListMyBuckets",
      "Effect": "Allow",
      "Action": "s3:ListAllMyBuckets",
      "Resource": "*"
    },
    {
      "Sid": "ManageLabBuckets",
      "Effect": "Allow",
      "Action": [
        "s3:CreateBucket",
        "s3:DeleteBucket",
        "s3:ListBucket",
        "s3:GetBucketTagging",
        "s3:PutBucketTagging",
        "s3:PutEncryptionConfiguration",
        "s3:GetEncryptionConfiguration",
        "s3:PutBucketPublicAccessBlock",
        "s3:GetBucketPublicAccessBlock",
        "s3:PutBucketPolicy",
        "s3:GetBucketPolicy",
        "s3:DeleteBucketPolicy"
      ],
      "Resource": "arn:aws:s3:::hl-m01-statements-*"
    },
    {
      "Sid": "ManageLabStatementObjects",
      "Effect": "Allow",
      "Action": [
        "s3:PutObject",
        "s3:GetObject",
        "s3:DeleteObject"
      ],
      "Resource": "arn:aws:s3:::hl-m01-statements-*/*"
    }
  ]
}

An optional C# helper that asks IAM to simulate the same policy, so you can turn "does my policy still work?" into an automated check:

SimulatePolicy.cs
// dotnet add package AWSSDK.IdentityManagement --version 4.1.1.2
// dotnet add package AWSSDK.SSO --version 4.1.0.2
// dotnet add package AWSSDK.SSOOIDC --version 4.1.0.2
using Amazon;
using Amazon.IdentityManagement;
using Amazon.IdentityManagement.Model;
using Amazon.Runtime.CredentialManagement;

var chain = new CredentialProfileStoreChain();
if (!chain.TryGetAWSCredentials("learn-sandbox", out var credentials))
{
    Console.Error.WriteLine("Profile learn-sandbox not found. Run: aws configure sso");
    return 2;
}

using var iam = new AmazonIdentityManagementServiceClient(credentials, RegionEndpoint.USEast1);

var policyJson = await File.ReadAllTextAsync("hl-m01-statement-lab-policy.json");
const string objectArn = "arn:aws:s3:::hl-m01-statements-111122223333-a1b2c3/statements/ACC-0000012345/2026-10.csv";

var response = await iam.SimulateCustomPolicyAsync(new SimulateCustomPolicyRequest
{
    PolicyInputList = [policyJson],
    ActionNames = ["s3:PutObject", "s3:DeleteObject", "s3:PutObjectAcl"],
    ResourceArns = [objectArn],
});

var failures = 0;
foreach (var result in response.EvaluationResults ?? [])
{
    Console.WriteLine($"{result.EvalActionName,-20} {result.EvalDecision}");
    var expectedAllowed = result.EvalActionName != "s3:PutObjectAcl";
    var isAllowed = result.EvalDecision == PolicyEvaluationDecisionType.Allowed;
    if (expectedAllowed != isAllowed) failures++;
}

Console.WriteLine(failures == 0 ? "Policy behaves as designed." : $"{failures} unexpected result(s).");
return failures == 0 ? 0 : 1;

Code explained line by line

The policy JSON:

  1. "Version": "2012-10-17" โ€” the policy-language version. Never change it to today's date.
  2. Statement ListMyBuckets โ€” s3:ListAllMyBuckets is an account-level action with no bucket ARN, so its resource must be *. It only reveals bucket names, not contents.
  3. Statement ManageLabBuckets โ€” bucket-level actions. arn:aws:s3:::hl-m01-statements-* matches any bucket whose name begins with that prefix (the lab appends your account ID and random hex). Bucket ARNs have no Region or account part.
  4. s3:ListBucket sits here, not in the object statement, because listing objects is an operation on the bucket.
  5. Statement ManageLabStatementObjects โ€” the /* suffix means "objects inside the bucket". A very common bug is granting s3:PutObject on the bucket ARN without /*; the call then fails with AccessDenied.
  6. There is no s3:PutBucketAcl, s3:PutObjectAcl or s3:*. The app cannot make anything public, even by mistake.

The C# helper:

  1. CredentialProfileStoreChain โ€” reads %USERPROFILE%\.aws\config; TryGetAWSCredentials builds SSO credentials from the profile. The AWSSDK.SSO and AWSSDK.SSOOIDC packages must be referenced or SSO profiles fail at runtime.
  2. RegionEndpoint.USEast1 โ€” IAM is a global service; its endpoint lives in us-east-1.
  3. SimulateCustomPolicyAsync โ€” sends your policy text to IAM and asks for a decision per action/resource pair. Nothing is created or attached.
  4. response.EvaluationResults ?? [] โ€” SDK for .NET v4 returns null (not an empty list) for missing collections, so guard it.
  5. PolicyEvaluationDecisionType.Allowed โ€” the SDK constant for allowed; the others are ExplicitDeny and ImplicitDeny.
  6. Exit code 0 or 1 โ€” so the check can run in a CI pipeline (Module 9).

Security considerations

  • Least privilege is a process, not a one-off. Start from the actions the code calls, add conditions, then tighten with IAM last-accessed data and, in production, Access Analyzer unused-access findings.
  • Prefer roles and temporary credentials everywhere. Applications on AWS get a role (Lambda execution role, ECS task role); pipelines use OIDC federation; humans use Identity Center.
  • Explicit denies for things that must never happen. TLS-only bucket policies, SCPs that stop anyone disabling CloudTrail, permissions boundaries for roles developers can create.
  • MFA for every human, enforced at Identity Center sign-in. For extra-sensitive actions IAM supports the aws:MultiFactorAuthPresent and aws:MultiFactorAuthAge condition keys.
  • Watch iam:PassRole. Being allowed to pass any role to a service is equivalent to having that role's permissions. Access Analyzer flags iam:PassRole with Resource: "*" as a security warning.
  • Audit: every IAM and STS call is recorded by AWS CloudTrail (Module 5 and Module 11).

โš  Learning shortcut โ€” not for production

You run the lab as SandboxAdmin, which has AdministratorAccess. The least-privilege policy in this lesson is only validated and simulated, not used. In a bank, the lab app would run under a role (or permission set) holding only hl-m01-statement-lab, created through a reviewed pull request, with a permissions boundary so the role can never be widened beyond an approved ceiling. Module 5 makes that switch.

โš  Learning shortcut โ€” not for production

The bucket-name wildcard hl-m01-statements-* lets the app manage any bucket with that prefix, including one created by another learner in the same account. Production policies pin the exact bucket ARN (or use tag-based conditions, called ABAC) and keep each workload in its own account.

Banking use case

Harbourline Bank's statement service generates monthly PDF and CSV statements for retail customers (all fictional in this course). The design review requires:

  • The statement generator (an ECS task in Module 3) has a task role that may s3:PutObject only under statements/ in one bucket, and only with server-side encryption.
  • The customer portal has a separate role that may s3:GetObject but never write or delete.
  • Operations engineers sign in through Identity Center with a read-only permission set for production; a break-glass permission set with write access requires a ticket and is alarmed.
  • A bucket policy denies non-TLS access and denies access from outside the bank's organisation using the aws:PrincipalOrgID condition key.
  • Access Analyzer external-access findings are reviewed weekly; any bucket shared outside the organisation is a security incident.

None of this makes the service compliant by itself. The bank's information-security, data-protection (UK GDPR) and audit teams still review the design, decide retention rules and approve who may read statements.

Common mistakes

  • Using "Resource": "arn:aws:s3:::bucket" for object actions โ†’ bucket and object ARNs look alike โ†’ AccessDenied on PutObject. Object actions need bucket/*.
  • Granting s3:* "to get it working" โ†’ it is quick โ†’ it includes PutBucketPolicy and DeleteBucket, so one bug can make data public or delete it. Grant named actions.
  • Creating IAM users with access keys for developers โ†’ old tutorials do it โ†’ keys leak into Git and backups. Use Identity Center and aws sso login.
  • Assuming a group can be a principal โ†’ Azure lets you assign roles to groups at any scope โ†’ in AWS you cannot name an IAM group in a bucket policy or trust policy.
  • Forgetting that an explicit deny anywhere wins โ†’ people add more allows to fix a deny โ†’ nothing changes. Find the deny (SCP, bucket policy, boundary) instead.
  • Editing the AWSReservedSSO_โ€ฆ role directly โ†’ it looks like any other role โ†’ Identity Center overwrites it. Change the permission set.
  • Trusting the console's "this policy is valid" as "this policy is safe" โ†’ validation checks grammar and some risky patterns, not intent. Simulate and test.

Troubleshooting

SymptomLikely causeFix
AccessDenied ... because no identity-based policy allows the s3:PutObject actionMissing allow, or allow on the bucket ARN without /*Add the action on arn:aws:s3:::bucket/*
... with an explicit deny in a service control policyAn SCP (for example the Region guardrail) blocks itUse an allowed Region or ask the organisation admin; adding allows will not help
... with an explicit deny in a resource-based policyThe bucket policy denies it (for example plain HTTP)Check the bucket policy conditions; make sure the client uses HTTPS
... because no permissions boundary allows ...The role has a permissions boundary that does not include the actionExtend the boundary through the approved process
InvalidClientTokenId or ExpiredTokenNot an IAM permissions problem: credentials are wrong or expiredaws sso login --profile learn-sandbox; remove stray AWS_ACCESS_KEY_ID variables
MalformedPolicyDocument on createBad JSON, unknown action, or wrong ARN formatRun aws accessanalyzer validate-policy and read the finding
A change "does not work" for a few secondsIAM eventual consistencyRetry after a short wait; never create and use a role in the same millisecond in production code
Simulator says allowed but the real call is deniedSimulator input ignores a resource policy, boundary or condition contextUse simulate-principal-policy with context entries, or read the full error message โ€” newer AWS error messages name the policy type that denied

Cost and cleanup

Cost: $0. IAM, STS, the policy simulator, Access Analyzer policy validation, policy generation and external access analysis have no charge. Two Access Analyzer features are charged (verified on the IAM Access Analyzer pricing page on 2026-11-17): unused access analysis at USD 0.20 per IAM role or user analysed per month, internal access analysis at USD 9.00 per monitored resource per Region per month, and custom policy checks at USD 0.0020 per API call. Do not create those analyzers in this lesson.

If you created the optional policy, remove it:

# Find the policy ARN, then delete it (it must not be attached to anything).
aws iam list-policies --scope Local --query "Policies[?PolicyName=='hl-m01-statement-lab'].Arn" --output text --profile learn-sandbox
aws iam delete-policy --policy-arn arn:aws:iam::111122223333:policy/hl-m01-statement-lab --profile learn-sandbox

# Confirm no customer managed policy with the lab name is left (should print nothing).
aws iam list-policies --scope Local --query "Policies[?starts_with(PolicyName, 'hl-m01')].PolicyName" --output text --profile learn-sandbox

# Course-wide check for anything else still tagged Project=cea-lab in this Region.
aws resourcegroupstaggingapi get-resources --tag-filters Key=Project,Values=cea-lab --region us-east-1 --profile learn-sandbox

Terraform users run terraform destroy; CDK users run cdk destroy.

Exercises

  • ๐ŸŸข Guided: Validate and simulate hl-m01-statement-lab-policy.json with the CLI commands above. Record the decision for s3:PutObject, s3:DeleteObject and s3:PutObjectAcl on the statement object, and for s3:DeleteBucket on hl-prod-payments-archive.
  • ๐ŸŸก Challenge: Add a condition so s3:CreateBucket is only allowed when the request goes to us-east-1, and so s3:PutObject is only allowed over TLS. Prove both conditions with simulate-custom-policy using --context-entries.
  • ๐Ÿ”ด Live problem: A ticket from the Harbourline statements team says: "Since this morning our job gets AccessDenied writing to hl-m01-statements-โ€ฆ/statements/ACC-0000012345/2026-11.csv. Nobody changed our role. Please just give us s3:* so we can hit the deadline." Decide what you would check, in what order, and what you would reply.

Assignment

In your learning-journal repository, add iam/hl-m01-statement-lab-policy.json and a iam/README.md that contains: a table mapping each SDK call in the lab to its IAM action and resource ARN, the output of validate-policy (no findings, or each finding explained), and the simulation results. Add one paragraph on how you would attach this policy to a dedicated Identity Center permission set in a real bank.

Solutions

Knowledge check

Interview questions

  • "Explain IAM policy evaluation in one minute." โ€” Everything starts denied. AWS collects every applicable policy. Any explicit deny ends it. Then every guardrail that applies โ€” SCPs, RCPs, permissions boundaries, session policies โ€” must allow it. Finally an identity-based or resource-based policy must explicitly allow it. Cross-account access needs both sides to agree.
  • "How do you give an application on AWS access to S3 without storing keys?" โ€” Give the compute an IAM role (Lambda execution role, ECS task role, EC2 instance profile). The SDK's default credential chain picks up temporary credentials automatically and refreshes them.
  • "How would you find over-privileged roles?" โ€” IAM last-accessed data per role, Access Analyzer unused-access findings (paid) and policy generation from CloudTrail activity, then tighten through reviewed IaC changes.
  • "Why not IAM users for developers?" โ€” Long-lived credentials, per-account identities and manual leaver processes. Identity Center federated from the corporate IdP gives MFA, short sessions and central joiner/mover/leaver control.

Certification practice

Completion checklist

  • I can name each principal type and say which ones humans should use
  • I can read every element of an IAM policy and explain default deny, explicit allow and explicit deny
  • I validated hl-m01-statement-lab-policy.json with Access Analyzer and simulated it
  • I can explain why s3:ListBucket uses the bucket ARN and s3:PutObject uses bucket/*
  • If I created the optional policy, I deleted it and confirmed nothing tagged Project=cea-lab remains

Key takeaways

  • Every AWS request is authenticated (who signed it) and then authorized against every applicable policy.
  • Default deny, explicit allow, explicit deny wins. SCPs, RCPs, permissions boundaries and session policies only cap permissions.
  • Roles plus STS give temporary credentials; humans use IAM Identity Center, applications use roles, nobody uses long-lived keys.
  • Least privilege means named actions on specific ARNs, with conditions โ€” validated with Access Analyzer and tested with the simulator.
  • API names and IAM action names differ; the Service Authorization Reference is the source of truth.

Further reading

Independent learning resource โ€” not affiliated with, endorsed or sponsored by Amazon Web Services. AWS and related marks are trademarks of Amazon.com, Inc. or its affiliates. All banking data in examples is fictional. Sample architectures are for learning and are not automatically compliant with GDPR, PCI DSS or any banking regulation.

On this page