Skip to content

ci: share gosec policy across local and CI scans - #2153

Merged
cristim merged 1 commit into
mainfrom
ci/gosec-single-source
Oct 8, 2026
Merged

cristim merged 1 commit into
mainfrom
ci/gosec-single-source

Conversation

@cristim

@cristim cristim commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

The changed-package hook suppressed 15 gosec rules, Make suppressed eight, and CI suppressed none. All three now use one wrapper that owns the pinned scanner and strict default policy. The hook retains selected-package coverage; Make and CI scan the root module and retain JSON/SARIF reports and failure statuses.

The wrapper verifies cached module build metadata and rejects missing reports and directory outputs. A Bash 3.2-compatible contract harness runs in CI. Unused duplicate installation/version declarations and obsolete multi-module SARIF merging are removed.

Validation: two independent implementation and two staged reviews; normal commit hooks including pinned actionlint and zizmor; shellcheck; realistic G304 fixture through the actual hook, Make target, and exact CI block. Before: hook/Make passed while CI failed. After: all three reject the same (G304, read.go, 3) finding. Clean fixture and full repository JSON/SARIF scans passed with matching empty findings. Pinned Go build and scoped SDK race tests passed.

The existing local full-suite failure #2150 remains separate. Embedded golangci-lint gosec settings are outside this three-caller change and tracked in #2152. No live cloud account was required.

Closes #1394

Summary by CodeRabbit

  • Chores
    • Go security scans now use a shared process across CI and local checks, with consistent report handling.
    • CI rejects missing or incomplete security scan reports instead of accepting them.
    • Local checks scan changed Go packages and skip files in test data directories.
  • Tests
    • Added checks for scan behavior, report creation, and error handling.

@cristim cristim added triaged Item has been triaged priority/p2 Backlog-worthy severity/medium Moderate harm urgency/this-quarter Within the quarter impact/internal Team-internal only effort/s Hours type/chore Maintenance / non-user-visible labels Oct 8, 2026
@coderabbitai

coderabbitai Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Warning

Review limit reached

  • Run on-demand review

This review includes 7 billable files and costs up to $1.75.

  • Ask an admin to make reviews automatic

Open in CodeRabbit

Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing.

Or wait 54 minutes for your next included review.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available. Your 78 included PR review attempts over the past 7 days set your current allowance at 1 review per hour.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository: LeanerCloud/cloud-commitments-cli/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: 3e3e38fb-a708-4a3e-b277-c9b46a9c31fd
📥 Commits

Reviewing files that changed from the base of the PR and between e30a57e and 5b6a3b0.

📒 Files selected for processing (7)
  • .github/workflows/ci.yml
  • .github/workflows/pre-commit.yml
  • .pre-commit-config.yaml
  • Makefile
  • scripts/gosec-hook.sh
  • scripts/run-gosec-test.sh
  • scripts/run-gosec.sh
📝 Walkthrough

Walkthrough

The pull request adds a shared gosec runner for package scans, Makefile targets, and CI. The runner validates options, installs and verifies gosec v2.28.0, and handles report output. CI checks the generated SARIF structure.

Changes

gosec scanning

Layer / File(s) Summary
Shared runner and contract checks
scripts/run-gosec.sh, scripts/run-gosec-test.sh
The new runner validates options, installs or verifies gosec v2.28.0, scans targets, and publishes nonempty reports. Contract checks cover argument forwarding, report handling, installation, and exit statuses.
Local scan entry points
scripts/gosec-hook.sh, Makefile, .pre-commit-config.yaml, .github/workflows/pre-commit.yml
The hook passes unique eligible package paths to the runner. Makefile scan and installation targets also use it. Pre-commit naming and cache descriptions no longer present gosec as a separately installed per-module tool.
CI scan and SARIF validation
.github/workflows/ci.yml
CI uses the scripts to produce one SARIF file, records nonzero statuses, and checks its version, runs, tool drivers, and results arrays.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~22 minutes

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant CI as GitHub Actions CI workflow
  participant Runner as scripts/run-gosec.sh
  participant Gosec as gosec
  participant SARIF as SARIF validation
  CI->>Runner: request SARIF scan
  Runner->>Gosec: scan targets and write report
  Gosec-->>Runner: report and exit status
  Runner-->>CI: report and exit status
  CI->>SARIF: validate version, runs, drivers, and results
Loading

Merge Risk: 🔵 Low · up to 5b6a3

