chore: init
This commit is contained in:
42 files changed
+601
No files matched your search
@@ -0,0 +1,18 @@
|
||||
# Firewall: drop all incoming traffic except replies, loopback, ICMP, DHCPv6 and ssh, and forward
|
||||
# nothing (rootless podman's networks live in Claude's own network namespace). Loaded by
|
||||
# nftables.service.
|
||||
destroy table inet firewall
|
||||
table inet firewall {
|
||||
chain input {
|
||||
type filter hook input priority filter; policy drop;
|
||||
ct state established,related accept
|
||||
ct state invalid drop
|
||||
iif lo accept
|
||||
meta l4proto { icmp, ipv6-icmp } accept
|
||||
ip6 saddr fe80::/10 udp dport 546 accept
|
||||
tcp dport 22 accept
|
||||
}
|
||||
chain forward {
|
||||
type filter hook forward priority filter; policy drop;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
# Grow the /var partition to fill the disk at boot (systemd-repart); x-systemd.growfs in /etc/fstab
|
||||
# then grows its filesystem.
|
||||
[Partition]
|
||||
Type=var
|
||||
@@ -0,0 +1,31 @@
|
||||
# Kernel hardening, mostly the KSPP recommendations (Talos sets these too), and one limit raised
|
||||
# for containers. Left out on purpose: user.max_user_namespaces=0 breaks rootless podman, and
|
||||
# kernel.modules_disabled=1 breaks loading the network modules podman needs.
|
||||
|
||||
# Hide kernel addresses (they help exploits bypass KASLR), even from root.
|
||||
kernel.kptr_restrict = 2
|
||||
# Only root may read the kernel log; it leaks addresses.
|
||||
kernel.dmesg_restrict = 1
|
||||
# No perf events for non-root users.
|
||||
kernel.perf_event_paranoid = 3
|
||||
# Harden the BPF JIT against JIT spraying.
|
||||
net.core.bpf_jit_harden = 2
|
||||
# No BPF for non-root users, and no switching it back on at runtime.
|
||||
kernel.unprivileged_bpf_disabled = 1
|
||||
# No kexec: no booting another kernel past Secure Boot.
|
||||
kernel.kexec_load_disabled = 1
|
||||
# No core dumps of setuid programs; they can hold secrets.
|
||||
fs.suid_dumpable = 0
|
||||
# No loading TTY line disciplines on demand; old ones had exploitable bugs.
|
||||
dev.tty.ldisc_autoload = 0
|
||||
# userfaultfd only for root; it makes kernel race exploits reliable.
|
||||
vm.unprivileged_userfaultfd = 0
|
||||
# No opening FIFOs and files owned by others in sticky directories like /tmp.
|
||||
fs.protected_fifos = 2
|
||||
fs.protected_regular = 2
|
||||
# ptrace only on your own descendants.
|
||||
kernel.yama.ptrace_scope = 1
|
||||
|
||||
# Containers (file watchers, systemd in containers) run out of Fedora's 128 inotify instances
|
||||
# per user; 8192 is common on Kubernetes nodes.
|
||||
fs.inotify.max_user_instances = 8192
|
||||
Binary file not shown.
@@ -0,0 +1,11 @@
|
||||
# DHCP on the real network cards. Kind=!* skips virtual links.
|
||||
[Match]
|
||||
Type=ether
|
||||
Kind=!*
|
||||
|
||||
[Network]
|
||||
DHCP=yes
|
||||
|
||||
[DHCPv4]
|
||||
# The hostname is the one asked at setup (agent-boot), not the DHCP server's.
|
||||
UseHostname=no
|
||||
@@ -0,0 +1,20 @@
|
||||
# Services enabled in the image (mkosi runs systemctl preset-all). Fedora disables getty@.service, the
|
||||
# login on the screen (tty1, and tty2-6 through its autovt@ alias); this file sorts first, so it wins.
|
||||
enable systemd-networkd.service
|
||||
enable systemd-resolved.service
|
||||
enable systemd-oomd.service
|
||||
enable nftables.service
|
||||
enable sshd.service
|
||||
enable getty@.service
|
||||
enable agent-setup@.service tty1 ttyS0
|
||||
enable etc-shadow.mount
|
||||
enable agent-boot.service
|
||||
enable claude-remote.path
|
||||
enable systemd-sysupdate-update.timer
|
||||
enable systemd-sysupdate-reboot.timer
|
||||
# Fedora enables these, but they do nothing here: no PAM or crypto changes on a read-only /etc,
|
||||
# no system or config extensions.
|
||||
disable authselect-apply-changes.service
|
||||
disable fips-crypto-policy-overlay.service
|
||||
disable systemd-sysext.service
|
||||
disable systemd-confext.service
|
||||
@@ -0,0 +1,15 @@
|
||||
# Applies the setup answers at every boot (see /usr/libexec/agent-boot). Before the setup is done
|
||||
# there are none; agent-setup starts this when it is.
|
||||
[Unit]
|
||||
Description=Apply agent setup
|
||||
ConditionPathExists=/var/lib/agent/hostname
|
||||
After=systemd-tmpfiles-setup.service
|
||||
Before=sshd.service claude-remote.service
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
RemainAfterExit=yes
|
||||
ExecStart=/usr/libexec/agent-boot
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -0,0 +1,21 @@
|
||||
# First boot: asks for the root password, hostname and ssh key, on the screen (tty1) and the serial
|
||||
# console (ttyS0) at once; whichever is answered first stops the other.
|
||||
[Unit]
|
||||
Description=Agent first-boot setup on %I
|
||||
ConditionPathExists=!/var/lib/agent/hostname
|
||||
After=systemd-tmpfiles-setup.service
|
||||
Before=getty@%i.service serial-getty@%i.service
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/libexec/agent-setup
|
||||
StandardInput=tty
|
||||
StandardOutput=tty
|
||||
TTYPath=/dev/%I
|
||||
TTYReset=yes
|
||||
TTYVHangup=yes
|
||||
# Answering on one console stops the setup on the other (SIGTERM), which is no failure.
|
||||
SuccessExitStatus=SIGTERM
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -0,0 +1,9 @@
|
||||
# Starts Claude (Remote Control) once it is logged in: at boot, or when the user first logs in.
|
||||
[Unit]
|
||||
Description=Start Claude Remote Control once logged in
|
||||
|
||||
[Path]
|
||||
PathExists=/var/lib/agent/claude/.credentials.json
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -0,0 +1,16 @@
|
||||
# Claude Code, in the background, controlled from claude.ai/code or the Claude app (Remote Control).
|
||||
# Works in Claude's home. Started by claude-remote.path once Claude is logged in.
|
||||
[Unit]
|
||||
Description=Claude Code Remote Control
|
||||
Wants=network-online.target user@1000.service
|
||||
After=network-online.target user@1000.service agent-boot.service
|
||||
|
||||
[Service]
|
||||
User=claude
|
||||
WorkingDirectory=~
|
||||
# In user.slice, so systemd-oomd kills it (or Claude's containers), not the system (user.slice.d).
|
||||
Slice=user.slice
|
||||
Environment=CLAUDE_CONFIG_DIR=/var/lib/agent/claude XDG_RUNTIME_DIR=/run/user/1000
|
||||
ExecStart=/usr/bin/claude remote-control --name %H
|
||||
Restart=always
|
||||
RestartSec=10s
|
||||
@@ -0,0 +1,14 @@
|
||||
# The root password. /etc is read-only, so agent-setup writes the shadow file to /var and this
|
||||
# mounts it over /etc/shadow.
|
||||
[Unit]
|
||||
Description=Root password from /var
|
||||
ConditionPathExists=/var/lib/agent/etc/shadow
|
||||
RequiresMountsFor=/var
|
||||
|
||||
[Mount]
|
||||
What=/var/lib/agent/etc/shadow
|
||||
Where=/etc/shadow
|
||||
Options=bind
|
||||
|
||||
[Install]
|
||||
WantedBy=local-fs.target
|
||||
@@ -0,0 +1,6 @@
|
||||
# Load our firewall (/usr/lib/agent/firewall.nft) instead of /etc/sysconfig/nftables.conf.
|
||||
[Service]
|
||||
ExecStart=
|
||||
ExecStart=/usr/sbin/nft -f /usr/lib/agent/firewall.nft
|
||||
ExecReload=
|
||||
ExecReload=/usr/sbin/nft -f /usr/lib/agent/firewall.nft
|
||||
@@ -0,0 +1,4 @@
|
||||
# The host key is made by agent-boot, once the setup is done; agent-setup then starts sshd.
|
||||
[Unit]
|
||||
After=agent-boot.service
|
||||
ConditionPathExists=/var/lib/agent/ssh_host_ed25519_key
|
||||
@@ -0,0 +1,7 @@
|
||||
# systemd-oomd for Claude and its containers: when they run the VM out of memory, kill the cgroup
|
||||
# responsible before the VM thrashes on zram swap or the kernel's OOM killer picks sshd.
|
||||
[Slice]
|
||||
# Memory pressure above 60% for 30s: kill the cgroup reclaiming the most memory.
|
||||
ManagedOOMMemoryPressure=kill
|
||||
# Swap over 90% full: kill the cgroup using the most swap.
|
||||
ManagedOOMSwap=kill
|
||||
@@ -0,0 +1,19 @@
|
||||
# Updates the root filesystem: writes the next version to the unused root partition.
|
||||
# Verify=yes: SHA256SUMS.gpg must be signed by a key in /usr/lib/systemd/import-pubring.pgp, and
|
||||
# SHA256SUMS checks each download.
|
||||
[Transfer]
|
||||
ProtectVersion=%A
|
||||
Verify=yes
|
||||
|
||||
[Source]
|
||||
Type=url-file
|
||||
Path=https://git.plabble.org/api/packages/Job79/generic/agent/latest/
|
||||
MatchPattern=agent_@v.root-%a.@u.raw.zst
|
||||
|
||||
[Target]
|
||||
Type=partition
|
||||
Path=auto
|
||||
MatchPattern=agent_@v
|
||||
MatchPartitionType=root
|
||||
PartitionFlags=0
|
||||
ReadOnly=1
|
||||
@@ -0,0 +1,17 @@
|
||||
# Updates the root filesystem's dm-verity hashes, next to 10-root.transfer (see it for Verify=yes).
|
||||
[Transfer]
|
||||
ProtectVersion=%A
|
||||
Verify=yes
|
||||
|
||||
[Source]
|
||||
Type=url-file
|
||||
Path=https://git.plabble.org/api/packages/Job79/generic/agent/latest/
|
||||
MatchPattern=agent_@v.root-%a-verity.@u.raw.zst
|
||||
|
||||
[Target]
|
||||
Type=partition
|
||||
Path=auto
|
||||
MatchPattern=agent_@v_verity
|
||||
MatchPartitionType=root-verity
|
||||
PartitionFlags=0
|
||||
ReadOnly=1
|
||||
@@ -0,0 +1,17 @@
|
||||
# Installs the next UKI, which systemd-boot boots by default. Verify=yes: see 10-root.transfer.
|
||||
[Transfer]
|
||||
ProtectVersion=%A
|
||||
Verify=yes
|
||||
|
||||
[Source]
|
||||
Type=url-file
|
||||
Path=https://git.plabble.org/api/packages/Job79/generic/agent/latest/
|
||||
MatchPattern=agent_@v.efi
|
||||
|
||||
[Target]
|
||||
Type=regular-file
|
||||
Path=/EFI/Linux
|
||||
PathRelativeTo=boot
|
||||
MatchPattern=agent_@v.efi
|
||||
Mode=0444
|
||||
InstancesMax=2
|
||||
@@ -0,0 +1,2 @@
|
||||
# The user Claude runs as; /etc/subuid and /etc/subgid give it the ids of rootless podman.
|
||||
u claude 1000 "Claude" /var/home/claude /bin/bash
|
||||
@@ -0,0 +1,10 @@
|
||||
# State kept across reboots: the setup answers, the ssh host key and Claude's login
|
||||
# (agent-boot wipes the rest of Claude's config).
|
||||
d /var/lib/agent 0755 root root -
|
||||
d /var/lib/agent/claude 0700 claude claude -
|
||||
# Wiped at every boot (D empties a directory at boot): Claude's home, with its podman storage, and
|
||||
# temporary files. These, /tmp and Claude's config are all that Claude can write.
|
||||
D /var/home/claude 0700 claude claude -
|
||||
D /var/tmp 1777 root root -
|
||||
# Start Claude's user manager at boot, for rootless podman and its own services.
|
||||
f /var/lib/systemd/linger/claude
|
||||
Executable
+9
@@ -0,0 +1,9 @@
|
||||
#!/bin/bash
|
||||
# Every boot (agent-boot.service), and after the setup: sets the hostname asked at setup (/etc is
|
||||
# read-only, so it is set on every boot), makes the ssh host key the first time, and wipes
|
||||
# Claude's config except its login, so Claude starts fresh but logged in.
|
||||
set -euo pipefail
|
||||
cd /var/lib/agent
|
||||
hostnamectl hostname --transient "$(cat hostname)"
|
||||
[[ -f ssh_host_ed25519_key ]] || ssh-keygen -q -t ed25519 -N '' -f ssh_host_ed25519_key
|
||||
find claude -mindepth 1 -maxdepth 1 ! -name .credentials.json ! -name .claude.json -exec rm -rf {} +
|
||||
Executable
+29
@@ -0,0 +1,29 @@
|
||||
#!/bin/bash
|
||||
# First boot: asks for the root password, the hostname and the ssh key of the user claude, on the
|
||||
# screen (tty1) and the serial console (ttyS0) at once (agent-setup@.service).
|
||||
# /etc is read-only, so the answers go to /var/lib/agent: the password to a shadow file there
|
||||
# (etc-shadow.mount puts it over /etc/shadow), the rest is applied by agent-boot at every boot.
|
||||
set -euo pipefail
|
||||
echo "== Agent setup =="
|
||||
|
||||
while :; do
|
||||
read -rsp "Root password: " pw; echo
|
||||
read -rsp "Again: " pw2; echo
|
||||
[[ -n $pw && $pw == "$pw2" ]] && break
|
||||
echo "Passwords do not match, try again."
|
||||
done
|
||||
install -d -m 0700 /var/lib/agent/etc
|
||||
cp /etc/passwd /etc/shadow /var/lib/agent/etc/
|
||||
echo "root:$pw" | chpasswd --prefix /var/lib/agent
|
||||
systemctl start etc-shadow.mount
|
||||
|
||||
read -rp "Hostname [agent]: " name
|
||||
read -rp "SSH public key for the user claude: " key
|
||||
[[ -n $key ]] && install -m 0644 /dev/stdin /var/lib/agent/authorized_keys <<<"$key"
|
||||
# Written last: its presence marks the setup as done.
|
||||
echo "${name:-agent}" > /var/lib/agent/hostname
|
||||
systemctl start agent-boot.service sshd.service
|
||||
echo "Done. Log in with ssh claude@<this VM>, run claude and log in with your account."
|
||||
echo "Remote Control then starts by itself."
|
||||
# Stop the setup on the other console, which then shows its login.
|
||||
systemctl --no-block stop "agent-setup@*.service"
|
||||
Reference in new issue
Block a user