How do you authenticate GitLab CI to AWS without storing keys?
AdvancedScenarioGitLab CI
Answer
Situation read → OIDC federation.
What I'd do →
- Declare
id_tokens: { AWS_TOKEN: { aud: https://gitlab.example.com } }in the job. - Create an IAM OIDC provider for the GitLab issuer and a role whose trust policy matches
sublikeproject_path:group/app:ref_type:branch:ref:main. - In the script:
aws sts assume-role-with-web-identity --role-arn $ROLE --role-session-name ci --web-identity-token "$AWS_TOKEN".
Why → Tokens are short-lived and identity-bound.
Interview tip → Same pattern as GitHub Actions OIDC.
More on GitLab CI
How does GitLab CI/CD work at a high level?BeginnerWhat is a GitLab Runner and what executors exist?IntermediateWhat are the types of runners (shared, group, project) and tags?IntermediateHow do `rules:` work and how do they replace `only/except`?IntermediateWhat are workflow rules and how do they prevent duplicate pipelines?AdvancedHow do artifacts and cache differ in GitLab CI?Intermediate