From 690874161d3feaec43ecd53f9bc1b8093f4fcf46 Mon Sep 17 00:00:00 2001 From: Distronode Date: Thu, 5 Nov 2026 23:32:22 -0500 Subject: [PATCH] ci: declare least-privilege token permissions in every workflow Every workflow now sets a read-only token at the top level (`permissions: contents: read`), and the jobs that write ask for it on the job itself: - ci.yml, docker-publish.yml, ns8-module.yml, test-module.yml had no top-level block, so they inherited the repository's default token. They now start read-only. The existing job-level grants are unchanged: docker-publish build (packages: write, push to GHCR) and release (contents: write, gh release create), ns8-module build (packages: write), test-module (statuses: write and pull-requests: write, used by the called NethServer workflow). - cla.yml granted actions, contents, pull-requests and statuses write to the whole workflow. They move to the cla job. statuses: write is dropped: contributor-assistant/github-action v2.6.1 never calls the commit statuses API. It commits signatures (contents), comments on the pull request (pull-requests) and re-runs the CLA run (actions). - audit.yml goes from read-all to contents: read. The sbom and claims-guard jobs only check out code and upload an artifact; the scorecard job already sets its own grants. pullfrog.yml and release-verify.yml already declare read-only top-level permissions and are unchanged. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/audit.yml | 6 +++++- .github/workflows/ci.yml | 5 +++++ .github/workflows/cla.yml | 19 +++++++++++++++---- .github/workflows/docker-publish.yml | 6 ++++++ .github/workflows/ns8-module.yml | 5 +++++ .github/workflows/test-module.yml | 7 +++++++ 6 files changed, 43 insertions(+), 5 deletions(-) diff --git a/.github/workflows/audit.yml b/.github/workflows/audit.yml index a8a904ac..b1654527 100644 --- a/.github/workflows/audit.yml +++ b/.github/workflows/audit.yml @@ -17,7 +17,11 @@ on: - cron: '20 6 * * 1' # weekly, Monday — catches newly-disclosed CVEs even with no code changes workflow_dispatch: -permissions: read-all +# Read the repository and nothing else. The SBOM and claims-guard jobs only +# check out code and upload a workflow artifact; the Scorecard job sets its +# own grants below. +permissions: + contents: read jobs: scorecard: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4bff0bce..e8c79eba 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,6 +9,11 @@ on: branches: [main] pull_request: +# Read-only token. The job checks out the repository and fetches the base +# branch, and writes nothing back to GitHub. +permissions: + contents: read + concurrency: group: ci-${{ github.ref }} cancel-in-progress: true diff --git a/.github/workflows/cla.yml b/.github/workflows/cla.yml index 97d99466..7a076cbc 100644 --- a/.github/workflows/cla.yml +++ b/.github/workflows/cla.yml @@ -20,15 +20,26 @@ on: pull_request_target: types: [opened, closed, synchronize] +# Nothing at the top level beyond reading the repository. The grants the +# CLA job needs are on the job itself, below. permissions: - actions: write - contents: write - pull-requests: write - statuses: write + contents: read jobs: cla: runs-on: ubuntu-latest + # What contributor-assistant/github-action does with the workflow token: + # contents: write commits each new signature to + # signatures/version1/cla.json on main + # pull-requests: write posts and updates the CLA comment on the pull request + # actions: write re-runs the pull request's failed CLA run once + # everyone has signed + # It never calls the commit statuses API, so `statuses: write` is not + # granted; the CLA result is the job's own pass or fail. + permissions: + actions: write + contents: write + pull-requests: write steps: - name: CLA Assistant if: (github.event.comment.body == 'recheck' || github.event.comment.body == 'I have read the CLA Document and I hereby sign the CLA') || github.event_name == 'pull_request_target' diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 52beaf75..804c62b0 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -34,6 +34,12 @@ concurrency: group: docker-publish-${{ github.ref }} cancel-in-progress: true +# Read-only by default. Each job below asks for what it needs on top: build +# pushes to GHCR (packages: write), release creates the GitHub Release +# (contents: write). +permissions: + contents: read + env: REGISTRY: ghcr.io # Hardcoded lowercase — GHCR tags reject the repo's actual "Calnode/calnode" diff --git a/.github/workflows/ns8-module.yml b/.github/workflows/ns8-module.yml index 7879ae16..0f31b269 100644 --- a/.github/workflows/ns8-module.yml +++ b/.github/workflows/ns8-module.yml @@ -35,6 +35,11 @@ concurrency: group: ns8-module-publish cancel-in-progress: false +# Read-only by default. Only the build job writes, to push the module image +# to GHCR (packages: write), and it says so itself. +permissions: + contents: read + jobs: validate: runs-on: ubuntu-latest diff --git a/.github/workflows/test-module.yml b/.github/workflows/test-module.yml index a05cd5bf..5265d365 100644 --- a/.github/workflows/test-module.yml +++ b/.github/workflows/test-module.yml @@ -60,9 +60,16 @@ on: # types: [completed] # ...after setting the do_token secret. +# Read-only by default; the job below grants what the reusable workflow uses. +permissions: + contents: read + jobs: test: name: Run tests + # The called workflow checks out code (contents: read), sets a commit + # status for the run (statuses: write) and comments UI screenshots on the + # pull request (pull-requests: write). permissions: contents: read pull-requests: write