Skip to content

test: cover harden_sysctl / harden_attack_surface invariants - #29

Merged
neohiro merged 1 commit into
mainfrom
test/hardening-coverage
Oct 9, 2026
Merged

neohiro merged 1 commit into
mainfrom
test/hardening-coverage

Conversation

@neohiro

@neohiro neohiro commented Oct 9, 2026

Copy link
Copy Markdown
Owner

Closes the coverage gap on the two hardening functions added in PR #25/#27/#28.

Neither function is directly executable in the test harness (they write /etc files and call systemctl/sudo), so the tests extract each function body and assert structurally. Each assertion pins a behaviour that was a real bug:

  • core network profile values: rp_filter, tcp_syncookies, accept_source_route, accept_redirects, tcp_rfc1337, log_martians
  • user.max_user_namespaces=0 remains gated on container-runtime detection
  • sysctl metrics count uses '|| true' on the grep -cE line, not '|| echo 0' which produced a doubled '00' and broke metrics arithmetic
  • SSH crypto directives split on the first space (splitting on '=' corrupted sshd_config)
  • sshd_config.d drop-ins are backed up before edits and restored on validation failure
  • login.defs ENCRYPT_METHOD is never downgraded to SHA512
  • squashfs is blacklisted conditionally and is absent from the static array
  • attack_surface and apt_https are reachable via --step

Negative controls: reintroducing the '=' split, the duplicated echo fallback, or removing the snap/squashfs triage each flip the corresponding assertion. Verified in-memory (no source mutation).

Both functions write system files and call systemctl/sudo, so the new tests
extract their bodies and assert structurally instead of executing them.

Pins regressions that were real bugs:
- core network profile values (rp_filter, syncookies, source_route,
  accept_redirects, rfc1337, log_martians)
- user.max_user_namespaces=0 stays gated on container detection
- sysctl metrics count uses '|| true' on the grep -cE line, not a
  duplicated '|| echo 0' fallback that yields '00'
- SSH crypto directives split on the first space, not '='
- sshd_config.d drop-ins are backed up before edits
- login.defs ENCRYPT_METHOD is never downgraded
- squashfs is blacklisted conditionally and stays out of the static array
- attack_surface and apt_https are reachable via --step
@neohiro
neohiro merged commit 7a58e61 into main Oct 9, 2026
8 checks passed
@neohiro
neohiro deleted the test/hardening-coverage branch October 9, 2026 18:25
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