Skip to content

Commit dd895e6

Browse files
committed
wip: resolute on apple silicon doesn't work yet - monit can't reload
1 parent c993c82 commit dd895e6

7 files changed

Lines changed: 117 additions & 26 deletions

File tree

bosh-stemcell/spec/assets/dpkg-list-ubuntu.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,6 @@ libpsl5t64:amd64
316316
libpwquality-common
317317
libpwquality1:amd64
318318
libpython3-stdlib:amd64
319-
libpython3.13-minimal:amd64
320-
libpython3.13-stdlib:amd64
321319
libpython3.14-minimal:amd64
322320
libpython3.14-stdlib:amd64
323321
libpython3.14:amd64
@@ -488,8 +486,6 @@ python3-uc-micro
488486
python3-wadllib
489487
python3-yaml
490488
python3-zipp
491-
python3.13
492-
python3.13-minimal
493489
python3.14
494490
python3.14-minimal
495491
quota

bosh-stemcell/spec/stemcells/warden_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# @AI-Generated
2+
# Modified with AI assistance using Cursor with Composer
3+
# Description:
4+
# 2026-04-07: Specs for warden ssh.socket mask and auditd foreground drop-in.
5+
16
require 'spec_helper'
27

38
describe 'Warden Stemcell', stemcell_image: true do
@@ -48,4 +53,23 @@
4853
end
4954
end
5055

56+
context 'SSH without socket activation (warden containers)' do
57+
describe file('/etc/systemd/system/ssh.socket') do
58+
it { should be_linked_to '/dev/null' }
59+
end
60+
61+
describe file('/etc/systemd/system/ssh.service.d/warden-no-socket-activation.conf') do
62+
it { should be_file }
63+
its(:content) { should include('RefuseManualStart=no') }
64+
end
65+
end
66+
67+
context 'auditd foreground (warden / Docker systemd ENOSYS)' do
68+
describe file('/etc/systemd/system/auditd.service.d/warden-auditd-foreground.conf') do
69+
it { should be_file }
70+
its(:content) { should include('Type=simple') }
71+
its(:content) { should include('ExecStart=/usr/sbin/auditd -n') }
72+
end
73+
end
74+
5175
end

bosh-stemcell/spec/support/os_image_shared_examples.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# @AI-Generated
2+
# Modified with AI assistance using Cursor with Composer
3+
# Description:
4+
# 2026-04-07: Align audit.rules expectations with shared_functions (no stime; always,exit for system-locale).
5+
16
shared_examples_for 'every OS image' do
27
let(:sshd_config) { file('/etc/ssh/sshd_config') }
38
let(:etc_environment) { file('/etc/environment') }
@@ -593,7 +598,7 @@
593598

594599
describe 'events that modify system date and time must be recorded (CIS-8.1.4)' do
595600
its(:content) { should match /^-a always,exit -F arch=b64 -S adjtimex -S settimeofday -k time-change$/ }
596-
its(:content) { should match /^-a always,exit -F arch=b32 -S adjtimex -S settimeofday -S stime -k time-change$/ }
601+
its(:content) { should match /^-a always,exit -F arch=b32 -S adjtimex -S settimeofday -k time-change$/ }
597602
its(:content) { should match /^-a always,exit -F arch=b64 -S clock_settime -k time-change$/ }
598603
its(:content) { should match /^-a always,exit -F arch=b32 -S clock_settime -k time-change$/ }
599604
its(:content) { should match /^-w \/etc\/localtime -p wa -k time-change$/ }
@@ -637,8 +642,8 @@
637642
end
638643

639644
describe 'record events that modify system network environment (CIS-4.1.6)' do
640-
its(:content) { should match /^-a exit,always -F arch=b64 -S sethostname -S setdomainname -k system-locale$/ }
641-
its(:content) { should match /^-a exit,always -F arch=b32 -S sethostname -S setdomainname -k system-locale$/ }
645+
its(:content) { should match /^-a always,exit -F arch=b64 -S sethostname -S setdomainname -k system-locale$/ }
646+
its(:content) { should match /^-a always,exit -F arch=b32 -S sethostname -S setdomainname -k system-locale$/ }
642647
its(:content) { should match /^-w \/etc\/issue -p wa -k system-locale$/ }
643648
its(:content) { should match /^-w \/etc\/issue\.net -p wa -k system-locale$/ }
644649
its(:content) { should match /^-w \/etc\/hosts -p wa -k system-locale$/ }

