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.
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
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 startReady
repository = "your-org/your-repo"main.tf, line 18
aws sts get-caller-identity
Shows the account and role you are signed in as. Check it before every apply.terraform init
Downloads the provider. Run it once per folder.terraform plan
Shows what will be created. Changes nothing. Read it.terraform apply
Shows the plan again and waits for you to type yes.terraform destroy
When you have finished. If it refuses, How to undo it below explains why.
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.
Open main.tf as plain text
StandardReady
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.
aws sts get-caller-identity
Shows the account and role you are signed in as. Check it before every apply.# terraform.tfvars allowed_subjects = ""
Create this file beside the others and fill in your values. Terraform reads it on its own.terraform init
Downloads the provider. Run it once per folder.terraform plan
Shows what will be created. Changes nothing. Read it.terraform apply
Shows the plan again and waits for you to type yes.terraform output verify
Prints the commands that prove it worked.
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.
Open main.tf as plain text
Open outputs.tf as plain text
Open variables.tf as plain text
Open versions.tf as plain text
HardenedReady
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.
aws sts get-caller-identity
Shows the account and role you are signed in as. Check it before every apply.# terraform.tfvars allowed_subjects = ""
Create this file beside the others and fill in your values. Terraform reads it on its own.terraform init
Downloads the provider. Run it once per folder.terraform plan
Shows what will be created. Changes nothing. Read it.terraform apply
Shows the plan again and waits for you to type yes.terraform output verify
Prints the commands that prove it worked.
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.
Open .checkov.yml as plain text
Open guard.yml as plain text
Open main.tf as plain text
Open outputs.tf as plain text
Open variables.tf as plain text
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.
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.
Terraform. Microsoft Entra workload identity federation on a managed identity, and AKS workload identity
What you need first
- A subscription and resource group where you can create a managed identity (Managed Identity Contributor) and role assignments (User Access Administrator or Owner on the scopes you grant). No Entra directory role is needed.
- The GitHub repository, and the branch or deployment environment allowed to deploy.
- For the Standard AKS credential, a cluster with its OIDC issuer and workload identity enabled.
- For the Standard sign-in log export, Security Administrator in the tenant and a Log Analytics workspace.
What it creates
- A user-assigned managed identity, which cannot have a secret or certificate
- A federated credential per allowed subject, trusting GitHub's issuer and the api://AzureADTokenExchange audience, each an exact match
- The Reader role on the resource group in the quick start, and the role assignments you name in Standard, each at a scope inside one resource group
- A federated credential for one AKS service account (Standard, optional)
- A tenant diagnostic setting sending service principal and managed identity sign-in logs to your workspace (Standard, optional)
The code
Quick startReady
subscription_id = "00000000-0000-0000-0000-000000000000"main.tf, line 21resource_group_name = "rg-deploy"main.tf, line 22repository = "your-org/your-repo"main.tf, line 23
az login
Signs the command line tool in. Terraform uses the same sign-in.export ARM_SUBSCRIPTION_ID=$(az account show --query id -o tsv)
Tells the provider which subscription. It stopped guessing in version 4.terraform init
Downloads the provider. Run it once per folder.terraform plan
Shows what will be created. Changes nothing. Read it.terraform apply
Shows the plan again and waits for you to type yes.terraform destroy
When you have finished. If it refuses, How to undo it below explains why.
Formatting passedValid passedLint passed
Security scan: zero checks passed, and none flagged.
Last run 2026-10-02 with OpenTofu v1.12.6 against hashicorp/azurerm 5.6.0.
Open main.tf as plain text
StandardReady
subscription_id. Subscription containing the identity and the resources it deploys to.resource_group_name. Resource group the identity lives in. Role assignments below may point at any resource group in the subscription, or anything inside one.repository. The GitHub repository allowed to sign in, as org/repo. Used in names and descriptions.allowed_subjects. GitHub token subjects allowed to sign in, matched exactly. 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. A repository created after 15 July 2026 carries IDs: repo:org@123456/repo@456789:ref:refs/heads/main. Read the value from a real token; the verify output shows how. At most 20.
az login
Signs the command line tool in. Terraform uses the same sign-in.export ARM_SUBSCRIPTION_ID=$(az account show --query id -o tsv)
Tells the provider which subscription. It stopped guessing in version 4.# terraform.tfvars subscription_id = "" resource_group_name = "" repository = "" allowed_subjects = ""
Create this file beside the others and fill in your values. Terraform reads it on its own.terraform init
Downloads the provider. Run it once per folder.terraform plan
Shows what will be created. Changes nothing. Read it.terraform apply
Shows the plan again and waits for you to type yes.terraform output verify
Prints the commands that prove it worked.
Formatting passedValid passedLint passed
Security scan: zero checks passed, and none flagged.
Last run 2026-10-02 with OpenTofu v1.12.6 against hashicorp/azurerm 5.6.0.
Open main.tf as plain text
Open outputs.tf as plain text
Open variables.tf as plain text
Open versions.tf as plain text
HardenedReady
subscription_id. Subscription containing the identity and the resources it deploys to.resource_group_name. Resource group the identity lives in. Role assignments below may point at any resource group in the subscription, or anything inside one.repository. The GitHub repository allowed to sign in, as org/repo. Used in names and descriptions.allowed_subjects. GitHub token subjects allowed to sign in, matched exactly. 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. A repository created after 15 July 2026 carries IDs: repo:org@123456/repo@456789:ref:refs/heads/main. Read the value from a real token; the verify output shows how. At most 20.
az login
Signs the command line tool in. Terraform uses the same sign-in.export ARM_SUBSCRIPTION_ID=$(az account show --query id -o tsv)
Tells the provider which subscription. It stopped guessing in version 4.# terraform.tfvars subscription_id = "" resource_group_name = "" repository = "" allowed_subjects = ""
Create this file beside the others and fill in your values. Terraform reads it on its own.terraform init
Downloads the provider. Run it once per folder.terraform plan
Shows what will be created. Changes nothing. Read it.terraform apply
Shows the plan again and waits for you to type yes.terraform output verify
Prints the commands that prove it worked.
Formatting passedValid passedLint passed
Security scan: zero checks passed, and none flagged.
Last run 2026-10-02 with OpenTofu v1.12.6 against hashicorp/azurerm 5.6.0.
Open .checkov.yml as plain text
Open guard.yml as plain text
Open main.tf as plain text
Open outputs.tf as plain text
Open variables.tf as plain text
Open versions.tf as plain text
How to check it worked
Run a workflow with id-token: write and azure/login@v2 from the allowed branch, and az commands succeed as the identity. From any other branch the sign-in fails with AADSTS70021, no matching federated identity record. The quick start prints a ready workflow with terraform output workflow, and the workflow prints the token's subject first.
Entra accepts a wrong subject at creation and refuses the exchange later, with no error on the credential itself. Check the subject against a real token; the workflow prints it.
There is no wildcard. One credential per branch or environment, and at most 20 per identity. Standard makes one per allowed subject.
A managed identity needs no Entra directory role to create, and nothing can add a secret to it. An app registration can have a secret added later, and in tenants that restrict app registration it needs Application Administrator, so this template uses the managed identity.
Adding a credential to a managed identity lands in the Azure activity log, while adding one to an app registration lands in the Entra audit log. Alerting on new credentials must watch both.
The AKS credential's subject is system:serviceaccount:<namespace>:<name>. Anyone who can run a pod with that service account in that namespace can act as the identity, so keep the namespace's RBAC tight.
The sign-in log export is one setting for the whole tenant. If another tool manages Entra diagnostic settings, leave sign_in_log_workspace_id empty and add the two categories there.
How to undo it
terraform destroy removes the identity, its credentials, and its role assignments. Workflows and pods using it fail on their next run. The diagnostic setting is removed too, which stops the export of every service principal sign-in in the tenant.
What it costs
Nothing for the identity, the credentials, or the token exchanges. Exported sign-in logs are billed by the workspace's ingestion volume.
Terraform. Workload Identity Federation for GitHub, and GKE Workload Identity
What you need first
- A project where you can create service accounts, workload identity pools, and IAM bindings.
- The GitHub repository allowed to deploy.
- For the Standard GKE binding, a cluster with Workload Identity turned on.
What it creates
- A workload identity pool, with a GitHub provider that accepts only the named repository and branch
- A service account that repository may act as, with the Browser role in the quick start
- The roles you name (Standard)
- A binding that lets one GKE service account act as it (Standard, optional)
- Data Access logging on the IAM credentials API, so every token minted is recorded (Standard)
The code
Quick startReady
project_id = "your-project-id"main.tf, line 16repository = "your-org/your-repo"main.tf, line 17
gcloud auth application-default login
The sign-in Terraform reads. A plain gcloud auth login is not enough.terraform init
Downloads the provider. Run it once per folder.terraform plan
Shows what will be created. Changes nothing. Read it.terraform apply
Shows the plan again and waits for you to type yes.terraform destroy
When you have finished. If it refuses, How to undo it below explains why.
Formatting passedValid passedLint passed
Security scan: six checks passed, and one rule flagged, each with a written reason:
Last run 2026-10-02 with OpenTofu v1.12.6 against hashicorp/google 8.4.0.
Open main.tf as plain text
StandardReady
project_id. Project containing the pool, the service account, and the resources it deploys to.repository. The GitHub repository allowed to sign in, as org/repo.allowed_subjects. GitHub token subjects allowed to sign in. 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.
gcloud auth application-default login
The sign-in Terraform reads. A plain gcloud auth login is not enough.# terraform.tfvars project_id = "" repository = "" allowed_subjects = ""
Create this file beside the others and fill in your values. Terraform reads it on its own.terraform init
Downloads the provider. Run it once per folder.terraform plan
Shows what will be created. Changes nothing. Read it.terraform apply
Shows the plan again and waits for you to type yes.terraform output verify
Prints the commands that prove it worked.
Formatting passedValid passedLint passed
Security scan: six checks passed, and one rule flagged, each with a written reason:
Last run 2026-10-02 with OpenTofu v1.12.6 against hashicorp/google 8.4.0.
Open main.tf as plain text
Open outputs.tf as plain text
Open variables.tf as plain text
Open versions.tf as plain text
HardenedReady
project_id. Project containing the pool, the service account, and the resources it deploys to.repository. The GitHub repository allowed to sign in, as org/repo.allowed_subjects. GitHub token subjects allowed to sign in. 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.
gcloud auth application-default login
The sign-in Terraform reads. A plain gcloud auth login is not enough.# terraform.tfvars project_id = "" repository = "" allowed_subjects = ""
Create this file beside the others and fill in your values. Terraform reads it on its own.terraform init
Downloads the provider. Run it once per folder.terraform plan
Shows what will be created. Changes nothing. Read it.terraform apply
Shows the plan again and waits for you to type yes.terraform output verify
Prints the commands that prove it worked.
Formatting passedValid passedLint passed
Security scan: six checks passed, and none flagged.
Last run 2026-10-02 with OpenTofu v1.12.6 against hashicorp/google 8.4.0.
Open .checkov.yml as plain text
Open guard.yml as plain text
Open main.tf as plain text
Open outputs.tf as plain text
Open variables.tf as plain text
Open versions.tf as plain text
How to check it worked
Run a workflow with id-token: write and google-github-actions/auth from the allowed branch, and gcloud commands succeed as the service account. From any other branch the token exchange is refused. The quick start prints a ready workflow with terraform output workflow.
The attribute condition is the control. Without it, any repository on GitHub can present a token to the pool, and only the service account binding stands in the way.
A deleted pool keeps its ID for 30 days, so both levels add a random suffix. Without one, a destroy followed by an apply fails with the ID already in use.
Token minting is a Data Access log on the IAM credentials API, and those are off by default. Standard switches it on. Without it, nobody can say which workflow or pod acted as the service account.
The Standard audit setting owns that one API's audit configuration for the whole project. If another tool manages it, merge the two first.
How to undo it
terraform destroy removes the binding, the service account, and the provider, and soft-deletes the pool for 30 days. Workflows using it fail on their next run.
What it costs
Nothing for federation. Data Access logs are billed by volume beyond the free allowance, and token records are small.
Terraform. Identity domain token exchange for GitHub Actions, and OKE workload identity
What you need first
- An identity domain where you can create applications, users, groups, and identity propagation trusts (Identity Domain Administrator, or Domain Administrator of that domain), and manage policies in the compartment.
- The GitHub repository, and the branch or deployment environment allowed to deploy.
- For the Standard OKE grants, an enhanced cluster. Basic clusters have no workload identity.
What it creates
- A confidential application that may call the token exchange endpoint and nothing else: no role, and no policy names it
- A service user, which cannot sign in or have a password or API key, in a group of its own
- An identity propagation trust that accepts GitHub's tokens, checked against GitHub's published keys, for the one application and the one audience, and maps each named subject to the service user
- A policy letting the group read the compartment in the quick start, and the grants you name in Standard, each inside one compartment
- A policy granting one OKE service account, named with its cluster and namespace, the same or its own grants (Standard, optional)
The code
Quick startReady
tenancy_ocid = "ocid1.tenancy.oc1..aaaaaaaa"main.tf, line 28compartment_ocid = "ocid1.compartment.oc1..aaaaaaaa"main.tf, line 29domain_url = "https://idcs-0123456789ab.identity.oraclecloud.com"main.tf, line 30region = "us-ashburn-1"main.tf, line 31repository = "your-org/your-repo"main.tf, line 32
oci os ns get
Prints your Object Storage namespace, which proves ~/.oci/config works.terraform init
Downloads the provider. Run it once per folder.terraform plan
Shows what will be created. Changes nothing. Read it.terraform apply
Shows the plan again and waits for you to type yes.terraform destroy
When you have finished. If it refuses, How to undo it below explains why.
Formatting passedValid passedLint passed
Security scan: one check passed, and none flagged.
Last run 2026-10-02 with OpenTofu v1.12.6 against oracle/oci 9.8.0.
Open main.tf as plain text
StandardReady
tenancy_ocid. The tenancy. Written into the session configuration the workflow builds.compartment_ocid. Compartment the pipeline deploys to. Every grant below is limited to it.identity_domain_ocid. OCID of the identity domain that contains the exchange client, the service user, and the trust. Its URL is looked up.region. Region identifier the workflow signs in to, such as us-ashburn-1.repository. The GitHub repository allowed to sign in, as org/repo. Used in names and descriptions.allowed_subjects. GitHub token subjects allowed to sign in, matched exactly. 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. A repository created after 15 July 2026 carries IDs: repo:org@123456/repo@456789:ref:refs/heads/main. Read the value from a real token; the verify output shows how.
oci os ns get
Prints your Object Storage namespace, which proves ~/.oci/config works.# terraform.tfvars tenancy_ocid = "" compartment_ocid = "" identity_domain_ocid = "" region = "" repository = "" allowed_subjects = ""
Create this file beside the others and fill in your values. Terraform reads it on its own.terraform init
Downloads the provider. Run it once per folder.terraform plan
Shows what will be created. Changes nothing. Read it.terraform apply
Shows the plan again and waits for you to type yes.terraform output verify
Prints the commands that prove it worked.
Formatting passedValid passedLint passed
Security scan: one check passed, and none flagged.
Last run 2026-10-02 with OpenTofu v1.12.6 against oracle/oci 9.8.0.
Open main.tf as plain text
Open outputs.tf as plain text
Open variables.tf as plain text
Open versions.tf as plain text
HardenedReady
tenancy_ocid. The tenancy. Written into the session configuration the workflow builds.compartment_ocid. Compartment the pipeline deploys to. Every grant below is limited to it.identity_domain_ocid. OCID of the identity domain that contains the exchange client, the service user, and the trust. Its URL is looked up.region. Region identifier the workflow signs in to, such as us-ashburn-1.repository. The GitHub repository allowed to sign in, as org/repo. Used in names and descriptions.allowed_subjects. GitHub token subjects allowed to sign in, matched exactly. 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. A repository created after 15 July 2026 carries IDs: repo:org@123456/repo@456789:ref:refs/heads/main. Read the value from a real token; the verify output shows how.
oci os ns get
Prints your Object Storage namespace, which proves ~/.oci/config works.# terraform.tfvars tenancy_ocid = "" compartment_ocid = "" identity_domain_ocid = "" region = "" repository = "" allowed_subjects = ""
Create this file beside the others and fill in your values. Terraform reads it on its own.terraform init
Downloads the provider. Run it once per folder.terraform plan
Shows what will be created. Changes nothing. Read it.terraform apply
Shows the plan again and waits for you to type yes.terraform output verify
Prints the commands that prove it worked.
Formatting passedValid passedLint passed
Security scan: one check passed, and none flagged.
Last run 2026-10-02 with OpenTofu v1.12.6 against oracle/oci 9.8.0.
Open .checkov.yml as plain text
Open guard.yml as plain text
Open main.tf as plain text
Open outputs.tf as plain text
Open variables.tf as plain text
Open versions.tf as plain text
How to check it worked
Run the quick start's workflow from the allowed branch: it exchanges its GitHub token for a session and oci iam compartment get succeeds. From any other branch the exchange is refused. In the compartment's audit log the calls carry the service user's name as the principal.
One secret remains in GitHub: the exchange application's client secret, because Oracle's token endpoint requires a confidential client to authenticate. The application has no role and no policy names it, so the secret alone cannot call any Oracle Cloud API. It only lets a GitHub token be presented, and the trust decides whose tokens count. Store it as a repository or environment secret and rotate it by tainting the application.
The trust's rule is the control. sub eq * maps every repository on GitHub to the service user. Both levels write sub eq '<one exact subject>', and the Standard plan rules refuse anything else.
GitHub's subject must be matched character for character, including the IDs newer repositories carry. The workflow prints the subject before it exchanges the token.
The session token is bound to a key pair the workflow generates for the run, so nothing from one run works in the next. It lasts at most an hour, and no longer than the GitHub token that bought it, which is short. The workflow prints when the session ends; a job that runs past it must exchange again.
The Hardened guard workflow signs in with an API key secret, as every Oracle Cloud guard here does. Once the trust exists, swap its sign-in step for the quick start's exchange and a read-only service user, and the guard has no key either.
A free identity domain allows two applications that are not Oracle's. A second repository can share the exchange application and the trust, with its own rule and service user, or use its own domain.
OKE workload identity has no identity object at all. The policy's where clause is the whole control, and it must name the principal type, the cluster, the namespace, and the service account together. Drop one and every pod in the cluster, or every cluster in the tenancy, qualifies. Standard writes all four, and its plan rules refuse an any-user grant missing any of them.
Statements are built from the group's name, '<domain>'/'<group>', so the plan can read them. A statement built from an OCID is unknown until apply, and the plan rules refuse it.
How to undo it
terraform destroy removes the policies, the trust, the group, the service user, and the application. Workflows and pods using them fail on their next run, and the client secret in GitHub becomes useless.
What it costs
Nothing. Identity domains of the free type, policies, token exchange, and the audit log carry no charge. An enhanced OKE cluster, needed for workload identity, is billed per cluster hour.
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.