diff --git a/components/kernel.yml b/components/kernel.yml
index ef50ac95e91e..f9d5678364b7 100644
--- a/components/kernel.yml
+++ b/components/kernel.yml
@@ -127,6 +127,7 @@ rules:
- package_iptables-nft_installed
- package_nfs-kernel-server_removed
- sebool_domain_kernel_load_modules
+- sysctl_conf_symlink_etc_sysctl_d
- sysctl_fs_protected_fifos
- sysctl_fs_protected_hardlinks
- sysctl_fs_protected_regular
@@ -201,6 +202,7 @@ rules:
- sysctl_net_ipv6_conf_default_forwarding
- sysctl_net_ipv6_conf_default_max_addresses
- sysctl_net_ipv6_conf_default_router_solicitations
+- sysctl_reapply_after_network
- sysctl_user_max_user_namespaces
- sysctl_user_max_user_namespaces_no_remediation
- sysctl_vm_mmap_min_addr
diff --git a/linux_os/guide/system/permissions/restrictions/sysctl_conf_symlink_etc_sysctl_d/bash/shared.sh b/linux_os/guide/system/permissions/restrictions/sysctl_conf_symlink_etc_sysctl_d/bash/shared.sh
new file mode 100644
index 000000000000..6964b1a5d77e
--- /dev/null
+++ b/linux_os/guide/system/permissions/restrictions/sysctl_conf_symlink_etc_sysctl_d/bash/shared.sh
@@ -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
diff --git a/linux_os/guide/system/permissions/restrictions/sysctl_conf_symlink_etc_sysctl_d/oval/shared.xml b/linux_os/guide/system/permissions/restrictions/sysctl_conf_symlink_etc_sysctl_d/oval/shared.xml
new file mode 100644
index 000000000000..b1df8e91f76b
--- /dev/null
+++ b/linux_os/guide/system/permissions/restrictions/sysctl_conf_symlink_etc_sysctl_d/oval/shared.xml
@@ -0,0 +1,24 @@
+
$ ls -l /etc/sysctl.d/99-sysctl.conf+ The output should show a symlink pointing to /etc/sysctl.conf. + +fixtext: |- + Create the symbolic link: +
# ln -sf /etc/sysctl.conf /etc/sysctl.d/99-sysctl.conf+ Apply the settings immediately: +
# systemctl restart systemd-sysctl.servicediff --git a/linux_os/guide/system/permissions/restrictions/sysctl_conf_symlink_etc_sysctl_d/tests/correct_symlink.pass.sh b/linux_os/guide/system/permissions/restrictions/sysctl_conf_symlink_etc_sysctl_d/tests/correct_symlink.pass.sh new file mode 100644 index 000000000000..4ad69f29e455 --- /dev/null +++ b/linux_os/guide/system/permissions/restrictions/sysctl_conf_symlink_etc_sysctl_d/tests/correct_symlink.pass.sh @@ -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 diff --git a/linux_os/guide/system/permissions/restrictions/sysctl_conf_symlink_etc_sysctl_d/tests/missing_symlink.fail.sh b/linux_os/guide/system/permissions/restrictions/sysctl_conf_symlink_etc_sysctl_d/tests/missing_symlink.fail.sh new file mode 100644 index 000000000000..ab977e397b8b --- /dev/null +++ b/linux_os/guide/system/permissions/restrictions/sysctl_conf_symlink_etc_sysctl_d/tests/missing_symlink.fail.sh @@ -0,0 +1,4 @@ +#!/bin/bash +# platform = multi_platform_all + +rm -f /etc/sysctl.d/99-sysctl.conf diff --git a/linux_os/guide/system/permissions/restrictions/sysctl_conf_symlink_etc_sysctl_d/tests/regular_file.fail.sh b/linux_os/guide/system/permissions/restrictions/sysctl_conf_symlink_etc_sysctl_d/tests/regular_file.fail.sh new file mode 100644 index 000000000000..4ae1d9edb3b5 --- /dev/null +++ b/linux_os/guide/system/permissions/restrictions/sysctl_conf_symlink_etc_sysctl_d/tests/regular_file.fail.sh @@ -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 diff --git a/linux_os/guide/system/permissions/restrictions/sysctl_conf_symlink_etc_sysctl_d/tests/wrong_target.fail.sh b/linux_os/guide/system/permissions/restrictions/sysctl_conf_symlink_etc_sysctl_d/tests/wrong_target.fail.sh new file mode 100644 index 000000000000..6597d2b07a0f --- /dev/null +++ b/linux_os/guide/system/permissions/restrictions/sysctl_conf_symlink_etc_sysctl_d/tests/wrong_target.fail.sh @@ -0,0 +1,4 @@ +#!/bin/bash +# platform = multi_platform_all + +ln -sf /etc/sysctl.d/10-something.conf /etc/sysctl.d/99-sysctl.conf diff --git a/linux_os/guide/system/permissions/restrictions/sysctl_reapply_after_network/bash/shared.sh b/linux_os/guide/system/permissions/restrictions/sysctl_reapply_after_network/bash/shared.sh new file mode 100644 index 000000000000..c5853b07e720 --- /dev/null +++ b/linux_os/guide/system/permissions/restrictions/sysctl_reapply_after_network/bash/shared.sh @@ -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 diff --git a/linux_os/guide/system/permissions/restrictions/sysctl_reapply_after_network/oval/shared.xml b/linux_os/guide/system/permissions/restrictions/sysctl_reapply_after_network/oval/shared.xml new file mode 100644 index 000000000000..7853ffdb8796 --- /dev/null +++ b/linux_os/guide/system/permissions/restrictions/sysctl_reapply_after_network/oval/shared.xml @@ -0,0 +1,37 @@ +
[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+ Then reload the systemd daemon and enable the service: +
$ sudo systemctl daemon-reload + $ sudo systemctl enable sysctl-reapply-network.service+ +rationale: |- + When a network interface is initialized, the Linux kernel may reset interface-level + and global sysctl values to their defaults. Running sysctl --system after + network interfaces are up ensures the hardened values from /etc/sysctl.conf + and /etc/sysctl.d/ are the final values in effect at runtime. +
$ systemctl is-enabled sysctl-reapply-network.service+ The output should be enabled. diff --git a/linux_os/guide/system/permissions/restrictions/sysctl_reapply_after_network/tests/service_disabled.fail.sh b/linux_os/guide/system/permissions/restrictions/sysctl_reapply_after_network/tests/service_disabled.fail.sh new file mode 100644 index 000000000000..be36c4d88382 --- /dev/null +++ b/linux_os/guide/system/permissions/restrictions/sysctl_reapply_after_network/tests/service_disabled.fail.sh @@ -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 diff --git a/linux_os/guide/system/permissions/restrictions/sysctl_reapply_after_network/tests/service_enabled.pass.sh b/linux_os/guide/system/permissions/restrictions/sysctl_reapply_after_network/tests/service_enabled.pass.sh new file mode 100644 index 000000000000..2f497ec3c2a1 --- /dev/null +++ b/linux_os/guide/system/permissions/restrictions/sysctl_reapply_after_network/tests/service_enabled.pass.sh @@ -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 diff --git a/linux_os/guide/system/permissions/restrictions/sysctl_reapply_after_network/tests/service_missing.fail.sh b/linux_os/guide/system/permissions/restrictions/sysctl_reapply_after_network/tests/service_missing.fail.sh new file mode 100644 index 000000000000..1e3445ae4db1 --- /dev/null +++ b/linux_os/guide/system/permissions/restrictions/sysctl_reapply_after_network/tests/service_missing.fail.sh @@ -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