Interview Prep/GitHub Actions/OIDC & Security Hardening

What should a hardened workflow header look like?

BeginnerConceptOIDC & Security Hardening
Answer
name: CI
on:
  pull_request:
  push:
    branches: [main]
permissions:
  contents: read
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: ${{ github.event_name == 'pull_request' }}
defaults:
  run:
    shell: bash
jobs:
  test:
    runs-on: ubuntu-24.04
    timeout-minutes: 15
    steps:
      - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
        with:
          persist-credentials: false

Read-only token, cancellation, strict shell, pinned OS, timeout, pinned action, no persisted credentials.

All GitHub Actions questions Roadmap: GitHub Actions

More on OIDC & Security Hardening