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.
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,Conditionand, 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-sandboxSSO 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
| Principal | What it is | Credentials | Who should use it at a bank |
|---|---|---|---|
| Root user | The identity created with the account (email + password) | Password, MFA; access keys are possible but must never exist | Nobody day to day. Break-glass only |
| IAM user | A long-lived identity defined inside one account | Console password and/or access keys (long-lived) | Almost never. Legacy integrations that cannot use roles, and even then reluctantly |
| IAM group | A collection of IAM users that share policies | None โ a group is not a principal and cannot sign requests | Only where IAM users still exist |
| IAM role | An identity with permissions but no permanent credentials; something must assume it | Temporary 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 session | The result of assuming a role: a temporary principal | Access key ID + secret + session token, with an expiry | This is what actually signs your requests |
| IAM Identity Center user | A workforce identity in Identity Center (or synced from Entra ID / Okta) | Browser sign-in + MFA; becomes a role session in each account | All 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:PutObjectvss3: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):
| Limit | Value |
|---|---|
| Size of one customer managed policy | 6,144 characters (whitespace not counted) |
| Inline policy total per role / user / group | 10,240 / 2,048 / 5,120 characters |
| Managed policies attached per role | 20 by default, can be raised to 25 |
| Managed policies attached per user | 10 by default, can be raised to 20 |
| Roles per account | 1,000 by default, can be raised to 10,000 |
| Role session duration | 15 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:*"includess3:DeleteBucketands3:PutBucketPolicy. Read the action list for each service in the Service Authorization Reference.
Microsoft / Azure comparison
| You know (Microsoft/Azure) | AWS equivalent | What's different |
|---|---|---|
| Entra ID user | IAM Identity Center user (workforce) | AWS IAM users also exist but are per-account and long-lived; humans should use Identity Center |
| Entra ID security group | Identity 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 scope | Attaching 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 secret | IAM user with access keys | Both are long-lived secrets; both are discouraged. Prefer roles + OIDC federation (GitHub Actions, Module 9) |
| Storage account access policy / container ACL | S3 bucket policy (resource-based policy) | Resource policies name a Principal and can grant cross-account access |
Azure Policy deny / management group guardrails | SCPs and RCPs in AWS Organizations | They cap permissions; they never grant |
| PIM eligible assignment | Separate permission set or role with short session | Just-in-time elevation needs extra tooling in AWS |
DefaultAzureCredential token from Entra ID | STS temporary credentials from a role session | AWS 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.
{
"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" }
}
}
]
}| Element | Meaning |
|---|---|
Version | The policy-language version. Always 2012-10-17; older versions lack features such as policy variables |
Statement | A list of rules. A policy can have one or many |
Sid | An optional label for humans and for tools. Use it to explain intent |
Effect | Allow or Deny |
Action | Which API actions, as service-prefix:ActionName. Wildcards allowed (s3:Get*) |
Resource | Which resources, as ARNs. Wildcards allowed |
Condition | Optional 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:
{
"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
| Type | Who maintains it | Reusable? | When to use |
|---|---|---|---|
AWS managed (arn:aws:iam::aws:policy/ReadOnlyAccess) | AWS; can change when services add actions | Yes, in every account | Starting 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 account | The normal choice for least privilege |
| Inline | You; embedded in one identity | No | A 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.
| ARN | Partition | Service | Region | Account | Resource |
|---|---|---|---|---|---|
arn:aws:s3:::hl-m01-statements-111122223333-a1b2c3 | aws | s3 | (empty โ bucket names are global) | (empty) | bucket name |
arn:aws:iam::111122223333:role/hl-m01-reader | aws | iam | (empty โ IAM is global) | 111122223333 | role path and name |
arn:aws:sts::111122223333:assumed-role/AWSReservedSSO_SandboxAdmin_0123abcd/alex.learner | aws | sts | (empty) | 111122223333 | role session |
arn:aws:kms:eu-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab | aws | kms | eu-west-2 | 111122223333 | key 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:
- 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.
- 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.
{
"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 action | Resource |
|---|---|---|
ListBucketsAsync | s3:ListAllMyBuckets | * (account level) |
PutBucketAsync | s3:CreateBucket | bucket |
PutBucketTaggingAsync / GetBucketTaggingAsync | s3:PutBucketTagging / s3:GetBucketTagging | bucket |
PutBucketEncryptionAsync | s3:PutEncryptionConfiguration | bucket |
PutPublicAccessBlockAsync | s3:PutBucketPublicAccessBlock | bucket |
PutBucketPolicyAsync | s3:PutBucketPolicy | bucket |
PutObjectAsync | s3:PutObject | object (bucket/*) |
ListObjectsV2Async | s3:ListBucket | bucket |
DeleteObjectAsync | s3:DeleteObject | object |
DeleteBucketAsync | s3:DeleteBucket | bucket |
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 tagsProject=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 theSandboxAdminrole โ Permissions tab. You will see the AWS managedAdministratorAccesspolicy. 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
PutObjectandDeleteBucket, 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-sandboxLine notes:
- PowerShell uses the backtick
`to continue a line; in CloudShell (bash) use\. simulate-custom-policyevaluates only the policy you pass in; it ignores SCPs and your real role.simulate-principal-policyuses 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,explicitDenyorimplicitDeny.
Infrastructure as Code
Both versions create the same customer managed policy, tagged per course conventions. Neither attaches it to anything.
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:
{
"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:
// 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:
"Version": "2012-10-17"โ the policy-language version. Never change it to today's date.- Statement
ListMyBucketsโs3:ListAllMyBucketsis an account-level action with no bucket ARN, so its resource must be*. It only reveals bucket names, not contents. - 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. s3:ListBucketsits here, not in the object statement, because listing objects is an operation on the bucket.- Statement
ManageLabStatementObjectsโ the/*suffix means "objects inside the bucket". A very common bug is grantings3:PutObjecton the bucket ARN without/*; the call then fails withAccessDenied. - There is no
s3:PutBucketAcl,s3:PutObjectAclors3:*. The app cannot make anything public, even by mistake.
The C# helper:
CredentialProfileStoreChainโ reads%USERPROFILE%\.aws\config;TryGetAWSCredentialsbuilds SSO credentials from the profile. TheAWSSDK.SSOandAWSSDK.SSOOIDCpackages must be referenced or SSO profiles fail at runtime.RegionEndpoint.USEast1โ IAM is a global service; its endpoint lives in us-east-1.SimulateCustomPolicyAsyncโ sends your policy text to IAM and asks for a decision per action/resource pair. Nothing is created or attached.response.EvaluationResults ?? []โ SDK for .NET v4 returnsnull(not an empty list) for missing collections, so guard it.PolicyEvaluationDecisionType.Allowedโ the SDK constant forallowed; the others areExplicitDenyandImplicitDeny.- Exit code
0or1โ 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:MultiFactorAuthPresentandaws:MultiFactorAuthAgecondition keys. - Watch
iam:PassRole. Being allowed to pass any role to a service is equivalent to having that role's permissions. Access Analyzer flagsiam:PassRolewithResource: "*"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:PutObjectonly understatements/in one bucket, and only with server-side encryption. - The customer portal has a separate role that may
s3:GetObjectbut 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:PrincipalOrgIDcondition 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 โAccessDeniedonPutObject. Object actions needbucket/*. - Granting
s3:*"to get it working" โ it is quick โ it includesPutBucketPolicyandDeleteBucket, 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
| Symptom | Likely cause | Fix |
|---|---|---|
AccessDenied ... because no identity-based policy allows the s3:PutObject action | Missing allow, or allow on the bucket ARN without /* | Add the action on arn:aws:s3:::bucket/* |
... with an explicit deny in a service control policy | An SCP (for example the Region guardrail) blocks it | Use an allowed Region or ask the organisation admin; adding allows will not help |
... with an explicit deny in a resource-based policy | The 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 action | Extend the boundary through the approved process |
InvalidClientTokenId or ExpiredToken | Not an IAM permissions problem: credentials are wrong or expired | aws sso login --profile learn-sandbox; remove stray AWS_ACCESS_KEY_ID variables |
MalformedPolicyDocument on create | Bad JSON, unknown action, or wrong ARN format | Run aws accessanalyzer validate-policy and read the finding |
| A change "does not work" for a few seconds | IAM eventual consistency | Retry 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 denied | Simulator input ignores a resource policy, boundary or condition context | Use 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-sandboxTerraform users run terraform destroy; CDK users run cdk destroy.
Exercises
- ๐ข Guided: Validate and simulate
hl-m01-statement-lab-policy.jsonwith the CLI commands above. Record the decision fors3:PutObject,s3:DeleteObjectands3:PutObjectAclon the statement object, and fors3:DeleteBucketonhl-prod-payments-archive. - ๐ก Challenge: Add a condition so
s3:CreateBucketis only allowed when the request goes tous-east-1, and sos3:PutObjectis only allowed over TLS. Prove both conditions withsimulate-custom-policyusing--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
s3:PutObject โ allowed and s3:DeleteObject โ allowed (statement ManageLabStatementObjects). s3:PutObjectAcl โ implicitDeny, because no statement mentions it โ default deny. s3:DeleteBucket on hl-prod-payments-archive โ implicitDeny, because that ARN does not match hl-m01-statements-*. validate-policy should return no errors; it may return no findings at all. Why: the policy only grants named actions on name-prefixed resources, so everything else falls through to the default deny.
Split s3:CreateBucket into its own statement with "Condition": { "StringEquals": { "aws:RequestedRegion": "us-east-1" } }, and move s3:PutObject into a statement with "Condition": { "Bool": { "aws:SecureTransport": "true" } }. Test with:
aws iam simulate-custom-policy --policy-input-list file://policy.json `
--action-names s3:CreateBucket --resource-arns "arn:aws:s3:::hl-m01-statements-test" `
--context-entries "ContextKeyName=aws:RequestedRegion,ContextKeyValues=eu-central-1,ContextKeyType=string" `
--query "EvaluationResults[].EvalDecision" --profile learn-sandboxExpect implicitDeny for eu-central-1 and allowed for us-east-1. Do the same with aws:SecureTransport as a boolean. Why: a condition that is not satisfied makes the allow statement not apply, so the request falls back to default deny. The TLS check is better as a deny in the bucket policy too, because identity policies only cover your own principals.
Do not grant s3:*. Read the full error message first: modern AWS access-denied messages say which type of policy caused it. Then check in this order: (1) Is the job using the expected role (CloudTrail event โ userIdentity.arn)? (2) Did an explicit deny appear โ a new SCP, a changed bucket policy (for example one requiring a specific encryption header or aws:PrincipalOrgID), or a permissions boundary? (3) Did the object key change so it no longer matches the allowed prefix? (4) Did the bucket name change so it no longer matches the ARN? Reply that you will fix the specific cause, and that s3:* would both fail to override an explicit deny and break least-privilege controls the bank must evidence. Why: most "nobody changed anything" IAM incidents are a change in a different policy layer.
Knowledge check
Answer: Denied. An explicit deny in any applicable policy always wins over any allow.
Answer: The trust policy (a resource-based policy on the role) says who may assume the role. The permission policies say what the resulting session may do.
Answer: It is an account-level action that does not act on a specific bucket, so there is no bucket ARN to scope it to.
Answer: No. SCPs (and RCPs, permissions boundaries and session policies) only set the maximum permissions. An identity or resource policy must still allow the action.
Answer: Policy validation, policy generation and external access analysis. Unused access analysis, internal access analysis and custom policy checks are charged.
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
A Harbourline Bank application running on Amazon EC2 needs to read objects from one S3 bucket. Which approach follows AWS best practice?
A. Create an IAM user, generate access keys and store them in appsettings.json
B. Attach an IAM role with a policy that allows s3:GetObject on that bucket to the instance
C. Use the root user's access keys in an environment variable
D. Make the bucket public and restrict it with obscure object names
Answer: B. A role provides temporary, automatically rotated credentials. A stores a long-lived secret in configuration. C uses the most powerful identity in the account. D exposes data publicly; obscurity is not access control.
A developer role has AdministratorAccess. The account is in an OU with an SCP that denies s3:DeleteBucket. The developer tries to delete a bucket in the account. What happens?
A. Allowed, because AdministratorAccess includes s3:*
B. Allowed, because the developer's identity policy is evaluated before SCPs
C. Denied, because the SCP's explicit deny overrides the identity-based allow
D. Denied only if the bucket policy also denies it
Answer: C. An explicit deny in an SCP applies to every principal in member accounts and overrides any allow. A and B ignore the deny-wins rule; order of evaluation does not let an allow beat a deny. D is wrong because one explicit deny is enough.
An application must upload files to s3://hl-prod-statements/statements/ and must not be able to read, delete or change permissions on any object. Which policy statement is most appropriate?
A. Allow s3:* on arn:aws:s3:::hl-prod-statements/*
B. Allow s3:PutObject on arn:aws:s3:::hl-prod-statements/statements/*
C. Allow s3:PutObject on arn:aws:s3:::hl-prod-statements
D. Allow s3:PutObject, s3:PutObjectAcl on arn:aws:s3:::hl-prod-statements/*
Answer: B. It grants only uploads, only under the required prefix. A grants reads, deletes and ACL changes. C uses the bucket ARN, which does not match object keys, so uploads would fail. D adds ACL changes the application must not have and widens the prefix.
A security team wants to identify IAM roles across their accounts that have permissions they have not used in 90 days, with minimum custom tooling. What should they use?
A. IAM Access Analyzer unused access analyzer B. IAM policy simulator C. AWS Trusted Advisor cost checks D. Amazon Inspector
Answer: A. The unused access analyzer reports unused roles, access keys, passwords and permissions (it is a paid feature). B tests hypothetical requests but does not report usage. C focuses on cost and other best-practice checks, not per-role permission usage. D scans workloads for software vulnerabilities.
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.jsonwith Access Analyzer and simulated it - I can explain why
s3:ListBucketuses the bucket ARN ands3:PutObjectusesbucket/* - If I created the optional policy, I deleted it and confirmed nothing tagged
Project=cea-labremains
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
- How IAM works
- Security best practices in IAM
- IAM JSON policy element reference
- Policy evaluation logic
- Identity-based policies and resource-based policies
- Managed policies and inline policies
- IAM roles and temporary security credentials
- Permissions boundaries
- ARNs
- IAM Access Analyzer, policy validation, policy generation and pricing
- IAM policy simulator
- Actions, resources and condition keys for Amazon S3
- IAM and STS quotas
- Related: Module 5 โ Security, SCS-C03 exam page
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.
AWS accounts and Organizations
Use AWS accounts as security, billing and quota boundaries, organise them with AWS Organizations and OUs, and choose the right organisation policy for a bank's guardrails.
The AWS Management Console
Sign in through IAM Identity Center, find your way around the console, use CloudShell, and build habits that stop wrong-Region and wrong-account mistakes.