Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: docs

on:
pull_request:
paths:
- docs/**
- "*.md"
- .github/workflows/docs.yml
schedule:
- cron: "41 5 * * 1"
workflow_dispatch:

permissions:
contents: read

jobs:
docs:
uses: phorge-fr/.github/.github/workflows/docs-lint.yml@main
with:
external-links: ${{ github.event_name != 'pull_request' }}
4 changes: 2 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Instructions for anyone working in this repository, human or AI assistant. The o

## What this repository is

The OpenTofu configuration and bootstrap scripts of the edge router (a MikroTik running RouterOS 7). It owns VLANs, addressing, DHCP, DNS records, the firewall, NAT, and the container that runs HAProxy to publish services. Start with [docs/architecture.md](docs/architecture.md); the rebuild procedure is [docs/runbook-reset.md](docs/runbook-reset.md).
The OpenTofu configuration and bootstrap scripts of the edge router (a MikroTik running RouterOS 7). It owns VLANs, addressing, DHCP, DNS records, the firewall, NAT, and the container that runs HAProxy to publish services. Start with [docs/explanation/architecture.md](docs/explanation/architecture.md) and [docs/reference/network-plan.md](docs/reference/network-plan.md); the rebuild procedure is [docs/how-to/reset-and-bootstrap-the-router.md](docs/how-to/reset-and-bootstrap-the-router.md).

Three layers, each with an owner ([decision 0001](docs/decisions/0001-three-configuration-layers.md)):

Expand Down Expand Up @@ -35,7 +35,7 @@ When a finding concerns a system-level setting, the answer is "this goes in `bas
- `prevent_destroy` guards the bridge, its ports, the VLANs and the IP addresses. The firewall order is managed with `routeros_move_items` and must match the live order.
- HAProxy routes are edited in `templates/haproxy.cfg.tftpl`; `tofu apply` pushes the file and the container reloads by itself ([decision 0002](docs/decisions/0002-haproxy-hot-reload.md)). Do not re-add a Terraform data model for routes. Changing a container attribute restarts it; do not change `entrypoint` or `cmd` of the production container in place.
- A new public host name needs a route in the HAProxy template (SNI and HTTP redirect): the edge does not forward unknown hosts to the right cluster.
- `api-ssl` of the router and the monitoring user's password are partly manual, see `phorge-fr/Hangar` `docs/runbooks/router-monitoring.md`.
- `api-ssl` of the router and the monitoring user's password are partly manual, see `phorge-fr/Hangar` `docs/how-to/fix-an-empty-router-dashboard.md`.

## Security reports

Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ OpenTofu configuration and bootstrap scripts of the edge router of the [Phorge](

Documentation:

- [Architecture and network plan](docs/architecture.md): topology, VLANs and addresses, wiring, hosts and clusters, public services, traffic flows, change checklists.
- [Reset and bootstrap runbook](docs/runbook-reset.md): rebuild the router from scratch and bring it back under OpenTofu.
- [Documentation index](docs/README.md): how-to guides, the network plan, the architecture and the decision records.
- [Reset and bootstrap the router](docs/how-to/reset-and-bootstrap-the-router.md): rebuild the router from scratch and bring it back under OpenTofu.

Sibling repositories: [FrontPlane](https://github.com/phorge-fr/Frontplane) (Kubernetes clusters), [Ansible](https://github.com/phorge-fr/Ansible) (storage, HPC and compute nodes).

Expand All @@ -32,7 +32,7 @@ terraform.tfvars Values: networks, DNS records, firewall, NAT, containers
templates/ HAProxy configuration template and the script that reloads it
certs/ Local trust anchor: the router CA (ignored by git, see the runbook)
defaults/ RouterOS scripts: factory defaults, base configuration, Phorge.dpk
docs/ Architecture and runbooks
docs/ Documentation by type: how-to, reference, explanation, decisions
```

One entry in `networks` (name, VLAN ID, CIDR, optionally a DHCP pool, node ranges and the host number of the public ingress) creates the VLAN, the router address (the last usable address of the subnet), the DHCP pool, network and server, the membership of the `phorge` interface list and the `<name>-nodes` address list. The ingress addresses also feed the HAProxy configuration and the rules that let the container reach them, so they exist in one place.
Expand All @@ -56,7 +56,7 @@ One entry in `networks` (name, VLAN ID, CIDR, optionally a DHCP pool, node range

The passwords of the extra RouterOS users declared in `users` go in `TF_VAR_user_passwords`, a JSON object keyed by user name (at least 24 random characters each). They never go in `terraform.tfvars`. A service that reads one of them keeps its own copy: the `mktxp` password is also stored SOPS-encrypted in the Frontplane repository.

The provider verifies the router certificate against `certs/router-ca.pem`, a local file that is not committed. Fetch it as described in [the runbook](docs/runbook-reset.md#6-bring-the-router-back-under-opentofu). The first run after a router reset can use `TF_VAR_insecure_tls=true` instead.
The provider verifies the router certificate against `certs/router-ca.pem`, a local file that is not committed. Fetch it as described in [the reset how-to](docs/how-to/reset-and-bootstrap-the-router.md#6-bring-the-router-back-under-opentofu). The first run after a router reset can use `TF_VAR_insecure_tls=true` instead.

2. Initialize:

Expand All @@ -74,7 +74,7 @@ One entry in `networks` (name, VLAN ID, CIDR, optionally a DHCP pool, node range

Run every command from the repository root so that `terraform.tfvars` is loaded. Without it the plan stops on missing required variables.

The HAProxy configuration is `templates/haproxy.cfg.tftpl`. Edit it and run `tofu apply`: the container reloads it by itself within about 15 seconds, without dropping connections (see [the runbook](docs/runbook-reset.md#haproxy-configuration-reload), including how to check that HAProxy accepted it). Do not edit the file on the router, the next apply would overwrite it.
The HAProxy configuration is `templates/haproxy.cfg.tftpl`. Edit it and run `tofu apply`: the container reloads it by itself within about 15 seconds, without dropping connections (see [the reset how-to](docs/how-to/reload-the-haproxy-configuration.md), including how to check that HAProxy accepted it). Do not edit the file on the router, the next apply would overwrite it.

The uploaded HAProxy configuration is adopted automatically (`import` block in `containers.tf`) because RouterOS file IDs shift when other files change.

Expand All @@ -83,14 +83,14 @@ The VLANs, IP addresses, bridges and bridge ports have `prevent_destroy`: a plan
## Conventions

- Every object created by OpenTofu carries a comment starting with `tofu;;;`.
- Firewall rules have a stable `id` and are placed on the router in list order by `routeros_move_items`. A rule with `before` sits right above the factory rule of that name in the same chain, the others go to the end of the chain. See [the runbook](docs/runbook-reset.md#firewall-rule-order).
- Firewall rules have a stable `id` and are placed on the router in list order by `routeros_move_items`. A rule with `before` sits right above the factory rule of that name in the same chain, the others go to the end of the chain. See [the reset how-to](docs/how-to/reset-and-bootstrap-the-router.md#firewall-rule-order).
- The state is local (`terraform.tfstate`, ignored by git) and encrypted with OpenTofu's native state encryption. Every command needs `source .env`, otherwise it stops with `Reference to undeclared key provider`. Keep a copy of the state after every apply.
- All three Phorge repositories are public. Never commit `.env`, the state (not even encrypted), a reset-edited `base_configuration.rsc` or any other plaintext secret.
- Commit messages follow Conventional Commits (`fix(fw): ...`, `chore(haproxy): ...`).

## Setting up the router for the first time

Follow [the runbook](docs/runbook-reset.md). In short: replace the placeholders in `defaults/base_configuration.rsc`, reset the router with the factory defaults, upload `defaults/Phorge.dpk`, import the base configuration, then run OpenTofu.
Follow [the reset how-to](docs/how-to/reset-and-bootstrap-the-router.md). In short: replace the placeholders in `defaults/base_configuration.rsc`, reset the router with the factory defaults, upload `defaults/Phorge.dpk`, import the base configuration, then run OpenTofu.

## Contributing

Expand Down
34 changes: 34 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Network documentation

Pages are grouped by what the reader wants, following [the organization's documentation standard](https://github.com/phorge-fr/.github/blob/main/docs/reference/documentation-standard.md).

## How-to guides

| Page | Task |
| --- | --- |
| [Reset and bootstrap the router](how-to/reset-and-bootstrap-the-router.md) | Rebuild the router from scratch and bring it back under OpenTofu |
| [Reload the HAProxy configuration](how-to/reload-the-haproxy-configuration.md) | Change a public route |
| [Change the network](how-to/change-the-network.md) | Add a VLAN, a flow or a public hostname |
| [Remove factory rules from the state](how-to/remove-factory-rules-from-the-state.md) | Clear a plan that wants to delete the factory firewall rules |

## Reference

| Page | Content |
| --- | --- |
| [Network plan](reference/network-plan.md) | Addresses, VLANs, wiring, hosts, public services and traffic flows |

## Explanation

| Page | Question it answers |
| --- | --- |
| [Architecture](explanation/architecture.md) | How the infrastructure and the repositories fit together |
| [Known inconsistencies](explanation/known-inconsistencies.md) | Where files and the live router disagreed |

## Decisions

| Record | Status |
| --- | --- |
| [0001 Three configuration layers](decisions/0001-three-configuration-layers.md) | accepted |
| [0002 Keep HAProxy, routes in a template, hot reload](decisions/0002-haproxy-hot-reload.md) | accepted |
| [0003 State and certificates are never committed](decisions/0003-state-and-certificates-not-committed.md) | accepted |
| [0004 Containers reach only what the rules allow](decisions/0004-container-network-containment.md) | accepted |
53 changes: 43 additions & 10 deletions docs/decisions/0001-three-configuration-layers.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,50 @@
# 0001: Three configuration layers
---
status: accepted
date: 2026-09-20
decision-makers: l-nmch
---

Status: accepted.
# Three configuration layers: factory, bootstrap script, OpenTofu

## Decision
## Context and problem statement

- `defaults/default_configuration.rsc` is the MikroTik factory configuration. Never edit it.
- `defaults/base_configuration.rsc` is the maintainer's own script that pre-provisions the router after a reset: DNS servers, hardening, certificates, services, Ethernet port MTU/L2MTU, which ports are disabled, the management LAN and base users.
- OpenTofu owns the network objects: VLANs, addresses, DHCP, DNS records, firewall, NAT, containers, HAProxy configuration.
The router was reset and rebuilt by hand once. Drift between the bootstrap script, the live router and the code caused an L2 MTU incident. Where does each kind of setting live?

## Why
## Decision drivers

The bootstrap must stay a plain RouterOS script under the maintainer's control. The router was once reset and rebuilt by hand, and drift between the bootstrap script, the live router and the code caused an L2 MTU incident. An experiment that managed Ethernet ports and the DNS settings in OpenTofu was stopped. All ports use the same large MTU (VLAN MTU depends on the bridge, which depends on the physical ports). The placeholders in the bootstrap script stay as they are (no templating).
* The bootstrap must stay a plain RouterOS script under the maintainer's control.
* OpenTofu should own only network objects, and only what it can also delete.

## Consequences
## Considered options

System-level settings never move into OpenTofu. A setting that OpenTofu cannot delete (the router API services) is set by hand and documented in the runbook.
* Three layers: factory configuration, the maintainer's bootstrap script, OpenTofu for the rest.
* OpenTofu for everything, including Ethernet ports and DNS settings.

## Decision outcome

Chosen option: "three layers".

* `defaults/default_configuration.rsc` is the MikroTik factory configuration. Never edit it.
* `defaults/base_configuration.rsc` is the maintainer's script that pre-provisions the router after a reset: DNS servers, hardening, certificates, services, Ethernet port MTU and L2MTU, which ports are disabled, the management LAN and base users.
* OpenTofu owns VLANs, addresses, DHCP, DNS records, the firewall, NAT, containers and the HAProxy configuration.

### Consequences

* Good, because a reset is a script plus `tofu apply`.
* Bad, because a system setting that OpenTofu cannot delete (the router API services) is set by hand and documented in the [reset how-to](../how-to/reset-and-bootstrap-the-router.md).

## Pros and cons of the options

### Three layers

* Good, because each layer has one owner.
* Bad, because one must know which layer a setting belongs to.

### OpenTofu for everything

* Good, because one tool.
* Bad, because an experiment that managed Ethernet ports and DNS in OpenTofu was stopped: the maintainer wants the bootstrap to be theirs, and all ports use the same large MTU (the VLAN MTU depends on the bridge, which depends on the ports).

## More information

The placeholders in the bootstrap script stay as they are (no templating).
62 changes: 51 additions & 11 deletions docs/decisions/0002-haproxy-hot-reload.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,58 @@
# 0002: Keep HAProxy, routes in a template, hot reload
---
status: accepted
date: 2026-09-21
decision-makers: l-nmch
---

Status: accepted, live.
# Keep HAProxy, routes in a template, hot reload

## Context
## Context and problem statement

The router runs HAProxy in a container to publish services by SNI and HTTP host. Options considered: a Kubernetes ingress (rejected: the platform's ingress does not route outside its cluster, and the official Traefik image has no 32-bit ARM build for this router), or an HAProxy Terraform provider (none can express SNI-based backend switching or the needed request rules).
The router runs HAProxy in a container to publish services by SNI and HTTP host. How are the routes edited, and how does a change reach HAProxy without an outage?

## Decision
## Decision drivers

Keep HAProxy. The routing rules are edited in `templates/haproxy.cfg.tftpl`; `tofu apply` renders and pushes the file and a wrapper script (`templates/haproxy-run.sh`) reloads HAProxy in place. The wrapper runs a private copy of the configuration published atomically, refuses an invalid file (the old configuration keeps running) and keeps the last good copy for restarts.
* Reload without restarting the container.
* Routes editable by hand in the repository.
* No component that cannot run on this 32-bit ARM router.

## Lessons
## Considered options

- Changing `entrypoint` or `cmd` of the production container in place once left it started but silent and unresponsive; only recreating it from its original definition recovered it. Validate wrapper changes on isolated throwaway containers first, then apply targeted.
- A syntactically valid but wrong configuration is not caught. `tofu apply` succeeds even when HAProxy refuses the file, so check the router log after an apply.
- A container attribute change still restarts the container (a few seconds).
- Rate limiting is out of scope until the client address HAProxy sees is the real one.
* Keep HAProxy, edit `templates/haproxy.cfg.tftpl`, reload in place.
* A Kubernetes ingress as the edge.
* An HAProxy Terraform provider or its Data Plane API.

## Decision outcome

Chosen option: "keep HAProxy with a template and an in-place reload". `tofu apply` renders and pushes the file; a wrapper script (`templates/haproxy-run.sh`) reloads HAProxy. The wrapper runs a private copy of the configuration published atomically, refuses an invalid file (the old configuration keeps running) and keeps the last good copy for restarts.

### Consequences

* Good, because adding a route is one edit and one apply.
* Bad, because a valid but wrong configuration is loaded as is, and `tofu apply` succeeds even when HAProxy refuses the file: read the router log after an apply ([how-to](../how-to/reload-the-haproxy-configuration.md)).
* Bad, because a change to a container attribute still restarts it (a few seconds), and rate limiting is out of scope until the client address HAProxy sees is the real one.

### Confirmation

The router log shows `haproxy.cfg changed: reloading` followed by `Loading success`.

## Pros and cons of the options

### HAProxy with a template

* Good, because it works today.
* Bad, because routes are text, not data.

### A Kubernetes ingress

* Good, because it reuses a cluster tool.
* Bad, because a cluster ingress does not route outside its cluster (Hangar decision 0005), and the official Traefik image has no 32-bit ARM build.

### An HAProxy provider or Data Plane API

* Good, because it models the routes as resources.
* Bad, because no provider can express SNI-based backend switching.

## More information

Changing `entrypoint` or `cmd` of the production container in place once left it started but silent and unresponsive; only recreating it from its original definition recovered it. Validate wrapper changes on isolated throwaway containers first, then apply targeted. A data model for routes was written and then removed on purpose: do not add one back.
38 changes: 35 additions & 3 deletions docs/decisions/0003-state-and-certificates-not-committed.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,37 @@
# 0003: State and certificates are never committed
---
status: accepted
date: 2026-09-20
decision-makers: l-nmch
---

Status: accepted.
# State and certificates are never committed

The repository is public with permanent history, the state has no locking and changes constantly. So: the state is not committed, not even encrypted; `certs/` (the router CA used to verify its HTTPS certificate) is gitignored and fetched with the runbook; the provider lock file is committed. State encryption is nevertheless on, with its passphrase only in the gitignored `.env`, which the maintainer keeps in a password manager.
## Context and problem statement

The repository is public with permanent history. The OpenTofu state has no locking and changes constantly, and the provider verifies the router certificate against a local CA file. What may be committed?

## Considered options

* Commit neither the state nor the CA file; encrypt the state locally.
* Commit the state encrypted.

## Decision outcome

Chosen option: "commit neither". The state is not committed, even encrypted; `certs/` is gitignored and fetched with [the reset how-to](../how-to/reset-and-bootstrap-the-router.md); the provider lock file is committed. State encryption stays on, with its passphrase only in the gitignored `.env`, which the maintainer keeps in a password manager.

### Consequences

* Good, because nothing recoverable sits in the permanent history.
* Bad, because the state lives on one machine; losing it means re-importing.

## Pros and cons of the options

### Commit neither

* Good, because no secret in history.
* Bad, because a single copy of the state.

### Commit the state encrypted

* Good, because a backup in Git.
* Bad, because permanent history, churn and no locking.
Loading
Loading