# STS, Assume Role and Federation

> Use temporary credentials everywhere: instance profiles, cross-account roles, and OIDC federation so GitHub Actions can deploy without stored keys. Free notes,...

Canonical: https://www.internhack.in/roadmaps/tracks/cloud-engineer/iam-roles-federation
Last updated: 2026-11-28

Use temporary credentials everywhere: instance profiles, cross-account roles, and OIDC federation so GitHub Actions can deploy without stored keys.

Intermediate · about 5 hours · difficulty 3/5

Learn first: [Policy Evaluation, Conditions and Resource Policies](https://www.internhack.in/roadmaps/tracks/cloud-engineer/iam-policy-evaluation), [Git and GitHub for Infrastructure Work](https://www.internhack.in/roadmaps/tracks/cloud-engineer/git-basics)

Long-term access keys are the number one way AWS accounts get compromised. The fix is temporary credentials from the **Security Token Service (STS)**.

### How assuming a role works

- A role has a **trust policy** (who may assume it) and **permission policies** (what it can do).
- A caller runs sts:AssumeRole and gets an access key, secret and session token that expire (15 minutes to 12 hours).
- Services like EC2 use an **instance profile**; ECS uses a **task role**; Lambda uses an **execution role**. The SDK picks these up automatically.

### Cross-account access

A role in a production account can trust a role in a tooling account. This is how companies separate dev, staging and prod into different accounts while letting a central pipeline deploy everywhere.

### Federation

- **IAM Identity Center** federates humans from a directory (Entra ID, Okta, Google Workspace) into AWS accounts with permission sets.
- **OIDC federation** lets external workloads assume roles without secrets. The most common example: a GitHub Actions workflow presents a signed token and AWS trusts it based on the repo and branch.
- **IAM Roles Anywhere** issues credentials to on-premises servers using X.509 certificates.

### Pitfalls

- A trust policy that allows any GitHub repository (missing the sub condition on repo and branch).
- Instance metadata exposed through SSRF bugs. Require **IMDSv2** on every EC2 instance.

You are ready to move on when you can configure a GitHub Actions workflow to assume an AWS role through OIDC and explain every line of its trust policy.

## Key concepts

- **STS and temporary credentials**
- **Trust policies**
- **Instance profiles, task roles, execution roles**
- **Cross-account roles**
- **GitHub Actions OIDC**
- **IAM Identity Center permission sets**
- **IMDSv2**
- **IAM Roles Anywhere**

## Mini project

Create an OIDC identity provider for GitHub and a role that only your cloud-notes repo's main branch can assume, with read-only S3 access. Add a workflow that runs aws sts get-caller-identity and aws s3 ls. This uses no billable resources; delete the role when finished.

## Check yourself

Why is GitHub OIDC federation safer than storing an access key as a GitHub secret, and what condition must the trust policy include?

## Free resources

- [IAM roles](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles.html) (AWS)
- [Configuring OpenID Connect in AWS (GitHub)](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/configuring-openid-connect-in-amazon-web-services) (GitHub)
- [configure-aws-credentials action](https://github.com/aws-actions/configure-aws-credentials) (AWS)

Previous: [Policy Evaluation, Conditions and Resource Policies](https://www.internhack.in/roadmaps/tracks/cloud-engineer/iam-policy-evaluation) · Next: [Multi-Account Strategy with AWS Organizations](https://www.internhack.in/roadmaps/tracks/cloud-engineer/organizations-scps)

## More in Identity and Access Management in Depth

- [IAM Users, Groups, Roles and Policies](https://www.internhack.in/roadmaps/tracks/cloud-engineer/iam-fundamentals)
- [Policy Evaluation, Conditions and Resource Policies](https://www.internhack.in/roadmaps/tracks/cloud-engineer/iam-policy-evaluation)
- [STS, Assume Role and Federation](https://www.internhack.in/roadmaps/tracks/cloud-engineer/iam-roles-federation)
- [Multi-Account Strategy with AWS Organizations](https://www.internhack.in/roadmaps/tracks/cloud-engineer/organizations-scps)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [Cloud Engineer (AWS) Roadmap](https://www.internhack.in/roadmaps/tracks/cloud-engineer)
