Skip to content
HoginHogin
Go back

AWS from scratch, part 2: IAM and PAM — Identity Center, permission sets and a life without eternal access keys

11 мин чтения

In part 1 we sealed root and split environments across member accounts. What remains is the most common source of incidents: people with IAM users and non-expiring access keys — in ~/.aws, in CI, in a terraform repo since 2021. Part 2 is about who enters AWS and how: Identity Center for people, roles for machines, hour-long sessions, and PAM practices — JIT elevation and audited break-glass.

Why now: in 2026 Identity Center grew up — February brought multi-region replication of the identity store, October brought network access controls, and AWS now describes governance automation — discovery and reporting over permission sets — in a dedicated post. What’s left is to stop handing out eternal keys.

Table of contents

Open Table of contents

Why the access key is a relic

An access key created “for a week” lives until someone deletes it by hand. It never expires, never rotates itself, and isn’t bound to a person or a device. Hence a whole class of incidents: the key migrates into a git repo, a laptop, CI, a script on a server — and every copy lives for years. A credential report on a grown-up account is a museum: keys of people who left, keys of services nobody remembers.

Worse: a leaked key is indistinguishable from a legitimate one. Everything it signs looks like normal traffic — neither GuardDuty nor a budget alarm can tell an attacker with a stolen key from your terraform.

An eternal access key vs an STS role session

The alternative has existed for years — STS: credentials are issued for a session and die with it. A leaked one-hour token is nearly worthless by the time anyone finds it. This isn’t “better key monitoring” — it’s the disappearance of the very artifact that can be lost.

Identity Center: one door for all people

IAM Identity Center (formerly AWS SSO) is the single entry point for humans: one portal, one MFA, one offboarding. The mechanics:

AWS-managed policies are a good start (ReadOnlyAccess covers 90% of daily work); custom ones get added surgically. The 2026 replication and network controls make the door fault-tolerant too: the central component of the scheme is no longer a SPOF.

Credentials for machines — also without keys

People are covered by Identity Center; everything else that reaches into AWS with credentials is services. Same rule: nobody stores an eternal secret.

People and machines all get temporary credentials — nobody holds an eternal key

Everyone gets their own lawful path to temporary credentials; eternal keys remain only where nobody bothered to look for them. Hunting them down is a separate step in the practical section.

The layered model of permissions

In part 1 we covered SCPs: permission is the intersection of the SCP chain and the IAM policy, and an SCP Allow grants nothing. Identity Center adds layers:

Effective rights = the intersection of SCP, permissions boundary and permission set

Each layer only narrows: “what’s possible at all” is set by denials at the top, “what’s possible for me” by the minimum at the bottom. The CLI has no call for a permission set boundary — the natural place is CloudFormation (AWS::SSO::PermissionSet, the PermissionsBoundary field).

JIT elevation and break-glass

PAM in AWS is not a separate product but a pattern of roles and permission sets:

Comparison in one table

IAM users with access keysIdentity Center + roles
Credentialsnon-expiring, in ~/.aws and CISTS tokens for 1–12 h
A leakworks until manually deletedthe session dies on its own
Offboardinghunt keys across all accountsdisable one user
MFAseparately in every accountonce, at the portal/IdP
Who can do whatcredential reports per accountpermission sets in one place
A key in a repothe company’s crown artifactdoesn’t exist as a class
Machinesthe same keys, “service” onesinstance profiles, IRSA, Roles Anywhere

What you need to close access in one evening

Prerequisites: part 1 done (organization, SCPs, accounts), AWS CLI v2, a Telegram bot for alerts.

1. Enable Identity Center. In the management account: console → IAM Identity Center → Enable, then immediately delegated administration — manage access from a dedicated identity account, not from management. Create an engineers group and attach your IdP if you have one.

2. A one-hour permission set:

PS_ARN=$(aws sso-admin create-permission-set \
  --instance-arn arn:aws:sso:::instance/ins-xxxx \
  --name engineer-readonly --session-duration "PT1H" \
  --query 'PermissionSet.PermissionSetArn' --output text)

aws sso-admin attach-managed-policy \
  --instance-arn arn:aws:sso:::instance/ins-xxxx \
  --permission-set-arn "$PS_ARN" \
  --managed-policy-arn "arn:aws:iam::aws:policy/ReadOnlyAccess"

aws sso-admin create-account-assignment \
  --instance-arn arn:aws:sso:::instance/ins-xxxx \
  --permission-set-arn "$PS_ARN" \
  --principal-id <group-id> --principal-type GROUP \
  --target-id 111122223333 --target-type AWS_ACCOUNT

Attach the boundary via CloudFormation as in the previous section. The client is one command — aws configure sso — yielding a profile with auto-refreshing tokens:

[profile prod-readonly]
sso_session = hogin
sso_account_id = 111122223333
sso_role_name = engineer-readonly
region = eu-central-1

