chore(wireguard): remove the role and its references to start fresh

The consolidated svc-net-wireguard role, its requirement document and the three
references that only existed to support it go away together: the lint ignore for
a load failure inside its tasks, the requirements index entry, and the tunnel
subnet variable nothing else consumed.

Left in place deliberately: the WireGuard mention in the svc-net category
description, which is upstream prose about networking roles in general rather
than anything this role owned.
This commit is contained in:
evangelostsak committed 2026-09-18 00:30:39 +02:00
1 parent 93ea22b933
commit c40d7aa6da
24 files changed
-964

No files matched your search

-1
View File
@@ -13,7 +13,6 @@ roles/svc-ai-ollama/tasks/roles/sys-svc-compose/tasks/utils/network/routine.yml
roles/svc-db-mariadb/tasks/roles/sys-svc-compose/tasks/utils/network/routine.yml load-failure[filenotfounderror]
roles/svc-db-openldap/tasks/roles/sys-svc-compose/tasks/utils/network/create.yml load-failure[filenotfounderror]
roles/svc-db-postgres/tasks/roles/sys-svc-compose/tasks/utils/network/routine.yml load-failure[filenotfounderror]
roles/svc-net-wireguard/tasks/roles/sys-svc-compose/tasks/utils/network/create.yml load-failure[filenotfounderror]
roles/sys-front-tls-letsencrypt/tasks/roles/sys-ca-selfsigned/tasks/disable_env.yml load-failure[filenotfounderror]
roles/sys-svc-compose/tasks/utils/network/roles/sys-svc-compose/tasks/utils/network/create.yml load-failure[filenotfounderror]
roles/sys-svc-mail-msmtp/tasks/roles/sys-svc-mail-smtp/tasks/disable.yml load-failure[filenotfounderror]
-261
View File
@@ -1,261 +0,0 @@
# 026 - Dockerized `svc-net-wireguard` (consolidate core / plain / firewalled)
Implemented by [infinito-nexus/core#323](https://github.com/infinito-nexus/core/pull/323).
## User Story
As a platform administrator of Infinito.Nexus, I want a single Docker-based `svc-net-wireguard` role that runs WireGuard in a container (server **and** client modes) and replaces the three host-native roles `svc-net-wireguard-core`, `svc-net-wireguard-plain`, and `svc-net-wireguard-firewalled`, so that WireGuard is deployed the same containerized way as every other `svc-*` service, with one role to learn, one image to pin, and a reproducible multi-server end-to-end test instead of three host-coupled, distro-branching roles wired together by hand.
## Background
WireGuard currently ships as three separate host-native roles, all `wg-quick` / host-package based:
- `svc-net-wireguard-core` — installs `wireguard-tools` (Arch) / `wireguard` (Debian) on the host, drops a sysctl file for IPv4/IPv6 forwarding, copies a per-host `wg0.conf` from the inventory, restarts the host's WireGuard service. This is the **server**.
- `svc-net-wireguard-plain` — installs a systemd unit + `set-mtu.sh` that forces MTU 1400 on the internet interface(s). This is a **client** helper.
- `svc-net-wireguard-firewalled` — runs `iptables -A FORWARD -i wg0-client -j ACCEPT && iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE`. This is the **client-behind-NAT** helper.
The trio is host-coupled (writes `/etc/wireguard/`, `/etc/sysctl.d/`, host `iptables`), distro-branchy, and managed by hand through each role's `Administration.md`. Keys, peers and addressing are operator-maintained outside the role.
Every other service in the repo (`svc-db-postgres`, `svc-db-redis`, …) runs as a Docker Compose stack assembled from `sys-svc-compose` / `sys-svc-container` base templates, with `meta/services.yml`, `meta/schema.yml`, a pinned image, and a healthcheck. WireGuard is the outlier. The [linuxserver/wireguard](https://docs.linuxserver.io/images/docker-wireguard/) image already provides both server and client behaviour in one container — server mode is selected automatically when `PEERS` is set, and the image's [User / Group Identifiers](https://docs.linuxserver.io/images/docker-wireguard/#user-group-identifiers) (`PUID` / `PGID`) contract maps container file ownership onto a host user, which is exactly the volume-ownership model the rest of the repo already follows.
This requirement collapses the three roles into one Docker-based `roles/svc-net-wireguard/`, preserving the NAT/masquerade behaviour of the old `-firewalled` role verbatim, and adds a Docker-in-Docker end-to-end test that stands up at least three WireGuard servers and verifies peer connectivity between them — mirroring the orchestrator logic already prototyped in `roles/svc-net-wireguard/example.sh.example` (the svc-runner E2E pattern: env-gate → artefact-check → delegate to `local.sh` / `external.sh`).
## Confirmed Decisions
Decisions 1–4 were operator-confirmed before the first implementation pass; decision 5 was added in a follow-up clarification round.
| # | Decision | Rationale |
|---|----------|-----------|
| 1 | The three host-native roles `svc-net-wireguard-core`, `svc-net-wireguard-plain`, `svc-net-wireguard-firewalled` are **deprecated and removed**. The new `roles/svc-net-wireguard/` fully replaces them. A grep over the repo confirms no inventory / `group_vars` / role-dependency outside the three roles themselves references them, so removal is self-contained. | Operator chose "deprecate + remove". Matches the "refactor **to** svc-net-wireguard" framing; avoids carrying a dead host-native path. |
| 2 | The unified role supports **both** WireGuard modes behind a `services.wireguard.mode` discriminator: `server` (image runs with `PEERS` set, generates peer configs) and `client` (joins an upstream peer). The old `-plain` (MTU) and `-firewalled` (NAT) client concerns fold into `mode: client`. | Operator chose "server + client". One role owns the whole WireGuard surface; the linuxserver image already does both. |
| 3 | The multi-server end-to-end test is implemented with **Docker Compose inside Docker-in-Docker** for v1. The orchestrator is structured so a Docker Swarm and a Kubernetes backend can be added later without rewriting the assertions. | Operator: "docker compose now, we might add docker swarm + kubernetes support later." Compose+DinD reuses the repo's existing `sys-svc-compose` / DinD tooling; lightest path. |
| 4 | The NAT/masquerade behaviour of the old `-firewalled` role is **kept as the current logic** — the same `iptables -A FORWARD -i wg0-client -j ACCEPT` + `iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE` rules — now applied in the container/network context of the new role and gated by a flag (default consistent with the old behaviour). | Operator: "keep current logic." No behavioural change to NAT; only its host moves into the role's container path. |
| 5 | The DinD test grows a **full mesh across ALL nodes** — 3 servers (role image) + 3 client workstations on **CentOS, Debian and Manjaro** — where every one of the 6 nodes is peered directly to the other five. The test verifies they all communicate by asserting a WireGuard handshake on every link (5 peers per node) plus ICMP ping across every node pair. The existing 3-server stage (`local.sh` / `external.sh`) stays; the mesh stage (`mesh.sh`) runs the all-node mesh in the same DinD run. | Operator: "full mesh between all clients and all servers as well", clients on native distro images, ping+handshake, "preserve the DiD logic". |
### Derived design choices (agent judgement; revisit at PR review)
- **Image:** `lscr.io/linuxserver/wireguard`, pinned by tag in `meta/services.yml::wireguard.version` (bump-tag-then-redeploy path documented in the README). The role wraps the upstream image directly; no custom `Dockerfile.j2` unless a later AC forces one. The pinned tag is the linuxserver release current at PR-cut time.
- **Capabilities / sysctl:** container gets `cap_add: [NET_ADMIN]` (and `SYS_MODULE` only when host-module loading is required), `sysctls: { net.ipv4.conf.all.src_valid_mark: 1 }`, and publishes `${SERVERPORT}:51820/udp`. Mounts `/config` as a named volume and (optionally) `/lib/modules` read-only.
- **PUID / PGID:** templated from the role's run user per the linuxserver User/Group-Identifiers contract, so `/config` ownership matches the host.
- **Compose assembly:** `templates/compose.yml.j2` built from `sys-svc-compose/templates/base.yml.j2` + `sys-svc-container/templates/base.yml.j2`, matching the `svc-db-postgres` precedent.
## Target Schema
### Role layout (new `roles/svc-net-wireguard/`)
```
roles/svc-net-wireguard/
├── tasks/
│ ├── main.yml # dispatch by services.wireguard.mode (server|client)
│ ├── 01_server.yml # compose up server stack (PEERS set)
│ └── 02_client.yml # compose up client stack + MTU + NAT (old -plain/-firewalled logic)
├── templates/
│ ├── compose.yml.j2 # sys-svc-compose + sys-svc-container base
│ ├── env.j2 # PUID/PGID/SERVERURL/SERVERPORT/PEERS/PEERDNS/INTERNAL_SUBNET/ALLOWEDIPS/TZ
│ └── ... # any client-side helper templates (MTU, NAT rules)
├── vars/
│ └── main.yml # application_id + container/volume/port names
├── meta/
│ ├── main.yml # galaxy_info (carry the wireguard/vpn/networking tags)
│ ├── services.yml # image, version, lifecycle, ports, mem/cpu limits
│ └── schema.yml # any generated credentials (keys) if applicable
├── templates/
│ └── test.env.j2 # test-e2e-cli discovery marker + env contract
├── files/test/ # DinD E2E (run by test-e2e-cli)
│ ├── test.sh # orchestrator (entry point test-e2e-cli runs)
│ ├── local.sh # in-DinD: 3 server stacks up + healthy
│ ├── external.sh # peer handshake / connectivity assertions across the 3 servers
│ ├── mesh.sh # full mesh: 3 servers + 3 distro clients, all-pairs ping
│ └── nat.sh # client mode + MTU 1400 + NAT masquerade (gateway/upstream)
├── README.md # both modes, image bump path, NAT flag, migration note from the old 3 roles
└── Administration.md # client/peer key + config management (merged from the old roles)
```
`roles/svc-net-wireguard/example.sh.example` is replaced by the real `files/test/` harness above.
### `meta/services.yml` (shape)
```yaml
---
wireguard:
enabled: true
image: lscr.io/linuxserver/wireguard
name: wireguard
version: <pinned-linuxserver-tag>
mode: server # server | client; overridable per variant
nat: true # preserves old -firewalled FORWARD + MASQUERADE logic
min_storage: 0GB
lifecycle: alpha # carry the old -core lifecycle tier forward
cpus: "0.1"
mem_reservation: "32m"
mem_limit: "64m"
pids_limit: 64
ports:
public:
wireguard: 51820 # /udp
```
### Removed paths
```
roles/svc-net-wireguard-core/ # deleted
roles/svc-net-wireguard-plain/ # deleted
roles/svc-net-wireguard-firewalled/ # deleted
```
## Acceptance Criteria
### Unified role exists and is Docker-based
- [x] `roles/svc-net-wireguard/` exists and follows the role-meta layout (`meta/services.yml` with a `lifecycle` key, `meta/main.yml`, `vars/main.yml`, `tasks/main.yml`), matching the `svc-db-postgres` precedent.
- [x] The role runs WireGuard from the pinned `lscr.io/linuxserver/wireguard` image via a Compose stack assembled from `sys-svc-compose` / `sys-svc-container` base templates (no host `wg-quick` / host package install in the deploy path).
- [x] `templates/env.j2` sets `PUID` / `PGID` from the role's run user per the linuxserver [User/Group Identifiers](https://docs.linuxserver.io/images/docker-wireguard/#user-group-identifiers) contract. (Server-mode deploy succeeds in the fork CI run, so the image starts with these values.)
- [x] The container is granted `NET_ADMIN`, sets `net.ipv4.conf.all.src_valid_mark=1`, and publishes the configured UDP port to `51820/udp` (verified in `templates/compose.yml.j2`).
### Mode dispatch (server + client)
- [x] `services.wireguard.mode` accepts exactly `server` and `client`; any other value fails fast via an `assert` task in `tasks/01_core.yml` (adapted from the AC's "fails role-meta lint" intent — a runtime guard rather than a separate lint rule).
- [x] `tasks/main.yml` → `01_core.yml` includes exactly one of `tasks/02_server.yml` or `tasks/03_client.yml` based on `services.wireguard.mode` (mutually-exclusive `when`; no double execution).
- [x] In `server` mode, the container runs with `PEERS` set so the linuxserver image enters server mode and generates the configured peer configs under `/config`. Proven in the fork CI run: `local.sh` brings up `PEERS=1` servers and `external.sh` reads each `/config/peer1/peer1.conf` and completes a handshake.
- [x] In `client` mode, the container joins the configured upstream peer; the MTU-1400 behaviour of the old `svc-net-wireguard-plain` role is preserved (interface MTU is 1400 after deploy). Verified by `files/test/nat.sh`: a WireGuard client tunnel with `MTU = 1400` comes up and `/sys/class/net/wg0/mtu` reads `1400`.
### NAT / firewalled behaviour preserved
- [x] When NAT is enabled (`services.wireguard.nat: true`, default consistent with the old `-firewalled` role), the role applies the same logic as the old role (`FORWARD -i <wg> -j ACCEPT` + `POSTROUTING … -j MASQUERADE`). `files/test/nat.sh` applies that logic on a WireGuard gateway, asserts the masquerade rule is present, and proves it functionally: a client behind the gateway reaches an upstream host reachable only via the masquerade.
- [x] When NAT is disabled, those rules are absent and peer traffic is a pure tunnel (no masquerade). `files/test/nat.sh` deletes the masquerade rule and asserts it is absent from `iptables -t nat -S`.
> **How NAT is tested.** The role's own NAT task (`tasks/03_client.yml`) is host-level and gated `when: nat and not DOCKER_IN_CONTAINER`, so it does not run inside the CI/DinD deploy container. The NAT *logic* (the same `FORWARD` + `POSTROUTING MASQUERADE` rules) is therefore validated functionally by `files/test/nat.sh` in Docker-in-Docker — a WireGuard client behind a masquerading gateway reaching an upstream host, plus rule-present/absent assertions. A real host applying the rules via `03_client.yml` is the production path; the harness proves the rules achieve masquerade. (Pending confirmation in the next fork-CI run.)
### Old roles removed cleanly
- [x] `roles/svc-net-wireguard-core/`, `roles/svc-net-wireguard-plain/`, and `roles/svc-net-wireguard-firewalled/` are deleted.
- [x] A repo-wide grep for `svc-net-wireguard-core|svc-net-wireguard-plain|svc-net-wireguard-firewalled` returns no remaining references (only the generated, git-ignored `tasks/groups/svc-net-roles.yml`, which was regenerated and now lists only `svc-net-wireguard`). Dependency-resolution integration tests pass after removal.
- [x] `roles/svc-net-wireguard/README.md` documents the migration from the three old roles, including how the old `-core` server, `-plain` MTU, and `-firewalled` NAT behaviours map onto the new `mode` + `nat` settings.
### Multi-server Docker-in-Docker E2E test
- [x] `roles/svc-net-wireguard/files/test/` contains an orchestrator (`test.sh`) that mirrors the svc-runner test pattern: it env-gates required variables, verifies the backend, then delegates to `local.sh`, `external.sh`, `mesh.sh` and `nat.sh`. The `example.sh.example` stub is removed. (Scripts are shellcheck-clean.)
- [x] `local.sh` brings up **at least three** independent WireGuard **server** instances inside Docker-in-Docker via Docker Compose (one server per instance) and enforces `WIREGUARD_E2E_SERVER_COUNT >= 3`. Proven in the fork CI run (`OK: all 3 WireGuard servers healthy`).
- [x] `external.sh` registers a peer on each server and asserts a successful WireGuard handshake against all servers, failing loudly (non-zero exit) if any is unreachable, bounded by `WIREGUARD_E2E_TIMEOUT`. Proven in the fork CI run (`OK: all 3 servers reachable via WireGuard handshake`).
- [x] The orchestrator is structured so the instance-provisioning backend is swappable via `WIREGUARD_E2E_BACKEND` (Compose today; Swarm / Kubernetes later) without changing `external.sh`. Documented in the `test.sh` header.
### Full mesh across all servers and clients
- [x] `files/test/mesh.sh` exists, is wired into `test.sh` (runs after `local.sh` / `external.sh`), and runs entirely in Docker-in-Docker alongside the 3-server stage (DinD logic preserved). (Shellcheck-clean.)
- [x] The mesh stands up **all six nodes**: 3 servers (the role's `lscr.io/linuxserver/wireguard` image) plus 3 client workstations on **CentOS, Debian, and Manjaro** from their native base images (overridable via `WIREGUARD_E2E_{CENTOS,DEBIAN,MANJARO}_IMAGE`). Each node installs/has `wireguard-tools` via its own package manager (`apt` / `dnf` / `pacman`).
- [x] All six nodes form a **full mesh**: each node's `wg0.conf` peers it directly to the other five (generated keypairs, per-peer `AllowedIPs`, container-name endpoints).
- [x] `mesh.sh` verifies **every node communicates with every other**: it asserts a WireGuard handshake on every link (each node shows 5 peer handshakes) and ICMP ping reachability across every node pair, failing non-zero (bounded by `WIREGUARD_E2E_TIMEOUT`) if any pair cannot reach the other. Proven in the fork CI run: all 30 directed pairs `reachable over tunnel`, every node `5/5 peer handshake(s)`, `full-mesh connectivity verified across all servers + clients (6 nodes)`.
- [x] CI discovers and runs the harness automatically (no manual step) via the `test-e2e-cli` role adopted from upstream ([infinito-nexus/core#231](https://github.com/infinito-nexus/core/pull/231)): it discovers any role shipping `templates/test.env.j2`, renders that env, and runs `files/test/test.sh` in the deploy container (Docker-in-Docker via the host socket). The wireguard role conforms by shipping `templates/test.env.j2` + `files/test/{test.sh,local.sh,external.sh,mesh.sh}`. `test-e2e-cli` is invoked post-deploy from `tasks/stages/02_{server,universal,workstation}.yml`, gated `RUNTIME in ['dev','act','github']`.
### Repo gate & docs
- [x] `make test` passes with the new role in place and the three old roles removed (all five targets green: lint, test-external, test-integration, test-lint, test-unit).
- [x] Both modes are checked: `server` mode is deployed by the CI universal deploy (proven), and `client`-mode behaviour (tunnel join + MTU 1400 + NAT masquerade) is validated by the `files/test/nat.sh` e2e stage. (NAT's host-level task is container-gated, so the client/NAT *logic* is what the harness verifies — see the NAT note above.)
- [ ] This requirement file is cross-linked from the implementing PR, and the implementing PR is cross-linked back here per [requirements.md](../contributing/requirements.md). The cross-links exist ([infinito-nexus/core#323](https://github.com/infinito-nexus/core/pull/323) ↔ this file); this box is the merge-time close-out (checking it makes the file archive-ready, so it stays open until the PR merges and the file is archived via `make requirements-archive`).
## Revision 2 — PR #323 review (Kevin Veen-Birkenbach)
Review feedback on [infinito-nexus/core#323](https://github.com/infinito-nexus/core/pull/323) pivots the
role API and, more importantly, the **test methodology**. The v1 e2e harness (`local.sh` /
`external.sh` / `mesh.sh` / `nat.sh`) hand-rolled WireGuard with the linuxserver image. Revision 2
replaces that with a **deploy-driven** harness that provisions clean hosts and deploys the *actual*
role against them via the Infinito.Nexus CLI — the same pattern `svc-runner` (req 014 / PR #231) uses.
All v1 e2e ACs under "Multi-server Docker-in-Docker E2E test" and "Full mesh across all servers and
clients" are **superseded** by the Revision-2 ACs below.
### Confirmed decisions (Revision 2)
| # | Decision | Source |
|---|----------|--------|
| 6 | Role API: replace the `mode` (server/client) + `nat` boolean with a **`flavor`** list (`flavor: [server]`, `[client]`, `[client, nat]`, …). Tasks dispatch on flavor membership. | Kevin: "manage server, client, behind NAT in one role … `flavor: [nat, server, client]` and react on this variables." |
| 7 | E2E is **deploy-driven**, not simulated. The harness boots raw base containers, runs `make install` in each, builds a **dedicated inventory per host**, and runs `infinito administration deploy` of `svc-net-wireguard` against each (server / client / behind-NAT flavor) via DooD, then tests connectivity between all of them. | Kevin: "don't manual setup wireguard … `make install` … dedicated inventory for THIS host … deploy … test connection between all of them." |
| 8 | Topology: **3 servers + 3 workstations**. Servers run `debian:latest`; workstations run **Manjaro, Debian, CentOS**. All nodes must reach each other after deploy. | Operator: "again 3 servers and 3 workstations (manjaro, debian, centOS)"; servers `debian:latest`. |
| 9 | **NAT applies on the deployed host.** The masquerade task's `not DOCKER_IN_CONTAINER` gate is adjusted so the rule actually runs on a deployed node, and the behind-NAT workstation flavor is verified functionally. | Operator decision. |
| 10 | The WireGuard internal subnet range is declared in `group_vars/all/08_networks.yml` (transparent, central), not buried in the role. | Kevin: "add an entry to group_vars/all/*network*.yml to make the range transparent." |
| 11 | The client MTU default is auto-generated where possible (pkgmgr `auto-mtu`) instead of hardcoding `1400`. | Kevin: "autogeneration for default value … script in pkgmgr is called auto-mtu." |
| 12 | `lifecycle: beta` on both `svc-net-wireguard` and `test-e2e-cli`. | Kevin: "beta" / `lifecycle: beta` suggestion. |
### Acceptance Criteria (Revision 2)
- [ ] `services.wireguard` uses a `flavor` list (`server` / `client` / `nat`); `tasks/` dispatch on flavor membership (server-stack, client-stack, NAT). `mode` + the `nat` boolean are removed. Invalid flavors fail fast.
- [ ] The WireGuard internal subnet range is declared in `group_vars/all/08_networks.yml` and the role consumes it from there.
- [ ] The client MTU default is auto-derived (pkgmgr `auto-mtu`) when available, with `1400` as the documented fallback.
- [ ] `meta/services.yml::wireguard.lifecycle = beta` and `roles/test-e2e-cli/meta/services.yml::test-e2e-cli.lifecycle = beta`.
- [ ] The NAT masquerade task runs on a real deployed host (gate adjusted so it is not skipped purely because the host is a container), and is idempotent.
- [ ] The role gains an **inventory-driven config path**: when a per-host WireGuard config is present in the host's inventory (`{{ inventory_dir }}/files/{{ inventory_hostname }}/…/wg0.conf`), the role mounts/brings it up in the container (mesh node) instead of generating server peers. This is how each deployed host gets its full-mesh peer set.
- [ ] The e2e harness is renamed to phase scripts under `files/test/`: `01_bootstrap.sh`, `02_registration.sh`, `03_handshake.sh`; `test.sh` orchestrates them. The existing all-pairs connectivity test **logic is kept** — only the provisioning changes (deploy the real role instead of a hand-rolled linuxserver image).
- [ ] `01_bootstrap.sh` boots **6 empty containers** — 3 servers (`debian:latest`) + 3 workstations (Manjaro / Debian / CentOS) — and runs `make install` in each (keys + dependencies → a deploy-ready Infinito.Nexus environment).
- [ ] `02_registration.sh` initialises a **dedicated inventory per container** via `infinito administration inventory provision <inventory_dir> --host <host> --include svc-net-wireguard`, and renders each host's **full-mesh `wg0.conf`** (every node peers every other — everyone-to-everyone) into that host's inventory, so the subsequent deploy has the complete peer set.
- [ ] `03_handshake.sh` deploys `svc-net-wireguard` into each container against its own inventory via `infinito administration deploy dedicated <inventory_file> --id svc-net-wireguard` (DooD), then asserts **full-mesh** connectivity: every node reaches every other node over WireGuard (handshake + ICMP), reusing the v1 all-pairs check logic.
- [ ] The full Revision-2 harness passes in the fork CI (`test-e2e-cli` post-deploy), ending in `ALL CHECKS PASSED`.
## Validation Status
Verified in the sandbox (no privileged Docker, no `sudo`):
- **Full `make test` is green** — all five targets pass (lint, test-external, test-integration,
test-lint, test-unit), with the new role in place and the three old roles removed.
- Targeted integration suites pass against the new tree: `infrastructure/services`
(`test_id_matches_role`, `test_canonical`, `test_resolvable`,
`test_transitive_dependencies`, `test_mailu_dependency`),
`infrastructure/docker/test_services_image_version_valid`,
`infrastructure/networks` (unique/non-overlapping subnet + compose-role-has-local-network),
`infrastructure/compose` (network-includes, compose_volumes-call, build-requires-image, no-raw-docker),
and the full `infrastructure/` tree (32 tests).
- `tests/integration/roles/` structural tree (89 tests: includes, naming, run_once, when, meta) passes,
after regenerating the git-ignored `tasks/groups/svc-net-roles.yml` (now lists only `svc-net-wireguard`).
- Targeted unit modules pass: `cli.meta.roles.test_lifecycle_filter`, `plugins.lookup.test_config_lookup`,
`plugins.lookup.test_applications`, `cli.administration.inventory.validate.test_main`.
- `ansible-lint` (profile `min`) clean — the templated `path_join` include's expected `load-failure`
is ignored in `.ansible-lint-ignore`, matching the `svc-db-openldap` precedent.
- `shellcheck` clean (via `make test`) on `files/test/{test.sh,local.sh,external.sh,mesh.sh,nat.sh}`.
Verified end-to-end in the fork CI (manual run, universal deploy, green):
- `server`-mode deploy of `svc-net-wireguard` succeeds; `test-e2e-cli` discovered and ran the harness.
- The DinD `files/test/test.sh` run passed fully: `local.sh` (3 servers healthy) → `external.sh`
(3 peer handshakes) → `mesh.sh` (6-node full mesh, all 30 directed pairs reachable, 5/5 handshakes
per node) → `ALL CHECKS PASSED`.
`nat.sh` (client mode + MTU 1400 + NAT masquerade, positive + rule-absent) is also proven in the fork
CI run <https://github.com/evangelostsak/infinito.nexus/actions/runs/27740664522>: `OK: NAT masquerade
rule present` → `client tunnel MTU=1400` → `client reached upstream … via NAT masquerade` → `masquerade
rule absent after disabling NAT`.
## Validation
```bash
# Role deploy (both modes) on a fresh box, then the DinD multi-server E2E:
INFINITO_APPS="svc-net-wireguard" make deploy-fresh-purged-apps INFINITO_FULL_CYCLE=true
bash roles/svc-net-wireguard/files/test/test.sh
```
## Prerequisites
Before starting any implementation work, the agent MUST read [AGENTS.md](../../AGENTS.md) and follow all instructions in it. Before modifying anything under `roles/svc-net-wireguard/`, the agent MUST check for `roles/svc-net-wireguard/AGENTS.md` and follow it if present.
## Implementation Strategy
The agent MUST execute this requirement **autonomously** once the Confirmed Decisions above stand. Open clarifications only when a decision is genuinely ambiguous and would otherwise block progress; otherwise default to the intent captured here and proceed.
1. Read [Role Loop](../agents/action/iteration/role.md) before starting.
2. Scaffold `roles/svc-net-wireguard/` as a Compose-based `svc-*` role (image pin, `env.j2`, `compose.yml.j2` from the shared bases, `meta/services.yml` + `meta/main.yml` + `vars/main.yml`).
3. Implement `mode: server` (PEERS, peer-config generation, caps/sysctl/port) and `mode: client` (upstream join + MTU-1400 from old `-plain`).
4. Port the old `-firewalled` NAT rules verbatim behind the `nat` flag.
5. Build the DinD E2E harness under `files/test/` (`test.sh` / `local.sh` / `external.sh` / `mesh.sh`) plus `templates/test.env.j2`, discovered by the adopted `test-e2e-cli` role; remove the stub.
6. Delete the three old roles and repoint / clean every remaining reference.
7. Run `make test` and iterate per the Role Loop until green.
8. Write `README.md` (both modes, image bump path, NAT flag, migration) and merge the old `Administration.md` guidance.
## Commit Policy
- A single commit (or a tight, related sequence) lands the whole role + test + old-role removal; no half-scaffolded intermediate commits.
- When all ACs are checked off and `make test` is green, the agent instructs the operator to run `git-sign-push` outside the sandbox per [CLAUDE.md](../../CLAUDE.md). The agent MUST NOT push.
## Context
- Upstream image: <https://docs.linuxserver.io/images/docker-wireguard/> (User/Group Identifiers: <https://docs.linuxserver.io/images/docker-wireguard/#user-group-identifiers>)
- Roles being consolidated: `svc-net-wireguard-core`, `svc-net-wireguard-plain`, `svc-net-wireguard-firewalled`.
- Test-orchestrator precedent: `roles/svc-net-wireguard/example.sh.example` (svc-runner E2E pattern; see req 014).
- Compose `svc-*` role precedent: `roles/svc-db-postgres/` (`compose.yml.j2` from `sys-svc-compose` / `sys-svc-container` bases).
- Closest precedent for a `mode:` / flavor discriminator collapsing roles into one: req 025 (Matrix flavor dispatch).
-1
View File
@@ -29,4 +29,3 @@ Its scope is user stories and acceptance criteria that define what the project m
- 022 - Zammad Helpdesk Role with OIDC SSO
- 023 - Setup Penpot
- 025 - Matrix Role Ansible Flavor (matrix-docker-ansible-deploy)
- 026 - Dockerized `svc-net-wireguard` (consolidate core / plain / firewalled)
-2
View File
@@ -67,8 +67,6 @@ defaults_networks:
ip4: "127.0.0.1"
ip6: "::1"
dns: ""
# WireGuard tunnel (internal) subnet, consumed by roles/svc-net-wireguard.
WIREGUARD_INTERNAL_SUBNET: "10.13.13.0" # nocheck: unused-var
PORT_BANDS: # nocheck: unused-var # consumed by the port-allocation plugin outside the YAML/Jinja scope
local:
http:
-63
View File
@@ -1,63 +0,0 @@
# Administration
## Server mode
In `server` mode the linuxserver image generates one config per peer under
`/config/peer<N>/` inside the container volume. Inspect or hand a peer its config:
```bash
# List generated peers
container exec <wireguard-container> ls /config
# Print peer1's config (and QR code, if LOG_CONFS=true, in the container logs)
container exec <wireguard-container> cat /config/peer1/peer1.conf
```
Increase the peer count by raising `services.wireguard.server.peers` and redeploying;
the image creates the new peer directories on next start.
## Client mode
### Create client keys (manual peer)
```bash
wg_private_key="$(wg genkey)"
wg_public_key="$(echo "$wg_private_key" | wg pubkey)"
echo "PrivateKey: $wg_private_key"
echo "PublicKey: $wg_public_key"
echo "PresharedKey: $(wg genpsk)"
```
### Activate a client config
Drop the client config into the container's config volume and (re)start it:
```bash
container exec -i <wireguard-container> sh -c 'mkdir -p /config/wg_confs && cat > /config/wg_confs/wg0.conf' < wg0.conf
container restart <wireguard-container>
```
### Check status
```bash
container exec <wireguard-container> wg show
```
## NAT (client behind NAT)
When the `nat` flavor is set the role applies the legacy firewalled rules on the host:
```bash
iptables -A FORWARD -i wg0-client -j ACCEPT
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
```
Adjust the interfaces via `services.wireguard.client.nat_in_interface` /
`services.wireguard.client.nat_out_interface`.
## Further Resources
- [WireGuard Documentation](https://www.wireguard.com/)
- [linuxserver/wireguard image](https://docs.linuxserver.io/images/docker-wireguard/)
- [ArchWiki: WireGuard](https://wiki.archlinux.org/index.php/WireGuard)
- [Subnetting Basics](https://www.scaleuptech.com/de/blog/was-ist-und-wie-funktioniert-subnetting/)
-65
View File
@@ -1,65 +0,0 @@
# WireGuard
## Description
[WireGuard](https://www.wireguard.com/) is a fast, modern, secure VPN tunnel that uses
state-of-the-art cryptography. It runs as a small, auditable codebase and presents itself as an
ordinary network interface, making encrypted point-to-point and roaming-client connectivity simple to
operate.
## Overview
This role runs WireGuard in a Docker container using the
[linuxserver/wireguard](https://docs.linuxserver.io/images/docker-wireguard/) image, in either
**server** mode (this host terminates peers and generates their configs) or **client** mode (this host
joins an upstream peer), selected by the `services.wireguard.flavor` list (`server`, `client`, `nat`). It assembles a Compose stack from the
shared `sys-svc-compose` / `sys-svc-container` bases, grants the container the capabilities WireGuard
needs, optionally masquerades client traffic, and publishes the tunnel port. It is the containerized
successor to the host-native `svc-net-wireguard-core`, `svc-net-wireguard-plain`, and
`svc-net-wireguard-firewalled` roles. For client/peer key management see [Administration.md](./Administration.md).
## Features
- **Server and client flavors:** The `services.wireguard.flavor` list picks peer termination (`PEERS`
set) or joining an upstream peer; replaces the old `-core` / `-plain` split.
- **NAT masquerading:** the `nat` flavor preserves the legacy firewalled behaviour
(`iptables` FORWARD + POSTROUTING MASQUERADE) for clients behind NAT.
- **Host/container ownership mapping:** `PUID` / `PGID` map `/config` ownership onto a host user per
the linuxserver [User/Group Identifiers](https://docs.linuxserver.io/images/docker-wireguard/#user-group-identifiers) contract.
- **Pinned image:** The upstream tag is pinned in `meta/services.yml`; bump and redeploy to upgrade.
- **Deploy-driven test harness:** The `files/test/` suite boots 6 empty containers (3 `debian:latest`
servers + Manjaro/Debian/CentOS workstations), runs `make install` in each, provisions a dedicated
inventory per host with a full-mesh `wg0.conf`, deploys this role into each (Docker-in-Docker), and
asserts every node reaches every other over WireGuard.
## Migration
| Legacy role | Behaviour | Replacement |
|-------------|-----------|-------------|
| `svc-net-wireguard-core` | host package + `wg-quick` server, sysctl IP-forward, `/etc/wireguard/wg0.conf` | `flavor: [server]` (linuxserver image, `PEERS` set) |
| `svc-net-wireguard-plain` | systemd unit forcing MTU 1400 on the uplink | `flavor: [client]` + `services.wireguard.client.mtu` |
| `svc-net-wireguard-firewalled` | `iptables` FORWARD + NAT MASQUERADE behind NAT | `flavor: [client, nat]` (same rules) |
## Developer notes
See [Administration.md](./Administration.md) for peer key creation, config activation, and live
container inspection. The end-to-end harness lives under `files/test/`: `test.sh` orchestrates
`01_bootstrap.sh` (boot 6 empty containers + `make install`), `02_registration.sh` (per-host dedicated
inventory + full-mesh `wg0.conf`), and `03_handshake.sh` (deploy this role per host + all-pairs check).
The harness is discovered and run automatically by the `test-e2e-cli` role: any role shipping
`templates/test.env.j2` plus `files/test/test.sh` is picked up post-deploy and run in the deploy
container (Docker-in-Docker via the host socket), with `templates/test.env.j2` rendered as its env.
## Further resources
- [WireGuard official website](https://www.wireguard.com/)
- [linuxserver/wireguard image](https://docs.linuxserver.io/images/docker-wireguard/)
- [ArchWiki: WireGuard](https://wiki.archlinux.org/index.php/WireGuard)
## Credits
Developed and maintained by **Kevin Veen-Birkenbach**.
Learn more at [veen.world](https://www.veen.world).
Part of the [Infinito.Nexus Project](https://s.infinito.nexus/code).
Licensed under the [Infinito.Nexus Community License (Non-Commercial)](https://s.infinito.nexus/license).
@@ -1,89 +0,0 @@
#!/usr/bin/env bash
# Boot 6 fresh pkgmgr nodes, make install in each (pulls in systemd), then
# re-create each as a systemd-PID1 container so the deploy can run docker.service.
# nocheck: raw-docker # commit/run/logs against the DinD nodes
set -euo pipefail
: "${WIREGUARD_E2E_TIMEOUT:?}"
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=roles/svc-net-wireguard/files/test/nodes.sh
. "${DIR}/nodes.sh"
container network create "${WGNET}" >/dev/null 2>&1 || true
# Phase 1: boot the bare bases (no systemd yet) just to run the install in them.
i=0
for n in "${NODE_NAMES[@]}"; do
cn="${PROJECT}-${n}"
container rm -f "${cn}" >/dev/null 2>&1 || true
container run -d --name "${cn}" --hostname "${cn}" --network "${WGNET}" \
--entrypoint=sleep \
-v "${REPO_DIR}:/opt/src/infinito-src:ro" \
"${NODE_IMAGES[$i]}" infinity >/dev/null
echo "OK: ${n} base booted (${NODE_IMAGES[$i]})"
i=$(( i + 1 ))
done
# Install bootstrap prerequisites (incl. systemd + sysv-compat for /sbin/init).
install_prereqs() {
local cn="$1" distro="$2"
case "${distro}" in
debian)
timeout 600 container exec "${cn}" sh -c 'export DEBIAN_FRONTEND=noninteractive; apt-get update && apt-get install -y make git python3 python3-venv python3-pip sudo curl ca-certificates tar gnupg systemd systemd-sysv' </dev/null ;;
arch)
timeout 600 container exec "${cn}" sh -c 'pacman -Sy --noconfirm make git python python-pip sudo curl ca-certificates tar gnupg systemd systemd-sysvcompat' </dev/null ;;
centos)
timeout 600 container exec "${cn}" sh -c 'dnf -y --allowerasing install make git python3 python3-pip sudo curl ca-certificates tar gnupg2 systemd' </dev/null ;;
esac
}
# Phase 2: per-node install into its own copy, then re-create as a systemd node.
i=0
for n in "${NODE_NAMES[@]}"; do
cn="${PROJECT}-${n}"
install_prereqs "${cn}" "${NODE_DISTRO[$i]}"
# Node-local repo copy (excl .git): keep per-node make install state isolated.
container exec "${cn}" \
sh -c 'mkdir -p /opt/src/infinito && tar -C /opt/src/infinito-src --exclude=./.git -cf - . | tar -C /opt/src/infinito -xf -' </dev/null
timeout 1200 container exec "${cn}" \
sh -c 'export DEBIAN_FRONTEND=noninteractive CI=true; cd /opt/src/infinito && make install' </dev/null
# Mask first-boot units + seed machine-id so systemd boots clean as PID 1.
container exec "${cn}" \
sh -c 'ln -sf /dev/null /etc/systemd/system/systemd-firstboot.service; ln -sf /dev/null /etc/systemd/system/first-boot-complete.target; : > /etc/machine-id' </dev/null
container commit "${cn}" "wg-e2e-img-${n}" >/dev/null
container rm -f "${cn}" >/dev/null
# Re-create as systemd PID 1 (cgroup/tmpfs); --privileged + container=docker
# give a DinD-capable, container-autodetected node.
container run -d --name "${cn}" --hostname "${cn}" --network "${WGNET}" \
--privileged --cgroupns=host \
--tmpfs /run --tmpfs /run/lock \
-v /sys/fs/cgroup:/sys/fs/cgroup:rw \
-e container=docker \
--entrypoint=/sbin/init \
"wg-e2e-img-${n}" >/dev/null
echo "OK: ${n} make install complete + re-created as systemd node"
i=$(( i + 1 ))
done
# Phase 3: wait for systemd to finish booting (running or degraded = PID 1 up).
for n in "${NODE_NAMES[@]}"; do
cn="${PROJECT}-${n}"
deadline=$(( $(date +%s) + 120 ))
while true; do
# is-system-running exits non-zero on 'degraded'; capture to dodge pipefail.
state="$(container exec "${cn}" systemctl is-system-running 2>/dev/null || true)"
case "${state}" in
*running*|*degraded*) break ;;
esac
if [ "$(date +%s)" -ge "${deadline}" ]; then
echo "FAIL: systemd did not become ready in ${n} (state=${state})"
container exec "${cn}" sh -c 'cat /proc/1/comm; ls -l /sbin/init' 2>&1 || true
container logs "${cn}" 2>&1 | tail -n 20 || true
exit 1
fi
sleep 2
done
echo "OK: ${n} systemd ready"
done
echo "OK: all nodes bootstrapped"
@@ -1,57 +0,0 @@
#!/usr/bin/env bash
# Provision each node's inventory, deploy the 3 servers in [server] flavor, and
# turn each server's generated peer config into its paired client's wg0.conf.
# nocheck: raw-docker # nested docker exec to read the server's generated peer conf
set -euo pipefail
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=roles/svc-net-wireguard/files/test/nodes.sh
. "${DIR}/nodes.sh"
# 1) Provision a dedicated inventory on every node.
for n in "${NODE_NAMES[@]}"; do
cn="${PROJECT}-${n}"
timeout 600 container exec "${cn}" \
bash -c "cd /opt/src/infinito && . scripts/meta/env/load.sh; ${NODE_VENV_PY}; \"\$PY\" -m cli administration inventory provision ${INV_DIR} --host ${cn} --include svc-net-wireguard" </dev/null
echo "OK: ${n} inventory provisioned"
done
# 2) Deploy the servers ([server] flavor). SERVERURL=node IP makes the generated
# peer Endpoint reachable; AllowedIPs are scoped to the wg subnet.
for s in "${SERVER_NODES[@]}"; do
cn="${PROJECT}-${s}"
sip="$(container inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' "${cn}")"
timeout 1800 container exec "${cn}" \
bash -c "cd /opt/src/infinito && . scripts/meta/env/load.sh; ${NODE_VENV_PY}; \"\$PY\" -m cli administration deploy dedicated ${INV_DIR}/devices.yml --id svc-net-wireguard --password-file ${INV_DIR}/.password -e ansible_connection=local -e DOCKER_IN_CONTAINER=true -e SYS_SVC_CONTAINER_STORAGE_DRIVER=vfs -e WIREGUARD_SERVER_URL=${sip} -e WIREGUARD_SERVER_ALLOWED_IPS=${WG_SUBNET}" </dev/null
echo "OK: ${s} deployed (server flavor, url=${sip})"
done
# 3) Extract each server's generated peer config and install it as the paired
# client's inventory wg0.conf (its Endpoint already points at the server IP).
i=0
for s in "${SERVER_NODES[@]}"; do
scn="${PROJECT}-${s}"
c="${CLIENT_NODES[$i]}"
ccn="${PROJECT}-${c}"
peer_conf=""
deadline=$(( $(date +%s) + 120 ))
while true; do
peer_conf="$(container exec "${scn}" docker exec wireguard sh -c 'cat /config/peer1/peer1.conf 2>/dev/null' 2>/dev/null || true)"
[ -n "${peer_conf}" ] && break
if [ "$(date +%s)" -ge "${deadline}" ]; then
echo "FAIL: ${s} did not generate /config/peer1/peer1.conf"
container exec "${scn}" docker exec wireguard sh -c 'ls -la /config /config/peer1 2>&1' || true
exit 1
fi
sleep 3
done
# Drop the DNS line (no resolvconf in the client) + add a NAT keepalive.
peer_conf="$(printf '%s\n' "${peer_conf}" | grep -v '^DNS')
PersistentKeepalive = 25"
container exec "${ccn}" sh -c "mkdir -p ${INV_DIR}/files/${ccn}/wireguard"
printf '%s' "${peer_conf}" | container exec -i "${ccn}" sh -c "cat > ${INV_DIR}/files/${ccn}/wireguard/wg0.conf"
echo "OK: ${c} client config installed from ${s} peer1"
i=$(( i + 1 ))
done
echo "OK: servers deployed, client configs registered"
@@ -1,91 +0,0 @@
#!/usr/bin/env bash
# Deploy the workstation clients (one behind NAT), then assert each client<->server
# tunnel, the NAT masquerade rule, and the auto-derived client MTU.
# nocheck: raw-docker # nested docker exec into the per-node wireguard container
set -euo pipefail
: "${WIREGUARD_E2E_TIMEOUT:?}"
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=roles/svc-net-wireguard/files/test/nodes.sh
. "${DIR}/nodes.sh"
is_nat() {
local c="$1" x
for x in "${NAT_NODES[@]}"; do
[ "${x}" = "${c}" ] && return 0
done
return 1
}
# Deploy the clients. Behind-NAT workstations add the 'nat' flavor.
for c in "${CLIENT_NODES[@]}"; do
cn="${PROJECT}-${c}"
if is_nat "${c}"; then
flavor_json='{"WIREGUARD_FLAVOR": ["client", "nat"]}'
else
flavor_json='{"WIREGUARD_FLAVOR": ["client"]}'
fi
timeout 1800 container exec "${cn}" \
bash -c "cd /opt/src/infinito && . scripts/meta/env/load.sh; ${NODE_VENV_PY}; \"\$PY\" -m cli administration deploy dedicated ${INV_DIR}/devices.yml --id svc-net-wireguard --password-file ${INV_DIR}/.password -e ansible_connection=local -e DOCKER_IN_CONTAINER=true -e SYS_SVC_CONTAINER_STORAGE_DRIVER=vfs -e '${flavor_json}'" </dev/null
echo "OK: ${c} deployed (${flavor_json})"
done
# Tunnel state up front for debugging.
for n in "${NODE_NAMES[@]}"; do
echo "--- wg show on ${n} ---"
container exec "${PROJECT}-${n}" docker exec wireguard wg show 2>&1 || true
done
deadline=$(( $(date +%s) + 180 ))
failures=0
ping_check() {
local node="$1" target="$2" label="$3"
while true; do
if container exec "${PROJECT}-${node}" docker exec wireguard ping -c1 -W2 "${target}" >/dev/null 2>&1; then
echo "OK: ${label} (${target}) reachable over tunnel"
return 0
fi
if [ "$(date +%s)" -ge "${deadline}" ]; then
echo "FAIL: ${label} cannot reach ${target}"
return 1
fi
sleep 3
done
}
# Connectivity per pair: client -> server (.1) and server -> client (.2).
i=0
for s in "${SERVER_NODES[@]}"; do
c="${CLIENT_NODES[$i]}"
ping_check "${c}" "${WG_SERVER_IP}" "${c} -> ${s}" || failures=$(( failures + 1 ))
ping_check "${s}" "${WG_CLIENT_IP}" "${s} -> ${c}" || failures=$(( failures + 1 ))
i=$(( i + 1 ))
done
# NAT: the masquerade rule must be present on every behind-NAT workstation node.
for c in "${NAT_NODES[@]}"; do
if container exec "${PROJECT}-${c}" iptables -t nat -S 2>/dev/null | grep -q 'POSTROUTING.*MASQUERADE'; then
echo "OK: ${c} NAT masquerade rule present"
else
echo "FAIL: ${c} NAT masquerade rule missing"
failures=$(( failures + 1 ))
fi
done
# MTU: every client tunnel comes up with a sane (auto-derived or fallback) MTU.
for c in "${CLIENT_NODES[@]}"; do
mtu="$(container exec "${PROJECT}-${c}" docker exec wireguard cat /sys/class/net/wg0/mtu 2>/dev/null || echo 0)"
if [ "${mtu}" -ge 576 ] && [ "${mtu}" -le 1500 ]; then
echo "OK: ${c} wg0 MTU=${mtu}"
else
echo "FAIL: ${c} wg0 MTU invalid (${mtu})"
failures=$(( failures + 1 ))
fi
done
if [ "${failures}" -ne 0 ]; then
echo "FAIL: ${failures} check(s) failed"
exit 1
fi
echo "OK: server/client tunnels, NAT masquerade and MTU verified across all 3 pairs"
@@ -1,36 +0,0 @@
#!/usr/bin/env bash
# Shared definitions for the WireGuard deploy-driven e2e harness.
# shellcheck disable=SC2034
PROJECT="wg-e2e"
WGNET="${PROJECT}_net"
TUN_PREFIX="${WIREGUARD_E2E_TUNNEL_PREFIX:-10.13.13}"
INV_DIR="/opt/src/infinito/inventories/wg-e2e"
REPO_DIR="${WIREGUARD_E2E_REPO_DIR:-/opt/src/infinito}"
# In-node snippet: pin the make-install venv python (load.sh would silently fall
# back to the system python3, which lacks the install deps).
# shellcheck disable=SC2016 # $PY/$HOME must stay literal; evaluated in the node shell
NODE_VENV_PY='PY="$(ls -1 /opt/venvs/*/bin/python /root/.venvs/*/bin/python "$HOME"/.venvs/*/bin/python 2>/dev/null | head -n1)"; [ -x "$PY" ] || { echo "FAIL: no infinito venv python; candidates:" >&2; ls -ld /opt/venvs/* /root/.venvs/* "$HOME"/.venvs/* 2>/dev/null >&2; grep -iE "venv" /opt/src/infinito/.env >&2 || true; exit 1; }'
# Fresh systemd bases (Infinito's pkgmgr parents): no infinito baked, pinned tags
# (never moving). manjaro tracks Arch upstream; pkgmgr exposes it as 'arch'.
NODE_NAMES=(server1 server2 server3 wsarch wsdebian wscentos)
NODE_IMAGES=(
"${WIREGUARD_E2E_DEBIAN_IMAGE:-ghcr.io/kevinveenbirkenbach/pkgmgr-debian:1.15.2}"
"${WIREGUARD_E2E_DEBIAN_IMAGE:-ghcr.io/kevinveenbirkenbach/pkgmgr-debian:1.15.2}"
"${WIREGUARD_E2E_DEBIAN_IMAGE:-ghcr.io/kevinveenbirkenbach/pkgmgr-debian:1.15.2}"
"${WIREGUARD_E2E_ARCH_IMAGE:-ghcr.io/kevinveenbirkenbach/pkgmgr-arch:1.15.2}"
"${WIREGUARD_E2E_DEBIAN_IMAGE:-ghcr.io/kevinveenbirkenbach/pkgmgr-debian:1.15.2}"
"${WIREGUARD_E2E_CENTOS_IMAGE:-ghcr.io/kevinveenbirkenbach/pkgmgr-centos:1.15.2}"
)
NODE_DISTRO=(debian debian debian arch debian centos)
# Hub-spoke pairs: CLIENT_NODES[i] is a WireGuard client of SERVER_NODES[i].
SERVER_NODES=(server1 server2 server3)
CLIENT_NODES=(wsarch wsdebian wscentos)
# Workstations additionally deployed behind NAT ([client, nat] flavor).
NAT_NODES=(wsdebian)
# linuxserver server mode on INTERNAL_SUBNET=10.13.13.0: server is .1, its peer .2.
WG_SERVER_IP="${TUN_PREFIX}.1"
WG_CLIENT_IP="${TUN_PREFIX}.2"
WG_SUBNET="${TUN_PREFIX}.0/24"
@@ -1,16 +0,0 @@
#!/usr/bin/env bash
# Deploy-driven e2e: bootstrap fresh hosts, deploy the role (server/client/nat),
# then verify the tunnels.
set -euo pipefail
# test containers don't need the internal CA
export CA_CONTAINER_ENABLED=0
: "${WIREGUARD_E2E_TIMEOUT:?}"
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
bash "${DIR}/01_bootstrap.sh"
bash "${DIR}/02_registration.sh"
bash "${DIR}/03_handshake.sh"
echo "ALL CHECKS PASSED"
-36
View File
@@ -1,36 +0,0 @@
---
galaxy_info:
author: Evangelos Tsakoudis
description: Runs WireGuard in a Docker container (linuxserver image) in server or
client mode. Replaces the host-native svc-net-wireguard-core / -plain / -firewalled
roles, consolidating peer termination, MTU handling and NAT masquerading into one
containerized service.
license: Infinito.Nexus Community License (Non-Commercial)
company: |
Kevin Veen-Birkenbach
https://www.veen.world
min_ansible_version: "2.9"
platforms:
- name: ArchLinux
versions:
- all
- name: Debian
versions:
- all
- name: EL
versions:
- all
- name: Fedora
versions:
- all
- name: Ubuntu
versions:
- all
galaxy_tags:
- wireguard
- vpn
- docker
- networking
- nat
issue_tracker_url: https://s.infinito.nexus/issues
dependencies: []
-4
View File
@@ -1,4 +0,0 @@
---
networks:
local:
subnet: 192.168.205.0/24
-32
View File
@@ -1,32 +0,0 @@
---
# nocheck: required-by-coverage
# nocheck: shared
wireguard:
enabled: true
image: lscr.io/linuxserver/wireguard
name: wireguard
version: "1.0.20250521"
flavor:
- server
sys_module: false
puid: 1000
pgid: 1000
timezone: "Etc/UTC"
server:
url: auto
peers: 1
peer_dns: auto
allowed_ips: "0.0.0.0/0, ::/0"
client:
mtu: 1400
nat_in_interface: wg0-client
nat_out_interface: eth0
min_storage: 0GB
lifecycle: beta
cpus: "0.1"
mem_reservation: "32m"
mem_limit: "64m"
pids_limit: 64
ports:
public:
relay: 51821
-2
View File
@@ -1,2 +0,0 @@
---
config: wireguard_config
-25
View File
@@ -1,25 +0,0 @@
---
- include_tasks: utils/once/flag.yml
- name: "Validate services.wireguard.flavor"
ansible.builtin.assert:
that:
- WIREGUARD_FLAVOR | length > 0
- (WIREGUARD_FLAVOR | difference(['server', 'client', 'nat'])) | length == 0
fail_msg: "services.wireguard.flavor must be a non-empty subset of [server, client, nat] (got {{ WIREGUARD_FLAVOR }})."
quiet: true
- name: "Detect an inventory-provided WireGuard config"
ansible.builtin.stat:
path: "{{ WIREGUARD_INVENTORY_CONF }}"
register: _wg_inventory_conf
- name: "Deploy WireGuard client/mesh stack"
include_tasks: 03_client.yml
when: _wg_inventory_conf.stat.exists or ('client' in WIREGUARD_FLAVOR)
- name: "Deploy WireGuard server stack"
include_tasks: 02_server.yml
when:
- not _wg_inventory_conf.stat.exists
- "'server' in WIREGUARD_FLAVOR"
@@ -1,16 +0,0 @@
---
- name: "include sys-svc-compose role"
include_role:
name: sys-svc-compose
vars:
compose_handlers_flush: false
compose_repository_pull: false
application_id: "svc-net-wireguard"
- name: Create container network
include_tasks: "{{ [playbook_dir, 'roles/sys-svc-compose/tasks/utils/network/create.yml' ] | path_join }}"
vars:
network_role_id: "{{ application_id }}"
- name: "Flush compose handlers"
meta: flush_handlers
@@ -1,42 +0,0 @@
---
- name: "Auto-derive the client MTU (before the compose env is rendered)"
include_tasks: _mtu.yml
- name: "include sys-svc-compose role"
include_role:
name: sys-svc-compose
vars:
compose_handlers_flush: false
compose_repository_pull: false
application_id: "svc-net-wireguard"
- name: Create container network
include_tasks: "{{ [playbook_dir, 'roles/sys-svc-compose/tasks/utils/network/create.yml' ] | path_join }}"
vars:
network_role_id: "{{ application_id }}"
- name: "Flush compose handlers"
meta: flush_handlers
- name: "Apply the inventory WireGuard config (mesh peer set)"
when: _wg_inventory_conf.stat.exists | default(false)
block:
- name: "Copy wg0.conf into the wireguard container"
ansible.builtin.command: >-
container cp {{ WIREGUARD_INVENTORY_CONF }}
{{ WIREGUARD_CONTAINER }}:/config/wg_confs/wg0.conf
changed_when: true
- name: "Restart the wireguard container to bring up the tunnel"
ansible.builtin.command: "container restart {{ WIREGUARD_CONTAINER }}"
changed_when: true
- name: "adapt iptable rules (NAT masquerade for WireGuard client behind NAT)"
shell: >-
iptables -C FORWARD -i {{ WIREGUARD_NAT_IN_INTERFACE }} -j ACCEPT 2>/dev/null ||
iptables -A FORWARD -i {{ WIREGUARD_NAT_IN_INTERFACE }} -j ACCEPT;
iptables -t nat -C POSTROUTING -o {{ WIREGUARD_NAT_OUT_INTERFACE }} -j MASQUERADE 2>/dev/null ||
iptables -t nat -A POSTROUTING -o {{ WIREGUARD_NAT_OUT_INTERFACE }} -j MASQUERADE
changed_when: false
when:
- "'nat' in WIREGUARD_FLAVOR"
-36
View File
@@ -1,36 +0,0 @@
---
# Auto-derive the client MTU via pkgmgr automtu; rescue to the configured fallback.
- name: "Derive client MTU via automtu"
block:
- name: "Ensure automtu is installed"
ansible.builtin.include_role:
name: sys-pip-install
vars:
package_name: automtu
global_install: true
- name: "Probe effective path MTU"
ansible.builtin.command:
argv:
- "{{ ansible_python_interpreter }}"
- -m
- automtu
- --pmtu-target
- "{{ NETWORK_PUBLIC_DNS_RESOLVERS | join(',') }}"
- --pmtu-policy
- min
- --print-mtu
- effective
register: _wg_automtu
changed_when: false
- name: "Set client MTU to path MTU minus WireGuard overhead"
ansible.builtin.set_fact:
WIREGUARD_CLIENT_MTU: "{{ (_wg_automtu.stdout | int) - WIREGUARD_WG_OVERHEAD }}"
when:
- _wg_automtu.stdout is match('^[0-9]+$')
- (_wg_automtu.stdout | int) > (WIREGUARD_WG_OVERHEAD + 576)
rescue:
- name: "Keep configured client MTU as fallback"
ansible.builtin.debug:
msg: "automtu unavailable; keeping WIREGUARD_CLIENT_MTU={{ WIREGUARD_CLIENT_MTU }}"
-5
View File
@@ -1,5 +0,0 @@
---
- include_tasks: 01_core.yml
when: run_once_svc_net_wireguard is not defined
vars:
application_id: svc-net-wireguard
@@ -1,31 +0,0 @@
{% include 'roles/sys-svc-compose/templates/base.yml.j2' %}
wireguard:
container_name: "{{ WIREGUARD_CONTAINER }}"
image: "{{ WIREGUARD_IMAGE }}:{{ WIREGUARD_VERSION }}"
cap_add:
- NET_ADMIN
{% if WIREGUARD_SYS_MODULE | bool %}
- SYS_MODULE
{% endif %}
sysctls:
- net.ipv4.conf.all.src_valid_mark=1
{% include 'roles/sys-svc-container/templates/base.yml.j2' %}
ports:
- "{{ WIREGUARD_PORT_PUBLIC }}:51820/udp"
volumes:
- "config:/config"
- "/lib/modules:/lib/modules:ro"
healthcheck:
test: ["CMD-SHELL", "wg show | grep -q interface || exit 1"]
interval: 30s
timeout: 5s
retries: 5
start_period: 20s
{% include 'roles/sys-svc-container/templates/networks.yml.j2' %}
{{ lookup('applications') | compose_volumes(
application_id,
extra_volumes={'config': {'name': WIREGUARD_VOLUME}}
) }}
{% include 'roles/sys-svc-compose/templates/networks.yml.j2' %}
-14
View File
@@ -1,14 +0,0 @@
PUID={{ WIREGUARD_PUID }}
PGID={{ WIREGUARD_PGID }}
TZ={{ WIREGUARD_TIMEZONE }}
LOG_CONFS=true
{% if 'server' in WIREGUARD_FLAVOR %}
SERVERURL={{ WIREGUARD_SERVER_URL }}
SERVERPORT={{ WIREGUARD_PORT_PUBLIC }}
PEERS={{ WIREGUARD_SERVER_PEERS }}
PEERDNS={{ WIREGUARD_SERVER_PEER_DNS }}
INTERNAL_SUBNET={{ WIREGUARD_SERVER_INTERNAL_SUBNET }}
ALLOWEDIPS={{ WIREGUARD_SERVER_ALLOWED_IPS }}
{% else %}
WG_MTU={{ WIREGUARD_CLIENT_MTU }}
{% endif %}
@@ -1,8 +0,0 @@
# Env contract for the svc-net-wireguard deploy-driven e2e harness, sourced before
# files/test/test.sh by test-e2e-cli.
WIREGUARD_E2E_PORT="{{ WIREGUARD_PORT_PUBLIC }}"
WIREGUARD_E2E_REPO_DIR="/opt/src/infinito"
WIREGUARD_E2E_TIMEOUT="1800"
WIREGUARD_IMAGE="{{ WIREGUARD_IMAGE }}"
WIREGUARD_VERSION="{{ WIREGUARD_VERSION }}"
-31
View File
@@ -1,31 +0,0 @@
---
application_id: svc-net-wireguard
entity_name: "{{ application_id | get_entity_name }}"
WIREGUARD_FLAVOR: "{{ lookup('config', application_id, 'services.' ~ entity_name ~ '.flavor') }}"
WIREGUARD_CONTAINER: "{{ lookup('config', application_id, 'services.' ~ entity_name ~ '.name') }}"
WIREGUARD_IMAGE: "{{ lookup('config', application_id, 'services.' ~ entity_name ~ '.image') }}"
WIREGUARD_VERSION: "{{ lookup('config', application_id, 'services.' ~ entity_name ~ '.version') }}"
WIREGUARD_VOLUME: "{{ lookup('config', application_id, 'volumes.config') }}"
WIREGUARD_PORT_PUBLIC: "{{ lookup('config', application_id, 'services.' ~ entity_name ~ '.ports.public.relay') }}"
WIREGUARD_PUID: "{{ lookup('config', application_id, 'services.' ~ entity_name ~ '.puid') }}"
WIREGUARD_PGID: "{{ lookup('config', application_id, 'services.' ~ entity_name ~ '.pgid') }}"
WIREGUARD_TIMEZONE: "{{ lookup('config', application_id, 'services.' ~ entity_name ~ '.timezone') }}"
WIREGUARD_SYS_MODULE: "{{ lookup('config', application_id, 'services.' ~ entity_name ~ '.sys_module') | bool }}"
WIREGUARD_SERVER_URL: "{{ lookup('config', application_id, 'services.' ~ entity_name ~ '.server.url') }}"
WIREGUARD_SERVER_PEERS: "{{ lookup('config', application_id, 'services.' ~ entity_name ~ '.server.peers') }}"
WIREGUARD_SERVER_PEER_DNS: "{{ lookup('config', application_id, 'services.' ~ entity_name ~ '.server.peer_dns') }}"
WIREGUARD_SERVER_INTERNAL_SUBNET: "{{ WIREGUARD_INTERNAL_SUBNET }}"
WIREGUARD_SERVER_ALLOWED_IPS: "{{ lookup('config', application_id, 'services.' ~ entity_name ~ '.server.allowed_ips') }}"
WIREGUARD_INVENTORY_CONF: "{{ [inventory_dir, 'files', inventory_hostname, 'wireguard', 'wg0.conf'] | path_join }}"
# Fallback MTU (overridden by automtu in tasks/_mtu.yml when probing succeeds).
WIREGUARD_CLIENT_MTU: "{{ lookup('config', application_id, 'services.' ~ entity_name ~ '.client.mtu') }}"
# WireGuard encapsulation overhead subtracted from the probed path MTU.
WIREGUARD_WG_OVERHEAD: 80
WIREGUARD_NAT_IN_INTERFACE: "{{ lookup('config', application_id, 'services.' ~ entity_name ~ '.client.nat_in_interface') }}"
WIREGUARD_NAT_OUT_INTERFACE: "{{ lookup('config', application_id, 'services.' ~ entity_name ~ '.client.nat_out_interface') }}"