Your deploy job uses a long-lived AWS access key stored in repo secrets. How do you improve it?
IntermediateScenarioGitHub Actions
Answer
Situation read → Static cloud keys in CI.
What I'd do →
- Create an IAM OIDC identity provider for
token.actions.githubusercontent.comand a role with a trust policy limited torepo:my-org/app:environment:productionin thesubclaim andaudofsts.amazonaws.com. - In the workflow, set
permissions: id-token: writeand useaws-actions/configure-aws-credentials@v4withrole-to-assume. - Delete the stored keys.
Why → OIDC yields short-lived credentials scoped to a repo, branch or environment, with nothing to leak.
Interview tip → A trust policy without a tight sub condition lets any repo assume the role.
More on GitHub Actions
What are workflows, jobs, steps and actions in GitHub Actions?BeginnerWhat events can trigger a workflow?BeginnerWhat is the difference between `pull_request` and `pull_request_target`?AdvancedWhat is a runner, and how do GitHub-hosted and self-hosted runners differ?BeginnerHow do you pass data between steps and between jobs?IntermediateHow does a build matrix work?Intermediate