Skip to main content
Cross-Cloud Identity Federation: Patterns That Replaced Our Long-Lived Keys

Cross-Cloud Identity Federation: Patterns That Replaced Our Long-Lived Keys

KU
· Founder & Chief Editor
• 8 min read•Updated •

OIDC federation between AWS, GCP, and CI providers lets you delete nearly every long-lived cloud credential. The setup, the gotchas, and the trust-relationship discipline.

Key takeaways

  • Cross-cloud identity federation replaces long-lived access keys with short-lived tokens.
  • The caller presents a signed OIDC token or signed AWS request, and the target cloud checks it against a trust policy before issuing credentials that expire in about an hour.
  • Pin trust policies to exact repos, branches and audiences, because the trust policy is the security boundary.

Cross-cloud identity federation replaces stored access keys with short-lived credentials issued at the moment of use. A caller (GitHub Actions, an AWS role, a GCP workload) presents a signed identity token, the target cloud verifies it against a trust policy, and returns credentials that expire, one hour by default on AWS. Nothing persistent to leak, rotate, or forget.

Verified against

aws-actions/configure-aws-credentials v6 (v6.3.0), google-github-actions/auth v3, against the GitHub Actions OIDC-in-AWS guide, the AWS IAM role session docs and Google Cloud Workload Identity Federation docs. Checked October 2026.

The typical starting point is AWS access keys scattered across many places: GitHub Actions secrets, GCP Secret Manager, engineer laptops, CI runners, long-running EC2 instances that should have used roles. Each one is a credential you have to find and rotate if anything leaks. The goal is zero long-lived cloud access keys outside of break-glass and the odd legacy integration. These are the federation patterns that get you there. For the GCP side in depth, see replacing GCP service account keys with Workload Identity Federation; for servers outside any cloud, IAM Roles Anywhere.

The shape of the problem

Long-lived credentials are the bottom rung of cloud security. They:

  • Are valid for months or years until you rotate them
  • Get copy-pasted into CI secrets, env files, dev laptops
  • Don't expire when an employee leaves
  • Are hard to inventory: you don't know where each one ended up
  • Leak in surprisingly many ways (a misconfigured logging line, a public repo push, a screenshot)

The fix is to replace them with short-lived tokens issued at the moment of use. AWS, GCP, and Azure all support this via trust relationships: an external identity provider (GitHub Actions, another cloud, another AWS account) presents a signed token; the target cloud verifies it; if the trust policy matches, it issues a temporary credential. On AWS, if the caller doesn't request a duration, that credential is valid for one hour.

The trust model in one paragraph

Federation works because both sides know how to verify a JWT. The caller's identity provider signs the JWT with a key whose public part is published at a well-known URL (the JWKS endpoint). The target cloud fetches that public key, verifies the signature, and checks the claims against a trust policy: rules like "this JWT must be issued by GitHub Actions, for the repo company/api, on a push to main." If all the claims match, the cloud hands back a short-lived access token (an AWS STS credential, a GCP access token).

GitHub Actions to AWS

The most common path, and the one we cover end to end in OIDC federation for GitHub Actions to AWS. Pattern:

  1. Create an IAM role in AWS with a trust policy that accepts GitHub Actions' OIDC token under specific conditions:
JSON
{
  "Version": "2012-10-17",
  "Statement": [{
    "Effect": "Allow",
    "Principal": {"Federated": "arn:aws:iam::123456789012:oidc-provider/token.actions.githubusercontent.com"},
    "Action": "sts:AssumeRoleWithWebIdentity",
    "Condition": {
      "StringEquals": {
        "token.actions.githubusercontent.com:aud": "sts.amazonaws.com",
        "token.actions.githubusercontent.com:sub": "repo:company/api:ref:refs/heads/main"
      }
    }
  }]
}

The sub condition is the security boundary. It says "this role can only be assumed from the company/api repo on the main branch." A different repo or a feature branch can't assume it.

  1. In the workflow:
.github/workflows/deploy.yml
permissions:
  id-token: write    # required for OIDC token issuance
  contents: read

steps:
  - uses: aws-actions/configure-aws-credentials@v6
    with:
      role-to-assume: arn:aws:iam::123456789012:role/github-deploy
      aws-region: us-east-1

After this step, the runner has temporary AWS credentials for the workflow run. No AWS_ACCESS_KEY_ID secret. GitHub's own guide pins the action to a full commit SHA rather than a tag, which we also do in production.

GitHub Actions to GCP

Same shape, different ceremony:

  1. Create a Workload Identity Pool and Provider in GCP that accepts GitHub's OIDC issuer, with an attribute condition on the repository.
  2. Grant access: either bind roles directly to the pool's principalSet:// identity, or let it impersonate a service account.
  3. In the workflow:
YAML
# .github/workflows/deploy.yml (GCP step)
- uses: google-github-actions/auth@v3
  with:
    workload_identity_provider: 'projects/123/locations/global/workloadIdentityPools/gh-pool/providers/gh-provider'
    service_account: 'deploy@my-project.iam.gserviceaccount.com'

The workflow gets a GCP access token for that service account.

AWS to GCP (workload-to-workload)

