Your GitHub Actions workflows deploy to AWS using stored access keys. How do you improve that?
AdvancedScenarioSecrets, Signing and Security
Answer
Situation read → Long-lived keys in secrets can leak and rarely get rotated.
What I'd do →
- Create an IAM OIDC identity provider for
token.actions.githubusercontent.com. - Create a role whose trust policy restricts
subtorepo:ORG/REPO:environment:production(or a branch/tag). - Use short-lived credentials in the workflow:
permissions:
id-token: write
contents: read
steps:
- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::123456789012:role/gha-deploy
aws-region: ap-south-1
- Delete the old access keys.
Why → Credentials last minutes and are bound to a specific repo and ref.
Interview tip → A loose sub condition (such as repo:ORG/*) is the classic misconfiguration.
More on Secrets, Signing and Security
A developer pushed an AWS access key to a public repo 10 minutes ago. What is your first move?BeginnerAfter rotating the leaked key, you must purge it from repository history. How?AdvancedA push is rejected: "GH013: Repository rule violations found ... Push cannot contain secrets". What do you do?IntermediateSecret scanning alerts have piled up, and many look like false positives or old test credentials.IntermediateYou must set up signed commits on your laptop. Which method do you pick?BeginnerYour GPG signing key expires next week. What is the correct way to handle it?Intermediate