feat(deploy): prepare the LXD host for the isolated runner and labs
This commit is contained in:
1 parent
63e6b41bec
commit
56dcf32f8c
4 files changed
+152
No files matched your search
Executable
+34
@@ -0,0 +1,34 @@
|
||||
#!/usr/bin/env bash
|
||||
# Creates the network ACLs referenced by lxd-preseed.yaml (TASK-592).
|
||||
# Run before the preseed. Rules are stateful: replies to allowed traffic pass.
|
||||
set -euo pipefail
|
||||
|
||||
# The ACL filters forwarded traffic before Docker masquerades it, so the
|
||||
# backend is matched by the app subnet; host-side tools come from the bridge
|
||||
# address. The token on the control API, not the source address, authorizes
|
||||
# callers: other containers of the app network reach the port but not the API.
|
||||
app_subnet="${APP_SUBNET:-172.29.79.0/24}"
|
||||
runner_host_side="${RUNNER_HOST_SIDE:-10.80.0.1/32}"
|
||||
runner_port="${RUNNER_PORT:-8443}"
|
||||
|
||||
ensure_acl() {
|
||||
lxc network acl show "$1" >/dev/null 2>&1 || lxc network acl create "$1" </dev/null
|
||||
}
|
||||
|
||||
# Runner: only the app network and host-side tools may open the control API; the
|
||||
# runner VM itself may not start any connection.
|
||||
ensure_acl lincodex-runner
|
||||
for source in "$app_subnet" "$runner_host_side"; do
|
||||
lxc network acl rule add lincodex-runner ingress action=allow protocol=tcp \
|
||||
source="$source" destination_port="$runner_port" 2>/dev/null || true
|
||||
done
|
||||
|
||||
# Lab management: the checker and the console gateway live on the host side
|
||||
# and connect to the nodes; the nodes may not start any connection.
|
||||
ensure_acl lincodex-labmgmt
|
||||
lxc network acl rule add lincodex-labmgmt ingress action=allow protocol=tcp \
|
||||
source=10.81.0.1/32 destination_port=22,8728,8729 2>/dev/null || true
|
||||
|
||||
# Guests get static addresses from the provisioner (cloud-init), so no DHCP
|
||||
# or DNS rule exists: a guest cannot send anything towards the host.
|
||||
lxc network acl list
|
||||
@@ -0,0 +1,68 @@
|
||||
# LXD host layout for the isolated runner and the practical labs (TASK-592).
|
||||
# Applied once on the app host with: lxd init --preseed < lxd-preseed.yaml
|
||||
# It only adds objects; it does not touch Docker, wg0 or the awg-lincodex tunnel.
|
||||
storage_pools:
|
||||
# Copy-on-write pool, so lab nodes are cloned from prepared snapshots in seconds.
|
||||
- name: lincodex
|
||||
driver: btrfs
|
||||
config:
|
||||
size: 40GiB
|
||||
networks:
|
||||
# The runner VM. Only the backend reaches it; the ACL below drops everything else.
|
||||
- name: lxdbr-runner
|
||||
type: bridge
|
||||
config:
|
||||
ipv4.address: 10.80.0.1/24
|
||||
ipv4.nat: "false"
|
||||
ipv6.address: none
|
||||
ipv4.dhcp: "false"
|
||||
raw.dnsmasq: port=0
|
||||
security.acls: lincodex-runner
|
||||
security.acls.default.ingress.action: drop
|
||||
security.acls.default.egress.action: drop
|
||||
# Management plane of the labs (checker and console gateway). Lab data links
|
||||
# are separate L2-only bridges created per lab by the provisioner.
|
||||
- name: lxdbr-labmgmt
|
||||
type: bridge
|
||||
config:
|
||||
ipv4.address: 10.81.0.1/24
|
||||
ipv4.nat: "false"
|
||||
ipv6.address: none
|
||||
ipv4.dhcp: "false"
|
||||
raw.dnsmasq: port=0
|
||||
security.acls: lincodex-labmgmt
|
||||
security.acls.default.ingress.action: drop
|
||||
security.acls.default.egress.action: drop
|
||||
profiles:
|
||||
- name: lincodex-runner
|
||||
description: Runner VM, 2 vCPU and 3 GiB (PRD Q11.1)
|
||||
config:
|
||||
limits.cpu: "2"
|
||||
limits.memory: 3GiB
|
||||
limits.memory.enforce: hard
|
||||
security.secureboot: "false"
|
||||
devices:
|
||||
root:
|
||||
type: disk
|
||||
path: /
|
||||
pool: lincodex
|
||||
size: 10GiB
|
||||
eth0:
|
||||
type: nic
|
||||
network: lxdbr-runner
|
||||
- name: lincodex-lab-small
|
||||
description: One lab node, 1 vCPU and up to 768 MiB
|
||||
config:
|
||||
limits.cpu: "1"
|
||||
limits.memory: 768MiB
|
||||
limits.memory.enforce: hard
|
||||
security.secureboot: "false"
|
||||
devices:
|
||||
root:
|
||||
type: disk
|
||||
path: /
|
||||
pool: lincodex
|
||||
size: 4GiB
|
||||
eth0:
|
||||
type: nic
|
||||
network: lxdbr-labmgmt
|
||||
@@ -710,6 +710,31 @@ When the local resolver does not return the public address, add `--resolve <doma
|
||||
|
||||
This is one edge host and one app host. There is no failover, no external uptime check, and no rate limiting at the edge (the frontend container applies coarse per-client limits, and the backend domain quotas are separate and not implemented yet). The certificate covers only the one name, the site is IPv4 only, and the ACME account has no contact address. The tunnel carries no authentication beyond the AmneziaWG keys, and the obfuscation parameters raise the cost of blocking but are not a security control.
|
||||
|
||||
## Isolated runner and lab host (LXD)
|
||||
|
||||
The code runner and the practical labs run as LXD virtual machines on the app host, outside the Docker stack. The layout is in `deploy/labs/`: `lxd-preseed.yaml` (storage pool, bridges, profiles) and `acls.sh` (network ACLs). Apply it once, as a member of the `lxd` group:
|
||||
|
||||
```bash
|
||||
bash deploy/labs/acls.sh
|
||||
```
|
||||
|
||||
```bash
|
||||
lxd init --preseed < deploy/labs/lxd-preseed.yaml
|
||||
```
|
||||
|
||||
What it creates:
|
||||
|
||||
- Storage pool `lincodex`: btrfs in a 40 GiB loop file, so lab nodes are cloned from prepared snapshots in seconds.
|
||||
- Bridge `lxdbr-runner` (`10.80.0.1/24`) for the runner VM and bridge `lxdbr-labmgmt` (`10.81.0.1/24`) for the lab management plane. Both have no NAT, no DHCP and no DNS (`ipv4.dhcp=false`, `raw.dnsmasq: port=0`): the provisioner gives guests static addresses through cloud-init, so a guest has nothing to send towards the host.
|
||||
- Network ACLs with default ingress and egress `drop`. `lincodex-runner` lets only the app network (`172.29.79.0/24`, matched before Docker masquerades it) and the host side of the bridge open TCP 8443; the token on the runner API authorizes the caller. `lincodex-labmgmt` lets only the host side open SSH and the RouterOS API (22, 8728, 8729) to the nodes. Guests can start no connection at all.
|
||||
- Profiles `lincodex-runner` (2 vCPU, 3 GiB, 10 GiB disk) and `lincodex-lab-small` (1 vCPU, 768 MiB, 4 GiB disk). For a VM the memory limit is the guest RAM, so it cannot be exceeded.
|
||||
|
||||
The `lxd` group is equivalent to root on the host. Only the lab provisioner and the operator use it; the backend and the other containers never get the LXD socket.
|
||||
|
||||
Verified on the app host (TASK-592): from a guest on `lxdbr-runner` the internet, the host SSH, the bridge address, the app network and the LAN router are unreachable; from the app network only TCP 8443 of the guest is reachable; a VM with the lab profile boots under nested KVM and sees one CPU and about 700 MiB. The host `ufw` denies incoming traffic by default, which also blocks DHCP to the bridges; static addressing avoids opening it.
|
||||
|
||||
Cleanup before the rollout removed only the Docker build cache (`docker builder prune -af`, about 8 GB). `apt-get clean` and `journalctl --vacuum-size=100M` need sudo and are left to the operator. Docker volumes, the images of the running stack, `wg0`, `awg-lincodex` and the `ufw` rules are not touched.
|
||||
|
||||
## Services and images
|
||||
|
||||
Container images use moving `latest` or `alpine` tags where the upstream publishes them. Check the current Compose references when updating the stack. These tags can move; the [release manifest](#release-manifest) records the actual image digests of a release. An SBOM is not produced yet. Application dependency lockfiles remain checked in separately.
|
||||
|
||||
@@ -712,6 +712,31 @@ Reload запускает новые workers с новым сертификат
|
||||
|
||||
Это один edge-хост и один app-хост. Нет failover, внешней проверки доступности и ограничения частоты запросов на edge (frontend контейнер применяет грубые лимиты на клиента, а доменные квоты backend отдельные и еще не реализованы). Сертификат покрывает только одно имя, сайт работает только по IPv4, у аккаунта ACME нет контактного адреса. Туннель не имеет аутентификации кроме ключей AmneziaWG, а параметры обфускации повышают цену блокировки, но не являются мерой безопасности.
|
||||
|
||||
## Изолированный хост раннера и лабораторий (LXD)
|
||||
|
||||
Раннер кода и практические лаборатории работают виртуальными машинами LXD на хосте приложения, вне Docker-стека. Раскладка лежит в `deploy/labs/`: `lxd-preseed.yaml` (хранилище, мосты, профили) и `acls.sh` (сетевые ACL). Применяется один раз пользователем из группы `lxd`:
|
||||
|
||||
```bash
|
||||
bash deploy/labs/acls.sh
|
||||
```
|
||||
|
||||
```bash
|
||||
lxd init --preseed < deploy/labs/lxd-preseed.yaml
|
||||
```
|
||||
|
||||
Что создаётся:
|
||||
|
||||
- Хранилище `lincodex`: btrfs в loop-файле на 40 GiB, чтобы узлы лабораторий клонировались из подготовленных снимков за секунды.
|
||||
- Мост `lxdbr-runner` (`10.80.0.1/24`) для VM раннера и мост `lxdbr-labmgmt` (`10.81.0.1/24`) для управляющей сети лабораторий. На обоих нет NAT, DHCP и DNS (`ipv4.dhcp=false`, `raw.dnsmasq: port=0`): провизионер выдаёт гостям статические адреса через cloud-init, поэтому гостю нечего отправлять в сторону хоста.
|
||||
- Сетевые ACL с действием `drop` по умолчанию для входящего и исходящего трафика. `lincodex-runner` разрешает открыть TCP 8443 только из сети приложения (`172.29.79.0/24`, сопоставляется до маскировки Docker) и со стороны хоста на мосту; вызывающего авторизует токен API раннера. `lincodex-labmgmt` разрешает только со стороны хоста SSH и RouterOS API (22, 8728, 8729) к узлам. Гости не могут открыть ни одного соединения.
|
||||
- Профили `lincodex-runner` (2 vCPU, 3 GiB, диск 10 GiB) и `lincodex-lab-small` (1 vCPU, 768 MiB, диск 4 GiB). Для VM лимит памяти равен памяти гостя, превысить его нельзя.
|
||||
|
||||
Группа `lxd` равносильна root на хосте. Её используют только провизионер лабораторий и оператор; backend и другие контейнеры сокет LXD не получают.
|
||||
|
||||
Проверено на хосте приложения (TASK-592): из гостя в `lxdbr-runner` недоступны интернет, SSH хоста, адрес моста, сеть приложения и роутер LAN; из сети приложения доступен только TCP 8443 гостя; VM с профилем лаборатории запускается во вложенной KVM и видит один CPU и около 700 MiB. `ufw` хоста по умолчанию запрещает входящий трафик, что блокирует и DHCP к мостам; статические адреса позволяют его не открывать.
|
||||
|
||||
Чистка перед раскаткой удалила только кеш сборки Docker (`docker builder prune -af`, около 8 ГБ). `apt-get clean` и `journalctl --vacuum-size=100M` требуют sudo и оставлены оператору. Тома Docker, образы работающего стека, `wg0`, `awg-lincodex` и правила `ufw` не затронуты.
|
||||
|
||||
## Сервисы и образы
|
||||
|
||||
Для контейнерных образов выбраны moving tags `latest` или `alpine`, если upstream публикует такой вариант. При обновлении Compose сверяйте актуальные ссылки на образы. Теги `latest` и `alpine` могут перемещаться; фактические image digests выпуска фиксирует [манифест выпуска](#манифест-выпуска). SBOM пока не формируется. Lockfiles прикладных зависимостей сохраняются отдельно.
|
||||
|
||||
Reference in new issue
Block a user