iac.htora.dev · security templates

Home/Templates/Cloud access for pipelines and pods without stored keys

Cloud access for pipelines and pods without stored keys

Pipelines and pods prove who they are with short-lived tokens, so there is no cloud key to leak.

Terraform

Why bother

A cloud access key stored in a pipeline secret or a pod is a credential that never expires on its own and works from anywhere. Workload identity federation swaps it for a token the platform issues per run, which the cloud checks against a trust policy. The risk moves to that trust policy: one missing condition and any repository or any pod can assume the role.

How you know it worked

Run the pipeline with no cloud secrets stored anywhere. It still deploys, and the cloud audit log shows a federated identity naming the repository and branch.

How it works

1The pipeline or pod asks for a tokenfrom GitHub or its cluster2The cloud checks the trust policywhich repository, which branch, which service account3It gets short-lived credentialsvalid for this run only4The audit log names the workloadthe repository and branch, or the pod
Step by step, from the thing that happens to the result you want.

Set it up

Pick your platform, then open the level you want. Each level is complete on its own. Read the comments in the files as you go. Anything with a real consequence is explained on the line where it happens.

Terraform. IAM OIDC provider for GitHub Actions, and EKS Pod Identity

What you need first

  • An account where you can create IAM roles and OIDC providers.
  • The GitHub repository, and the branch or deployment environment allowed to deploy.
  • For the Standard pod role, an EKS cluster with the Pod Identity agent add-on installed.

What it creates

  • GitHub's OIDC provider in the account, or a lookup of the existing one (Standard)
  • A role only the named repository and branch can assume, read-only in the quick start
  • The policies you name, and an optional permissions boundary (Standard)
  • A role for one Kubernetes service account, tied to it by a Pod Identity association (Standard, optional)

The code

Quick startReadyone file, 110 lines
One file. GitHub's OIDC provider, a read-only role for one repository's main branch, and a ready workflow that proves it.
Change these first
  • repository = "your-org/your-repo" main.tf, line 18
Run it
  1. aws sts get-caller-identity
    Shows the account and role you are signed in as. Check it before every apply.
  2. terraform init
    Downloads the provider. Run it once per folder.
  3. terraform plan
    Shows what will be created. Changes nothing. Read it.
  4. terraform apply
    Shows the plan again and waits for you to type yes.
  5. terraform destroy
    When you have finished. If it refuses, How to undo it below explains why.
Download main.tf
Checks

Formatting passedValid passedLint passed

Security scan: 19 checks passed, and none flagged.

Last run 2026-10-02 with OpenTofu v1.12.6 against hashicorp/aws 6.66.0.

outcomes/workload-identity/aws/t0
main.tf
Open main.tf as plain text
StandardReadyfour files, 210 lines
Adds several branches or environments with wildcards refused, your own policies, a permissions boundary, reuse of an existing provider, and an optional role for one EKS service account through Pod Identity.
Change these first
  • allowed_subjects. GitHub token subjects allowed to assume the role. repo:org/repo:ref:refs/heads/main is one branch; repo:org/repo:environment:production is one deployment environment, which can require a reviewer in GitHub.
Run it
  1. aws sts get-caller-identity
    Shows the account and role you are signed in as. Check it before every apply.
  2. # terraform.tfvars
    allowed_subjects = ""
    Create this file beside the others and fill in your values. Terraform reads it on its own.
  3. terraform init
    Downloads the provider. Run it once per folder.
  4. terraform plan
    Shows what will be created. Changes nothing. Read it.
  5. terraform apply
    Shows the plan again and waits for you to type yes.
  6. terraform output verify
    Prints the commands that prove it worked.
Download all four files as a zip
Checks

Formatting passedValid passedLint passed

Security scan: 31 checks passed, and none flagged.

Last run 2026-10-02 with OpenTofu v1.12.6 against hashicorp/aws 6.66.0.

