| 1 | # The default base is the official Debian 13 multi-platform manifest. |
| 2 | # A build may select another verified Debian 13 base with BASE_IMAGE. |
| 3 | ARG BASE_IMAGE=debian:13-slim@sha256:a72b4433de1cf7d6bae0c4cee74d0547f58601a643b3375f070c51600d63b6b2 |
| 4 | FROM ${BASE_IMAGE} |
| 5 | |
| 6 | ENV container=docker |
| 7 | COPY apt-bootstrap.sh /usr/local/lib/cage-apt-bootstrap |
| 8 | COPY restore-apt-sources.sh /usr/local/lib/cage-image-restore-sources |
| 9 | ARG DEBIAN_MIRROR=http://deb.debian.org |
| 10 | RUN sed -i "s#http://deb.debian.org#${DEBIAN_MIRROR}#g" /etc/apt/sources.list.d/debian.sources \ |
| 11 | && printf '#!/bin/sh\nexit 101\n' > /usr/sbin/policy-rc.d \ |
| 12 | && chmod 0755 /usr/sbin/policy-rc.d \ |
| 13 | && sh /usr/local/lib/cage-apt-bootstrap \ |
| 14 | && apt-get update \ |
| 15 | && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ |
| 16 | systemd systemd-sysv dbus dbus-user-session libpam-systemd sudo \ |
| 17 | openssh-server openssh-client iproute2 fuse3 sshfs socat \ |
| 18 | ca-certificates curl git jq python3 python3-apt zsh procps \ |
| 19 | && rm /usr/sbin/policy-rc.d \ |
| 20 | && rm -rf /var/lib/apt/lists/* \ |
| 21 | && useradd --create-home --uid 1000 --user-group --shell /bin/bash cage \ |
| 22 | && printf 'cage ALL=(ALL) NOPASSWD: ALL\n' > /etc/sudoers.d/cage \ |
| 23 | && chmod 0440 /etc/sudoers.d/cage \ |
| 24 | && printf 'user_allow_other\n' > /etc/fuse.conf \ |
| 25 | && install -d -m 0700 -o cage -g cage /home/cage/.ssh \ |
| 26 | && install -d -m 0755 /etc/systemd/system.conf.d \ |
| 27 | && printf '[Manager]\nDefaultTasksMax=infinity\n' > /etc/systemd/system.conf.d/90-cage-container.conf \ |
| 28 | && install -d -m 0755 /etc/ssh/sshd_config.d /etc/systemd/system/ssh.service.d \ |
| 29 | && printf '%s\n' 'PermitRootLogin no' 'PasswordAuthentication no' \ |
| 30 | 'KbdInteractiveAuthentication no' 'AuthenticationMethods publickey' \ |
| 31 | 'AuthorizedKeysFile /etc/ssh/cage_authorized_keys' 'AllowTcpForwarding yes' \ |
| 32 | 'GatewayPorts no' 'X11Forwarding no' 'AllowUsers cage' \ |
| 33 | > /etc/ssh/sshd_config.d/10-cage.conf \ |
| 34 | && printf '[Service]\nExecStartPre=\nExecStartPre=/usr/bin/ssh-keygen -A\nExecStartPre=/usr/sbin/sshd -t\n' \ |
| 35 | > /etc/systemd/system/ssh.service.d/10-cage-hostkeys.conf \ |
| 36 | && systemctl enable ssh.service \ |
| 37 | && rm -f /etc/ssh/ssh_host_* /etc/machine-id /var/lib/dbus/machine-id \ |
| 38 | && touch /etc/machine-id \ |
| 39 | && ln -s /etc/machine-id /var/lib/dbus/machine-id \ |
| 40 | && sh /usr/local/lib/cage-image-restore-sources |
| 41 | |
| 42 | # PID 1 owns its services. Container stop must let systemd stop them in order. |
| 43 | # Persistent files remain in the same container until an explicit migration. |
| 44 | STOPSIGNAL SIGRTMIN+3 |
| 45 | CMD ["/sbin/init"] |