Skip to content

feat: --fail-on severity gate + SARIF parity for agent/CI gating#6

Merged
stxkxs merged 1 commit into
mainfrom
fail-on-and-sarif
May 29, 2026
Merged

feat: --fail-on severity gate + SARIF parity for agent/CI gating#6
stxkxs merged 1 commit into
mainfrom
fail-on-and-sarif

Conversation

@stxkxs
Copy link
Copy Markdown
Member

@stxkxs stxkxs commented May 29, 2026

See the commit message for full detail. First part of the approved AI-agent-readiness plan (the MCP server + AGENTS.md follow in a separate PR so the new dependency is reviewed in isolation).

Summary

  • --fail-on <severity> exit-code gate — exit 2 when any finding meets/exceeds the threshold (1 stays reserved for command errors, 0 = clean). New cmd/gate.go (gate[T]/gateBool), wired into iam/storage/network/certs/tags/secrets/audit/k8s-rbac/lambda (severity), compliance (failed-control severity), and drift (any modified/deleted). Cost/orphans/quota/inventory intentionally ungated.
  • SARIF parity — new writers for k8s rbac, lambda audit, compliance, drift, joining the existing five domains. Cost/orphans/quota/inventory stay JSON-only (SARIF isn't for non-security findings).
  • Testscmd/gate_test.go (first tests in the cmd package) + round-trip cases in internal/output/sarif_test.go.

Verification

go build, go test ./..., go vet, and golangci-lint v2.12.2 (uncapped) all pass. Binary confirms the --fail-on flag and the new sarif output formats. (E2E exit-code behaviour against live findings needs cloud creds; gate logic is unit-tested.)

Follow-on (next PR)

cloudgov mcp serve mode + AGENTS.md — makes cloudgov a first-class MCP tool for fab agents. Adds the one new dependency (Go MCP SDK).

cloudgov could only report findings, never gate on them, and emitted
SARIF for just 5 of its security domains — both block clean use in CI
pipelines and in the fab merge-gate. This adds a severity-based
exit-code contract and rounds out SARIF coverage. First part of the
AI-agent-readiness plan; the MCP server + AGENTS.md follow separately.

─── Exit-code gate (--fail-on) ───

- cmd/gate.go (new): a generic gate[T](items, sev) helper and
  gateBool(cond), plus the package exitCode/failOn vars. Exit codes are
  now 0 = clean, 1 = command error (unchanged), 2 = a finding met or
  exceeded the --fail-on threshold. Reuses cloud.SeverityRank.
- cmd/root.go: new persistent --fail-on <severity> flag
  (CRITICAL/HIGH/MEDIUM/LOW); Execute() exits with the gate code on the
  success path. Default behaviour (flag unset) is unchanged.
- Wired into the security/posture commands: iam scan, storage audit,
  network audit, certs, tags, secrets, audit, k8s rbac, lambda audit
  (severity-gated); compliance (gates on failed-control severity); drift
  (gates on any modified/deleted resource). cost/orphans/quota/inventory
  are intentionally not gated — they aren't pass/fail checks.

─── SARIF parity ───

- internal/output/sarif.go: new WriteK8sSARIF, WriteLambdaSARIF,
  WriteComplianceSARIF, WriteDriftSARIF, plus a shared
  sarifReport/encodeSARIF helper. Compliance maps failed controls to
  their severity level and omits passes; drift maps modified->warning /
  deleted->error and omits in-sync.
- Wired `--output sarif` into k8s rbac, lambda audit, compliance, and
  drift (joining iam/storage/network/certs/secrets/audit).
  cost/orphans/quota/inventory stay JSON-only — SARIF isn't the right
  format for non-security findings.

─── Tests ───

- cmd/gate_test.go (new): table-driven coverage of the gate threshold
  logic and gateBool (the cmd package had no tests before).
- internal/output/sarif_test.go: round-trip tests for the four new
  writers (valid SARIF 2.1.0, level mapping, pass/in-sync omission) and
  the new rule builders.

Verification: go build ./..., go test ./..., go vet ./..., and
golangci-lint v2.12.2 (uncapped) all pass. Binary confirmed: --fail-on
is registered and k8s/lambda/compliance/drift advertise the sarif
output format. End-to-end exit-code behaviour against live findings
needs cloud creds; the gate logic itself is unit-tested.

Co-authored-by: stxkxsbot <275011021+stxkxsbot@users.noreply.github.com>
@stxkxs stxkxs marked this pull request as ready for review May 29, 2026 18:42
@stxkxs stxkxs merged commit ec713f3 into main May 29, 2026
4 checks passed
@stxkxs stxkxs deleted the fail-on-and-sarif branch May 29, 2026 18:42
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