Skip to content

ci: add GitHub Actions security audit script#3600

Open
zackverham wants to merge 5 commits intomainfrom
add-gha-security-audit-script
Open

ci: add GitHub Actions security audit script#3600
zackverham wants to merge 5 commits intomainfrom
add-gha-security-audit-script

Conversation

@zackverham
Copy link
Collaborator

@zackverham zackverham commented Feb 23, 2026

Summary

This is the result of working through a suggestion proposed by @dotNomad to capture some of the improvements we made to tidy up our github actions. Those best practices are things we want to continue to maintain moving forward, so this script helps us to mitigate drift over time. It also is something that we could probably apply to other repositories, if we can figure out the right set of validations here.

I don't have any ideas on how often we want to run this, or where the results should live, or anything like that. But it does capture the work in a set of repeatable checks that we can kick off via a github action manually, which is nice.


Adds a Python script to audit GitHub Actions workflows for common security best practices. This script captures the security hardening improvements that have been applied to this repository, making them repeatable and auditable.

Security Checks

The script checks for 8 categories of security issues:

Check Description
1. Explicit permissions All workflows should declare minimum required permissions
2. No secrets: inherit Pass secrets explicitly to limit exposure
3. Fork PR protection Jobs using secrets should skip fork PRs
4. Tag ancestry verification Tag-triggered releases should verify tag is on main
5. workflow_dispatch protection Publish/release workflows need environment protection
6. Overly permissive No write-all or unnecessary contents: write
7. Pinned actions Don't use @main or @master for external actions
8. Dangerous patterns No untrusted input injection, no risky pull_request_target

Usage

# Run the audit
python scripts/audit_gha_security.py

# Run tests
cd scripts && python -m unittest test_audit_gha_security -v

Current Results

Running against this repo's workflows shows 3 warnings (no errors):

  • nightly-prerelease.yaml: Missing tag ancestry verification
  • nightly-prerelease.yaml: Has workflow_dispatch without environment protection
  • e2e.yaml: Uses posit-dev/with-connect@main (unpinned action)

Test plan

  • All 28 unit tests pass
  • Script runs successfully against current workflows
  • Can be used to audit other repositories

🤖 Generated with Claude Code

Adds a Python script to audit GitHub Actions workflows for common
security best practices. The script checks for:

1. Explicit permissions declarations
2. No 'secrets: inherit' usage
3. Fork PR protection for jobs using secrets
4. Tag ancestry verification on release workflows
5. Workflow dispatch protection on publish/release workflows
6. Overly permissive permissions
7. Pinned action versions (no @main/@master)
8. Dangerous patterns (untrusted input, pull_request_target)

Based on security hardening work applied to this repository.

Run with: python scripts/audit_gha_security.py
Run tests: cd scripts && python -m unittest test_audit_gha_security

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@zackverham zackverham requested a review from a team as a code owner February 23, 2026 16:13
zackverham and others added 4 commits February 23, 2026 11:32
- `just audit-gha-security` - Run the security audit
- `just test-scripts` - Now also runs audit script tests

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The script now supports:
- `--format json` for programmatic/machine-readable output
- `--github-actions` for explicit GHA mode (also auto-detected via GITHUB_ACTIONS env)
- GitHub Actions workflow commands (::error::, ::warning::, ::notice::, ::group::)
- File and line annotations for errors/warnings
- Step summary output (GITHUB_STEP_SUMMARY)
- Output variables (GITHUB_OUTPUT): error_count, warning_count, has_errors, has_warnings
- `--no-color` flag for CI environments
- `--workflows-dir` to specify custom path

Tests updated to cover new functionality (34 tests total).

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Adds a manual workflow_dispatch trigger to run the GHA security
audit script on demand.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Removed unnecessary comment about security hardening.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant