Skip to content

Lesson 5 of 9 · 26m

Least Privilege: permissions, OIDC, and Secret Handling

How GITHUB_TOKEN really works, why explicit permissions are non-negotiable, and how OIDC replaces long-lived cloud credentials.

The fastest way to turn CI into an incident is a workflow with write-all tokens, cloud keys in repository secrets, and no clear ownership of what can deploy. The secure baseline is boring: explicit permissions, short-lived identity, and secrets scoped as narrowly as the platform allows.

Start with almost nothing

GITHUB_TOKEN is created for each workflow run. Default permissions vary by repository and organization settings, so relying on defaults is sloppy. Declare the minimum at workflow level and expand at job level only where needed.

permissions:
  contents: read
jobs:
  test:
    permissions: {contents: read}
    runs-on: ubuntu-latest
    steps: [uses: actions/checkout@v4]
  release:
    needs: test
    if: startsWith(github.ref, 'refs/tags/v')
    permissions: {contents: write, id-token: write}
    runs-on: ubuntu-latest

If a job only tests code, it does not need write access. If it comments on pull requests, grant pull-requests: write to that job, not the whole workflow.

OIDC replaces cloud access keys

Actions can request an OpenID Connect token signed by GitHub. Cloud providers validate the token and exchange it for short-lived cloud credentials based on audience, repository, branch, environment, or workflow claims.

permissions: {id-token: write, contents: read}
steps:
  - uses: aws-actions/configure-aws-credentials@v4
    with:
      role-to-assume: arn:aws:iam::123456789012:role/github-deploy-production
      aws-region: us-east-1

The important half is the AWS role trust policy. It should constrain the subject claim, for example to repo:myorg/api:environment:production, not every workflow in the organization. OIDC is powerful because repository compromise no longer means compromise of a static cloud key sitting in a secret for three years.

Secrets are exposure, not architecture

Repository secrets are available to workflows in that repository. Environment secrets add protection rules and reviewers. Organization secrets are convenient but broad. Ask: what is the blast radius if this value leaks through a malicious pull request, compromised action, or maintainer mistake?

deploy:
  environment: production
  steps:
    - run: ./deploy.sh
      env:
        DEPLOY_TOKEN: ${{ secrets.PRODUCTION_DEPLOY_TOKEN }}

Pass secrets into env at the narrowest step. Do not write them to files unless the tool requires it. Do not echo them. Do not pass them to untrusted action inputs when a supported native integration exists.

Masking is only a safety net: GitHub masks exact secret values in logs, but transformations are not reliably masked. Base64-encoded secrets, JSON-embedded secrets, and accidental substring output can leak. Treat logs as public within your organization and sometimes outside it.

Field notes

  • permissions: {} is valid and means no permissions; use it when a workflow needs no repository token access.
  • id-token: write does not authenticate to your cloud by itself; it only lets the job request the token.
  • Rotate old static cloud keys even after migrating to OIDC; unused keys are still compromise material.
  • Environment protection rules are part of the security boundary. Configure required reviewers and deployment branches deliberately.

Was this lesson helpful?

Sign in to rate