Join our Newsletter — 33% off our NHI Course
Home› Guides› How to federate Jenkins to AWS, Azure and…
Guide Cloud & Workload Identity

How to federate Jenkins to AWS, Azure and Google Cloud with OIDC instead of stored keys: Short-lived build tokens, tightly scoped cloud trust

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, under the editorial direction of Lalit Choda Updated 20 November 2026 15 min read
On this page

Jenkins can stop storing cloud access keys altogether by issuing each build a short-lived OpenID Connect ID token that AWS, Azure and Google Cloud exchange for temporary credentials. Jenkins controllers often hold the longest-lived cloud credentials in an organisation: access keys, service principal secrets and service account key files pasted into the credentials store years ago and copied into dozens of jobs. This guide shows how to replace them with federation using the Jenkins OpenID Connect Provider plugin, how to configure the trust on each cloud, and how to scope that trust so one compromised job cannot reach everything.

If you first need to find out which static keys your Jenkins estate holds, start with our How to audit Jenkins credentials and secrets guide. This page picks up where that audit ends: you know what keys exist, and now you want them gone.

Key takeaways

  • The OpenID Connect Provider plugin lets Jenkins sign a JWT for each build with a keypair held on the controller, and publishes the public key so cloud providers can verify it.
  • Each cloud needs three values to match the token: issuer, audience and subject. By default the subject is the job URL, so trust is naturally per job.
  • The trust condition on the cloud side is the real access control. A broad subject match turns federation into a shared key with extra steps.
  • Use the file credential type where a tool reads a token file (AWS web identity, Google Cloud external account configuration) and the string type where a tool takes the token as a value (Azure CLI and Terraform).
  • A new token is issued every time a withCredentials block is entered, so wrap each cloud operation in its own block on long builds.
  • If the cloud cannot reach your controller, publish the discovery document and public key at an alternate static issuer URL instead of exposing Jenkins to the internet.
  • Keep the plugin updated: the plugin page records advisory SECURITY-3574 for insufficient claim validation in version 96.vee8ed882ec4d and earlier.

Why stored cloud keys in Jenkins are a problem

A stored cloud key is a non-human identity credential with no natural end date. It is valid on the controller, in every agent workspace it is copied to, in console logs if a script echoes it, and anywhere a plugin or Groovy script can read the credentials store. Rotating it means touching every job that uses it, so in practice it rarely happens. MITRE ATT&CK tracks the relevant behaviour as Credentials In Files and the follow-on use of stolen keys as Valid Accounts: Cloud Accounts.

Federation changes the shape of the risk. Jenkins keeps a signing key, not a cloud key. Each build receives a fresh, timestamped token with limited validity, and the cloud provider decides, per token, whether the claims inside it satisfy a trust policy. The cloud credential the build ends up with is temporary and issued by the cloud itself. There is no long-lived secret left to leak from a workspace, and revoking access is a change to one trust policy rather than a hunt through job configurations. Our Workload Identity Federation vs Static Cloud Keys page covers the general trade-off; the rest of this guide is the Jenkins-specific build.

How Jenkins OIDC federation works

