diff --git a/.github/ACTIONS.md b/.github/ACTIONS.md index d357982..f6d427e 100644 --- a/.github/ACTIONS.md +++ b/.github/ACTIONS.md @@ -4,12 +4,11 @@ This guide describes the checked-in workflows. Follow each linked YAML file for ## Workflows -| Workflow | Events | Jobs | -| ---------------------------------------------------------------- | --------------------------- | ----------------- | -| [dependabot-auto-merge.yml](workflows/dependabot-auto-merge.yml) | `pull_request` | `dependabot` | -| [deploy-storybook.yml](workflows/deploy-storybook.yml) | `push`, `workflow_dispatch` | `build`, `deploy` | -| [lint.yml](workflows/lint.yml) | `push`, `pull_request` | `lint-and-build` | -| [storybook.yml](workflows/storybook.yml) | `push`, `pull_request` | `build` | +| Workflow | Events | Jobs | +| ------------------------------------------------------ | --------------------------- | ----------------- | +| [deploy-storybook.yml](workflows/deploy-storybook.yml) | `push`, `workflow_dispatch` | `build`, `deploy` | +| [lint.yml](workflows/lint.yml) | `push`, `pull_request` | `lint-and-build` | +| [storybook.yml](workflows/storybook.yml) | `push`, `pull_request` | `build` | ## Parallel steps @@ -32,11 +31,12 @@ and release-proposal references use immutable commit pins with version comments. | [actions/deploy-pages](https://github.com/actions/deploy-pages) | `v5.0.1` | `368f82528645a54fb793d4d04e342629a3f51346` | | [actions/setup-node](https://github.com/actions/setup-node) | `v7.1.0` | `949feb2413d6458794dcd2491c4babbbce0c15c1` | | [actions/upload-pages-artifact](https://github.com/actions/upload-pages-artifact) | `v5.0.0` | `fc324d3547104276b827a68afc52ff2a11cc49c9` | -| [dependabot/fetch-metadata](https://github.com/dependabot/fetch-metadata) | `v3.1.0` | `25dd0e34f4fe68f24cc83900b1fe3fe149efef98` | | [oven-sh/setup-bun](https://github.com/oven-sh/setup-bun) | `v2.2.0` | `0c5077e51419868618aeaa5fe8019c62421857d6` | ## Greenkeeping +All dependency updates, including Dependabot patch and minor updates, require maintainer review and manual merging. Passing CI and a semver label do not establish that an upstream change is safe. There is no workflow that approves or merges dependency PRs: changes merged to `main` can publish the public Storybook. + [Dependabot configuration](dependabot.yml) checks GitHub Actions weekly and groups their updates. Review the upstream release notes, runtime requirements, permissions, and changes to inputs or artifact behavior before merging. Update SHA pins to the release commit, retaining the version comment where present. 1. Update every reference to the affected action, including local composite actions under `.github/actions/`. diff --git a/.github/workflows/dependabot-auto-merge.yml b/.github/workflows/dependabot-auto-merge.yml deleted file mode 100644 index b08c07b..0000000 --- a/.github/workflows/dependabot-auto-merge.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: Dependabot Auto-Merge - -on: - pull_request: - branches: [main] - -permissions: - contents: write - pull-requests: write - -jobs: - dependabot: - runs-on: ubuntu-latest - if: ${{ github.actor == 'dependabot[bot]' }} - steps: - - name: Dependabot metadata - id: metadata - uses: dependabot/fetch-metadata@25dd0e34f4fe68f24cc83900b1fe3fe149efef98 # v3.1.0 - with: - github-token: '${{ secrets.GITHUB_TOKEN }}' - - - name: Auto-approve PR - run: gh pr review --approve "$PR_URL" - env: - PR_URL: ${{ github.event.pull_request.html_url }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Auto-merge PR - if: ${{ steps.metadata.outputs.update-type != 'version-update:semver-major' }} - run: gh pr merge --auto --squash "$PR_URL" - env: - PR_URL: ${{ github.event.pull_request.html_url }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/deploy-storybook.yml b/.github/workflows/deploy-storybook.yml index c2c1435..9c4955d 100644 --- a/.github/workflows/deploy-storybook.yml +++ b/.github/workflows/deploy-storybook.yml @@ -5,11 +5,9 @@ on: branches: [main] workflow_dispatch: -# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages +# Build dependency code without deployment authority. permissions: contents: read - pages: write - id-token: write # Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. # However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. @@ -58,6 +56,9 @@ jobs: path: ./storybook-static deploy: + permissions: + pages: write + id-token: write environment: name: github-pages url: ${{ steps.deployment.outputs.page_url }} diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 94b484b..eec6943 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -27,6 +27,9 @@ jobs: with: node-version: 26.13.0 + - name: Test workflow security policy + run: node --test scripts/check-workflow-security.mjs + - name: Test release metadata guard run: node --test scripts/check-release-guard.mjs diff --git a/.github/workflows/storybook.yml b/.github/workflows/storybook.yml index d45dbbb..52d6d1b 100644 --- a/.github/workflows/storybook.yml +++ b/.github/workflows/storybook.yml @@ -6,6 +6,9 @@ on: pull_request: branches: [main] +permissions: + contents: read + jobs: build: runs-on: ubuntu-latest diff --git a/scripts/check-workflow-security.mjs b/scripts/check-workflow-security.mjs new file mode 100644 index 0000000..e515baa --- /dev/null +++ b/scripts/check-workflow-security.mjs @@ -0,0 +1,38 @@ +import assert from 'node:assert/strict' +import { readFileSync, readdirSync } from 'node:fs' +import test from 'node:test' + +const directory = new URL('../.github/workflows/', import.meta.url) +const workflows = readdirSync(directory) + .filter((name) => /\.ya?ml$/.test(name)) + .map((name) => [name, readFileSync(new URL(name, directory), 'utf8')]) + +test('dependency updates require manual review and merging', () => { + for (const [name, source] of workflows) { + assert.doesNotMatch(source, /gh\s+pr\s+(?:review|merge)\b/, name) + assert.doesNotMatch( + source, + /(?:auto-approve|enable-pull-request-automerge|merge-me|automerge-action)@/i, + name, + ) + assert.doesNotMatch(source, /pull-requests:\s*write/, name) + } +}) + +test('PR build workflows explicitly use read-only tokens', () => { + const pullRequestWorkflows = workflows.filter(([, source]) => source.includes('pull_request:')) + for (const [name, source] of pullRequestWorkflows) { + assert.match(source, /^permissions:\n contents: read\n/m, name) + assert.doesNotMatch(source, /:\s*write\b|write-all|secrets\./, name) + } +}) + +test('only the isolated Pages deploy job has deployment authority', () => { + const source = readFileSync(new URL('deploy-storybook.yml', directory), 'utf8') + const [build, deploy] = source.split('\n deploy:\n') + assert.match(build, /^permissions:\n contents: read\n/m) + assert.doesNotMatch(build, /:\s*write\b|write-all/) + assert.match(deploy, /^ permissions:\n pages: write\n id-token: write\n/) + assert.doesNotMatch(deploy, /checkout@|bun (?:ci|install|run)|npm |pnpm /) + assert.match(deploy, /needs: build/) +})