feat(hardening-basic): add nullable inotify sysctl limits #60
No reviewers
Labels
No labels
bug
cannot reproduce
duplicate
enhancement
help wanted
invalid
need info
need triage
need verification
not a bug
question
wontfix
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
claudiomaradonna/castrum!60
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feat/inotify-sysctl"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Why
hardening-basicwrites/etc/sysctl.d/99-hardening.conffrom fixedkeys, then applies it and reads every key back from the kernel. A
container host whose workloads watch many files can exhaust the kernel's
per-user inotify defaults, and the role had no way to raise them: a value
set by hand in another drop-in would be neither managed nor checked.
What changed
Two variables,
hardening_sysctl_fs_inotify_max_user_instancesandhardening_sysctl_fs_inotify_max_user_watches, default tonull. Whenset, each adds its
fs.inotify.*line to99-hardening.conf, where theexisting apply-and-verify step applies and reads it back. When unset, the
drop-in renders byte-for-byte as before, so hosts that do not set them
see no change. They follow the role's other nullable sysctls, such as
hardening_sysctl_vm_mmap_rnd_bits, and the role README documents them.The
workstationmolecule scenario sets both and asserts their lines;the
defaultscenario asserts nofs.inotifyline when unset.How to verify
Prerequisites: Setup and rootless podman.
./tests/molecule/run.sh roles/hardening-basicpasses on the branch;on main the
workstationscenario's "Assert set inotify limits landin the drop-in" fails, while the
defaultpin passes on both.the variables unset, then diff: no difference. With
hardening_sysctl_fs_inotify_max_user_instances=4096andhardening_sysctl_fs_inotify_max_user_watches=1048576the branch addsonly those two lines.
Run: scenario 2, as written, with ansible's
templatemodule (no diffunset; two added lines set).
make checkpassed on every commit and onthe tip. Untested: scenario 1 and
make test, because the authoringsession had no podman; expected to pass.
Considerations
Each inotify watch in use costs about 1 KB of kernel memory, so
1048576 watches can reach about 1 GB if all are used; the defaults stay
off for that reason.
Review ready:
d7934291b8Review: approved
Reviewed
d7934291b815: 0 blocking and 1 minor findings.Reproduced
bac9cf1lands before the feature commit, and main's render holds no inotify line, so the default pin passes on main.Questions and details
@ -74,0 +76,4 @@{% endif %}{% if hardening_sysctl_fs_inotify_max_user_watches is not none %}fs.inotify.max_user_watches={{ hardening_sysctl_fs_inotify_max_user_watches }}{% endif %}Minor: When both values are set, the watches line sits flush against the net.ipv6 group; every other rendered group is blank-line separated. An empty line inside a combined is-not-none guard would restore it without changing the unset render.