Skip to content

fix: tighten workflow permissions, add security hardening, and fix uv tool invocations#702

Merged
jmeridth merged 2 commits intomainfrom
fix/tighten-workflow-permissions-and-security-hardening
Mar 14, 2026
Merged

fix: tighten workflow permissions, add security hardening, and fix uv tool invocations#702
jmeridth merged 2 commits intomainfrom
fix/tighten-workflow-permissions-and-security-hardening

Conversation

@jmeridth
Copy link
Collaborator

What

Move elevated permissions from workflow level to job level across four workflows (mark-ready-when-ready, scorecard, stale, contributor_report) so each job only holds the permissions it actually needs. Add step-security/harden-runner to all eight workflows that define steps. Add CodeQL SAST scanning and dependency-review workflows. Add pre-commit configuration with gitleaks, formatting hooks, and local linter hooks. Fix Makefile to invoke flake8, pytest, pylint, and mypy via uv run python -m since they lack console script entry points in the uv venv. Upgrade PyJWT from 2.11.0 to 2.12.1 to address CVE-2026-32597.

Why

Workflow-level write permissions apply to every job in the workflow, granting broader access than necessary. Moving them to job level follows the principle of least privilege. Harden-runner audits outbound network calls from GitHub-hosted runners, improving supply-chain visibility. CodeQL and dependency-review close gaps in static analysis and vulnerable-dependency detection. The Makefile commands failed under uv because those packages don't install console scripts; python -m ensures the tools are always found. PyJWT <= 2.11.0 doesn't validate the RFC 7515 crit header parameter (CVSS 7.5).

Notes

  • The uv run to uv run python -m change also affects CI since python-package calls make lint and make test
  • release.yml, auto-labeler.yml, and pr-title.yml use reusable workflows at the job level so harden-runner cannot be added there; it must go in the reusable workflow definitions instead
  • pylint was also changed to python -m beyond what the upstream stale-repos PR did, since it failed the same way as flake8/mypy/pytest
  • PyJWT is a transitive dependency; verify downstream consumers aren't relying on the old crit-header-ignored behavior
  • The scorecard workflow previously used permissions: read-all which granted read access to all scopes; now explicitly scoped to only what's needed

@jmeridth jmeridth requested a review from zkoppert as a code owner March 14, 2026 01:51
Copilot AI review requested due to automatic review settings March 14, 2026 01:51
@github-actions github-actions bot added the fix label Mar 14, 2026
@jmeridth jmeridth force-pushed the fix/tighten-workflow-permissions-and-security-hardening branch from ba93395 to 293d51c Compare March 14, 2026 01:53
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR strengthens the repo’s supply-chain/security posture and dev tooling by adding pre-commit hooks, tightening GitHub Actions permissions, hardening runners, and updating a dependency lock entry.

Changes:

  • Add a .pre-commit-config.yaml with gitleaks + Python formatting/lint/type-check hooks.
  • Harden multiple GitHub Actions workflows (runner hardening + more granular permissions) and add new Dependency Review + CodeQL workflows.
  • Bump pyjwt in uv.lock and adjust Makefile commands to run tools via python -m ....

Reviewed changes

Copilot reviewed 12 out of 14 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
uv.lock Updates locked pyjwt version and artifact hashes/URLs.
Makefile Runs pytest/flake8/pylint/mypy via python -m under uv run.
.pre-commit-config.yaml Introduces pre-commit hooks for secrets scanning and Python tooling.
.github/workflows/stale.yaml Adds runner hardening and scopes permissions at job level.
.github/workflows/scorecard.yml Adds runner hardening and narrows default permissions.
.github/workflows/python-package.yml Adds runner hardening to CI test workflow.
.github/workflows/mark-ready-when-ready.yml Moves elevated permissions to job level and adds runner hardening.
.github/workflows/linter.yaml Adds runner hardening to the linter workflow.
.github/workflows/docker-image.yml Adds runner hardening to Docker build workflow.
.github/workflows/dependency-review.yml Adds dependency review workflow for PR dependency changes.
.github/workflows/copilot-setup-steps.yml Adds runner hardening to Copilot setup steps.
.github/workflows/contributor_report.yaml Adds runner hardening and adjusts permissions structure.
.github/workflows/codeql.yml Adds CodeQL scanning workflow with pinned actions and runner hardening.

… tool invocations

## What

Move elevated permissions from workflow level to job level across four workflows
(mark-ready-when-ready, scorecard, stale, contributor_report) so each job only
holds the permissions it actually needs. Add step-security/harden-runner to all
eight workflows that define steps. Add CodeQL SAST scanning and dependency-review
workflows. Add pre-commit configuration with gitleaks, formatting hooks, and local
linter hooks. Fix Makefile to invoke flake8, pytest, pylint, and mypy via
`uv run python -m` since they lack console script entry points in the uv venv.
Upgrade PyJWT from 2.11.0 to 2.12.1 to address CVE-2026-32597.

## Why

Workflow-level write permissions apply to every job in the workflow, granting
broader access than necessary. Moving them to job level follows the principle of
least privilege. Harden-runner audits outbound network calls from GitHub-hosted
runners, improving supply-chain visibility. CodeQL and dependency-review close
gaps in static analysis and vulnerable-dependency detection. The Makefile commands
failed under uv because those packages don't install console scripts; `python -m`
ensures the tools are always found. PyJWT <= 2.11.0 doesn't validate the RFC 7515
`crit` header parameter (CVSS 7.5).

## Notes

- The `uv run` to `uv run python -m` change also affects CI since python-package calls `make lint` and `make test`
- release.yml, auto-labeler.yml, and pr-title.yml use reusable workflows at the job level so harden-runner cannot be added there; it must go in the reusable workflow definitions instead
- pylint was also changed to `python -m` beyond what the upstream stale-repos PR did, since it failed the same way as flake8/mypy/pytest
- PyJWT is a transitive dependency; verify downstream consumers aren't relying on the old crit-header-ignored behavior
- The scorecard workflow previously used `permissions: read-all` which granted read access to all scopes; now explicitly scoped to only what's needed

Signed-off-by: Jason Meridth <jmeridth@gmail.com>
@jmeridth jmeridth force-pushed the fix/tighten-workflow-permissions-and-security-hardening branch from bec6a6d to f01eb88 Compare March 14, 2026 02:28
@zkoppert
Copy link
Collaborator

The Autobuild step in codeql.yml is a no-op for Python since CodeQL analyzes source directly without a build step. Please remove the Autobuild step and its surrounding comments to keep the workflow clean.

Signed-off-by: jmeridth <jmeridth@gmail.com>
Copy link
Collaborator

@zkoppert zkoppert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - minor note: consider removing the Autobuild step from codeql.yml since it's a no-op for Python.

@jmeridth jmeridth merged commit e26b4f3 into main Mar 14, 2026
39 checks passed
@jmeridth jmeridth deleted the fix/tighten-workflow-permissions-and-security-hardening branch March 14, 2026 04:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants