CI/CD and infrastructure as code · senior
CI/CD security: workflows, leaked keys and trusted images
CI holds powerful credentials, so workflow triggers, token permissions, action pinning, OIDC and image signing all matter. Leaked keys need a fast, complete response.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- pull_request_target runs in the base repository context with secrets and a write token. Building the pull request's code there runs untrusted code with those secrets. Use pull_request for untrusted code and deploy only on push to main.
- Putting ${{ github.event.pull_request.title }} directly in a run step is script injection. Pass such values through env and quote them.
- Set least-privilege permissions for the token, not write-all.
- Pin third-party actions to a full commit SHA. Tags can move: tj-actions tags were repointed to malicious code in March 2025.
- Use OIDC roles with a trust policy limited to the repository and branch instead of long-lived cloud keys.
- A leaked key: deactivate it at once, check quarantine policy, keep evidence, then investigate with CloudTrail across all regions for calls from that key. Deleting the key stops new calls but not resources it created or temporary credentials already issued, so revoke sessions.
- Prevent with OIDC, secret scanning, and short-lived credentials.
- Only our images in production: protected main, trusted build, SBOM and provenance, signing (cosign keyless with the CI identity), and admission control (Kyverno or a policy controller) that verifies the signature identity before a pod starts.
The red pen
Common traps: mistake → fix
Mistake: Private repositories keep secrets safe
Fix: keys leak through forks, logs and mistakes.
Mistake: Version tags are immutable
Fix: they can be moved; pin to a SHA.
Mistake: Deleting the key ends the incident
Fix: check what it created and what sessions exist.
Easy to hard
Questions interviewers ask, easy to hard
- Is this GitHub Actions workflow safe?
- An AWS key from CI leaked to a public repo. What do you do?
- How do you guarantee only our images run in production?
- Why OIDC instead of access keys?
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.