stemcell_builder/lib/helpers.sh

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# @AI-Generated
2+
# Modified with AI assistance using Cursor with Composer
3+
# Description:
4+
# 2026-04-06: run_in_chroot: stdin-free bash -c + env (fixes pipelines e.g. grub-mkpasswd); setsid -f -w around unshare (avoids SIGTTOU stops); chroot env sets DEBIAN_FRONTEND + SYSTEMD_OFFLINE + proxies.
5+
16
function disable {
27
if [ -e $1 ]
38
then
@@ -24,18 +29,37 @@ function run_in_chroot {
2429
disable $chroot/sbin/initctl
2530
disable $chroot/usr/sbin/invoke-rc.d
2631

27-
# `unshare -f -p` to prevent `kill -HUP 1` from causing `init` to exit;
28-
unshare -f -p -m $SHELL <<EOS
29-
mkdir -p $chroot/dev
30-
mount -n --bind /dev $chroot/dev
31-
mount -n --bind /dev/shm $chroot/dev/shm
32-
mount -n --bind /dev/pts $chroot/dev/pts
32+
# unshare: isolate mounts + PID namespace (see comment in original helpers).
33+
# Inner shell must not read its script from stdin (heredoc): that breaks stdin for
34+
# nested pipelines (e.g. grub-mkpasswd-pbkdf2). Pass command via env instead.
35+
#
36+
# setsid -f -w: new session without a controlling tty so apt/dpkg stderr does not
37+
# trigger SIGTTOU (job-control stop, ps state T) under sudo / nested ptys.
38+
env RUN_IN_CHROOT_ROOT="$chroot" \
39+
RUN_IN_CHROOT_CMD="$script" \
40+
RUN_IN_CHROOT_HTTP_PROXY="${http_proxy:-}" \
41+
RUN_IN_CHROOT_HTTPS_PROXY="${https_proxy:-}" \
42+
RUN_IN_CHROOT_NO_PROXY="${no_proxy:-}" \
43+
setsid -f -w -- unshare -f -p -m /bin/bash -c '
44+
set -e
45+
chroot="$RUN_IN_CHROOT_ROOT"
46+
mkdir -p "$chroot/dev"
47+
mount -n --bind /dev "$chroot/dev"
48+
mount -n --bind /dev/shm "$chroot/dev/shm"
49+
mount -n --bind /dev/pts "$chroot/dev/pts"
3350
34-
mkdir -p $chroot/proc
35-
mount -n --bind /proc $chroot/proc
51+
mkdir -p "$chroot/proc"
52+
mount -n --bind /proc "$chroot/proc"
3653
37-
chroot $chroot env -i PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin http_proxy=${http_proxy:-} https_proxy=${https_proxy:-} no_proxy=${no_proxy:-} bash -e -c "$script"
38-
EOS
54+
chroot "$chroot" env -i \
55+
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \
56+
DEBIAN_FRONTEND=noninteractive \
57+
SYSTEMD_OFFLINE=1 \
58+
http_proxy="$RUN_IN_CHROOT_HTTP_PROXY" \
59+
https_proxy="$RUN_IN_CHROOT_HTTPS_PROXY" \
60+
no_proxy="$RUN_IN_CHROOT_NO_PROXY" \
61+
bash -e -c "$RUN_IN_CHROOT_CMD"
62+
'
3963

4064
# Enable daemon startup
4165
enable $chroot/sbin/initctl
@@ -93,4 +117,3 @@ function is_x86_64() {
93117
return 1
94118
fi
95119
}
96-

stemcell_builder/lib/prelude_apply.bash

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# @AI-Generated
2+
# Modified with AI assistance using Cursor with Composer
3+
# Description:
4+
# 2026-04-06: pkg_mgr: drop redundant DEBIAN_FRONTEND export (set in run_in_chroot env).
5+
16
source $base_dir/lib/prelude_common.bash
27
source $base_dir/lib/helpers.sh
38

@@ -24,7 +29,7 @@ git config --global --add safe.directory /opt/bosh
2429

2530
function pkg_mgr {
2631
run_in_chroot $chroot "apt-get update"
27-
run_in_chroot $chroot "export DEBIAN_FRONTEND=noninteractive; apt-get --fix-broken --no-install-recommends --assume-yes $*"
32+
run_in_chroot $chroot "apt-get --fix-broken --no-install-recommends --assume-yes $*"
2833
run_in_chroot $chroot "apt-get clean"
2934
}
3035

stemcell_builder/stages/base_warden/apply.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
#!/usr/bin/env bash
2+
# @AI-Generated
3+
# Modified with AI assistance using Cursor with Composer
4+
# Description:
5+
# 2026-04-07: Mask ssh.socket and enable ssh.service for warden; auditd Type=simple + auditd -n (Docker ENOSYS on PID file refs).
26

37
set -e
48

@@ -78,13 +82,44 @@ rosetta_services=(
7882
systemd-networkd
7983
systemd-logind
8084
systemd-timesyncd
85+
systemd-udevd
86+
logrotate
8187
auditd
8288
)
8389

90+
#todo: add udevd test
91+
8492
for service in "${rosetta_services[@]}"; do
8593
mkdir -p "$chroot/etc/systemd/system/${service}.service.d"
8694
cp "$assets_dir/rosetta-compat.conf" "$chroot/etc/systemd/system/${service}.service.d/rosetta-compat.conf"
8795
done
8896

8997
# Mask systemd-binfmt.service which fails under Rosetta emulation
9098
run_in_chroot "$chroot" "systemctl mask systemd-binfmt.service"
99+
100+
# auditd: systemd can return ENOSYS when creating pidfd/cgroup references from PIDFile under Docker/Colima
101+
# ("Failed to create reference to PID ... auditd.pid"). Foreground auditd avoids forking + PIDFile lifecycle quirks.
102+
mkdir -p "$chroot/etc/systemd/system/auditd.service.d"
103+
cat > "$chroot/etc/systemd/system/auditd.service.d/warden-auditd-foreground.conf" <<'UNIT'
104+
[Service]
105+
Type=simple
106+
PIDFile=
107+
ExecStart=
108+
ExecStart=/usr/sbin/auditd -n
109+
UNIT
110+
111+
# TODO: maybe this should go up out of warden?
112+
run_in_chroot "$chroot" "systemctl mask nvmf-autoconnect.service"
113+
114+
115+
# Ubuntu enables OpenSSH via ssh.socket (socket activation). systemd's listener stub fork can fail with
116+
# ENOSYS ("Function not implemented") under Docker/Colima and similar, especially with Rosetta x86_64
117+
# emulation — see journalctl -u ssh.socket. Use the traditional ssh.service so sshd binds port 22 itself.
118+
mkdir -p "$chroot/etc/systemd/system/ssh.service.d"
119+
cat > "$chroot/etc/systemd/system/ssh.service.d/warden-no-socket-activation.conf" <<'UNIT'
120+
[Unit]
121+
# When ssh.socket is masked, sshd must start via ssh.service; drop RefuseManualStart from the vendor unit.
122+
RefuseManualStart=no
123+
UNIT
124+
run_in_chroot "$chroot" "systemctl mask ssh.socket"
125+
run_in_chroot "$chroot" "systemctl enable ssh.service"

stemcell_builder/stages/bosh_audit/shared_functions.bash

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
#!/usr/bin/env bash
2+
# @AI-Generated
3+
# Modified with AI assistance using Cursor with Composer
4+
# Description:
5+
# 2026-04-07: Audit rules: drop stime, use always,exit for system-locale, heredoc append (no leading blank line), tidy privileged header line.
26

37
set -e
48

59
base_dir=$(readlink -nf $(dirname $0)/../..)
610
source $base_dir/lib/prelude_apply.bash
711

812
function write_shared_audit_rules {
9-
echo '
13+
cat <<'AUDIT_RULES' >> "$chroot/etc/audit/rules.d/audit.rules"
1014
-w /sbin/insmod -p x -k modules
1115
-w /sbin/rmmod -p x -k modules
1216
-w /sbin/modprobe -p x -k modules
@@ -20,7 +24,7 @@ function write_shared_audit_rules {
2024
2125
# Record events that modify system date and time
2226
-a always,exit -F arch=b64 -S adjtimex -S settimeofday -k time-change
23-
-a always,exit -F arch=b32 -S adjtimex -S settimeofday -S stime -k time-change
27+
-a always,exit -F arch=b32 -S adjtimex -S settimeofday -k time-change
2428
-a always,exit -F arch=b64 -S clock_settime -k time-change
2529
-a always,exit -F arch=b32 -S clock_settime -k time-change
2630
-w /etc/localtime -p wa -k time-change
@@ -52,8 +56,8 @@ function write_shared_audit_rules {
5256
-w /etc/security/opasswd -p wa -k identity
5357
5458
# Record events that modify system network environment
55-
-a exit,always -F arch=b64 -S sethostname -S setdomainname -k system-locale
56-
-a exit,always -F arch=b32 -S sethostname -S setdomainname -k system-locale
59+
-a always,exit -F arch=b64 -S sethostname -S setdomainname -k system-locale
60+
-a always,exit -F arch=b32 -S sethostname -S setdomainname -k system-locale
5761
-w /etc/issue -p wa -k system-locale
5862
-w /etc/issue.net -p wa -k system-locale
5963
-w /etc/hosts -p wa -k system-locale
@@ -135,7 +139,7 @@ function write_shared_audit_rules {
135139
136140
# Recorde execution of unix_update
137141
-a always,exit -F path=/sbin/unix_update -F perm=x -F auid>=500 -F auid!=4294967295 -k privileged-unix-update
138-
' >> $chroot/etc/audit/rules.d/audit.rules
142+
AUDIT_RULES
139143
}
140144

141145
function override_default_audit_variables {
@@ -154,7 +158,6 @@ function override_default_audit_variables {
154158
}
155159

156160
function record_use_of_privileged_binaries {
157-
echo '
158-
# Record use of privileged commands' >> $chroot/etc/audit/rules.d/audit.rules
161+
echo '# Record use of privileged commands' >> $chroot/etc/audit/rules.d/audit.rules
159162
find $chroot/bin $chroot/sbin $chroot/usr/bin $chroot/usr/sbin $chroot/boot -xdev \( -perm -4000 -o -perm -2000 \) -type f | sed -e s:^${chroot}:: | awk '{print "-a always,exit -F path=" $1 " -F perm=x -F auid>=500 -F auid!=4294967295 -k privileged" }' >> $chroot/etc/audit/rules.d/audit.rules
160163
}

0 commit comments

Comments
 (0)