-
Notifications
You must be signed in to change notification settings - Fork 803
Add sysctl persistence rules for Debian #14768
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # platform = multi_platform_all | ||
| # reboot = false | ||
| # strategy = configure | ||
| # complexity = low | ||
| # disruption = low | ||
|
|
||
| [ -f /etc/sysctl.conf ] || install -m 0644 /dev/null /etc/sysctl.conf | ||
| ln -sf /etc/sysctl.conf /etc/sysctl.d/99-sysctl.conf | ||
| systemctl restart systemd-sysctl.service |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| <def-group> | ||
| <definition class="compliance" id="{{{ rule_id }}}" version="1"> | ||
| {{{ oval_metadata("/etc/sysctl.d/99-sysctl.conf must be a symlink to /etc/sysctl.conf so that systemd-sysctl loads it at boot.", rule_title=rule_title) }}} | ||
| <criteria> | ||
| <criterion comment="/etc/sysctl.d/99-sysctl.conf is a symlink pointing to /etc/sysctl.conf" | ||
| test_ref="test_{{{ rule_id }}}"/> | ||
| </criteria> | ||
| </definition> | ||
|
|
||
| <unix:symlink_test check="all" check_existence="all_exist" | ||
| comment="/etc/sysctl.d/99-sysctl.conf is a symlink pointing to /etc/sysctl.conf" | ||
| id="test_{{{ rule_id }}}" version="1"> | ||
| <unix:object object_ref="object_{{{ rule_id }}}"/> | ||
| <unix:state state_ref="state_{{{ rule_id }}}"/> | ||
| </unix:symlink_test> | ||
|
|
||
| <unix:symlink_object id="object_{{{ rule_id }}}" version="1"> | ||
| <unix:filepath>/etc/sysctl.d/99-sysctl.conf</unix:filepath> | ||
| </unix:symlink_object> | ||
|
|
||
| <unix:symlink_state id="state_{{{ rule_id }}}" version="1"> | ||
| <unix:canonical_path operation="equals">/etc/sysctl.conf</unix:canonical_path> | ||
| </unix:symlink_state> | ||
| </def-group> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| documentation_complete: true | ||
|
|
||
| title: 'Ensure /etc/sysctl.d/99-sysctl.conf Is a Symlink to /etc/sysctl.conf' | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add test scenarios for the rules.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added test scenarios for sysctl_conf_symlink_etc_sysctl_d: correct_symlink.pass, missing_symlink.fail, wrong_target.fail, regular_file.fail. For sysctl_reapply_after_network: service_enabled.pass, service_disabled.fail, service_missing.fail. |
||
|
|
||
| description: |- | ||
| The file <tt>/etc/sysctl.d/99-sysctl.conf</tt> must be a symbolic link | ||
| pointing to <tt>/etc/sysctl.conf</tt>. This symlink is normally created by | ||
| the <tt>procps</tt> package and ensures that <tt>systemd-sysctl</tt> | ||
| processes <tt>/etc/sysctl.conf</tt> with the correct priority during boot. | ||
| Without it, kernel parameter settings written to <tt>/etc/sysctl.conf</tt> | ||
| are silently ignored by <tt>systemd-sysctl</tt> and do not persist across | ||
| reboots. | ||
|
|
||
| rationale: |- | ||
| When <tt>/etc/sysctl.d/99-sysctl.conf</tt> is absent or is not a symlink to | ||
| <tt>/etc/sysctl.conf</tt>, <tt>systemd-sysctl</tt> does not load | ||
| <tt>/etc/sysctl.conf</tt> during boot. As a result, any kernel parameters | ||
| configured in that file — including security hardening settings — are not | ||
| applied at startup, undermining system hardening. | ||
|
|
||
| severity: medium | ||
|
|
||
| platform: machine | ||
|
|
||
| references: | ||
| nist: CM-6(a) | ||
|
|
||
| ocil_clause: '/etc/sysctl.d/99-sysctl.conf does not exist or is not a symlink to /etc/sysctl.conf' | ||
|
|
||
| ocil: |- | ||
| Verify that <tt>/etc/sysctl.d/99-sysctl.conf</tt> is a symbolic link | ||
| pointing to <tt>/etc/sysctl.conf</tt>: | ||
| <pre>$ ls -l /etc/sysctl.d/99-sysctl.conf</pre> | ||
| The output should show a symlink pointing to <tt>/etc/sysctl.conf</tt>. | ||
|
|
||
| fixtext: |- | ||
| Create the symbolic link: | ||
| <pre># ln -sf /etc/sysctl.conf /etc/sysctl.d/99-sysctl.conf</pre> | ||
| Apply the settings immediately: | ||
| <pre># systemctl restart systemd-sysctl.service</pre> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| #!/bin/bash | ||
| # platform = multi_platform_all | ||
|
|
||
| touch /etc/sysctl.conf | ||
| ln -sf /etc/sysctl.conf /etc/sysctl.d/99-sysctl.conf |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| #!/bin/bash | ||
| # platform = multi_platform_all | ||
|
|
||
| rm -f /etc/sysctl.d/99-sysctl.conf |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| #!/bin/bash | ||
| # platform = multi_platform_all | ||
|
|
||
| rm -f /etc/sysctl.d/99-sysctl.conf | ||
| touch /etc/sysctl.d/99-sysctl.conf |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| #!/bin/bash | ||
| # platform = multi_platform_all | ||
|
|
||
| ln -sf /etc/sysctl.d/10-something.conf /etc/sysctl.d/99-sysctl.conf |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| # platform = multi_platform_debian | ||
| # reboot = false | ||
| # strategy = configure | ||
| # complexity = low | ||
| # disruption = low | ||
|
|
||
| SERVICE_FILE="/etc/systemd/system/sysctl-reapply-network.service" | ||
|
|
||
| cat > "${SERVICE_FILE}" << 'EOF' | ||
| [Unit] | ||
| Description=Re-apply sysctl hardening after network interfaces come up | ||
| After=networking.service systemd-networkd.service | ||
| DefaultDependencies=no | ||
|
|
||
| [Service] | ||
| Type=oneshot | ||
| ExecStart=/sbin/sysctl --system | ||
| RemainAfterExit=yes | ||
|
|
||
| [Install] | ||
| WantedBy=multi-user.target | ||
| EOF | ||
|
|
||
| chown root:root "${SERVICE_FILE}" | ||
| chmod 0644 "${SERVICE_FILE}" | ||
|
|
||
| systemctl daemon-reload | ||
| systemctl enable sysctl-reapply-network.service | ||
|
|
||
| if [[ $(systemctl is-system-running) != "offline" ]]; then | ||
| systemctl start sysctl-reapply-network.service | ||
| fi |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| <def-group> | ||
| <definition class="compliance" id="{{{ rule_id }}}" version="1"> | ||
| {{{ oval_metadata("Ensure sysctl-reapply-network.service exists and is enabled.", rule_title=rule_title) }}} | ||
| <criteria operator="AND"> | ||
| <criterion comment="sysctl-reapply-network.service file exists" | ||
| test_ref="test_{{{ rule_id }}}_file_exists"/> | ||
| <criterion comment="sysctl-reapply-network.service is enabled" | ||
| test_ref="test_{{{ rule_id }}}_enabled"/> | ||
| </criteria> | ||
| </definition> | ||
|
|
||
| <unix:file_test check="all" check_existence="at_least_one_exists" | ||
| comment="sysctl-reapply-network.service file exists" | ||
| id="test_{{{ rule_id }}}_file_exists" version="1"> | ||
| <unix:object object_ref="object_{{{ rule_id }}}_file"/> | ||
| </unix:file_test> | ||
|
|
||
| <unix:file_object id="object_{{{ rule_id }}}_file" version="1"> | ||
| <unix:filepath>/etc/systemd/system/sysctl-reapply-network.service</unix:filepath> | ||
| </unix:file_object> | ||
|
|
||
| <linux:systemdunitproperty_test check="all" | ||
| id="test_{{{ rule_id }}}_enabled" version="1" | ||
| comment="sysctl-reapply-network.service is enabled"> | ||
| <linux:object object_ref="object_{{{ rule_id }}}_unitfilestate"/> | ||
| <linux:state state_ref="state_{{{ rule_id }}}_enabled"/> | ||
| </linux:systemdunitproperty_test> | ||
|
|
||
| <linux:systemdunitproperty_object id="object_{{{ rule_id }}}_unitfilestate" version="1"> | ||
| <linux:unit>sysctl-reapply-network.service</linux:unit> | ||
| <linux:property>UnitFileState</linux:property> | ||
| </linux:systemdunitproperty_object> | ||
|
|
||
| <linux:systemdunitproperty_state id="state_{{{ rule_id }}}_enabled" version="1"> | ||
| <linux:value>enabled</linux:value> | ||
| </linux:systemdunitproperty_state> | ||
| </def-group> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| documentation_complete: true | ||
|
|
||
| title: 'Ensure sysctl network settings are re-applied after network interfaces come up' | ||
|
|
||
| description: |- | ||
| On Debian systems, the kernel resets certain network sysctl values when a | ||
| network interface is brought up, overriding hardened settings applied at | ||
| early boot by <tt>systemd-sysctl.service</tt>. | ||
| <br/><br/> | ||
| Create a systemd oneshot service | ||
| <tt>/etc/systemd/system/sysctl-reapply-network.service</tt>: | ||
| <pre>[Unit] | ||
| Description=Re-apply sysctl hardening after network interfaces come up | ||
| After=networking.service systemd-networkd.service | ||
| DefaultDependencies=no | ||
|
|
||
| [Service] | ||
| Type=oneshot | ||
| ExecStart=/sbin/sysctl --system | ||
| RemainAfterExit=yes | ||
|
|
||
| [Install] | ||
| WantedBy=multi-user.target</pre> | ||
| Then reload the systemd daemon and enable the service: | ||
| <pre>$ sudo systemctl daemon-reload | ||
| $ sudo systemctl enable sysctl-reapply-network.service</pre> | ||
|
|
||
| rationale: |- | ||
| When a network interface is initialized, the Linux kernel may reset interface-level | ||
| and global sysctl values to their defaults. Running <tt>sysctl --system</tt> after | ||
| network interfaces are up ensures the hardened values from <tt>/etc/sysctl.conf</tt> | ||
| and <tt>/etc/sysctl.d/</tt> are the final values in effect at runtime. | ||
| <br/><br/> | ||
| Using <tt>DefaultDependencies=no</tt> prevents the ordering cycle that would arise | ||
| from modifying <tt>systemd-sysctl.service</tt> itself to depend on | ||
| <tt>network-online.target</tt>. | ||
|
|
||
| severity: medium | ||
|
|
||
| platform: machine | ||
|
|
||
| ocil_clause: 'the sysctl-reapply-network service does not exist or is not enabled' | ||
|
|
||
| ocil: |- | ||
| Verify that the <tt>sysctl-reapply-network.service</tt> unit is enabled: | ||
| <pre>$ systemctl is-enabled sysctl-reapply-network.service</pre> | ||
| The output should be <tt>enabled</tt>. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| #!/bin/bash | ||
| # platform = multi_platform_all | ||
|
|
||
| SERVICE_FILE="/etc/systemd/system/sysctl-reapply-network.service" | ||
|
|
||
| cat > "${SERVICE_FILE}" << 'EOF' | ||
| [Unit] | ||
| Description=Re-apply sysctl hardening after network interfaces come up | ||
| After=networking.service systemd-networkd.service | ||
| DefaultDependencies=no | ||
|
|
||
| [Service] | ||
| Type=oneshot | ||
| ExecStart=/sbin/sysctl --system | ||
| RemainAfterExit=yes | ||
|
|
||
| [Install] | ||
| WantedBy=multi-user.target | ||
| EOF | ||
|
|
||
| systemctl daemon-reload | ||
| systemctl disable sysctl-reapply-network.service |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| #!/bin/bash | ||
| # platform = multi_platform_all | ||
|
|
||
| SERVICE_FILE="/etc/systemd/system/sysctl-reapply-network.service" | ||
|
|
||
| cat > "${SERVICE_FILE}" << 'EOF' | ||
| [Unit] | ||
| Description=Re-apply sysctl hardening after network interfaces come up | ||
| After=networking.service systemd-networkd.service | ||
| DefaultDependencies=no | ||
|
|
||
| [Service] | ||
| Type=oneshot | ||
| ExecStart=/sbin/sysctl --system | ||
| RemainAfterExit=yes | ||
|
|
||
| [Install] | ||
| WantedBy=multi-user.target | ||
| EOF | ||
|
|
||
| systemctl daemon-reload | ||
| systemctl enable sysctl-reapply-network.service |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| #!/bin/bash | ||
| # platform = multi_platform_all | ||
|
|
||
| systemctl disable sysctl-reapply-network.service 2>/dev/null || true | ||
| rm -f /etc/systemd/system/sysctl-reapply-network.service | ||
| systemctl daemon-reload |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FTBFS because the new added rules aren't part of any component. Each rule needs to be listed in at least 1 file in components directory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added both sysctl_conf_symlink_etc_sysctl_d and sysctl_reapply_after_network to components/kernel.yml