Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bob/bob.conf
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Packages=podman
openssh-sftp-server
udev
libsnappy1v5
apparmor

BuildPackages=build-essential
git
Expand Down
3 changes: 3 additions & 0 deletions bob/kernel.config
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ CONFIG_IP_NF_TARGET_REDIRECT=y
CONFIG_IP_NF_MANGLE=y
CONFIG_IP_NF_RAW=y
CONFIG_NET_SCHED=y
CONFIG_SECURITY_APPARMOR=y
CONFIG_SECURITY_APPARMOR_BOOTPARAM_VALUE=1
CONFIG_DEFAULT_SECURITY_APPARMOR=y
46 changes: 46 additions & 0 deletions bob/mkosi.extra/etc/apparmor.d/searcher-container
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include <tunables/global>

profile searcher-container flags=(attach_disconnected,mediate_deleted) {
#include <abstractions/base>

network,
capability,
file,
umount,

# Allow signals from privileged profiles and from within the same profile
signal (receive) peer=unconfined,
signal (send,receive) peer=searcher-container,
# Allow signals from podman/runc/crun
signal (receive) peer={/usr/bin/,/usr/sbin/,}{podman,runc,crun*},

deny @{PROC}/* w, # deny write for all files directly in /proc (not in a subdir)
# deny write to files not in /proc/<number>/** or /proc/sys/**
deny @{PROC}/{[^1-9],[^1-9][^0-9],[^1-9s][^0-9y][^0-9s],[^1-9][^0-9][^0-9][^0-9/]*}/** w,
deny @{PROC}/sys/[^k]** w, # deny /proc/sys except /proc/sys/k* (effectively /proc/sys/kernel)
deny @{PROC}/sys/kernel/{?,??,[^s][^h][^m]**} w, # deny everything except shm* in /proc/sys/kernel/
deny @{PROC}/sysrq-trigger rwklx,
deny @{PROC}/kcore rwklx,

deny mount,

deny /sys/[^f]*/** wklx,
deny /sys/f[^s]*/** wklx,
deny /sys/fs/[^c]*/** wklx,
deny /sys/fs/c[^g]*/** wklx,
deny /sys/fs/cg[^r]*/** wklx,
deny /sys/firmware/** rwklx,
deny /sys/devices/virtual/powercap/** rwklx,
deny /sys/kernel/security/** rwklx,
Comment on lines +17 to +34
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not that familiar with apparmor profiles, but maybe we should make deny-all by default and only allowlist what's required?


# suppress ptrace denials when using 'ps' inside a container
ptrace (trace,read,tracedby,readby) peer=searcher-container,

# Additional rules for searcher-specific paths
/persistent/** rw,
/etc/searcher/** r,
/var/log/searcher/** w,
/var/log/lighthouse/** r,
/secrets/** r,
/tmp/jwt.hex r,
}
4 changes: 2 additions & 2 deletions bob/mkosi.extra/etc/systemd/system/searcher-container.service
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[Unit]
Description=Searcher SSH Container
After=dropbear.service searcher-firewall.service persistent-mount.service
Requires=dropbear.service searcher-firewall.service persistent-mount.service
After=dropbear.service searcher-firewall.service persistent-mount.service apparmor.service
Requires=dropbear.service searcher-firewall.service persistent-mount.service apparmor.service

[Service]
Type=oneshot
Expand Down
4 changes: 4 additions & 0 deletions bob/mkosi.extra/usr/bin/init-container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ ENGINE_API_PORT=8551
EL_P2P_PORT=30303
SEARCHER_INPUT_CHANNEL=27017

# Enabling apparmor profile
/usr/sbin/apparmor_parser -r /etc/apparmor.d/searcher-container

echo "Starting $NAME..."
su -s /bin/sh searcher -c "cd ~ && podman run -d \
--name $NAME --replace \
--security-opt apparmor=searcher-container \
-p ${SEARCHER_SSH_PORT}:22 \
-p ${ENGINE_API_PORT}:${ENGINE_API_PORT} \
-p ${EL_P2P_PORT}:${EL_P2P_PORT} \
Expand Down
1 change: 1 addition & 0 deletions bob/mkosi.postinst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ for service in \
searcher-log-writer.service \
wait-for-key.service \
searcher-firewall.service \
apparmor.service \
dropbear.service \
lighthouse.service \
searcher-container.service \
Expand Down