
Letting Cloud Agents Query Production with OIDC Instead of Secrets
A fascinating technical post from Formal caught the attention of cloud engineers this week: they’re letting their AI agents query production databases directly—but here’s the twist that makes it interesting. Instead of managing long-lived secrets or API keys, they’re using OIDC (OpenID Connect) workload identity federation. This isn’t just clever; it fundamentally changes how we think about securing automated systems that need production access.
The timing couldn’t be better. As organizations race to deploy AI agents and automated workflows that interact with production infrastructure, the secret sprawl problem has become crushing. Every CI/CD pipeline, every Lambda function, every container needs credentials. And those credentials become attack vectors, compliance nightmares, and operational headaches. Let’s dig into the technical approach that solves this—one you can implement today regardless of whether you’re building AI agents or just trying to secure your existing automation.
Table of Contents
- Why OIDC Workload Identity Actually Matters
- How OIDC Federation Works Under the Hood
- Implementing OIDC Workload Identity in AWS
- The GCP Approach to Service Account Federation
- Common Patterns for Production Access
Why OIDC Workload Identity Actually Matters
Traditional secret management follows a painful pattern: generate a credential with broad permissions, store it somewhere “secure,” rotate it periodically (if you’re diligent), and hope nobody extracts it from your CI logs or container environment variables. Even with tools like HashiCorp Vault or AWS Secrets Manager, you’re still dealing with long-lived credentials that can be exfiltrated and replayed.
OIDC workload identity flips this model entirely. Instead of your GitHub Actions workflow holding an AWS access key, GitHub itself becomes a trusted identity provider. AWS validates the JWT token GitHub issues to your workflow, verifies it comes from your repository and branch, then grants temporary credentials—typically valid for an hour or less. No secrets to rotate, no keys to leak. If someone compromises your repository, they still can’t replay those tokens from outside your CI environment.
For engineers looking to deepen their understanding of identity federation patterns across cloud platforms, Coursera offers specialized courses on cloud security architecture that cover these modern authentication approaches in depth.
The Token Flow That Changes Everything
Here’s what happens when a GitHub Actions workflow needs to access your AWS account. GitHub issues a JWT token containing claims about the workflow: the repository name, branch, commit SHA, and more. Your workflow sends this token to AWS STS (Security Token Service). AWS validates the token against the OIDC provider configuration you’ve set up, checks that the claims match your trust policy, and returns temporary credentials. Those credentials expire automatically—no cleanup needed.
This same pattern works for Kubernetes pods accessing cloud resources, for one cloud service accessing another cloud provider, and yes, for AI agents querying production databases. The key insight is that identity becomes tied to the execution context itself, not to a secret stored somewhere.
How OIDC Federation Works Under the Hood
Before jumping into implementations, understanding the protocol flow saves hours of debugging later. OIDC builds on OAuth 2.0, adding an identity layer through standardized JWT tokens. When we talk about workload identity federation, we’re leveraging OIDC’s ability to establish trust between different identity providers.
The trust establishment happens once during setup. You configure your cloud provider (AWS, GCP, Azure) to trust tokens from an external OIDC provider like GitHub, GitLab, or even another cloud. This involves exchanging public keys and defining which token claims you’ll validate. Once configured, the runtime flow is lightweight: present token, validate claims, receive temporary credentials.
Implementing OIDC Workload Identity in AWS
Let’s build a practical example: configuring GitHub Actions to deploy to AWS without any long-lived credentials. This pattern works identically whether you’re deploying applications, running database queries, or letting agents access production resources.
First, create the OIDC identity provider in AWS. This establishes GitHub as a trusted issuer:
# Create OIDC provider for GitHub Actions in AWS
aws iam create-open-id-connect-provider \
--url https://token.actions.githubusercontent.com \
--client-id-list sts.amazonaws.com \
--thumbprint-list 6938fd4d98bab03faadb97b34396831e3780aea1
# Create an IAM role that trusts tokens from your specific repository
aws iam create-role \
--role-name GitHubActionsProductionAccess \
--assume-role-policy-document '{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Principal": {
"Federated": "arn:aws:iam::ACCOUNT_ID:oidc-provider/token.actions.githubusercontent.com"
},
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": {
"token.actions.githubusercontent.com:aud": "sts.amazonaws.com"
},
"StringLike": {
"token.actions.githubusercontent.com:sub": "repo:your-org/your-repo:ref:refs/heads/main"
}
}
}]
}'
Notice the StringLike condition on the sub claim. This ensures only workflows running from the main branch of your specific repository can assume this role. If someone forks your repository or creates a pull request from an external fork, they can’t assume this role—even though they’re running on GitHub Actions.
Your GitHub Actions workflow then becomes remarkably simple:
# .github/workflows/deploy.yml snippet showing OIDC authentication
name: Deploy to Production
on: push
permissions:
id-token: write # Required to request the JWT
contents: read
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: arn:aws:iam::ACCOUNT_ID:role/GitHubActionsProductionAccess
aws-region: us-east-1
- run: aws rds-data execute-statement --resource-arn $DB_ARN --sql "SELECT * FROM users"
No secrets in your repository settings. No access keys in environment variables. The credentials exist only in memory during workflow execution and expire automatically.
The GCP Approach to Service Account Federation
Google Cloud’s implementation of workload identity federation is similarly elegant but uses different terminology. Instead of creating an OIDC provider, you create a Workload Identity Pool and configure attribute mappings from the external token to GCP identities.
The power of GCP’s approach lies in its attribute mapping flexibility. You can extract arbitrary claims from the incoming JWT and use them to make authorization decisions. Want to grant different permissions based on the Git branch? Map the branch claim to a custom attribute and use it in IAM conditions.
For engineers working across multiple cloud providers and wanting to build expertise in identity patterns that span platforms, DataCamp provides hands-on exercises that let you practice these configurations in live cloud environments.
Common Patterns for Production Access
Beyond CI/CD pipelines, workload identity federation shines in several production scenarios. Kubernetes pods running in GKE or EKS can assume IAM roles to access cloud resources without storing service account keys in secrets. Cross-cloud architectures can use OIDC federation to let GCP services authenticate to AWS resources or vice versa.
The pattern Formal describes—letting agents query production—extends this naturally. An agent running as a Kubernetes pod or Lambda function receives its identity from the execution environment. That identity maps to specific database permissions through OIDC federation. The agent can query production, but only within the constraints defined by its token claims and IAM policies. Access is scoped to what’s needed, not what’s convenient.
This principle of least privilege becomes architecturally enforceable rather than procedurally aspirational. You’re not trusting developers to create narrow access keys; you’re using identity federation to ensure that only the right context can access the right resources. And because the credentials are temporary, even a compromised agent can’t leak long-lived access.
Implementing Production Database Access
For database access specifically, combine workload identity with database-native authentication mechanisms. AWS RDS supports IAM database authentication where the database password is a short-lived token generated from your IAM credentials. Connect workload identity to IAM role assumption, then use those temporary credentials to generate a database authentication token. The entire chain—from workload execution to database query—uses no long-lived secrets.
This approach scales from simple automation scripts to complex AI agents that need production visibility. The security model remains consistent: identity is contextual, credentials are ephemeral, access is auditable through cloud provider logs rather than application-level secrets management.
Master OIDC Federation on AWS
Build production-ready workload identity architectures with hands-on courses covering AWS IAM federation, temporary credentials, and zero-trust security patterns you can deploy this week.