Sikau

GitHub Actions · Day 7 · about 30 min

Secrets and permissions

Repository secrets, masking, and least-privilege GITHUB_TOKEN.

Keys don't belong in YAML

Deploying needs credentials — an API token, an SSH key. Writing them in the workflow would leak them to anyone who can read the repo. secrets are stored encrypted in the repository settings and injected at run time, and GitHub masks them as * in logs.

Using secrets safely

name: Deploy
on: push
permissions:
  contents: read
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npm ci && npm run build
      - name: Deploy
        run: ./scripts/deploy.sh
        env:
          DEPLOY_TOKEN: ${{ secrets.DEPLOY_TOKEN }}
      - run: echo "Oops, printing $DEPLOY_TOKEN"
        env:
          DEPLOY_TOKEN: ${{ secrets.DEPLOY_TOKEN }}
  • Secrets aren't passed to workflows triggered from forks.
  • Prefer short-lived credentials (OIDC) over long-lived keys when your cloud supports it.
  • vars.NAME holds non-secret configuration.

The rest of this lesson

  • Secrets into stepsexplain
  • The GITHUB_TOKENexplain
  • Missing secret?predict
  • Safe or unsafe?match
  • Your turnwrite code
  • Badge quizquiz
  • What you learnedrecap

Continue this lesson free — run real code in your browser

Continue with Google

See all 12 lessons of GitHub Actions