outcomes/workload-identity/aws/t1
main.tf
Open main.tf as plain text
outputs.tf
Open outputs.tf as plain text
variables.tf
Open variables.tf as plain text
versions.tf
Open versions.tf as plain text
HardenedReadysix files, 245 lines
Standard as a module. Plan rules refuse IAM users, access keys, or console passwords, a GitHub trust without an exact subject or audience, a wildcard principal, sessions over an hour, administrator policies attached. A daily plan reports drift, and the scan fails on any unexplained finding.
Change these first
  • allowed_subjects. GitHub token subjects allowed to assume the role. repo:org/repo:ref:refs/heads/main is one branch; repo:org/repo:environment:production is one deployment environment, which can require a reviewer in GitHub.
Run it
  1. aws sts get-caller-identity
    Shows the account and role you are signed in as. Check it before every apply.
  2. # terraform.tfvars
    allowed_subjects = ""
    Create this file beside the others and fill in your values. Terraform reads it on its own.
  3. terraform init
    Downloads the provider. Run it once per folder.
  4. terraform plan
    Shows what will be created. Changes nothing. Read it.
  5. terraform apply
    Shows the plan again and waits for you to type yes.
  6. terraform output verify
    Prints the commands that prove it worked.
Download all six files as a zip
Checks

Formatting passedValid passedLint passed

Security scan: 31 checks passed, and none flagged.

Last run 2026-10-02 with OpenTofu v1.12.6 against hashicorp/aws 6.66.0.

outcomes/workload-identity/aws/t2
.checkov.yml
Open .checkov.yml as plain text
guard.yml
Open guard.yml as plain text
main.tf
Open main.tf as plain text
outputs.tf
Open outputs.tf as plain text
variables.tf
Open variables.tf as plain text
versions.tf
Open versions.tf as plain text

How to check it worked

Run a workflow with id-token: write from the allowed branch, and aws sts get-caller-identity shows the role. From any other branch the sign-in is refused. The quick start prints a ready workflow with terraform output workflow.

What catches people

A trust policy that checks only the audience lets every repository on GitHub assume the role, because every workflow gets tokens from the same issuer. The subject condition is the control, and the Standard version refuses wildcards in the organisation or repository.

An account has one OIDC provider per URL. If one already exists, the quick start fails with EntityAlreadyExists. Standard can look up the existing one.

The workflow needs permissions: id-token: write. Without it GitHub issues no token, and the error talks about credentials, which sends people looking in the wrong place.

The pod role trusts the Pod Identity service across the account. Whoever can create Pod Identity associations can hand the role to any pod, so keep eks:CreatePodIdentityAssociation to a few people.

How to undo it

terraform destroy removes the role and the provider, and workflows using it fail on their next run. With create_oidc_provider set to false, the shared provider is left in place.

What it costs

Nothing. IAM roles and OIDC providers are free.

Good to know

  • GitHub's token subject names the branch, tag, pull request, or deployment environment the workflow ran in. An environment is the strongest choice, because GitHub can require a named reviewer before any job in it starts. A job that names an environment gets a subject naming the environment, with no branch in it, so allow that subject.
  • AWS records every federated sign-in in CloudTrail with the token's subject. On Google Cloud the same record needs Data Access logs on the IAM credentials API, which Standard switches on. Azure keeps token exchanges in the tenant's sign-in logs for seven days on Entra ID Free and 30 on P1 and P2, and Standard can export them. Oracle Cloud's audit log names the service user on every call, for 365 days.
  • Repositories created on GitHub after 15 July 2026 carry IDs in the token subject, repo:org@123456/repo@456789:ref:refs/heads/main, and older repositories can opt in. Every cloud here matches the subject exactly, so read it from a real token before writing it down. Each quick start's workflow prints it.

Registry 0.23.0. Built 2026-11-17.

Made by Habibullah Tora. Source on GitHub. Code under the MIT licence, writing under CC BY 4.0.