Skip to content

chore: Enforce GitHub Actions security policy#1223

Merged
hatayama merged 3 commits into
v3-betafrom
feature/hatayama/harden-ci-security-checks
May 27, 2026
Merged

chore: Enforce GitHub Actions security policy#1223
hatayama merged 3 commits into
v3-betafrom
feature/hatayama/harden-ci-security-checks

Conversation

@hatayama

Copy link
Copy Markdown
Owner

Summary

  • Pin GitHub Actions workflow dependencies to immutable commit SHAs.
  • Add CI coverage that rejects unpinned workflow actions and unsafe pull request cache settings.

User Impact

  • Pull request and release workflows become less vulnerable to upstream tag drift.
  • Future workflow changes fail locally and in CI when they reintroduce unpinned actions or unsafe pull request Go caching.

Changes

  • Replaced remote workflow action version tags with full commit SHAs.
  • Disabled setup-go caching in the pull request security scan workflow.
  • Added Go architecture tests for workflow action pinning and pull request cache policy.
  • Documented the repository policy and update flow in docs/github-actions-security.md.

Verification

  • go test ./internal/architecture -run 'TestWorkflowActions|TestPullRequestWorkflow' -count=1
  • scripts/test-cli-minimum-version-warning-workflow.sh
  • scripts/test-native-cli-publish-workflow.sh
  • scripts/test-release-please-config.sh
  • git diff --check
  • scripts/check-go-cli.sh

Closes #1221

Out of scope: moving the CLI minimum warning comment implementation to Go is tracked separately in #1222.

Pin workflow actions to immutable commit SHAs so CI behavior cannot drift through moving tags, and add architecture tests that keep new workflow changes on the same policy.

Disable setup-go caching in the pull request security scan because PR workflows should not restore Go module caches from untrusted changes.
@coderabbitai

coderabbitai Bot commented May 27, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 61af57d2-e5ee-4023-b02c-7e648140e2b0

📥 Commits

Reviewing files that changed from the base of the PR and between 9d83354 and f5e44d3.

📒 Files selected for processing (1)
  • Packages/src/Cli~/internal/architecture/github_actions_security_test.go

📝 Walkthrough

Walkthrough

Pins GitHub Actions usages across repository workflows to specific commit SHAs, adds PR cache-safety constraints, introduces a security policy document, and implements Go tests that enforce these workflow rules by scanning .github/workflows YAML files.

Changes

GitHub Actions Security Hardening and Enforcement

