GitHub Actions Fundamentals interview question · Most asked
How do you keep secrets safe in GitHub Actions, and why use OIDC to reach the cloud?
How you'd do it Asked in DevOps Engineer interviews
Summary
Store secrets in repository, organisation or environment secrets (never in the YAML), give the GITHUB_TOKEN the
least permissions it needs, and prefer OIDC federation to cloud providers: the workflow exchanges a
short-lived GitHub-signed token for temporary cloud credentials, so there are no long-lived access keys to leak or
rotate.
Longer Answer
- Environment secrets for production, released only to jobs that pass the environment's protection rules.
- Masking: Actions masks registered secrets in logs, but transformed values (base64, substrings) aren't masked; don't print secrets at all.
- Forks: secrets aren't passed to
pull_requestruns from forks, which is intentional; don't work around it withpull_request_targetplus checkout of untrusted code. - OIDC:
permissions: id-token: write, then the cloud trusts tokens from your repo, branch or environment (AWSAssumeRoleWithWebIdentity, Azure federated credentials, GCP Workload Identity Federation). Scope the trust policy to the exact repository and branch or environment.
Example
permissions:
id-token: write
contents: read
jobs:
deploy:
environment: production
runs-on: ubuntu-latest
steps:
- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::123456789012:role/gha-deploy
aws-region: eu-west-1
Key Points
- Secrets in settings, scoped to environments.
- Least-privilege GITHUB_TOKEN.
- OIDC gives short-lived cloud credentials.
- Scope cloud trust to repo and branch/environment.
Explanation
What interviewers look for
OIDC understanding and scoping, plus awareness of fork and masking pitfalls.
More GitHub Actions Fundamentals questions
- Explain how a GitHub Actions workflow is structured: events, jobs, steps, runners and actions.
- Write a GitHub Actions workflow that tests, builds and pushes a Docker image, and deploys only from main.
- How do you speed up slow GitHub Actions workflows?
- Reusable workflows or composite actions: what's the difference, and when do you use each?
- How do you add approval gates to deployments in GitHub Actions?
- Why should you pin third-party actions to a commit SHA?
- What are the security risks of pull_request_target and self-hosted runners?
- How does the GITHUB_TOKEN work, and how do you limit its permissions?