Files
kevinveenbirkenbachandClaude Opus 5.5 5b2b44f94a fix(sys-ctl-hlth-runtime): skip network mounts in the host scan
Root cause: on PR 2009 (run 43802337071, swarm job odoo#1) the
sys-ctl-hlth-runtime unit failed because the Trivy rootfs scan of a
swarm node hit its 5 minute timeout. The wrk-02 journal shows the walk
stuck in /var/lib/infinito, which on a swarm node with storage.backend
nfs is the NFS mount of the cluster-shared volumes. The host metrics of
the same window rule out load. Every node walked the whole shared state
over NFS, plus the node-local backup store bound over it.

Fix:
- The check reads /proc/self/mountinfo when it scans the host and skips
  every mount other than / whose type is a network or automount
  filesystem (nfs, nfs4, cifs, sshfs, ceph, glusterfs, autofs and the
  other types in NETWORK_FSTYPES). It prints one info line per skipped
  mount. Mount points are octal-unescaped and read with surrogateescape.
  The printed line escapes undecodable bytes, so a strict UTF-8 stdout
  cannot crash the check, and every non-printable character, so a mount
  point holding a newline cannot forge journal lines or JSON events.
- The static DIR_VAR_LIB exclude is not needed: swarm nodes and the
  controller mount it as nfs or nfs4, which the detection catches, and a
  compose host scans it again as before. The new group path
  DIR_BACKUPS_NODE replaces the client role's private backup dir var and
  is excluded statically, since it is a local tree.
- Trivy gets one --skip-dirs per path, each value CSV-quoted: Trivy
  parses every value as CSV, so an unquoted comma splits a path even
  when it stands alone (checked on trivy 0.76.1).
- Every skip path is glob-escaped for Trivy, Syft and Grype, which all
  match with doublestar v4. One unbalanced [ in a skip path made Trivy
  0.76.1 drop every skip path sorted after it, which would bring back
  the walk of the Docker data root and the NFS state. An unescaped *
  also skipped sibling directories.
- README: the host scan does not see software on a network-mounted
  /opt, /home, /usr/local or /var (with /var also the package
  database), and volume content is scanned in neither compose nor swarm
  mode. That covers runtime installs and the image content Docker copies
  into an empty named volume on first mount, such as hermes_data at
  /opt/data, which stays at its first version after image upgrades.

Evidence:
- 10 files changed, 565 insertions, 12 deletions.
- test_network_mounts 10 passed, test_script 163 passed,
  test_host_excludes 3 passed, each file run alone; ruff and the
  repository comment lint are clean on every staged file.
- Negative controls, all red: no report lines, no wiring of the mounts
  into the scan, Syft or Grype excludes dropped, no glob escaping, no
  CSV quoting, no surrogateescape, raw print of an undecodable path, no
  host-target guard, no nfs type, no DIR_BACKUPS_NODE exclude, and
  test_script without its fixed mount list (15 failures).
- A mount point /srv/a\012forged prints as one line ending in
  /srv/a\nforged; without the escape the line splits and "forged"
  stands alone (negative control red).
- Trivy 0.76.1 on test trees: unescaped skips walked x[y and z and
  skipped sa by mistake; escaped skips leave only sa.
- Three review rounds; the last independent re-check confirmed the
  escaping on trivy 0.76.1 and doublestar v4 in Syft v1.55.0 and Grype
  v0.121.0.
- MEDUSA scan of the 10 files against e0f751eb4e, rerun after the
  escape fix: security 100, 0 critical, 0 new findings.
- Quality gate: pending, CI. The local quality-high run was cancelled by
  operator order before it started; the 90/5 below covers fix and break
  only.

🎯 Fix: 92 %
💥 Break: 4 %
💸 Tokens: –
⏱️ Velocity: –
🛡️ Security: 100 %
🏆 Score: 88
🚦 Gate: ✅ 90/5, tokens and velocity <= 100, security 100 %

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 09:54:43 +00:00

6 lines
111 B
Python

from pathlib import Path
PROJECT_ROOT: Path = Path(__file__).resolve().parents[6]
__all__ = ["PROJECT_ROOT"]