Layer / File(s) Summary
Security Policy Documentation
docs/github-actions-security.md
Establishes required action SHA pinning, the update procedure, how to resolve nested action paths, mandates setup-go disable caching in PR workflows, and requires actions/cache in PRs to be guarded by HAS_UNITY_LICENSE.
Workflow Action Pinning
.github/workflows/build-and-test.yml, .github/workflows/cli-minimum-version-warning.yml, .github/workflows/native-cli-publish.yml, .github/workflows/release-failure-notify.yml, .github/workflows/release-please.yml, .github/workflows/security-scan.yml, .github/workflows/unity-compile-check-and-test-runner.yml, .github/workflows/unity-editmode-tests.yml
Pins marketplace actions to specific commit SHAs (e.g., actions/checkout, actions/setup-go, actions/setup-dotnet, actions/cache, actions/upload-artifact, googleapis/release-please-action, github/codeql-action/upload-sarif, game-ci/*). Security-scan and other PR workflows also set setup-go to cache: false and apply license guards where required.
Workflow Security Enforcement Tests
Packages/src/Cli~/internal/architecture/github_actions_security_test.go
Adds Go tests: TestWorkflowActionsUseCommitPins (enforces 40-hex SHA pins), TestPullRequestWorkflowsDisableSetupGoCache (requires cache: false for actions/setup-go in PR workflows), TestPullRequestWorkflowCacheActionsRequireTrustedUnitySecrets (requires if: env.HAS_UNITY_LICENSE == 'true' for actions/cache in PR workflows). Includes YAML parsing and helper utilities.

Sequence Diagram(s)

sequenceDiagram
  participant Developer
  participant Workflows as Workflow Files
  participant Tests as Security Tests
  participant CI as CI System

  Developer->>Workflows: pin actions to commit SHAs
  Developer->>Workflows: add cache: false to PR setup-go and guard actions/cache
  CI->>Tests: run workflow compliance tests
  Tests->>Workflows: scan .github/workflows/*.yml
  Tests->>Tests: validate SHA pinning and PR cache rules
  Tests-->>CI: report results
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~40 minutes

Possibly related PRs

  • hatayama/unity-cli-loop#1220: Related workflow edits addressing actions/setup-go cache behavior in pull-request builds, which the new enforcement tests validate.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 22.22% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'chore: Enforce GitHub Actions security policy' clearly summarizes the main objective of the PR, which is to enforce security policies for GitHub Actions workflows.
Description check ✅ Passed The description is directly related to the changeset, covering the summary of changes, user impact, specific modifications, verification steps, and noting out-of-scope work.
Linked Issues check ✅ Passed The PR comprehensively addresses all acceptance criteria from issue #1221: implements consistent SHA pinning across workflows, adds CI checks for unpinned actions and unsafe cache usage, and documents the policy.
Out of Scope Changes check ✅ Passed All changes are directly aligned with issue #1221 objectives; the PR properly scopes out CLI minimum warning Go implementation (#1222) which is tracked separately.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/hatayama/harden-ci-security-checks

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@Packages/src/Cli`~/internal/architecture/github_actions_security_test.go:
- Around line 120-127: The parser in parseUsesAction incorrectly assumes "uses:"
has no leading "-" and that step boundaries only start at "- name:", which lets
unnamed steps (e.g., "- uses: actions/checkout@v2") bypass checks; update
parseUsesAction to accept an optional leading "-" (trim leading "- " before
checking for "uses:") and add/adjust the higher-level step-parsing logic that
groups lines into a step context so attributes (uses:, name:, with:, etc.) are
only interpreted within the same step block — ensure step start is detected for
lines beginning with "-" followed by "name:" or "uses:" and that subsequent
indented lines are attached to that step to prevent attribute bleed between
neighboring steps.
- Around line 130-137: The function workflowRunsOnPullRequest only detects block
keys and misses inline "on:" forms; update it to also handle lines starting with
"on:" by parsing the remainder of that line for "pull_request" or
"pull_request_target" (e.g., "on: pull_request" and "on: [push, pull_request]")
and, if "on:" appears alone, scan subsequent indented lines until the next
top-level key to find those same identifiers; ensure you still return true for
existing block-form checks (strings.HasPrefix(trimmedLine, "pull_request:") /
"pull_request_target:") and add the new logic that normalizes and searches
comma/bracket-separated lists and simple inline values.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 6a05eb43-3dc6-4541-aae0-03ee697f5591

📥 Commits

Reviewing files that changed from the base of the PR and between 73db4b4 and 4be46a0.

📒 Files selected for processing (10)
  • .github/workflows/build-and-test.yml
  • .github/workflows/cli-minimum-version-warning.yml
  • .github/workflows/native-cli-publish.yml
  • .github/workflows/release-failure-notify.yml
  • .github/workflows/release-please.yml
  • .github/workflows/security-scan.yml
  • .github/workflows/unity-compile-check-and-test-runner.yml
  • .github/workflows/unity-editmode-tests.yml
  • Packages/src/Cli~/internal/architecture/github_actions_security_test.go
  • docs/github-actions-security.md

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

1 issue found across 10 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread Packages/src/Cli~/internal/architecture/github_actions_security_test.go Outdated
Cover unnamed GitHub Actions steps and inline pull request triggers so the workflow security policy tests cannot miss valid workflow syntax or read settings from neighboring steps.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

2 issues found across 1 file (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread Packages/src/Cli~/internal/architecture/github_actions_security_test.go Outdated
Comment thread Packages/src/Cli~/internal/architecture/github_actions_security_test.go Outdated
Only direct GitHub Actions trigger entries under on: should decide whether a workflow is pull-request driven. This keeps nested values such as workflow_run filters from being treated as PR triggers while still supporting inline map syntax.
@hatayama
hatayama merged commit 7c365ee into v3-beta May 27, 2026
8 checks passed
@hatayama
hatayama deleted the feature/hatayama/harden-ci-security-checks branch May 27, 2026 05:38
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.

2 participants