Less common but useful when a workload running on AWS needs to write to a GCP bucket. Pattern:

  1. AWS workload (Lambda, ECS task) has an IAM role.
  2. A GCP Workload Identity Pool has an AWS provider for your account, with an attribute condition such as assertion.arn.startsWith('arn:aws:sts::AWS_ACCOUNT_ID:assumed-role/').
  3. The workload builds a SigV4-signed GetCallerIdentity request with its existing role credentials and sends it to Google's Security Token Service. Google checks it against AWS STS and returns a short-lived access token. The AWS secret key never leaves the workload.

Google's docs now recommend granting roles directly to the federated principal where the product supports it, with service account impersonation as the fallback. The reverse direction (GCP to AWS) has a similar shape. We use AWS to GCP for analytics: Lambda functions that push data into BigQuery without storing GCP credentials.

The trust policy is your security boundary

This is where most federation setups go wrong. The trust policy controls who can use this role. Get it wrong and you've replaced a leaked-key risk with an "anyone can assume your role" risk.

What we enforce in every trust policy:

Specific repo and branch. repo:company/api:ref:refs/heads/main. Not repo:company/* (any repo). Not repo:company/api:* (any branch).

Audience claim. For the official AWS action, aud is sts.amazonaws.com. Always set it explicitly.

Environment claim when using GitHub Actions environments. A sub of repo:company/api:environment:prod restricts which environment can assume the role. Especially useful for prod-only roles.

StringEquals over StringLike where you can. Pattern matching is for cases that genuinely need it; exact match is safer.

We had one setup early on where StringLike was used with a * that was a typo and accidentally matched too much. A security review caught it. Specificity over flexibility.

What we federated, in order

The migration took about a year, prioritized roughly by risk:

  1. GitHub Actions to AWS (usually where most stored credentials live)
  2. GitHub Actions to GCP (same pattern, fewer credentials)
  3. EC2 instance roles: replaced any access-key-on-instance with IAM instance profiles
  4. Cross-account AWS roles: internal accounts assuming roles in others via STS rather than embedded keys
  5. AWS to GCP workload federation (analytics path)
  6. Engineer-laptop SSO via AWS IAM Identity Center for ad-hoc CLI work

After step 6, all that remained was one legacy integration with a partner service that doesn't support OIDC. That one stays on a long-lived key, rotated quarterly, scoped narrowly. We track remaining keys with AWS Config rules plus a custom audit, and alert if federation failures spike, since an IdP outage now blocks deploys.

Common mistakes

Over-permissive trust policies. repo:company/* accepts any repo in the org. Use the specific repo.

Forgetting id-token: write. GitHub Actions workflows need this permission to request an OIDC token. Without it, the federation step fails with a confusing error.

Wrong audience. GCP and AWS both check audience values; using the wrong one fails verification. Read the docs for the target.

Long session durations. An IAM role's maximum session duration defaults to 1 hour and can be raised to 12. We keep CI roles at 1 hour. Longer sessions mean more blast radius if a runner is compromised mid-run.

Same role for too many things. A "general deploy" role with every permission defeats the point. We have separate roles per service or per environment, sized with the approach in cloud IAM least-privilege without breakage.

Questions people ask

How do I give GitHub Actions access to AWS without access keys?

Register token.actions.githubusercontent.com as an IAM OIDC identity provider, create a role whose trust policy allows sts:AssumeRoleWithWebIdentity with aud set to sts.amazonaws.com and sub pinned to your repo and branch, grant the workflow id-token: write, and use aws-actions/configure-aws-credentials with role-to-assume. No secret is stored anywhere.

Can an AWS workload access GCP without a service account key?

Yes. Create a Workload Identity Pool with an AWS provider for your account. The workload signs a GetCallerIdentity request with its existing IAM role credentials and exchanges it at Google's Security Token Service for a short-lived token. Grant roles to the federated principal directly, or let it impersonate a service account where a product requires that.

How long do federated AWS credentials last?

One hour by default. A role's maximum session duration can be set anywhere from 1 to 12 hours, and callers can request up to that maximum. For CI we leave it at 1 hour; a deploy rarely needs more, and a shorter window limits what a stolen token can do.

Federation is one of those cleanup projects where the moment you finish it, you wonder how you ever lived without it. Long-lived access keys in CI secrets and env files just become a thing you stopped doing. The trust-policy discipline is the part that takes practice; the rest is mechanical.

Sources

Explore topics:SecurityAWSCloud
React
Share this post
Cite this article
Plain text

Kiril Urbonas (2026). Cross-Cloud Identity Federation: Patterns That Replaced Our Long-Lived Keys. DevOpsNess. Updated 2026-11-11. https://www.devopsness.com/blog/cross-cloud-identity-federation-patterns

Markdown

[Cross-Cloud Identity Federation: Patterns That Replaced Our Long-Lived Keys](https://www.devopsness.com/blog/cross-cloud-identity-federation-patterns) (Kiril Urbonas, DevOpsNess, updated 2026-11-11)

KU

Kiril Urbonas

Founder & Chief Editor

607 articles
View all articles by Kiril Urbonas

You might have missed

Evergreen posts worth revisiting.