瀏覽代碼

docs: state update, baseline, harden, applications in the stage guides and the edge design (#232) (#285)

* docs: first-hour order in the stage guides and edge design, pinned by a test (#232)

State "update, baseline, harden, then applications" in the stage 1, AWS access and
telemetry guides and the edge DMZ design (section 4.4.1: no service until its own
stack is approved, exact version pins from each project's releases, a staggered
reboot slot per edge droplet between 01:00 and 03:00 Eastern). Correct the lesson
about what the cloud-init template does and does not do, and re-read the PHP
advisory facts on 2026-10-23. tests/test_update_order_pinned.py pins the guides,
the edge design and the template's real structure.

The template text is unchanged on purpose: its rendered user-data is pinned by a
golden hash because a change replaces the live droplets.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

* docs: address review on #285 (supersede note, ruling vs record dates, per-file order phrase, #305)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
ChiefGyk3D 1 月之前
父節點
當前提交
7a7b1b2e72

+ 2 - 0
docs/stages/01-access.md

@@ -24,6 +24,8 @@ DigitalOcean droplets always have a public address. You cannot remove it. So the
 
 ## 2a. Droplet hardening
 
+Order: update, baseline, harden, then applications. This is the order in the [first-hour lesson](../wiki/First-Hour-on-a-New-System-Updates-and-Baseline.md), and the cloud-init template follows it (the template's own text is not changed to say so: a comment would change the rendered user-data, and a golden-hash test in `modules/twingate-bootstrap/tests/bootstrap.tftest.hcl` pins the live connectors' user-data byte for byte, because a change replaces the droplets. A comment can go in with the next deliberate template change and its new golden hash; that leftover is tracked in issue #305). Step 1 is the first-boot `package_update` and `package_upgrade` plus `unattended-upgrades`. Step 2 is a baseline you take by hand right after first boot (cloud-init does not record one; the lesson has a read-only script for it). Step 3 is the list below. Step 4 is the connector, installed last. Cloud-init runs its modules in its own order, not file order: `write_files` places files first, the package update runs next, and `runcmd` switches the hardening on and then installs the connector, so nothing is active before the update and the hardening is on before the connector arrives.
+
 Each connector's cloud-init (`modules/twingate-bootstrap/cloud-init.yaml.tftpl`) sets up:
 
 - One login user, `cah-admin`, with the admin public key and passwordless sudo. No password exists (`lock_passwd`), root is disabled (`disable_root`) and the default `ubuntu` user is not created.

+ 2 - 0
docs/stages/02-telemetry.md

@@ -19,6 +19,8 @@ Outputs: `scrape_targets` (sensitive; empty unless metrics are on), `site_identi
 
 ## 2. Settings
 
+Order: update, baseline, harden, then applications. This stage creates no host. The host-side pieces it connects to (the node exporter and the Wazuh agent with auditd, in stack 10) install into the connectors after the update and the hardening described in the [stage 1 guide](01-access.md#2a-droplet-hardening), and a new baseline is taken after they are added. See the [first-hour lesson](../wiki/First-Hour-on-a-New-System-Updates-and-Baseline.md).
+
 Every variable is typed, validated and listed in [the settings reference](../wiki/Settings-Reference.md) (generated from `docs/settings.json`). `terraform.tfvars.example` shows the shape with documentation-range values and both flags false.
 
 - `resource_key` builds names and is **immutable** for the life of the stack: changing it replaces every object. Use the same value as the site's stacks 00 and 10. Empty means the region.

+ 2 - 0
docs/stages/aws-access.md

@@ -59,6 +59,8 @@ The gate for each state, run on copies of the repository with only the flags cha
 
 ## 4. Bootstrap (when the check has passed)
 
+Order on every instance: update, baseline, harden, then applications. The AWS connectors use the same cloud-init template as the DigitalOcean ones (`modules/twingate-bootstrap`), so the order is the one in the [stage 1 guide](01-access.md#2a-droplet-hardening) and the [first-hour lesson](../wiki/First-Hour-on-a-New-System-Updates-and-Baseline.md): update and automatic security updates first, a baseline you take by hand, the hardening, and the connector last. Amazon Linux behaves differently from Ubuntu at launch (see the lesson); this stack uses the Ubuntu image path through the shared template.
+
 1. Create `cah-aws-00-foundation` rooted at `stacks/aws/00-foundation`, labeled `cah-aws` (not `cah`), with the push policy attached first, then the AWS integration and the `cah-doppler-aws` context, and `TF_VAR_region` set.
 2. Create `cah-aws-10-access` rooted at `stacks/aws/10-access`, labeled `cah-aws`, push policy first, then **the same AWS integration and the `cah-doppler-aws` context attached to this stack too** (a stack dependency passes the mapped outputs, not credentials, so the access stack gets none from the foundation stack). It depends on the foundation stack, with this mapping:
 

+ 11 - 0
docs/superpowers/specs/2026-10-19-edge-dmz-design.md

@@ -177,6 +177,17 @@ Reused unchanged where it applies: one non-root user, no password auth, unattend
 
 Cloud Firewall limits that matter here, read from https://docs.digitalocean.com/products/networking/firewalls/details/limits/ on 2026-10-19: 50 rules per firewall, 10 droplets and 5 tags per firewall, and the firewall is free. One droplet is far under all three. The same page says cloud firewalls cannot be applied to load balancers, which matters for option B.
 
+### 4.4.1 Install order, pins and reboot slots (maintainer ruling 2026-10-22, recorded here 2026-10-23, issue #232)
+
+> **Supersedes the single-module text.** Where this design describes one `modules/edge-host` with cloud-init and pinned packages for all five daemons (the host description and the file list in section 10), that text is superseded by this per-service ruling: the edge host installs no daemon, and each service arrives through its own stack. Those sections are left as written.
+
+The order on every host is the one in [First hour on a new system](../wiki/First-Hour-on-a-New-System-Updates-and-Baseline.md): update (and switch on unattended security updates), take a baseline, harden, then applications. For the edge that means:
+
+- **No service is installed until its own stack is built and approved.** The edge host's first boot installs no daemon. Its cloud-init updates the system, writes the hardening and stops. Each service (Reticulum, lxmd, i2pd, Mosquitto, iperf3) arrives later, through its own stack (see [stack per service](2026-10-22-stack-per-service.md)), after the maintainer approves that stack. Nothing in this design is approved to build.
+- **Exact version pins from each project's releases.** Each service is pinned to an exact version read from that project's own releases page (or its package archive's version list), never `latest` and never a range. The implementation PR records the version, the link and the date it was read, and a version that was not read is written UNVERIFIED instead of guessed. This design names no version number, because I did not read any release page for it.
+- **A staggered reboot slot per edge droplet.** Each edge droplet gets its own reboot slot, set as a variable, between 01:00 and 03:00 Eastern. That is before the Twingate connectors' windows (connector a at 04:00, connector b at 05:00), so a reboot problem on the edge is seen before the access path restarts. No two droplets share a minute. A template test is planned that fails if any two droplets, edge or connector, share a reboot minute; it is not built.
+- **Enterprises use rings of devices.** A company does the same thing with groups: a small canary ring first, then wider rings after a soak period. The lesson's [stagger section](../wiki/First-Hour-on-a-New-System-Updates-and-Baseline.md#stagger-your-maintenance-windows) covers the names.
+
 ### 4.5 Services
 
 Per the handoff: `rnsd` with `enable_transport = Yes` and a `TCPServerInterface`; `lxmd` as a propagation node with storage and transfer limits; i2pd with SAM on loopback, an inbound port that stays closed until the i2pd stack is built and that i2pd then picks at random (ruling 11, not a security measure), and capped transit; Mosquitto with TLS and authentication, private broker for the maintainer's nodes by default; iperf3 with `--rsa-private-key-path` and `--authorized-users-path`, key material from Doppler. Option names for Reticulum, lxmd and i2pd have changed between releases, and whether the distro's iperf3 is built with OpenSSL auth support is UNVERIFIED. The implementation PR checks each against the version it pins and records the link, as the handoff requires.

+ 8 - 5
docs/wiki/First-Hour-on-a-New-System-Updates-and-Baseline.md

@@ -115,7 +115,7 @@ A single window for everything is the easy plan and the wrong one. **Stagger** m
 
 The two Twingate connector droplets are a pair: either one keeps access working while the other is down. Their windows are set so the pair never reboots together: connector a reboots at 04:00 and connector b at 05:00 Eastern, and the weekly connector package update runs on Sundays half an hour after each reboot (04:30 for a, 05:30 for b) ([Droplet hardening: updates](Droplet-Hardening.md#updates), read in this repository 2026-10-22). The template comment gives the reason for using a cron entry: `cron.weekly` "would fire on both connectors at the same moment, and the whole point of two connectors is that they never restart together".
 
-**The plan for the edge droplets (a maintainer ruling for the DMZ draft; planned, not built).** The edge stacks are not applied and nothing in the [edge DMZ design](../superpowers/specs/2026-10-19-edge-dmz-design.md) is approved to build. The ruling is that each edge service stack gets one slot, set as a variable, in a window **before** the connectors' windows, and a test fails if any two droplets share a minute. I did not find that test in the repository; it is part of the plan. The design itself says the edge host's reboot window must not collide with the connectors' ("a reboot window that does not collide with the connectors'").
+**The plan for the edge droplets (a maintainer ruling for the DMZ draft; planned, not built).** The edge stacks are not applied and nothing in the [edge DMZ design](../superpowers/specs/2026-10-19-edge-dmz-design.md) is approved to build. The ruling (made 2026-10-22, recorded in the design's section 4.4.1 on 2026-10-23), is that each edge droplet gets its own reboot slot, set as a variable, between 01:00 and 03:00 Eastern, which is before the connectors' 04:00 and 05:00, and that no two droplets share a minute. The test that fails on a shared minute is part of the plan; I did not find it in the repository. The design itself says the edge host's reboot window must not collide with the connectors' ("a reboot window that does not collide with the connectors'").
 
 ### The enterprise version: groups, rings and waves
 
@@ -172,9 +172,10 @@ The risk of *not* updating is real as well: the October 2026 flaws are critical
 Read these in the repository; I read them on 2026-10-22.
 
 - **Step 1 is in cloud-init.** `modules/twingate-bootstrap/cloud-init.yaml.tftpl` sets `package_update: true` and `package_upgrade: true` (update everything at first boot), installs `unattended-upgrades`, writes `/etc/apt/apt.conf.d/20auto-upgrades` (daily list refresh and daily unattended run) and an override file that allows only the release security origins (and the ESM security origins), removes unused dependencies and reboots at a set time. **Cloud-init** is the first-boot configuration that runs once when a cloud machine starts. The connector software comes from a third-party repository, so it is not in the allowed origins; the template adds a weekly `cron.d` entry that updates just that package and restarts its service. The template's comments say the first boot "races Ubuntu's own apt-daily and unattended-upgrades for the dpkg lock", so the install waits for it ([stage 1 guide](../stages/01-access.md)).
-- **The order inside the file** is: update, install the unattended-upgrades package, write the hardening (sshd, sysctl, firewall) and install the connector last. That matches steps 1, 3 and 4.
-- **Step 2 is not built.** The template does not record a baseline at first boot. Issue #232's second "done when" item (the stage guides and templates state the same order, with a test) is not done by this page. A baseline hook in cloud-init would be new code and needs its own approval.
-- **Edge droplets install no service until its own stack is built and approved** (maintainer ruling). The edge design ([edge DMZ design](../superpowers/specs/2026-10-19-edge-dmz-design.md), a draft, nothing in it approved to build or spend) says the host's software is pinned by version and checksum, "current releases only", that operating system packages come through unattended upgrades, and that the host is rebuilt on a schedule "because the host cannot be patched by hand". That is the order applied to a service host: the host is patched and baselined first; each service arrives later through its own stack, with a version read from that project's releases page and not `latest`. A template test that fails on an unpinned package name is listed in the design as the check; I did not check whether it exists.
+- **The order inside the file.** Cloud-init runs its modules in its own order, not file order: `write_files` places the files first, the package update and upgrade run next, and `runcmd` switches the hardening on and then installs the connector last. So nothing is active before the update, and the hardening is on before the connector arrives. That matches steps 1, 3 and 4.
+- **The same sentence is in every place that describes it.** The [stage 1 guide](../stages/01-access.md#2a-droplet-hardening), the [AWS access guide](../stages/aws-access.md), the [telemetry guide](../stages/02-telemetry.md) and the edge design all say "update, baseline, harden, then applications". The template itself does not say it in a comment: any text added to it changes the rendered user-data, and a golden-hash test pins the live connectors' user-data byte for byte (a change would replace the droplets), so a comment waits for the next deliberate template change. `tests/test_update_order_pinned.py` fails if a guide stops saying it or if the template's real structure (update before the connector install, hardening before the connector install) changes.
+- **Step 2 is not automated.** The template does not record a baseline at first boot. You take it by hand right after first boot, with the script in Exercise 3. A baseline hook in cloud-init would be new code and needs its own approval.
+- **Edge droplets install no service until its own stack is built and approved** (maintainer ruling of 2026-10-22, recorded in section 4.4.1 of the design on 2026-10-23). The edge design ([edge DMZ design](../superpowers/specs/2026-10-19-edge-dmz-design.md), a draft, nothing in it approved to build or spend) says the host's software is pinned by version and checksum, "current releases only", that operating system packages come through unattended upgrades, and that the host is rebuilt on a schedule "because the host cannot be patched by hand". That is the order applied to a service host: the host is patched and baselined first; each service arrives later through its own stack, with a version read from that project's releases page and not `latest`. A template test that fails on an unpinned package name is listed in the design as the check; `modules/edge-host` does not exist yet (checked 2026-10-23), so neither does the test.
 - **Containers.** Nothing in the current stacks runs a container ([Backups, recovery and patching](Backups-Recovery-and-Patching.md)); the container row above is about stage 3 and your own machines.
 
 ## Free path: a lab with nothing to lose
@@ -588,7 +589,9 @@ All read-only requests; retrieved **2026-10-22**. "Read" means I read the passag
 | Edge design: pinned by version and checksum, unattended upgrades, scheduled rebuild, a test for unpinned packages | [edge DMZ design](../superpowers/specs/2026-10-19-edge-dmz-design.md) | Read; it is a draft and the test's existence is **not verified** |
 | Baseline script and drift demo output | Exercise 3 | **Observed** 2026-10-22, Ubuntu 24.04 container, rootless Podman, no network |
 | Connector a reboots 04:00, b 05:00; weekly connector update Sundays 04:30 and 05:30; `cron.weekly` would fire on both at once | [Droplet hardening: updates](Droplet-Hardening.md#updates), `modules/twingate-bootstrap/cloud-init.yaml.tftpl` comment | Read in this repository |
-| Edge droplets: one slot per edge service stack, a variable, before the connectors' windows, a test that no two droplets share a minute | Maintainer ruling 2026-10-22 as given to me; [edge DMZ design](../superpowers/specs/2026-10-19-edge-dmz-design.md) says the reboot window must not collide with the connectors' | Plan only; the test and the variable are **not built and not found in the repository** |
+| Edge droplets: each gets its own reboot slot between 01:00 and 03:00 Eastern, set as a variable, before the connectors' 04:00 and 05:00; no two share a minute; no service installed until its own stack is built and approved; exact version pins from each project's releases | Maintainer ruling 2026-10-22 as given to me, recorded in section 4.4.1 of the [edge DMZ design](../superpowers/specs/2026-10-19-edge-dmz-design.md) on 2026-10-23 | Plan only; the edge module, the variable and the collision test are **not built** (`modules/edge-host` does not exist, checked 2026-10-23); the design names no version because none was read |
+| The order (update, baseline, harden, then applications) is stated in the stage 1, AWS access and telemetry guides and the edge design, and a test pins it and the template's real structure; the template carries no comment about it (it would change the pinned user-data) | `tests/test_update_order_pinned.py` | Written and run 2026-10-23 |
+| PHP security releases and the two CVE ids above still read as written | [php.net](https://www.php.net/) fetched again 2026-10-23: front page shows 8.5.12, CVE-2026-109618 and CVE-2026-109619 and the "updating is the only safe choice" line; the first advisory URL returned HTTP 200 | Re-read |
 | Autopatch groups; Test and Last rings present by default | [Autopatch groups overview](https://learn.microsoft.com/en-us/windows/deployment/windows-autopatch/deploy/windows-autopatch-groups-overview) | Read in part |
 | Intune update rings: deferrals, restarts, deadlines; commonly used for test, pilot, production stages | [Intune update rings](https://learn.microsoft.com/en-us/mem/intune/protect/windows-10-update-rings) | Read in part |
 | WSUS computer groups | Microsoft page (404 on the URL tried) | **Not read (est.)** |

+ 60 - 0
tests/test_update_order_pinned.py

@@ -0,0 +1,60 @@
+"""The order of a new machine's first hour is stated the same way everywhere it is described.
+
+Issue #232: update, baseline, harden, then applications. The stage guides and the edge design must
+say it, the template's real structure must follow it (the
+update before the connector install, the hardening switched on before the connector install), and
+the edge design must record the install rule, the version pins and the reboot-slot window.
+"""
+
+import re
+from pathlib import Path
+
+ROOT = Path(__file__).resolve().parent.parent
+TEMPLATE = ROOT / "modules" / "twingate-bootstrap" / "cloud-init.yaml.tftpl"
+EDGE = ROOT / "docs" / "superpowers" / "specs" / "2026-10-19-edge-dmz-design.md"
+LESSON = ROOT / "docs" / "wiki" / "First-Hour-on-a-New-System-Updates-and-Baseline.md"
+GUIDES = [ROOT / "docs" / "stages" / n for n in ("01-access.md", "aws-access.md", "02-telemetry.md")]
+ORDER = "update, baseline, harden, then applications"
+
+
+def read(p: Path) -> str:
+    return p.read_text(encoding="utf-8")
+
+
+SHORT = ORDER
+LONG = "update (and switch on unattended security updates), take a baseline, harden, then applications"
+REQUIRED = {**{g: SHORT for g in GUIDES}, EDGE: LONG}
+
+
+def test_every_guide_and_the_edge_design_state_the_order():
+    assert len(REQUIRED) == len(GUIDES) + 1
+    for p, phrase in REQUIRED.items():
+        flat = re.sub(r"\s+", " ", read(p)).lower()
+        assert phrase in flat, f"{p.name} must carry: {phrase}"
+
+
+def test_the_template_follows_the_order():
+    t = read(TEMPLATE)
+    assert t.index("package_update: true") < t.index("package_upgrade: true") < t.index("\nruncmd:")
+    assert "unattended-upgrades" in t.split("write_files:")[0]
+    run = t.split("\nruncmd:")[1]
+    harden = run.index("sshd -t && systemctl restart ssh")
+    connector = run.index("apt-get install -yq twingate-connector")
+    assert harden < connector, "hardening must be switched on before the connector is installed"
+
+
+def test_edge_design_records_the_edge_rules():
+    flat = re.sub(r"\s+", " ", read(EDGE))
+    assert "No service is installed until its own stack is built and approved" in flat
+    assert "Exact version pins from each project's releases" in flat
+    assert "between 01:00 and 03:00 Eastern" in flat
+    assert "04:00" in flat and "05:00" in flat
+    assert "No two droplets share a minute" in flat
+    assert "rings of devices" in flat
+
+
+def test_slot_window_is_before_the_connector_windows():
+    # The connector windows the design and the lesson cite come from the real droplet hardening page.
+    hardening = read(ROOT / "docs" / "wiki" / "Droplet-Hardening.md")
+    assert "04:00" in hardening and "05:00" in hardening
+    assert "between 01:00 and 03:00 Eastern" in read(LESSON)