The change appears mergeable. Local contract-test runs retain temporary files, but no material scanning failure was established.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 3 files. (4 skipped: 4 … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: consolidating the gosec policy across local and CI scans.
Linked Issues check ✅ Passed Issue #1394 has coding requirements. scripts/run-gosec.sh owns the pinned gosec version and scanner module. The pre-commit hook, Makefile security-scan-go, and CI security scan invoke it. The ho…
Out of Scope Changes check ✅ Passed The changes remain within issue #1394. The cache and installation changes support shared gosec ownership. The SARIF changes support the single CI report. The contract harness provides automated covera…
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 3 files. (4 skipped: 4 unsupported.)

✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@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.

🔇 Additional comments (7)
scripts/run-gosec.sh (1)

1-65: LGTM!

scripts/gosec-hook.sh (1)

4-18: LGTM!

Makefile (1)

87-87: LGTM!

Also applies to: 106-106

.pre-commit-config.yaml (1)

160-161: LGTM!

.github/workflows/pre-commit.yml (1)

47-53: LGTM!

Also applies to: 149-149

.github/workflows/ci.yml (1)

378-388: LGTM!

scripts/run-gosec-test.sh-5-5 (1)

5-5: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

⚠️ Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.

Clean up the scratch directory with an EXIT trap.

The script creates scratch with mktemp -d but never removes it. This happens on success and on failure. Every local or CI run leaves behind a fake go binary, a scanner, a gosec cache, and the reports. Register cleanup right after you create the directory. If you want to keep the directory for debugging, delete it only on success, or gate the deletion behind an environment variable.

Proposed fix
 scratch=$(mktemp -d)
+trap 'rm -rf "$scratch"' EXIT

Based on learnings: "any temporary file or directory created with mktemp or similar must be cleaned up via a trap ... set immediately after creation."

Source: Learnings


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository: LeanerCloud/cloud-commitments-cli/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: 6d86066c-a5f3-4339-9d98-af1ebc1c724e
📥 Commits

Reviewing files that changed from the base of the PR and between e30a57e and 5b6a3b0.

📒 Files selected for processing (7)
  • .github/workflows/ci.yml
  • .github/workflows/pre-commit.yml
  • .pre-commit-config.yaml
  • Makefile
  • scripts/gosec-hook.sh
  • scripts/run-gosec-test.sh
  • scripts/run-gosec.sh

Included review availability: This review used your included allowance. 0 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 1 review per hour.

@cristim

cristim commented Oct 8, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor
⚠️ Action not completed

Review rate limited.


Your included review limit is currently reached under our Fair Usage Limits Policy. Your current included review allowance is based on your included PR review attempts over the past 7 days. This review may still proceed through usage-based billing if eligible. Your next included review will be available in 54 minutes.

@cristim

cristim commented Oct 8, 2026

Copy link
Copy Markdown
Member Author

Independent review is clean at 5b6a3b0020899d1f5315aef29af36fe41055b21d against e30a57eaf54c465b6f56719eff95d85fe9be481e. Two implementation passes, two staged passes, and committed-head verification found no remaining actionables. The committed diff matches staged SHA256 3fd92f0f2b7f82f5d4b52d0b46b40170524fbe0e53b8bc3937292a13c7f2d01e.

Independent real-path checks confirm the Bash 3.2 contract, directory-output rejection, and exact CI block's report/failure behavior. Removing the guard makes the regression fail. Actual scanner G304 fixture outputs agree across hook/Make/CI; strict repository JSON/SARIF scans agree. Fixture report-error probes are labeled separately from real scans. Pinned workflow commit hooks passed normally.

Fresh exact-head CI runs37728064787 and37728064679 both succeeded, including unit/integration/security/workflow checks. Working tree is clean and PR merge state is CLEAN. CodeRabbit explicitly returned quota exhaustion, so its success check is not a clean review. Owner-authorized quota waiver applies with independent adversarial review, local verification, and green CI; retrospective review stays on the coordinator's existing cadence.

Scope remains the three standalone callers. Embedded golangci policy assessment is tracked in #2152; existing local full-suite capture deadlock remains #2150. No protection bypass or live-cloud purchase.

@cristim
cristim merged commit 7055a1a into main Oct 8, 2026
12 checks passed
@cristim

cristim commented Oct 8, 2026

Copy link
Copy Markdown
Member Author

Merged normally as 7055a1abd41bf19d2adf220a7f28791ab9efee1e. Its tree 023d33980e3e1b79eca5b01f97ff827111102ebd exactly matches the independently reviewed head. The actual post-merge Bash 3.2 contract check passed; post-merge build/test run37730179191 and pre-commit run37730179314 both completed successfully at this merge SHA.

Issue1394 is closed. All source branches, tests, metadata, and verification artifacts were preserved. CodeRabbit review was quota-waived with independent evidence; retrospective full review is recorded for the coordinator's existing cadence. Embedded gosec assessment remains #2152. Local act simulation hit GitHub408 twice; actual CI and exact local run-block evidence passed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/s Hours impact/internal Team-internal only priority/p2 Backlog-worthy severity/medium Moderate harm triaged Item has been triaged type/chore Maintenance / non-user-visible urgency/this-quarter Within the quarter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ci: pre-commit gosec hook and CI enforce DIFFERENT gosec rule sets [cli part]

1 participant