carlos / platform Public

pdf-host: admit a standby console's security group too

New optional input additional_client_security_group_ids: each group is
admitted on TCP 3000 beside client_security_group_id, the lookups are
keyed by list position so an id created in the same apply still plans,
and a precondition refuses a group outside the client VPC. Adding a
group changes the ingress rule in place. Lets a deployment admit its
failover standby up front instead of editing during an incident (Bill's
review of Tito infra #61). Astra R1 NOT READY, R2 READY AFTER FIXES,
census approved; README by Luna.

Squashed from pdf-host-client-groups into main.
claude agent, operated by paul@keymail.dev 156b978d9a5e623ee25ee0b8c167f9c32391680c parent c48e91e
15 files changed, +339 −4
  • docs/superpowers/notes/census-proposal-pdf-host-client-groups.md +28 −0
  • docs/superpowers/reviews/CODEX-FINDINGS-PDF-HOST-CLIENT-GROUPS-FIXES.md +22 −0
  • docs/superpowers/reviews/CODEX-FINDINGS-PDF-HOST-CLIENT-GROUPS-R1.md +37 −0
  • docs/superpowers/reviews/CODEX-FINDINGS-PDF-HOST-CLIENT-GROUPS-R2.md +43 −0
  • docs/superpowers/reviews/CODEX-REVIEW-BRIEF-PDF-HOST-CLIENT-GROUPS-FIXES.md +3 −0
  • docs/superpowers/reviews/CODEX-REVIEW-BRIEF-PDF-HOST-CLIENT-GROUPS-R2.md +18 −0
  • docs/superpowers/reviews/CODEX-REVIEW-BRIEF-PDF-HOST-CLIENT-GROUPS.md +14 −0
  • infra/modules/pdf-host/README.md +18 −3
  • infra/modules/pdf-host/main.tf +15 −1
  • infra/modules/pdf-host/tests/computed.tftest.hcl +40 −0
  • infra/modules/pdf-host/tests/computed/main.tf +13 −0
  • infra/modules/pdf-host/tests/pdf_host.tftest.hcl +61 −0
  • infra/modules/pdf-host/variables.tf +10 −0
  • internal/provision/testdata/plan14-root-reads-chain.tsv +1 −0
  • internal/provision/testdata/plan14-root-reads-pdf-host-client-groups.tsv +16 −0

CI passed — run details

diff --git a/docs/superpowers/notes/census-proposal-pdf-host-client-groups.md b/docs/superpowers/notes/census-proposal-pdf-host-client-groups.md
new file mode 100644
index 000000000..cae747330
--- /dev/null
+++ b/docs/superpowers/notes/census-proposal-pdf-host-client-groups.md
@@ -0,0 +1,28 @@
+# Census approval: pdf-host-client-groups
+
+Ruling `census-ruling-pdf-host-client-groups`. The independent reviewer approves or rejects every change below, 2 with a new disposition; nothing goes to the census owner (Paul, #280, 2026-10-26).
+
+| unit | change | read sites | what changed |
+|---|---|---|---|
+| `infra/modules/pdf-host/main.tf` `external` | body | unchanged (1) | Adds data.aws_security_group.additional_client keyed by list position and admits those groups on TCP 3000 beside the client group; a precondition refuses a group outside the client VPC. No new root read; box, role and fence unchanged. |
+| `infra/modules/pdf-host/tests/pdf_host.tftest.hcl` `external` | body | unchanged (1) | Mock tests: standby admitted, other-VPC refused, malformed refused, duplicates collapse. |
+| `infra/modules/pdf-host/variables.tf` `external` | body | unchanged (1) | New optional input additional_client_security_group_ids (list of sg ids, default empty, validated). No new read. |
+
+Envelopes re-pinned: `infra/modules/pdf-host`, `infra/modules/pdf-host/tests`, `infra/modules/pdf-host/tests/computed`.
+
+Review: a model from the other family than the author reads the branch's diff against main on the amadan.net remote (`origin` or `amadan`, whichever points at amadan.net) and gives a verdict for every unit and every re-pinned envelope above. For a unit, compare the change with its recorded disposition and basis below; for an envelope, read every changed function in the package and what it reaches. Reject if the change lets root open, run, query or follow anything it did not before from a path or input a tenant, an app or a box agent can create, write or name; if it weakens a check, refusal, validation, argument or environment the basis relies on; or if the diff cannot settle either. Otherwise approve. Record each verdict on #280 with the tip. A rejected unit goes back to the author to correct; nothing escalates to the census owner.
+
+Recorded dispositions, which each change must still satisfy:
+
+- `infra/modules/pdf-host/main.tf` `external`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-design-pdf-service;basis=OpenTofu module source defining the PDF engine box, security group and SSM-only role; never read by the CARLOS root binary or a box agent at runtime
+- `infra/modules/pdf-host/tests/pdf_host.tftest.hcl` `external`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-design-pdf-service;basis=mock-provider tests cover loopback names, mapped IPv6 and userinfo, case-insensitive HTTP, public hostname boundaries and the case-sensitive file exemption; retain private engine-port, metadata/fence retry and Docker memory checks; no live infrastructure calls; never read by the CARLOS root binary or a box agent at runtime
+- `infra/modules/pdf-host/variables.tf` `external`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-design-pdf-service;basis=OpenTofu module inputs now reject memory_max below 6 MiB while retaining whole MiB/GiB validation; never read by the CARLOS root binary or a box agent at runtime
+
+New dispositions, which census-propose wrote and the reviewer checks against the unit's reads and the diff:
+
+- new `infra/modules/pdf-host/tests/computed.tftest.hcl:external`: reads +file:external; written legacy, accepted-legacy, frozen
+- new `infra/modules/pdf-host/tests/computed/main.tf:external`: reads +file:external; written legacy, accepted-legacy, frozen
+
+Seal: `94ccbabaf19c3a449cec248a0c32fcc8593c82d3f7f433c6a48b6e0fdf068167` → `e8beda8fd31db92f742943be631e8d034bbb4880225e69a680d5a0be893807af`.
+
+Overlay: `internal/provision/testdata/plan14-root-reads-pdf-host-client-groups.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`.
diff --git a/docs/superpowers/reviews/CODEX-FINDINGS-PDF-HOST-CLIENT-GROUPS-FIXES.md b/docs/superpowers/reviews/CODEX-FINDINGS-PDF-HOST-CLIENT-GROUPS-FIXES.md
new file mode 100644
index 000000000..dab2b3193
--- /dev/null
+++ b/docs/superpowers/reviews/CODEX-FINDINGS-PDF-HOST-CLIENT-GROUPS-FIXES.md
@@ -0,0 +1,22 @@
+Reviewed `37fe57c1..8664539e` within R2’s existing budget.
+
+All paths below are relative to `infra/modules/pdf-host/`.
+
+| Census unit or envelope | Verdict | Evidence |
+|---|---|---|
+| `main.tf:external` | APPROVED | Source unchanged; revised claim preserves its basis. |
+| `variables.tf:external` | APPROVED | Source unchanged; validation retained. |
+| `tests/pdf_host.tftest.hcl:external` | APPROVED | Source unchanged; existing guards retained. |
+| `tests/computed.tftest.hcl:external` | APPROVED | Lines 23–40 add mocked apply coverage and document the remaining gap. No new root runtime reads. |
+| `tests/computed/main.tf:external` | APPROVED | Fixture unchanged; accepted-legacy disposition remains appropriate. |
+| Module envelope | APPROVED | Production source unchanged; README lines 131–133 correct acceptance checks. |
+| `tests` envelope | APPROVED | Only the reviewed computed-test additions changed. |
+| `tests/computed` envelope | APPROVED | Fixture and envelope unchanged. |
+
+P2-1: **Partly resolved** — positive computed-ID apply coverage added; negative apply coverage remains absent. I agree with accepting the documented fixture limitation for this bounded follow-up.
+
+P2-2: **Resolved** — acceptance checks now require access from every admitted group and denial from a box in none.
+
+All five unit digests, five legacy fingerprints, three envelope hashes and the chain seal match. Formatting passed. Tests could not execute: fixture module not installed. `git diff --check` flags only two Markdown hard-break lines in the saved R2 findings. No files changed or subagents used.
+
+**READY**
\ No newline at end of file
diff --git a/docs/superpowers/reviews/CODEX-FINDINGS-PDF-HOST-CLIENT-GROUPS-R1.md b/docs/superpowers/reviews/CODEX-FINDINGS-PDF-HOST-CLIENT-GROUPS-R1.md
new file mode 100644
index 000000000..abc3a304c
--- /dev/null
+++ b/docs/superpowers/reviews/CODEX-FINDINGS-PDF-HOST-CLIENT-GROUPS-R1.md
@@ -0,0 +1,37 @@
+Reviewed `origin/main` (`c48e91e5`) through `7d6c4fff7263940d32d5c40a0b395b10a4c368f8`, round 1 of 3.
+
+**P1 — A standby group created in the same apply prevents planning.**
+
+At [main.tf:6](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/pdf-host-client-groups/infra/modules/pdf-host/main.tf:6), `for_each = toset(var.additional_client_security_group_ids)` makes the group IDs the instance keys. When the README’s `module.standby_ie.security_group_id` comes from a group being created or replaced, its ID is unknown during planning. OpenTofu rejects the `for_each` before the VPC precondition can run. The documented configuration therefore requires a separate targeted apply.
+
+OpenTofu requires every set member used by `for_each` to be known before apply: [https://opentofu.org/docs/language/meta-arguments/for_each/](https://opentofu.org/docs/language/meta-arguments/for_each/).
+
+**Fix:** key the data lookups by known list positions, for example `{ for index, id in var.additional_client_security_group_ids : tostring(index) => id }`. Keep deduplication in the ingress expression and retain the VPC precondition. Add a regression using a known-length list containing an ID computed during apply, including rejection when its resolved VPC differs.
+
+**Fault family:** plan-time instance identity must not depend on IDs generated during apply.
+
+No separate P2 or P3 findings.
+
+The remaining checks:
+
+- **Ingress:** one TCP 3000 rule, with no CIDR or self setting. `distinct(concat(...))` removes duplicates, including repetition of the primary group. An empty list preserves the previous ingress value; byte-identical plans were not verified.
+- **Replacement:** with known IDs and an unchanged primary group, the additional groups affect only inline ingress. The AWS provider updates these rules in place; the instance retains the same security-group reference. This is source verification, not an executed transition plan. Provider source: [https://github.com/hashicorp/terraform-provider-aws/blob/v6.0.0/internal/service/ec2/vpc_security_group.go](https://github.com/hashicorp/terraform-provider-aws/blob/v6.0.0/internal/service/ec2/vpc_security_group.go).
+- **VPC check:** every additional lookup is compared with the primary group’s VPC. No bypass found for known IDs. Unknown IDs encounter the P1 above.
+- **Tests:** by inspection, removing standby admission breaks the positive assertion; removing the precondition or input validation leaves its corresponding expected failure unsatisfied. The tests do not cover computed IDs, duplicates, or add/remove replacement behavior.
+- **README:** accurate for existing groups, but its “from the start” example exposes the P1 when the standby group is new.
+
+Census verdicts apply to the recorded root-read dispositions, independently of the functional blocker:
+
+| Changed unit or envelope | Verdict | Evidence |
+|---|---|---|
+| `infra/modules/pdf-host/main.tf:external` | APPROVED | Lines 5–8, 23–51: operator-supplied groups only; no new root runtime reads. IAM, instance configuration and fence unchanged. |
+| `infra/modules/pdf-host/variables.tf:external` | APPROVED | Lines 15–23: optional validated input; existing validations retained. |
+| `infra/modules/pdf-host/tests/pdf_host.tftest.hcl:external` | APPROVED | Lines 344–385: mock-provider tests only; existing guards retained. |
+| `infra/modules/pdf-host` envelope | APPROVED | Both changed source files reviewed with their consumers; init template, outputs and provider requirements unchanged. |
+| `infra/modules/pdf-host/tests` envelope | APPROVED | Only the three reviewed test runs were added. |
+
+All three unit fingerprints and both envelope hashes match the overlay.
+
+`tofu fmt -check -recursive` and `git diff --check` passed. `tofu test` stopped because the required AWS provider was unavailable: zero tests passed, 22 skipped. No files were changed or subagents used.
+
+**NOT READY**
\ No newline at end of file
diff --git a/docs/superpowers/reviews/CODEX-FINDINGS-PDF-HOST-CLIENT-GROUPS-R2.md b/docs/superpowers/reviews/CODEX-FINDINGS-PDF-HOST-CLIENT-GROUPS-R2.md
new file mode 100644
index 000000000..bcec1babf
--- /dev/null
+++ b/docs/superpowers/reviews/CODEX-FINDINGS-PDF-HOST-CLIENT-GROUPS-R2.md
@@ -0,0 +1,43 @@
+R1 P1: **resolved** — list-position keys support computed IDs in a known-length list. The requested apply-time rejection regression remains missing.
+
+Reviewed `origin/main` (`c48e91e5`) through `ef49fa874fd8715021fba4922b34229362d18943`, round 2 of 3. HEAD adds only the review brief.
+
+**P2 — Missing computed-ID VPC rejection test.**
+[computed.tftest.hcl:16](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/pdf-host-client-groups/infra/modules/pdf-host/tests/computed.tftest.hcl:16) only plans. The other-VPC test supplies a known ID. Neither exercises a computed ID whose lookup resolves to another VPC during apply, as requested in R1. A regression affecting deferred validation could therefore escape these tests.
+
+Add mocked apply coverage for computed IDs resolving to matching and different VPCs; confirm the rejection case fails when the precondition is removed. **Fault family:** VPC membership must be checked before admitting a group, including when its ID becomes known during apply.
+
+**P2 — README acceptance check contradicts standby admission.**
+[README.md:131](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/pdf-host-client-groups/infra/modules/pdf-host/README.md:131) requires a box outside the console’s group to be denied. A standby belonging only to an additional group should succeed, so a correct deployment can fail this check.
+
+Require success from the primary and additional groups, and denial from a box belonging to none of them. **Fault family:** acceptance checks must match the configured ingress boundary.
+
+No remaining P1 or separate P3 findings.
+
+The other checks:
+
+- **Ingress:** one TCP 3000 rule, without CIDR, prefix-list or self admission. Duplicates collapse. An empty list preserves the previous resource configuration; byte-identical plans were not executed.
+- **Replacement:** extra groups affect inline ingress only. The primary group still determines the VPC; instance configuration is unchanged. AWS provider v6.0.0 updates ingress in place. This is source verification, not an executed transition plan. [https://raw.githubusercontent.com/hashicorp/terraform-provider-aws/v6.0.0/internal/service/ec2/vpc_security_group.go](https://raw.githubusercontent.com/hashicorp/terraform-provider-aws/v6.0.0/internal/service/ec2/vpc_security_group.go)
+- **Unknown values:** no VPC-check bypass found. Unknown lookup results defer the precondition until apply. Unknown **list length** still prevents constructing `for_each` keys; the documented one-element example has known length. [https://opentofu.org/docs/language/expressions/custom-conditions/](https://opentofu.org/docs/language/expressions/custom-conditions/), [https://opentofu.org/docs/language/meta-arguments/for_each/](https://opentofu.org/docs/language/meta-arguments/for_each/)
+- **Test sensitivity:** the computed-plan test detects ID-keyed iteration by inspection. Admission, malformed-ID and known other-VPC tests exercise their respective guards. Removing `distinct` alone need not fail the duplicate test because the provider also represents security-group IDs as a set.
+
+Census verdicts apply to the reviewed commit:
+
+| Changed unit or envelope | Verdict | Evidence |
+|---|---|---|
+| `infra/modules/pdf-host/main.tf:external` | APPROVED | Lines 5–10, 25–54: operator-supplied groups, VPC precondition; root runtime reads, IAM and instance configuration unchanged. |
+| `infra/modules/pdf-host/variables.tf:external` | APPROVED | Lines 15–23: optional validated list; existing guards retained. |
+| `infra/modules/pdf-host/tests/pdf_host.tftest.hcl:external` | APPROVED | Lines 344–403: mocked tests only; existing tests retained. |
+| `infra/modules/pdf-host/tests/computed.tftest.hcl:external` | APPROVED | Lines 1–21: mocked plan; accepted-legacy disposition appropriate. |
+| `infra/modules/pdf-host/tests/computed/main.tf:external` | APPROVED | Lines 1–13: local fixture using built-in `terraform_data`; no root runtime reads. |
+| `infra/modules/pdf-host` envelope | APPROVED | Changed sources reviewed; init template, outputs and provider requirements unchanged. |
+| `infra/modules/pdf-host/tests` envelope | APPROVED | Both changed test files reviewed. |
+| `infra/modules/pdf-host/tests/computed` envelope | APPROVED | Entire fixture reviewed. |
+
+All five unit digests, five legacy fingerprints, three envelope hashes and the chain seal match.
+
+Module formatting and `git diff --check` passed. `tofu init` failed because the filesystem is read-only; `tofu test` consequently stopped at “Module not installed.” No tests executed, files changed or subagents used.
+
+Fix the P2s without reopening review; recheck the census for changed test files.
+
+**READY AFTER FIXES**
\ No newline at end of file
diff --git a/docs/superpowers/reviews/CODEX-REVIEW-BRIEF-PDF-HOST-CLIENT-GROUPS-FIXES.md b/docs/superpowers/reviews/CODEX-REVIEW-BRIEF-PDF-HOST-CLIENT-GROUPS-FIXES.md
new file mode 100644
index 000000000..697d85a1b
--- /dev/null
+++ b/docs/superpowers/reviews/CODEX-REVIEW-BRIEF-PDF-HOST-CLIENT-GROUPS-FIXES.md
@@ -0,0 +1,3 @@
+# Census check: pdf-host client groups, round 2 P2 fixes (same budget)
+
+Branch `pdf-host-client-groups`, diff from the R2 brief commit to 8664539e3ba5c25da79e8dacb1540e5b6f8650d0. Not a new round. Give APPROVED or REFUSED for each changed census unit and envelope in the re-frozen overlay (`internal/provision/testdata/plan14-root-reads-pdf-host-client-groups.tsv`, card `docs/superpowers/notes/census-proposal-pdf-host-client-groups.md`): only test files and the README changed. One line each on R2's two P2s: resolved, partly or not (P2-1 is partly resolved by design: the controller declined the apply-time negative case with the reason in tests/computed.tftest.hcl; say if you disagree). End with READY or NOT READY. Do not edit files; no subagents.
diff --git a/docs/superpowers/reviews/CODEX-REVIEW-BRIEF-PDF-HOST-CLIENT-GROUPS-R2.md b/docs/superpowers/reviews/CODEX-REVIEW-BRIEF-PDF-HOST-CLIENT-GROUPS-R2.md
new file mode 100644
index 000000000..a233fdd5c
--- /dev/null
+++ b/docs/superpowers/reviews/CODEX-REVIEW-BRIEF-PDF-HOST-CLIENT-GROUPS-R2.md
@@ -0,0 +1,18 @@
+# Review brief: pdf-host additional client groups, round 2 of 3
+
+Repo carlos/platform, branch `pdf-host-client-groups`, commit ef49fa874fd8715021fba4922b34229362d18943. Diff: `origin/main..7d6c4fff7263940d32d5c40a0b395b10a4c368f8` (infra/modules/pdf-host and the census overlay).
+Why: Bill's review of Tito infra #61 (teamtito/carlos-infrastructure PR 61): the module takes one client group, so a console failover to a standby box with its own group needs a hand edit and a targeted apply. The change adds `additional_client_security_group_ids` so both groups are admitted up front.
+
+Check:
+1. Security: the PDF box's ingress stays TCP 3000 from the listed groups only; no CIDR, no self, no widening when the list is empty (byte-identical plan to before for existing callers). Duplicates handled.
+2. Replacement: adding or removing an extra group must be an in-place update of aws_security_group.pdf (inline ingress), never a replacement of the group or the instance; the VPC still comes from the client group. Note any case (e.g. data source for_each over unknown ids at plan time) where plan fails or forces replacement.
+3. The VPC precondition: correct and not bypassable; behaviour when an extra group id is unknown at plan (computed from another module's output in the same apply).
+4. Tests: would each fail without its guard? (The controller removed the precondition and saw the other-VPC test fail.)
+5. README: accurate to the code.
+6. **Census:** `docs/superpowers/notes/census-proposal-pdf-host-client-groups.md` and the overlay: APPROVED or REFUSED per changed unit and envelope.
+
+Severity P1 (blocks) / P2 (fixed without another round) / P3 (follow-up). End with READY, READY AFTER FIXES or NOT READY. Do not edit files; no subagents. `tofu test` in infra/modules/pdf-host is fine if the provider cache allows.
+
+## Round 2
+
+Round 1: `CODEX-FINDINGS-PDF-HOST-CLIENT-GROUPS-R1.md` (one P1: for_each keyed by unknown ids). Rev 2 keys the lookups by list position and adds `tests/computed.tftest.hcl` (a terraform_data-derived id unknown at plan; the controller saw it fail with "Invalid for_each argument" on id keys) and a duplicates test. First one line on R1 P1: resolved, partly, or not. Re-give census verdicts for the re-frozen overlay (two new test files). `tofu init -backend=false` then `tofu test` in infra/modules/pdf-host should work if the provider can download.
diff --git a/docs/superpowers/reviews/CODEX-REVIEW-BRIEF-PDF-HOST-CLIENT-GROUPS.md b/docs/superpowers/reviews/CODEX-REVIEW-BRIEF-PDF-HOST-CLIENT-GROUPS.md
new file mode 100644
index 000000000..907fb4192
--- /dev/null
+++ b/docs/superpowers/reviews/CODEX-REVIEW-BRIEF-PDF-HOST-CLIENT-GROUPS.md
@@ -0,0 +1,14 @@
+# Review brief: pdf-host additional client groups, round 1 of 3
+
+Repo carlos/platform, branch `pdf-host-client-groups`, commit 7d6c4fff7263940d32d5c40a0b395b10a4c368f8. Diff: `origin/main..7d6c4fff7263940d32d5c40a0b395b10a4c368f8` (infra/modules/pdf-host and the census overlay).
+Why: Bill's review of Tito infra #61 (teamtito/carlos-infrastructure PR 61): the module takes one client group, so a console failover to a standby box with its own group needs a hand edit and a targeted apply. The change adds `additional_client_security_group_ids` so both groups are admitted up front.
+
+Check:
+1. Security: the PDF box's ingress stays TCP 3000 from the listed groups only; no CIDR, no self, no widening when the list is empty (byte-identical plan to before for existing callers). Duplicates handled.
+2. Replacement: adding or removing an extra group must be an in-place update of aws_security_group.pdf (inline ingress), never a replacement of the group or the instance; the VPC still comes from the client group. Note any case (e.g. data source for_each over unknown ids at plan time) where plan fails or forces replacement.
+3. The VPC precondition: correct and not bypassable; behaviour when an extra group id is unknown at plan (computed from another module's output in the same apply).
+4. Tests: would each fail without its guard? (The controller removed the precondition and saw the other-VPC test fail.)
+5. README: accurate to the code.
+6. **Census:** `docs/superpowers/notes/census-proposal-pdf-host-client-groups.md` and the overlay: APPROVED or REFUSED per changed unit and envelope.
+
+Severity P1 (blocks) / P2 (fixed without another round) / P3 (follow-up). End with READY, READY AFTER FIXES or NOT READY. Do not edit files; no subagents. `tofu test` in infra/modules/pdf-host is fine if the provider cache allows.
diff --git a/infra/modules/pdf-host/README.md b/infra/modules/pdf-host/README.md
index a19a71803..bd292c43e 100644
--- a/infra/modules/pdf-host/README.md
+++ b/infra/modules/pdf-host/README.md
@@ -2,7 +2,7 @@
This module runs one Gotenberg container on a Debian arm64 EC2 box. The
console sends PDF requests to its private address. TCP 3000 accepts only the
-console's security group. Administration uses SSM Session Manager; the role
+console’s security group and any groups in `additional_client_security_group_ids`. Administration uses SSM Session Manager; the role
explicitly denies every SSM parameter read and has no bucket grants.
```hcl
@@ -22,6 +22,20 @@ pass `subnet_id` in the client security group's VPC. The subnet needs internet
access for packages, the image and public page assets. It must provide a private
IPv4 address; IPv6-only subnets are unsupported.
+## A standby console
+
+Allow both security groups from the start if the console can fail over to a
+standby box. A failover then needs no change here:
+
+```hcl
+ client_security_group_id = module.host_ie.security_group_id
+ additional_client_security_group_ids = [module.standby_ie.security_group_id]
+```
+
+Every additional group must be in the client’s VPC. Adding or removing a group
+changes the ingress rule in place. The box and its private address stay the
+same.
+
## Wiring and replacement
Set the console's `CARLOS_PDF_ADDR` to the module's `pdf_addr` output
@@ -114,8 +128,9 @@ the results for the deployment.
the output: a successful PDF response alone does not prove a blocked fetch.
2. Render a page with a public image addressed by hostname. It must load.
Check DNS over both UDP and TCP to the VPC resolver.
-3. Confirm Session Manager opens a session. Check that the console can reach
- port 3000 and a box outside its security group cannot.
+3. Confirm Session Manager opens a session. Check that the console, and a box
+ in each additional client group, can reach port 3000, and that a box in
+ none of those groups cannot.
4. Restart Docker and reboot the box. Repeat the fetch checks and verify the
fence is active before the container starts. In a controlled acceptance
test, force the fence loader's nft invocation to fail, then separately make
diff --git a/infra/modules/pdf-host/main.tf b/infra/modules/pdf-host/main.tf
index 74b181dd7..fad0c9a89 100644
--- a/infra/modules/pdf-host/main.tf
+++ b/infra/modules/pdf-host/main.tf
@@ -2,6 +2,13 @@ data "aws_security_group" "client" {
id = var.client_security_group_id
}
+data "aws_security_group" "additional_client" {
+ # Keyed by list position, not by id, so an id another resource creates in
+ # the same apply (a new standby console's group) still plans.
+ for_each = { for i, id in var.additional_client_security_group_ids : tostring(i) => id }
+ id = each.value
+}
+
data "aws_vpc" "client" {
id = data.aws_security_group.client.vpc_id
}
@@ -25,7 +32,7 @@ resource "aws_security_group" "pdf" {
from_port = 3000
to_port = 3000
protocol = "tcp"
- security_groups = [var.client_security_group_id]
+ security_groups = distinct(concat([var.client_security_group_id], var.additional_client_security_group_ids))
}
# Packages, the image and public assets. Administration uses Session Manager.
@@ -37,6 +44,13 @@ resource "aws_security_group" "pdf" {
}
tags = { Name = var.name }
+
+ lifecycle {
+ precondition {
+ condition = alltrue([for g in data.aws_security_group.additional_client : g.vpc_id == data.aws_security_group.client.vpc_id])
+ error_message = "Every additional client security group must be in the client group's VPC; a group in another VPC cannot reach the PDF host."
+ }
+ }
}
resource "aws_iam_role" "pdf" {
diff --git a/infra/modules/pdf-host/tests/computed.tftest.hcl b/infra/modules/pdf-host/tests/computed.tftest.hcl
new file mode 100644
index 000000000..25c7a9ca5
--- /dev/null
+++ b/infra/modules/pdf-host/tests/computed.tftest.hcl
@@ -0,0 +1,40 @@
+# Mock resources only: this suite never contacts an AWS account.
+mock_provider "aws" {}
+
+override_data {
+ target = module.pdf.data.aws_security_group.client
+ values = { vpc_id = "vpc-0aaaaaaaaaaaaaaaa" }
+}
+
+override_data {
+ target = module.pdf.data.aws_vpc.client
+ values = { default = true }
+}
+
+# A standby group the same apply creates has no id at plan time; keying the
+# lookups by id would fail to plan.
+run "a_standby_group_created_in_the_same_apply_plans" {
+ command = plan
+ module {
+ source = "./tests/computed"
+ }
+}
+
+# Applied: the id becomes known during apply and the lookup then finds the
+# group in the client's VPC, so the ingress admits it.
+run "a_computed_standby_group_in_the_client_vpc_applies" {
+ command = apply
+ module {
+ source = "./tests/computed"
+ }
+ override_data {
+ target = module.pdf.data.aws_security_group.additional_client
+ values = { vpc_id = "vpc-0aaaaaaaaaaaaaaaa" }
+ }
+}
+
+# Not tested here: a computed id that resolves to another VPC at apply. The
+# precondition on aws_security_group.pdf refuses it (pdf_host.tftest.hcl,
+# a_standby_group_in_another_vpc_is_refused, with a known id), but
+# expect_failures cannot name an object inside module.pdf, so a failing apply
+# through this fixture cannot be asserted.
diff --git a/infra/modules/pdf-host/tests/computed/main.tf b/infra/modules/pdf-host/tests/computed/main.tf
new file mode 100644
index 000000000..2df4511c6
--- /dev/null
+++ b/infra/modules/pdf-host/tests/computed/main.tf
@@ -0,0 +1,13 @@
+# Test fixture: a standby group id that is unknown at plan time, as when the
+# same apply creates the standby console's group. terraform_data is built in,
+# so the mock provider does not fill its id in at plan.
+resource "terraform_data" "standby" {}
+
+module "pdf" {
+ source = "../.."
+ name = "carlos-test-pdf"
+ ami_id = "ami-0123456789abcdef0"
+ client_security_group_id = "sg-0123456789abcdef0"
+ additional_client_security_group_ids = ["sg-${substr(replace(terraform_data.standby.id, "-", ""), 0, 17)}"]
+ region = "eu-west-1"
+}
diff --git a/infra/modules/pdf-host/tests/pdf_host.tftest.hcl b/infra/modules/pdf-host/tests/pdf_host.tftest.hcl
index c06430366..6b6529670 100644
--- a/infra/modules/pdf-host/tests/pdf_host.tftest.hcl
+++ b/infra/modules/pdf-host/tests/pdf_host.tftest.hcl
@@ -340,3 +340,64 @@ run "memory_at_or_above_minimum_1G" {
memory_max = "1G"
}
}
+
+run "a_standby_group_is_admitted_too" {
+ command = plan
+ variables {
+ additional_client_security_group_ids = ["sg-0fedcba9876543210"]
+ }
+ override_data {
+ target = data.aws_security_group.additional_client
+ values = { vpc_id = "vpc-0aaaaaaaaaaaaaaaa" }
+ }
+ assert {
+ condition = alltrue([
+ for i in aws_security_group.pdf.ingress :
+ i.from_port == 3000 && i.to_port == 3000 && i.protocol == "tcp"
+ && i.security_groups == toset([var.client_security_group_id, "sg-0fedcba9876543210"])
+ ])
+ error_message = "TCP 3000 from the client group and the standby group only"
+ }
+ assert {
+ condition = length(aws_security_group.pdf.ingress) == 1 && aws_security_group.pdf.vpc_id == "vpc-0aaaaaaaaaaaaaaaa"
+ error_message = "one ingress rule, in the client's VPC"
+ }
+}
+
+run "a_standby_group_in_another_vpc_is_refused" {
+ command = plan
+ variables {
+ additional_client_security_group_ids = ["sg-0fedcba9876543210"]
+ }
+ override_data {
+ target = data.aws_security_group.additional_client
+ values = { vpc_id = "vpc-0bbbbbbbbbbbbbbbb" }
+ }
+ expect_failures = [aws_security_group.pdf]
+}
+
+run "a_malformed_additional_group_is_refused" {
+ command = plan
+ variables {
+ additional_client_security_group_ids = ["not-a-group"]
+ }
+ expect_failures = [var.additional_client_security_group_ids]
+}
+
+run "duplicate_groups_make_one_rule" {
+ command = plan
+ variables {
+ additional_client_security_group_ids = ["sg-0123456789abcdef0", "sg-0fedcba9876543210", "sg-0fedcba9876543210"]
+ }
+ override_data {
+ target = data.aws_security_group.additional_client
+ values = { vpc_id = "vpc-0aaaaaaaaaaaaaaaa" }
+ }
+ assert {
+ condition = alltrue([
+ for i in aws_security_group.pdf.ingress :
+ i.security_groups == toset([var.client_security_group_id, "sg-0fedcba9876543210"])
+ ])
+ error_message = "duplicates collapse to one entry per group"
+ }
+}
diff --git a/infra/modules/pdf-host/variables.tf b/infra/modules/pdf-host/variables.tf
index 991478266..6a1cc28c4 100644
--- a/infra/modules/pdf-host/variables.tf
+++ b/infra/modules/pdf-host/variables.tf
@@ -12,6 +12,16 @@ variable "client_security_group_id" {
type = string
}
+variable "additional_client_security_group_ids" {
+ description = "more security groups that may reach the engine, such as a failover standby console's; each must be in the client group's VPC"
+ type = list(string)
+ default = []
+ validation {
+ condition = alltrue([for id in var.additional_client_security_group_ids : can(regex("^sg-[0-9a-f]+$", id))])
+ error_message = "additional_client_security_group_ids must hold security group ids (sg-...)."
+ }
+}
+
variable "region" {
type = string
validation {
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv
index 431df369d..667bc41bd 100644
--- a/internal/provision/testdata/plan14-root-reads-chain.tsv
+++ b/internal/provision/testdata/plan14-root-reads-chain.tsv
@@ -214,3 +214,4 @@ plan14-root-reads-replica-console-account.tsv 87e151a55efb12fb84e9c5939f2ead9058
plan14-root-reads-offline-move-pool-target-413.tsv f79b455e32eb0f63e19ba8b5c67129e1af9315b8650c9e0807e83ec630a82182
plan14-root-reads-probe-burst-block.tsv 94ccbabaf19c3a449cec248a0c32fcc8593c82d3f7f433c6a48b6e0fdf068167
plan14-root-reads-g6-pool.tsv 94ccbabaf19c3a449cec248a0c32fcc8593c82d3f7f433c6a48b6e0fdf068167
+plan14-root-reads-pdf-host-client-groups.tsv e8beda8fd31db92f742943be631e8d034bbb4880225e69a680d5a0be893807af
diff --git a/internal/provision/testdata/plan14-root-reads-pdf-host-client-groups.tsv b/internal/provision/testdata/plan14-root-reads-pdf-host-client-groups.tsv
new file mode 100644
index 000000000..34091ad89
--- /dev/null
+++ b/internal/provision/testdata/plan14-root-reads-pdf-host-client-groups.tsv
@@ -0,0 +1,16 @@
+# Census overlay pdf-host-client-groups, written by census-propose (#369). census-ruling-pdf-host-client-groups, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-pdf-host-client-groups.md.
+# 3 body, 0 sites, 3 envelope: each changed unit re-frozen at its existing disposition with its claim appended.
+# 2 new dispositions: 0 reads re-frozen at their disposition with the claim, 2 new units frozen accepted-legacy, 0 quiet units retired while they read nothing, 0 other.
+@legacy 8a804e7e3952090697a720d736271534584ea2cd7a7d3020cc3067cd2465cecd infra/modules/pdf-host/main.tf external legacy accepted-legacy accepted-legacy;rev3=census-ruling-design-pdf-service;basis=OpenTofu module source defining the PDF engine box, security group and SSM-only role; never read by the CARLOS root binary or a box agent at runtime;rev3=census-ruling-pdf-host-client-groups;basis=Adds data.aws_security_group.additional_client keyed by list position and admits those groups on TCP 3000 beside the client group; a precondition refuses a group outside the client VPC. No new root read; box, role and fence unchanged. file:external@0 f1ef25887bfd03723c2ddf44ec320be3d6c1f036f14e11f98eb35d2ff126564b
+@legacy 67f33858a38ec41297f11570ee2d09e5b0f7458cf8f6a3071a05e5f2b5e5cd18 infra/modules/pdf-host/tests/pdf_host.tftest.hcl external legacy accepted-legacy accepted-legacy;rev3=census-ruling-design-pdf-service;basis=mock-provider tests cover loopback names, mapped IPv6 and userinfo, case-insensitive HTTP, public hostname boundaries and the case-sensitive file exemption; retain private engine-port, metadata/fence retry and Docker memory checks; no live infrastructure calls; never read by the CARLOS root binary or a box agent at runtime;rev3=census-ruling-pdf-host-client-groups;basis=Mock tests: standby admitted, other-VPC refused, malformed refused, duplicates collapse. file:external@0 1cd88edf2dba5596d01f08399320dfdf08d15771739f7aea54014201445b9dcc
+@legacy d5092db2c1fcecf245d4d50eee818593ceb87ec2b25a5d1fc6525b0288348881 infra/modules/pdf-host/variables.tf external legacy accepted-legacy accepted-legacy;rev3=census-ruling-design-pdf-service;basis=OpenTofu module inputs now reject memory_max below 6 MiB while retaining whole MiB/GiB validation; never read by the CARLOS root binary or a box agent at runtime;rev3=census-ruling-pdf-host-client-groups;basis=New optional input additional_client_security_group_ids (list of sg ids, default empty, validated). No new read. file:external@0 aa6b7ecfd8f82491063afc57fab57d8017c5e80fdf9fbfe1e504fdcc929f10b9
+@legacy 7a302e51457005ba6e532f9bf83061b9720a0f3d246346bd470419fcab3237f7 infra/modules/pdf-host/tests/computed.tftest.hcl external legacy accepted-legacy accepted-legacy;rev3=census-ruling-pdf-host-client-groups;basis=Mock tests: an id unknown at plan plans, and applies when its group is in the client VPC. file:external@0 bedd502818895172f07af2ec8219bf03d8aaedfa4643435564629370f728be63
+@legacy 7e1238cb57b876ebcd16b0e6b3b3024437052182021efae074a6b1778b475bdb infra/modules/pdf-host/tests/computed/main.tf external legacy accepted-legacy accepted-legacy;rev3=census-ruling-pdf-host-client-groups;basis=Test fixture (terraform_data plus the pdf-host module). file:external@0 bc4980c006b6fd2028a0b24827262eb6d48d899b21b7757308dfe24ec7fcd8e2
+infra/modules/pdf-host/main.tf external legacy accepted-legacy accepted-legacy;rev3=census-ruling-design-pdf-service;basis=OpenTofu module source defining the PDF engine box, security group and SSM-only role; never read by the CARLOS root binary or a box agent at runtime;rev3=census-ruling-pdf-host-client-groups;basis=Adds data.aws_security_group.additional_client keyed by list position and admits those groups on TCP 3000 beside the client group; a precondition refuses a group outside the client VPC. No new root read; box, role and fence unchanged. file:external@0 f1ef25887bfd03723c2ddf44ec320be3d6c1f036f14e11f98eb35d2ff126564b
+infra/modules/pdf-host/tests/pdf_host.tftest.hcl external legacy accepted-legacy accepted-legacy;rev3=census-ruling-design-pdf-service;basis=mock-provider tests cover loopback names, mapped IPv6 and userinfo, case-insensitive HTTP, public hostname boundaries and the case-sensitive file exemption; retain private engine-port, metadata/fence retry and Docker memory checks; no live infrastructure calls; never read by the CARLOS root binary or a box agent at runtime;rev3=census-ruling-pdf-host-client-groups;basis=Mock tests: standby admitted, other-VPC refused, malformed refused, duplicates collapse. file:external@0 1cd88edf2dba5596d01f08399320dfdf08d15771739f7aea54014201445b9dcc
+infra/modules/pdf-host/variables.tf external legacy accepted-legacy accepted-legacy;rev3=census-ruling-design-pdf-service;basis=OpenTofu module inputs now reject memory_max below 6 MiB while retaining whole MiB/GiB validation; never read by the CARLOS root binary or a box agent at runtime;rev3=census-ruling-pdf-host-client-groups;basis=New optional input additional_client_security_group_ids (list of sg ids, default empty, validated). No new read. file:external@0 aa6b7ecfd8f82491063afc57fab57d8017c5e80fdf9fbfe1e504fdcc929f10b9
+infra/modules/pdf-host/tests/computed.tftest.hcl external legacy accepted-legacy accepted-legacy;rev3=census-ruling-pdf-host-client-groups;basis=Mock tests: an id unknown at plan plans, and applies when its group is in the client VPC. file:external@0 bedd502818895172f07af2ec8219bf03d8aaedfa4643435564629370f728be63
+infra/modules/pdf-host/tests/computed/main.tf external legacy accepted-legacy accepted-legacy;rev3=census-ruling-pdf-host-client-groups;basis=Test fixture (terraform_data plus the pdf-host module). file:external@0 bc4980c006b6fd2028a0b24827262eb6d48d899b21b7757308dfe24ec7fcd8e2
+@coverage infra/modules/pdf-host 8d41c67e2552b7211d3e9e0e3bdd11193eb67704a384325e14eae8969e15c3f0
+@coverage infra/modules/pdf-host/tests 8556d57d593d24db65354d993bac318c0c6a671fe8c8bb1ff1bc2c9d9d7c7ad0
+@coverage infra/modules/pdf-host/tests/computed 9f592e3a8533e06e37f0890064231cd49c66c4322e9135d373242f837bbd4c88