|
| 1 | +require "spec_helper" |
| 2 | + |
| 3 | +describe "Rosetta Warden Stemcell", stemcell_image: true do |
| 4 | + context "arm64 systemd binaries (Rosetta pidfd fix)" do |
| 5 | + # On Apple Silicon (arm64 kernel + Rosetta x86_64 emulation), systemd v256+ |
| 6 | + # calls pidfd_open and pidfd_send_signal which Rosetta does not translate for |
| 7 | + # x86_64 processes, causing ENOSYS. These assertions verify that all key |
| 8 | + # systemd binaries have been replaced with arm64 ELF equivalents so they run |
| 9 | + # natively on the arm64 kernel without Rosetta translation. |
| 10 | + |
| 11 | + # Only service daemons are replaced with arm64; user-facing CLI tools in |
| 12 | + # /usr/bin/ (systemctl, journalctl, etc.) remain x86-64 because they |
| 13 | + # communicate with PID1 over D-Bus and never call pidfd themselves. |
| 14 | + %w[ |
| 15 | + /usr/lib/systemd/systemd |
| 16 | + /usr/lib/systemd/systemd-executor |
| 17 | + /usr/lib/systemd/systemd-journald |
| 18 | + /usr/lib/systemd/systemd-logind |
| 19 | + /usr/lib/systemd/systemd-networkd |
| 20 | + /usr/lib/systemd/systemd-resolved |
| 21 | + /usr/lib/systemd/systemd-shutdown |
| 22 | + ].each do |bin| |
| 23 | + describe command("file #{bin}") do |
| 24 | + its(:stdout) { should match(/ELF 64-bit.*ARM aarch64/) } |
| 25 | + end |
| 26 | + end |
| 27 | + |
| 28 | + # arm64 runtime libraries land in /lib/aarch64-linux-gnu/ via Ubuntu multiarch. |
| 29 | + # On Ubuntu 22.04+ (UsrMerge), /lib is a symlink to usr/lib; the real file is |
| 30 | + # at /lib/aarch64-linux-gnu/libc.so.6 (resolves via the UsrMerge symlink). |
| 31 | + describe file("/lib/aarch64-linux-gnu/libc.so.6") do |
| 32 | + it { should be_file } |
| 33 | + end |
| 34 | + |
| 35 | + # The arm64 ELF interpreter is at the multiarch path; /lib/ld-linux-aarch64.so.1 |
| 36 | + # is a symlink to it but ShelloutTypes::File cannot check symlink targets reliably. |
| 37 | + describe file("/lib/aarch64-linux-gnu/ld-linux-aarch64.so.1") do |
| 38 | + it { should be_file } |
| 39 | + end |
| 40 | + |
| 41 | + describe file("/usr/lib/aarch64-linux-gnu/systemd/libsystemd-shared-259.so") do |
| 42 | + it { should be_file } |
| 43 | + end |
| 44 | + end |
| 45 | + |
| 46 | + context "Rosetta x86_64 emulation compatibility for Apple Silicon" do |
| 47 | + # These systemd drop-in overrides disable security features that conflict |
| 48 | + # with Rosetta's JIT compilation on Apple Silicon Macs. |
| 49 | + |
| 50 | + rosetta_services = %w[ |
| 51 | + systemd-journald |
| 52 | + systemd-resolved |
| 53 | + systemd-networkd |
| 54 | + systemd-logind |
| 55 | + systemd-timesyncd |
| 56 | + auditd |
| 57 | + ] |
| 58 | + |
| 59 | + rosetta_services.each do |service| |
| 60 | + describe file("/etc/systemd/system/#{service}.service.d/rosetta-compat.conf") do |
| 61 | + it { should be_file } |
| 62 | + its(:content) { should include("MemoryDenyWriteExecute=no") } |
| 63 | + its(:content) { should include("LockPersonality=no") } |
| 64 | + its(:content) { should include("NoNewPrivileges=no") } |
| 65 | + end |
| 66 | + end |
| 67 | + |
| 68 | + describe file("/etc/systemd/system/systemd-binfmt.service") do |
| 69 | + it { should be_linked_to File::NULL } |
| 70 | + end |
| 71 | + end |
| 72 | + |
| 73 | + context "SSH without socket activation (Rosetta/Colima ENOSYS)" do |
| 74 | + describe file("/etc/systemd/system/ssh.socket") do |
| 75 | + it { should be_linked_to File::NULL } |
| 76 | + end |
| 77 | + |
| 78 | + describe file("/etc/systemd/system/ssh.service.d/warden-no-socket-activation.conf") do |
| 79 | + it { should be_file } |
| 80 | + its(:content) { should include("RefuseManualStart=no") } |
| 81 | + end |
| 82 | + end |
| 83 | + |
| 84 | + context "auditd foreground (Rosetta/Colima Docker pidfd ENOSYS)" do |
| 85 | + # Under Docker/Colima with Rosetta emulation, systemd cannot create pidfd |
| 86 | + # references or cgroup entries for processes started with Type=forking + PIDFile. |
| 87 | + # Running auditd with -n (no-fork / foreground) avoids the fork-and-PIDFile |
| 88 | + # lifecycle entirely, so systemd tracks the process directly without pidfd. |
| 89 | + describe file("/etc/systemd/system/auditd.service.d/warden-auditd-foreground.conf") do |
| 90 | + it { should be_file } |
| 91 | + its(:content) { should include("Type=simple") } |
| 92 | + its(:content) { should include("ExecStart=/usr/sbin/auditd -n") } |
| 93 | + end |
| 94 | + end |
| 95 | + |
| 96 | + context "restrict access to the su command CIS-9.5 (Rosetta PAM override)" do |
| 97 | + # The Rosetta stemcell replaces /etc/pam.d/su with a minimal config that |
| 98 | + # avoids unix-chkpwd (which AppArmor blocks under Lima/Rosetta, causing every |
| 99 | + # su invocation to fail with "Authentication failure" even for root). |
| 100 | + # pam_wheel.so use_uid is kept in the replacement config so that the CIS-9.5 |
| 101 | + # requirement — only wheel-group members may use su — is still enforced. |
| 102 | + # This test verifies that the override did not inadvertently remove the wheel check. |
| 103 | + describe command('grep "^\s*auth\s*required\s*pam_wheel.so\s*use_uid" /etc/pam.d/su') do |
| 104 | + it("exits 0") { expect(subject.exit_status).to eq(0) } |
| 105 | + end |
| 106 | + end |
| 107 | +end |
0 commit comments