[sso-session hogin]
sso_start_url = https://d-xxxx.awsapps.com/start
sso_region = eu-central-1
sso_registration_scopes = sso:account:access

3. A break-glass role with an alert. Trust policy (trust.json) — only from the security account, only with MFA:

{
  "Version": "2012-10-17",
  "Statement": [{
    "Effect": "Allow",
    "Principal": { "AWS": "arn:aws:iam::111122223333:root" },
    "Action": "sts:AssumeRole",
    "Condition": {
      "StringEquals": { "aws:PrincipalOrgID": "o-xxxx" },
      "Bool": { "aws:multifactorAuthPresent": "true" }
    }
  }]
}

Attach AdministratorAccess to the role. An EventBridge rule catches its use:

aws events put-rule --name break-glass-alert \
  --event-pattern '{"source":["aws.iam"],
    "detail-type":["AWS API Call via CloudTrail"],
    "detail":{"eventName":["AssumeRole"],
      "requestParameters":{"roleArn":[{"prefix":"arn:aws:iam::444455556666:role/break-glass"}]}}}'

The target is a small Lambda hitting the Bot API (code below), plus invoke permission:

import json, os, urllib.request

TOKEN, CHAT = os.environ["TG_TOKEN"], os.environ["TG_CHAT"]

def handler(event, _):
    who = event["detail"]["requestParameters"].get("roleSessionName", "?")
    text = f"⚠️ break-glass assumed by {who} in {event['detail']['awsRegion']}"
    urllib.request.urlopen(urllib.request.Request(
        f"https://api.telegram.org/bot{TOKEN}/sendMessage",
        data=json.dumps({"chat_id": CHAT, "text": text}).encode(),
        headers={"Content-Type": "application/json"}))
    return {"ok": True}

4. Hunt legacy keys. IAM Access Analyzer with unused-access analysis:

aws accessanalyzer create-analyzer --analyzer-name org-unused \
  --type ORGANIZATION \
  --configuration '{"UnusedAccessAnalysis":{"unusedAccessAge":90}}'

Findings — unused access keys, unused roles — first update-access-key --status Deactivate, a month of observation, then deletion.

5. SSM Session Manager instead of SSH. Give instances the AmazonSSMManagedInstanceCore role (the agent is already in AL2023 and Ubuntu AMIs), log sessions to S3/CloudWatch via the SSM-SessionManagerRunShell document, and drop ingress port 22 from the security group:

aws ssm update-document --name SSM-SessionManagerRunShell \
  --content file://session-prefs.json --document-version '$LATEST'
{
  "schemaVersion": "1.0",
  "description": "Session Manager logs to S3 and CloudWatch",
  "sessionType": "Standard_Stream",
  "inputs": {
    "s3BucketName": "company-ssm-logs",
    "s3KeyPrefix": "sessions",
    "s3EncryptionEnabled": true,
    "cloudWatchLogGroupName": "/aws/ssm/sessions"
  }
}

For EKS pods the same agent runs as a sidecar — a session into the pod without port 22 and without keys, logged like instance sessions.

How to verify

Every item is one command:

# eternal keys still present in the account
for u in $(aws iam list-users --query 'Users[].UserName' --output text); do
  aws iam list-access-keys --user-name "$u" \
    --query 'AccessKeyMetadata[].[UserName,AccessKeyId,Status]' --output text
done

# a permission set's duration
aws sso-admin describe-permission-set \
  --instance-arn arn:aws:sso:::instance/ins-xxxx \
  --permission-set-arn "$PS_ARN" \
  --query 'PermissionSet.[Name,SessionDuration]'

# unused findings
aws accessanalyzer list-findings --analyzer-arn "$ARN" \
  --filter '{"status":{"eq":["ACTIVE"]},"findingType":{"eq":["UnusedAccessKey"]}}'

And two live checks. First, a session without SSH: aws ssm start-session --target i-0abc… must open a shell and drop a log into the S3 bucket. Second, break-glass itself: assume the role by hand and make sure the Telegram message arrives within seconds. If it does, the loop is closed: the privilege exists, but it cannot be used invisibly.

Pitfalls

Where the series goes next

Part 3 — logs and detection: the CloudTrail organization trail, GuardDuty and Security Hub — how to notice what still leaks through. Part 4 — infrastructure protection: VPC isolation, KMS, Backup. Part 5 — the workload: EKS and RDS on a secured baseline, including the IRSA from this part.

Bottom line

Keys that never expire are the main source of AWS incidents: they get copied, forgotten and lost, and a stolen key’s usage is indistinguishable from legitimate work. Temporary credentials retire the whole class not by monitoring but by removing the artifact worth stealing: Identity Center for people, instance profiles and Roles Anywhere for machines, hour-long sessions, break-glass with an alert. The trade — one evening of setup and the habit of aws sso login instead of a Tab through ~/.aws. Next part: seeing what still leaks through — logs and detection.


Share this post:

Next Post
AWS from scratch, part 1: the account, root, MFA and Organizations — the foundation security starts with