EduFlow
AWS Cloud Foundations
0%

Section 2 · Identity and Security

Identity Center for People, Roles for Workloads

17 min3 min readPut in order

Lesson at a glance

Give people access through IAM Identity Center and code access through IAM roles, so that Lantern runs with no long-term access keys on laptops, servers or in Git.

  1. 1People: IAM Identity Center
  2. 2Workloads: roles, not keys
  3. 3The mistake that ends in a large bill

No video here — just the real thing: a written lesson, runnable examples, a quiz and practice.

Section one ended with one admin user for one person in one account. Lantern now has six volunteers, a dev account and a production account, a Lambda function and a nightly job on EC2. If every one of those needs an IAM user with access keys, you end up with a dozen long-lived secrets scattered across laptops and servers. This lesson removes nearly all of them.

People: IAM Identity Center

AWS IAM Identity Center is where your workforce signs in. Each person gets one identity, either in Identity Center’s built-in directory or synced from an identity provider such as Microsoft Entra ID, Okta or Google Workspace. They sign in once, with MFA, at an AWS access portal URL, and see every account they are allowed into.

What they can do in each account comes from permission sets: a named bundle of policies, such as DeveloperAccess or ReadOnly. When you assign “volunteer Rita, permission set DeveloperAccess, account lantern-dev”, Identity Center creates a matching IAM role in that account, and Rita’s session assumes it. Nobody has an IAM user; nobody has a long-term key.

Identity Center is designed to run with AWS Organizations, which groups Lantern’s accounts under one management account. Note one practical catch: on the Free account plan, joining an organisation upgrades the account to the Paid plan, so this is a step for when Lantern goes to production.

On the CLI, aws configure sso writes a profile, and aws sso login opens the browser to sign in:

~/.aws/config
[sso-session lantern]
sso_start_url = https://lantern.awsapps.com/start
sso_region = eu-west-1
sso_registration_scopes = sso:account:access

[profile lantern-dev]
sso_session = lantern
sso_account_id = 444455556666
sso_role_name = DeveloperAccess
region = eu-west-1
Terminal
aws sso login --sso-session lantern
aws sts get-caller-identity --profile lantern-dev

The Arn that comes back now reads assumed-role/AWSReservedSSO_DeveloperAccess_…/rita: a role session, not a user.

Workloads: roles, not keys

Code needs credentials too, and the answer is always a role that the platform assumes for you:

  • Lambda: every function has an execution role.
  • EC2: an instance profile delivers the role’s credentials through the instance metadata service.
  • Amazon ECS: a task role per task definition.
  • CI/CD outside AWS, such as GitHub Actions: an OpenID Connect identity provider in IAM, so the pipeline exchanges its own token for a role session.

A role always has two policies. The trust policy says who may assume it:

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

The permissions policy says what the role may do once assumed, written exactly like last lesson’s policies.

The Lambda service asks STS to assume the lantern-rsvp role. STS checks the trust policy and returns temporary credentials. The function code uses them to call DynamoDB, where IAM checks the role's permissions policy. Lambda rsvp function AWS STS checks trust policy DynamoDB checks permissions 1 AssumeRole 2 temp credentials 3 PutItem, signed
Lambda assumes its execution role, then calls DynamoDB with temporary credentials

Your code then contains no credentials at all. The AWS SDKs use a default credential chain that finds the role’s temporary credentials automatically:

rsvp/index.mjs
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";

// No keys here: the SDK finds the execution role's temporary credentials.
const client = new DynamoDBClient({});
// …handler code that calls client.send(…)

The mistake that ends in a large bill

Sometimes an access key is genuinely unavoidable, such as a third-party tool that only accepts keys. Then: one IAM user per tool, a least-privilege policy, a aws:SourceIp condition if the tool has fixed addresses, and rotation on a schedule.

Retiring an existing key is a careful sequence, because deleting a key that something still uses breaks production. Check when it was last used:

Terminal
aws iam get-access-key-last-used --access-key-id AKIAIOSFODNN7EXAMPLE

Once nothing has used it since the replacement went live, deactivate it first (reversible), wait, and delete it only when nothing has complained. A key you suspect has leaked is different: deactivate it immediately and investigate afterwards.

That completes identity. Section three puts it to work as you pick Lantern’s compute, storage, database and network.

Key takeaways

  • IAM Identity Center gives each person one sign-in, with MFA, to every account they need, and hands out short-term credentials through permission sets.
  • Workloads get permissions from roles, such as a Lambda execution role or an EC2 instance profile, and the AWS SDKs find those temporary credentials without any code.
  • A role has two policies; the trust policy says who may assume it, and the permissions policy says what it may then do.
  • Long-term access keys in code, config files or environment variables are one of the most common ways AWS accounts get compromised.
  • When retiring an access key, confirm it is unused with its last-used date, deactivate it, and only then delete it.

Further reading

Check your understanding

3 questions

Question 1 of 3

Lantern’s RSVP function must write to DynamoDB. How should it get credentials?

Question 2 of 3

A role’s permissions policy allows dynamodb:PutItem on the RSVP table, but EC2 instances fail to assume the role. Which policy is most likely wrong?

Question 3 of 3

Lantern now has separate dev and production accounts and six volunteers. What is the best way to give the volunteers console and CLI access?

Practice

Put in order

Retire the nightly job's access key

Lantern’s nightly export job runs on an EC2 instance and reads an access key from /etc/lantern/.env. The key has not leaked; you are replacing it with a role during a quiet week, without breaking the job. Put the steps in a safe order.

Use the arrow buttons to reorder.

  1. 1Deactivate the old access key and watch the next few runs.
  2. 2Run aws iam get-access-key-last-used after the next nightly run to confirm the old key is idle.
  3. 3Create a role with a trust policy for ec2.amazonaws.com and attach the permissions policy.
  4. 4Attach the role to the EC2 instance through an instance profile.
  5. 5Delete the old access key.
  6. 6Write a least-privilege permissions policy for exactly what the export job does.
  7. 7On the instance, run aws sts get-caller-identity and confirm the ARN is an assumed-role session.
  8. 8Remove the access key from /etc/lantern/.env and restart the job.