Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/scripts/test-native-queue-workflows.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3
"""Structural contracts for required native queue workflows (not a Go runner)."""
import pathlib
import re
import unittest

import yaml
Expand Down Expand Up @@ -69,6 +70,30 @@ def test_dependabot_runs_the_same_trusted_pr_verifier(self):
self.assertEqual(job["name"], "verify PR contents")
self.assertIn("docker run --rm", job["steps"][-1]["run"])

def test_gosec_concurrency_fits_the_runner_cpu_limit(self):
# gosec defaults -concurrency to runtime.NumCPU(), which inside a
# runner pod is the NODE's vCPU count, not the pod's cgroup limit.
# Unbounded, every worker type-checks and builds SSA for its own
# package at once, and the pod is OOM-killed or evicted mid-Scan:
# "runner lost communication", hivecommons/hive#16040. The pod CPU
# limit is a ceiling, not a memory proof: it only guarantees gosec
# never runs more workers than the pod can schedule.
values = yaml.safe_load(
(ROOT / "src/deploy/ci-runners/lke/hive-runners-lke-values.yaml").read_text())
runner = next(c for c in values["template"]["spec"]["containers"]
if c["name"] == "runner")
cpu = str(runner["resources"]["limits"]["cpu"])
cpu_limit = int(cpu[:-1]) // 1000 if cpu.endswith("m") else int(float(cpu))
for file in ("go-security-analysis.yml",
"integration-technical-go-security-analysis.yml"):
with self.subTest(file=file):
steps = workflow(file)["jobs"]["gosec"]["steps"]
scan = next(s for s in steps if s.get("name") == "Scan")["run"]
match = re.search(r"\bgosec\b.*\s-concurrency[ =](\d+)\b", scan)
self.assertIsNotNone(match, f"gosec must pass an explicit -concurrency: {scan!r}")
self.assertGreaterEqual(int(match.group(1)), 1)
self.assertLessEqual(int(match.group(1)), cpu_limit)


if __name__ == "__main__":
unittest.main()
10 changes: 9 additions & 1 deletion .github/workflows/go-security-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,18 @@ jobs:
# of the triage issue #4903; do not flip it before the
# HIGH-severity findings are resolved, and do not delete the step to make
# the summary look clean.
#
# -concurrency 4: gosec defaults to runtime.NumCPU(), which in a runner
# pod is the NODE's 32 vCPUs, not the pod's 6-CPU limit
# (src/deploy/ci-runners/lke/hive-runners-lke-values.yaml). Each worker
# type-checks and builds SSA for its own package, so 32 at once pushed
# the pod far past its 3Gi request and it was killed mid-Scan — the
# "runner lost communication" failures of #16040. Keep this at or below
# the runner CPU limit (test-native-queue-workflows.py enforces it).
- name: Scan
working-directory: src
continue-on-error: true
run: gosec -exclude-generated ./... ./crux/...
run: gosec -concurrency 4 -exclude-generated ./... ./crux/...

golangci-lint:
needs: required-context-scope
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/integration-candidate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1856,7 +1856,7 @@ jobs:
- name: Scan
working-directory: src
continue-on-error: true
run: gosec -exclude-generated ./... ./crux/...
run: gosec -concurrency 4 -exclude-generated ./... ./crux/...
env:
GO_CACHE_GUARD_BUILD_CACHE: ${{ 'job' || 'job' }}
security-golangci-lint:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ jobs:
- name: Scan
working-directory: src
continue-on-error: true
run: gosec -exclude-generated ./... ./crux/...
run: gosec -concurrency 4 -exclude-generated ./... ./crux/...
golangci-lint:
needs: required-context-scope
if: ${{ always() && (needs.required-context-scope.result != 'success' || needs.required-context-scope.outputs.run-go-security == 'true') && !(github.event_name == 'pull_request' && startsWith(github.head_ref, 'release-gate/')) }}
Expand Down
Loading