The plugin documentation describes the model simply. Jenkins holds an asymmetric keypair. When a build asks for an ID token credential, Jenkins signs a JWT with the private key. The public key is served anonymously so that external services can verify signatures. The exchange then runs as follows:

  1. A pipeline step enters a withCredentials block bound to an OpenID Connect id token credential.
  2. Jenkins mints a JWT containing the issuer (iss), the subject (sub, by default the job URL such as https://jenkins.example.com/job/my-job/), the audience (aud) configured on the credential, and by default the build number.
  3. The build passes the token to the cloud's token service.
  4. The cloud fetches the issuer's discovery document and public keys, verifies the signature, and checks issuer, audience and subject against the trust you configured.
  5. If everything matches, the cloud returns short-lived credentials scoped to a role, managed identity or service account.

Microsoft's workload identity federation overview describes the same six-step pattern from the Entra side, and the token exchange itself follows the general idea standardised in RFC 8693 OAuth 2.0 Token Exchange. For a vendor-neutral explanation of the concepts, see our Workload Identity Federation Guide.

Before you start

  • Plugin version. Install or update the OpenID Connect Provider plugin to the current release. Do not run version 96.vee8ed882ec4d or earlier.
  • Issuer reachability. Each cloud must be able to fetch the issuer's /.well-known/openid-configuration document and public keys over HTTPS. If your controller is internal only, plan for the alternate issuer described below.
  • A trusted TLS certificate on the issuer. AWS validates the JWKS endpoint's certificate against trusted root CAs by default and falls back to configured thumbprints when it cannot. A publicly trusted certificate avoids thumbprint maintenance.
  • A job inventory. List which jobs use which cloud keys today, and what each actually needs to do. You will build one trust relationship per job or per tightly defined group of jobs, so this list is your migration plan.
  • Cloud administrator access. You need rights to create an IAM OIDC provider and role in AWS, a federated identity credential on a user-assigned managed identity or app registration in Azure, and a workload identity pool and provider in Google Cloud.

Step 1: create the ID token credential in Jenkins

The plugin adds two credential types:

Credential typeWhat the build receivesUse it for
OpenID Connect id tokenThe token as secret textAzure CLI az login --federated-token, Terraform ARM_OIDC_TOKEN, HashiCorp Vault JWT login
OpenID Connect id token as fileA path to a temporary file containing the tokenAWS AWS_WEB_IDENTITY_TOKEN_FILE, Google Cloud external account configuration files

When you create the credential:

  • Give it a predictable ID such as oidc-aws-prod, so pipelines can reference it clearly.
  • Set the audience the target cloud expects. The plugin documentation lists sts.amazonaws.com for AWS, api://AzureADTokenExchange for Azure, and the full workload identity provider resource path for Google Cloud.
  • Decide where it lives. A credential at the Jenkins root uses the default issuer, typically https://YOUR_JENKINS_HOST/oidc. Credentials can also be created in a folder. After saving, open the credential's Update page to see the exact issuer URI it generated, and copy that value rather than guessing it.
  • Create one credential per cloud audience. A token minted for AWS should not also be acceptable to Azure.

Optionally, adjust the token contents under Manage Jenkins, Configure Global Security, OpenID Connect, Claim templates. Each template defines one claim from a fixed string or build variable such as ${BRANCH_NAME} or ${BUILD_NUMBER}, typed as string, boolean or integer, and applied to build tokens, non-build tokens or both. Every template set must still include sub. Changing the subject format changes what every cloud trust must match, so decide on it before you configure any cloud.

Step 2: decode a test token before configuring any cloud

The single most common failure is a subject that does not match. Microsoft notes that a federated credential with the wrong subject is still created successfully, and the failure only shows up later as an unhelpful token exchange error. Before touching cloud configuration, run a throwaway job that binds the credential, then decode the JWT payload (not the signature) with a local tool and record the exact iss, sub and aud values. Do not print the raw token to the console log of a real job.

Watch for two Jenkins-specific details. Branch names containing / are URL-encoded in multibranch job URLs, so the subject contains the encoded form. And the issuer string, including any path, must match the cloud configuration exactly: both AWS and Azure treat these values as case-sensitive.

Step 3: configure the cloud trust

The three providers below are listed alphabetically. Each section covers the minimum configuration and the claim that does the scoping.

AWS

Follow the AWS guide to create an IAM OIDC identity provider:

  1. In IAM, choose Identity providers, Add provider, OpenID Connect. The provider URL is your Jenkins issuer. It must begin with https://, is case-sensitive, may include a path, must not include a port or query string, and must be unique in the account.
  2. Set the audience to the value configured on the Jenkins credential, conventionally sts.amazonaws.com.
  3. Create an IAM role whose trust policy allows sts:AssumeRoleWithWebIdentity from that provider, with conditions on both the audience and the subject claim. Match the subject to the specific job URL from Step 2.
  4. Attach only the permissions that job needs.

In the pipeline, bind the file credential to AWS_WEB_IDENTITY_TOKEN_FILE and set AWS_ROLE_ARN. The AWS SDKs and CLI then assume the role automatically. An illustrative pipeline fragment:

withCredentials([file(credentialsId: 'oidc-aws-prod', variable: 'AWS_WEB_IDENTITY_TOKEN_FILE')]) { withEnv(['AWS_ROLE_ARN=arn:aws:iam::111122223333:role/jenkins-deploy-web']) { sh 'aws sts get-caller-identity' } }

AWS limits a provider to between 1 and 100 audiences and 1 to 5 thumbprints, and accepts at most 100 RSA and 100 EC keys in the JWKS. Role assumptions appear in CloudTrail as AssumeRoleWithWebIdentity events.

Azure

Azure trusts external tokens through a federated identity credential on a user-assigned managed identity or an app registration. Microsoft's guide to configuring a user-assigned managed identity to trust an external identity provider sets out the rules:

  1. Create a user-assigned managed identity (system-assigned identities are not supported for federation) and grant it an Azure RBAC role on the narrowest scope that works.
  2. Add a federated identity credential, for example with az identity federated-credential create using --issuer set to your Jenkins issuer, --subject set to the exact sub from Step 2, and --audiences api://AzureADTokenExchange.
  3. Remember the constraints: exactly one audience, no wildcards in any property, a unique issuer and subject pair per identity, and a limit of 20 federated credentials per identity.

In the pipeline, bind the string credential and pass it to az login --federated-token along with the identity's client ID and tenant, or expose it as ARM_OIDC_TOKEN for Terraform. Because each federated credential matches one subject and an identity holds at most 20, the limit is a useful forcing function: if you need more, you probably want more identities with narrower roles. Our How to audit Entra workload identity federated credentials guide covers reviewing these over time.

Google Cloud

Google Cloud uses a workload identity pool with an OIDC provider, described in Workload Identity Federation with other identity providers:

  1. Create the pool with gcloud iam workload-identity-pools create, preferably in a dedicated project.
  2. Add an OIDC provider with gcloud iam workload-identity-pools providers create-oidc, giving the Jenkins issuer URI, the attribute mapping google.subject=assertion.sub, and an attribute condition.
  3. Grant access. Google recommends granting roles directly to the federated principal on the resource. Where an API needs it, grant roles/iam.workloadIdentityUser on a dedicated service account and let the federated identity impersonate it.
  4. Generate a credential configuration file with gcloud iam workload-identity-pools create-cred-config, pointing the credential source at a local file. The file contains no private key.

Unless you configure a custom audience, the token's aud must be the provider's full resource name, which is why the Jenkins credential's audience is set to that path. In the pipeline, bind the file credential to the path named in the configuration file and set GOOGLE_APPLICATION_CREDENTIALS to the configuration file. Google also states that tokens must carry an exp no more than 24 hours after iat, must be signed with RS256 or ES256, and that the signing key should not be reused with other services. The plugin documentation notes that Google Cloud polls the issuer every few minutes whether or not the pool is in use, so keep the issuer available.

Step 4: scope the trust so one job cannot become every job

Federation is only as strong as the condition on the cloud side. The plugin documentation is direct about this: restrict trust using sub and other claims, because an overly broad trust policy grants wide access. Practical rules:

  • One role or identity per deployment boundary. A production deploy job and a test job should map to different cloud roles even if the same team owns both.
  • Match the full subject. In AWS, match the complete job URL rather than a prefix. Azure enforces exact matching anyway. In Google Cloud, write an attribute condition that names the allowed subjects.
  • Add claims for branch context. If only the main branch may deploy, add a claim template that carries ${BRANCH_NAME} and require it in the cloud condition, where the cloud supports conditions on that claim. Our How to Scope CI OIDC Trust to Branch and Environment guide covers this pattern in depth.
  • Remember who can edit jobs. The subject identifies a job, not the person who changed its Jenkinsfile. Anyone who can change the pipeline definition of a trusted job can use its cloud access, so Jenkins job and folder permissions become part of your cloud access model.
  • Least privilege on the cloud role. Federation removes the stored key; it does not reduce the permissions attached to the role.

When the cloud cannot reach Jenkins

Many controllers sit on internal networks. Rather than opening Jenkins to the internet, the plugin supports an alternate issuer: you host two small static JSON files (the discovery document and the public key set) at a public URL, and Jenkins sets the iss claim to that alternate issuer. Jenkins still signs every token with the private key on the controller; only the public half is published, and it rarely changes. The plugin notes that credentials using an alternate issuer must be in the global credentials domain.

Google Cloud offers another route: upload the JWKS directly to the provider with --jwk-json-path, up to eight keys. Updating replaces all uploaded keys and the old ones cannot be restored, so treat that file as part of your key rotation runbook. Whichever option you use, the static files become a dependency: if they are deleted or changed incorrectly, every federated build fails.

Long builds, rotation and retiring the old keys

Because a fresh token is issued each time a withCredentials block is entered, wrap each cloud interaction in its own block rather than binding once at the top of a long pipeline. That keeps each token close to the operation that uses it.

To rotate the signing keypair, click Update and re-save the credential, or recreate it. If you use an alternate issuer or uploaded JWKS, publish the new public key before switching, and keep the old one available until no tokens signed with it remain valid. Key management practice in NIST SP 800-57 Part 1 applies to this keypair just as to any other signing key.

Retire the old static keys deliberately:

  1. Migrate one job, confirm it works through federation, and confirm in cloud audit logs that it no longer uses the old key.
  2. Disable, rather than delete, the old access key or secret and wait through at least one full release cycle.
  3. Delete the cloud key and the Jenkins credential together, and record the change in your NHI inventory.

Common failure patterns

  • Subject copied from documentation, not from a real token. URL-encoded branch names, trailing slashes and folder paths all change sub. Always decode a real token first.
  • Issuer mismatch. A trailing slash, a different hostname or an upper-case character in the issuer breaks validation on AWS and Azure, which match case-sensitively.
  • One credential, many audiences. Reusing a single token audience across clouds or environments makes tokens more widely acceptable than they need to be.
  • Wildcard or prefix trust in AWS. Matching every job under a Jenkins host lets any job, including a newly created one, assume the role.
  • Federation added, old key kept. Teams migrate the pipeline but leave the static key enabled "just in case", so the risk never actually goes away.
  • Issuer unavailable. Controller maintenance, an expired TLS certificate on the issuer or a deleted static JWKS file stops every federated build at once.
  • Outdated plugin. Versions affected by SECURITY-3574 had insufficient claim validation.

Practitioner checklist

  • OpenID Connect Provider plugin installed at the current version, above 96.vee8ed882ec4d.
  • Issuer URL copied from the credential's Update page and served with a publicly trusted TLS certificate, or an alternate static issuer published.
  • One ID token credential per cloud audience, with file or string type chosen to match the tool.
  • Real token decoded and the exact iss, sub and aud recorded before cloud configuration.
  • AWS: IAM OIDC provider plus a role per job with conditions on audience and full subject.
  • Azure: user-assigned managed identity with a federated credential whose subject matches exactly, and a narrowly scoped RBAC role.
  • Google Cloud: dedicated pool project, google.subject=assertion.sub, an attribute condition, and direct resource grants where possible.
  • Each cloud call wrapped in its own withCredentials block.
  • Jenkins job and folder permissions reviewed, since editing a trusted job grants its cloud access.
  • Old static keys disabled, then deleted, and the inventory updated.
  • Keypair rotation and issuer availability added to your runbooks.

Standards and references

Related NHI Mgmt Group resources: How to audit Jenkins credentials and secrets · Jenkins Security Guide · Workload Identity Federation Guide · Cross-cloud workload identity federation

PDF for subscribers

Take this guide with you

Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick both boxes to continue.