GitLab CI/CD OIDC Keyless Cloud Auth Prompt
Replace long-lived AWS/GCP/Azure keys stored as CI variables with short-lived OIDC tokens minted per-job via id_tokens, scoped by branch, environment, and protected status.
- Target user
- Platform engineers hardening pipeline access to cloud accounts
- Difficulty
- Advanced
- Tools
- Claude, ChatGPT
The prompt
You are a cloud security engineer who has eliminated static cloud credentials from GitLab pipelines by adopting OIDC federation. You know exactly which JWT claims to trust and which are forgeable by any developer. I will provide: - Our cloud provider(s) and which accounts pipelines deploy to - The static keys currently stored as CI/CD variables - Our branch/tag/environment naming conventions - Whether we self-host GitLab or use GitLab.com (the issuer URL differs) Your job: 1. **Why keyless** — explain the risk of static `AWS_SECRET_ACCESS_KEY` in CI variables (exfiltration via a malicious MR, no rotation, broad scope) vs. per-job OIDC tokens that expire in minutes. 2. **id_tokens block** — show the `id_tokens:` keyword to request a JWT with the correct `aud` (audience) per cloud, and explain why audience matters. 3. **Trust policy claims** — this is the crux: write the cloud-side trust condition and explain which claims to match on. Strongly recommend scoping on `sub`, `project_path`, `ref`, `ref_protected`, and `environment` — and warn that matching only on broad claims like project namespace lets any fork-MR branch assume the role. 4. **AWS / GCP / Azure specifics** — for the relevant provider, give the federated identity setup: AWS IAM OIDC provider + `AssumeRoleWithWebIdentity`, GCP Workload Identity Federation, or Azure federated credentials. Include the role/SA permission boundary. 5. **Per-environment scoping** — show how to mint different roles for staging vs. production by gating on `ref_protected == true` and the GitLab environment name, so an unprotected branch can never touch prod. 6. **Migration** — run OIDC and static keys in parallel, cut over one job, then delete the static variables and confirm nothing breaks. 7. **Validation** — decode a sample token's claims, confirm token TTL, and verify the trust policy rejects an unprotected branch. Output as: (a) the `id_tokens:` + job snippet, (b) the cloud trust policy with claim conditions, (c) a least-privilege permission boundary, (d) a migration/cutover checklist, (e) the top misconfigurations that leave the role assumable by any branch. Bias toward: least privilege, scoping on protected + environment claims, deleting static keys the moment OIDC works.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
GitLab CI/CD id_tokens to AWS STS AssumeRoleWithWebIdentity Prompt
Wire a GitLab id_token directly into AWS STS AssumeRoleWithWebIdentity so jobs get short-lived AWS credentials with no stored access keys — including the IAM trust policy conditions that pin the role to your project, branch, and environment.
-
GitLab CI/CD Variable Masking & Protected Hardening Prompt
Audit and harden GitLab CI/CD variables — masking, protected/expanded flags, scoping, and leak prevention — so secrets never appear in job logs or untrusted branch pipelines.
-
GitLab CI/CD Protected Environments & Deployment Approvals Prompt
Lock down production with protected environments, deployment approval rules (multiple approvers, required groups), and deployment-only access so a green pipeline can't ship to prod without the right humans signing off.
-
GitLab Runner Tags, Protected & Job Isolation Hardening Prompt
Lock down which runners pick up which jobs using tags, protected-runner flags, and project/group assignment so untrusted MR jobs never execute on privileged deploy runners.
More GitLab CI/CD prompts & error guides
Browse every GitLab CI/CD prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.