feat(labs): add the labd provisioner with clone pool, time to live and limits

This commit is contained in:
shira committed 2026-10-11 15:43:04 +03:00
1 parent 9fdaa62b9b
commit 9385b2ddd4
53 files changed
+14675 -6

No files matched your search

+26
View File
@@ -0,0 +1,26 @@
# Example settings of labd for /etc/lincodex-labd/labd.env on the app host.
# The file holds no secret: the token, certificate, and key are separate files
# that only the lincodex-labd user can read. See labd/README.en.md.
# Listen on the gateway of the application Docker network, so that only the
# backend reaches the API; the host firewall opens the port to that network.
LABD_LISTEN_ADDRESS=172.29.79.1:8445
LABD_ALLOWED_CLIENTS=172.29.79.0/24
LABD_TLS_CERT_FILE=/etc/lincodex-labd/tls.crt
LABD_TLS_KEY_FILE=/etc/lincodex-labd/tls.key
LABD_API_TOKEN_FILE=/etc/lincodex-labd/api-token
LABD_LXD_SOCKET=/var/snap/lxd/common/lxd/unix.socket
LABD_LXD_PROJECT=default
LABD_STATE_FILE=/var/lib/lincodex-labd/labs.json
# Guest memory of all labs together. One lincodex-lab-small node is 768 MiB;
# leave room for the core stack and the runner VM.
LABD_MEMORY_BUDGET_MIB=3072
LABD_MAX_LABS=0
LABD_MAX_LIFETIME=2h
LABD_MGMT_NETWORK=lxdbr-labmgmt
LABD_MGMT_SUBNET=10.81.0.0/24
LABD_MGMT_HOST_ADDRESS=10.81.0.1
LABD_MGMT_FIRST_ADDRESS=10.81.0.16
+55
View File
@@ -0,0 +1,55 @@
# systemd unit of the lab provisioner labd on the app host.
#
# labd is the only process that talks to the LXD API. The lxd group is
# equivalent to root on the host, so the unit gives the process nothing else:
# no capabilities, a read-only file system except its state directory and the
# LXD socket, and no other secrets than its own TLS pair and API token in
# /etc/lincodex-labd/ (owner lincodex-labd, mode 0600). The settings come from
# /etc/lincodex-labd/labd.env; see deploy/labs/labd.env.example.
[Unit]
Description=Lincodex lab provisioner (labd)
Wants=network-online.target
After=network-online.target snap.lxd.daemon.service docker.service
[Service]
Type=simple
User=lincodex-labd
Group=lincodex-labd
SupplementaryGroups=lxd
EnvironmentFile=/etc/lincodex-labd/labd.env
ExecStart=/usr/local/bin/lincodex-labd
Restart=on-failure
RestartSec=5s
# Longer than LABD_SHUTDOWN_TIMEOUT, so a drain finishes before SIGKILL. A
# kill is still safe: the next start finishes every lab from the state file.
TimeoutStopSec=45s
StateDirectory=lincodex-labd
StateDirectoryMode=0700
UMask=0077
ReadWritePaths=/var/snap/lxd/common/lxd/unix.socket
NoNewPrivileges=yes
CapabilityBoundingSet=
AmbientCapabilities=
ProtectSystem=strict
ProtectHome=yes
PrivateTmp=yes
PrivateDevices=yes
ProtectKernelTunables=yes
ProtectKernelModules=yes
ProtectKernelLogs=yes
ProtectControlGroups=yes
ProtectClock=yes
ProtectHostname=yes
RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6
RestrictNamespaces=yes
RestrictRealtime=yes
RestrictSUIDSGID=yes
LockPersonality=yes
MemoryDenyWriteExecute=yes
SystemCallArchitectures=native
SystemCallFilter=@system-service
# A refused system call fails with EPERM instead of killing the process.
SystemCallErrorNumber=EPERM
[Install]
WantedBy=multi-user.target