fix: suppress CIS noise - #9061
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the VHD CIS reporting script to reduce intermittent CIS assessor failures caused by background processes recreating or rewriting /var/log files with more permissive permissions during the scan window.
Changes:
- Adds a
normalize_log_permshelper and runs it repeatedly in a background loop during CIS assessment. - Adds cleanup logic (
stop_perms_guard+trap ... EXIT) to ensure the background guard is stopped before report uploads.
| normalize_log_perms() { | ||
| find /var/log -type f -exec chmod 640 {} \; | ||
| } |
| # at 0640 for the entire assessment phase by re-normalizing in the background, | ||
| # then stop the guard before reading/uploading the reports. | ||
| normalize_log_perms | ||
| ( while :; do normalize_log_perms; sleep 2; done ) & |
Windows Unit Test Results 3 files 11 suites 47s ⏱️ Results for commit 345f697. ♻️ This comment has been updated with latest results. |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (3)
vhdbuilder/packer/cis-report.sh:65
chmod 640sets permissions to exactly 0640, which can increase access for files that are already more restrictive (e.g., 0600). Since the CIS rule is "0640 or more restrictive", prefer removing the disallowed bits rather than forcing 0640. This also lets you batchchmodcalls via-exec ... +for better performance.
reset_log_perms() {
find /var/log -type f -exec chmod 640 {} \;
}
vhdbuilder/packer/cis-report.sh:76
- The permissions guard runs in a background subshell, and because the script has
set -xenabled, each loop iteration will be xtraced (every ~2s) and can significantly spam build logs during the assessor run. Consider disabling xtrace in the guard subshell.
reset_log_perms
( while :; do reset_log_perms; sleep 2; done ) &
PERMS_GUARD_PID=$!
vhdbuilder/packer/cis-report.sh:80
stop_perms_guardkills only the subshell PID. Ifreset_log_permsis in the middle of afindwhen the signal arrives, thefindprocess can be orphaned and keep chmod'ing during uploads. Killing the guard's process group helps ensure any in-flightfind/chmodchildren are terminated too.
[ -n "${PERMS_GUARD_PID:-}" ] || return 0
kill "$PERMS_GUARD_PID" 2>/dev/null || true
wait "$PERMS_GUARD_PID" 2>/dev/null || true
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (3)
vhdbuilder/packer/cis-report.sh:65
reset_log_permscurrently forces every/var/logfile to exactly0640, which can relax more-restrictive modes (e.g.0600 -> 0640) and runs onechmodper file. You can avoid broadening permissions and reduce work by only touching files with disallowed bits and clearing them (while keeping already-restrictive files as-is).
# Reset /var/log permissions to satisfy the CIS logfile-access control
# (6.1.3.1 / 6.1.4.1), which requires generic /var/log files to be 0640 or
# more restrictive.
reset_log_perms() {
find /var/log -type f -exec chmod 640 {} \;
}
vhdbuilder/packer/cis-report.sh:76
- The permissions guard loop runs under
set -e; ifreset_log_permsreturns non-zero (e.g. transientfinderrors during log rotation), the background subshell can exit and stop enforcing perms, bringing back the flake. Make the loop resilient by ignoring errors inside the guard.
reset_log_perms
( while :; do reset_log_perms; sleep 2; done ) &
PERMS_GUARD_PID=$!
vhdbuilder/packer/cis-report.sh:84
- The guard cleanup is only trapped on
EXIT. If this script is interrupted/terminated (e.g. CI cancellation sending SIGTERM), being explicit about trappingINT/TERMhelps ensure the background process is always reaped.
# Ensure the guard is reaped even if the assessor exits non-zero under set -e.
trap stop_perms_guard EXIT
| # (6.1.3.1 / 6.1.4.1), which requires generic /var/log files to be 0640 or | ||
| # more restrictive. | ||
| reset_log_perms() { | ||
| find /var/log -type f -exec chmod 640 {} \; |
There was a problem hiding this comment.
should we explicitly use chmod 0640?
What this PR does / why we need it:
This PR adds a loop that constantly changes file permissions while the CIS assessor runs in order to prevent guest agent extension logs from causing the assessor to report failures outside of Node SIG control.
Which issue(s) this PR fixes:
Not a public issues
Fixes #