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

Members can save this page, take notes and track progress. See membership · Sign in

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_request runs from forks, which is intentional; don't work around it with pull_request_target plus checkout of untrusted code.
  • OIDC: permissions: id-token: write, then the cloud trusts tokens from your repo, branch or environment (AWS AssumeRoleWithWebIdentity, 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

← All GitHub Actions Fundamentals questions

Last reviewed · By the ByteCamel team · How we write content

Was this page helpful?

Report a mistake