region HA P3b: whole-branch review round 1 fixes
Preserve fixed-box startup and exact-alias behavior, retain scoped SNS alert delivery, bound group reader retries, and publish ingress boot parameters from the regional NLB addresses.
Co-Authored-By: GPT-6 Astra (codex) <noreply@openai.com>
infra/modules/region-host/group.tf+9 −1infra/modules/region-host/group_alarms.tf+33 −7infra/modules/region-host/outputs.tf+1 −1infra/modules/region-host/tests/group.tftest.hcl+11 −1infra/modules/region-host/tests/group_alarms.tftest.hcl+49 −2internal/edgesfile/nameauthority.go+4 −3internal/edgesfile/nameauthority_test.go+25 −0internal/host/edgesfile.go+1 −1internal/host/edgesschedule.go+12 −1internal/host/edgesschedule_test.go+60 −0internal/host/group_boot.go+3 −3internal/host/group_fixed_entry_test.go+78 −0
CI failed — run details
Intent
<task-notification> <task-id>bbx7ho0jg</task-id> <tool-use-id>toolu_01P5kEE3MFecu3ck45przmoS</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/05c816f1-0a2d-43e3-9285-de8352549786/tasks/bbx7ho0jg.output</output-file> <status>completed</status> <summary>Background command "D=/home/paulca/amadan.net/carlos/platform/.claude/worktrees/region-ha-p3b-build/.superpowers/sdd/2026-11-04-region-ha-p3b-group; $D/wait-astra.sh mc $D/merge-copy-report.md" completed (exit code 0)</summary> </task-notification>
<task-notification> <task-id>ac38250d30e33464a</task-id> <tool-use-id>toolu_01GL8JGuQ4tRfnpUg17YWyBC</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/05c816f1-0a2d-43e3-9285-de8352549786/tasks/ac38250d30e33464a.output</output-file> <status>completed</status> <summary>Agent "Branch review A: names, gate, metrics" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>Verdict for area A: **READY AFTER FIXES**, with 0 P1, 1 P2 and 6 P3. The full review is in `/home/paulca/amadan.net/carlos/platform/.claude/worktrees/region-ha-p3b-build/.superpowers/sdd/2026-11-04-region-ha-p3b-group/branch-review-r1-A.md`. **Fixed boxes:** with no group present, the flagship's behaviour is unchanged on every path in my area. - **Edges file:** the only byte change is the added `names-2` capability, which causes one republish per box after the roll. - **Name resolution:** for boxes without admission fields, the peer fold, home election, `ExactHome`/`Owner` and `DeploymentRoutesComplete` all pick the same winner as before. - **Update gate:** it does nothing until a group has been seen. - **Metrics and listeners:** the fixed metrics client and its inputs are unchanged, and the listener wrapper returns the original listener on a fixed box. For sophie and leo, the changes are the ones Task 1 intends: a closed owner keeps its name (503), hops and door calls to a held name get 503, and their own exact aliases are now ranked against peers' claims. **P2-1** (`internal/edgesfile/nameauthority.go:629-682`): - **Problem:** the "admission-aware" flag is set from wildcard catch-all claims even when an exact claim decides the name. So one unrelated catch-all from an admission-aware box switches off the rule that a legacy box always serves its own exact alias. - **New evidence:** the ledger closed this as T1 P3-c on the basis that it only happens in group mode. That isn't true: sophie and leo already publish admission fields today, so other dev boxes are exposed as soon as this release rolls, with or without a group. - **Confirmed:** a scratch overlay test (since deleted) showed the local alias switching to a backhaul to the peer once the unrelated catch-all is present. - **Impact:** it's not unsafe (no ping-pong), but it is a behaviour change on today's fleet that nothing justifies. - **Fix:** compute that flag only from the claims actually used, and add the case as a regression test. **P3 follow-ups** (no further round): 1. `homeEntry.routeExists` is written but never read. 2. `KnownHost` now also allows certificate requests for names held by a closed box with no address, which contradicts its doc comment. 3. A group box whose first edges publication is refused (readers not ready) can then wait up to 300s before retrying, eating into the 900s launch-hook deadline. Suggest capping that retry at about 30s. 4. Card: group boxes publish no memory or clock metrics unless `CARLOS_HOST_METRICS=cloudwatch` is in the SSM settings. Without it, every group alarm fires on missing data at launch. 5. Card: the release pin for the first `names-2` release is empty by design. So while any group edges file exists, every fixed box refuses all system updates, forward ones included, until those `g-*` files are deleted. 6. Card: main's P2b-1 capacity code (merged into this branch) automatically counts group boxes as capacity and as places to put new instances. The card should say whether new instances may land on them during the first-service window. **Deferred list:** none of the ledger's deferred P3s needs to become P2 except T1 P3-c (now P2-1). I also confirmed that T1 P3-b covers the time before the edge's first fold, when the update gate sees an empty snapshot. It stays a Task 8 preflight item. **Cross-area boundaries:** checked and consistent. - The reader-readiness check behind the first publication and the launch CONTINUE runs in the same process as the edge cache it reads. - Metric names and dimensions match the alarms in `group_alarms.tf`. - Merging main's P2b-1 is compatible: capacity checks capabilities by membership, and the console and host derive group references identically.</result> <usage><subagent_tokens>207339</subagent_tokens><tool_uses>58</tool_uses><duration_ms>703040</duration_ms></usage> </task-notification>
<task-notification> <task-id>a7e06e107f2503c06</task-id> <tool-use-id>toolu_01DRpCVx6B1tSmC3oUgU1eAk</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/05c816f1-0a2d-43e3-9285-de8352549786/tasks/a7e06e107f2503c06.output</output-file> <status>completed</status> <summary>Agent "Branch review B: boot, admission, guard" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>**Verdict for area B: READY AFTER FIXES.** One P1 must be fixed before merge; it is a one-line change plus a test, with no new review round. I found 0 P2 and 4 P3. **P1-1: a fixed box can stop starting its agent.** A new check refuses to start the agent when admission is on (`CARLOS_GROUP_ADMISSION=1`) but either `CARLOS_HIBERNATE_BUCKET` or `CARLOS_HIBERNATE_REGION` is unset. It runs before the code asks whether the box is a group box, so fixed boxes hit it too (`group_boot.go:22-25`). - **Where it bites:** the agent at start (`agent.go:236-239`), bootstrap on `/`, and `system install-channel`. On a fixed box the agent would crash-loop. - **Evidence:** main has no such check, and `CARLOS_HIBERNATE_REGION` is documented as optional. I ran one focused probe test and it rejects a fixed environment with admission on and no hibernate region. The only existing test of the rule uses a group box, so the intent was group-only. - **Exposure:** sophie and leo are probably safe, because the infrastructure repo's `bootstrap-box.sh` writes both variables. I could not check their live host.env without AWS. - **Fix:** move the hibernation check below the "is this a group box" return. Group boxes are still covered, because the group host.env assembly already requires both values to match the marker. Add a fixed-box test that must pass. **P3 items (none block merge):** - **P3-1:** the root adopt passes stay armed on group boxes and are not admission-aware. Two of their calls can start a stopped tenant unit on a closed member. This is unreachable today: it needs unit-backing columns that reconcile never writes, so an operator would have to stamp them by hand on the member. It belongs in the runbook, plus a refusal before G2. - **P3-2:** the group drop-in's `Requires=nftables.service` carries an explicit nftables restart through to `carlos-edge`, bypassing the permit guard. Only an operator or a hand-run apt could trigger it. Add a runbook line. - **P3-3:** a repair through `carlos adopt` uses up the operator's permit and then fails. The adopt units have no netlink access, so clearing the hairpin fails. This extends the ledger's existing "Task 7 netlink" item. - **P3-4:** departure work on fixed boxes now stops early on a cancelled context. The outcome is the same; I recorded it so the fixed-box audit is complete. Fixed-box byte identity holds apart from P1-1 and P3-4, across admission, the address readers, `system apply`, unit repair, bootstrap, install-channel and host-env write. The three area packages also build for darwin and windows. None of the deferred P3 items in the ledger needs fixing before a dormant merge. The full report, with evidence and the integration checks, is at `/home/paulca/amadan.net/carlos/platform/.claude/worktrees/region-ha-p3b-build/.superpowers/sdd/2026-11-04-region-ha-p3b-group/branch-review-r1-B.md`.</result> <usage><subagent_tokens>238178</subagent_tokens><tool_uses>74</tool_uses><duration_ms>817031</duration_ms></usage> </task-notification>
<task-notification> <task-id>ae8736b3b1d0dee5e</task-id> <tool-use-id>toolu_01Brdi1wZiBeNQ1rC2Rjy8QB</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/05c816f1-0a2d-43e3-9285-de8352549786/tasks/ae8736b3b1d0dee5e.output</output-file> <status>completed</status> <summary>Agent "Branch review C: infra and hairpin" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>**Area C verdict: READY AFTER FIXES.** 0 P1, 1 P2, 4 P3. Nothing fell in the hairpin trust boundary, so stopping rule 2 is not triggered. The full report is in `/home/paulca/amadan.net/carlos/platform/.claude/worktrees/region-ha-p3b-build/.superpowers/sdd/2026-11-04-region-ha-p3b-group/branch-review-r1-C.md`. **P2-1, Task 6 alarms: group alarm emails would likely never be sent.** - `aws_sns_topic_policy.group_launch_failed` (`group_alarms.tf:145`) replaces the alerts topic's default policy with a single `events.amazonaws.com` publish statement. - That default policy is what lets same-account CloudWatch alarms publish to the topic. Without it, the capacity, memory, clock, clock-missing and termination-queue-age alarms can no longer send. The memory alarm is the D3 memory-headroom witness. - The statement also has no source condition, so any account's EventBridge rule could publish to the topic. - This rests on how AWS documents the default policy, not on a live test. - Fix: restore the owner statement, add a CloudWatch statement limited to this account's alarms, and limit the EventBridge statement to the launch-failed rule. Add tests for all three, and send one test alarm to the inbox on the switch-on card. - Fixed mode is unaffected; this only bites at group switch-on. **P3s (follow-up list):** 1. On group boxes the whole instance-control probe now runs under the hairpin lock's 60-second limit and holds the lock throughout. A probe that runs past 60 seconds fails readiness. If it also overlaps admission, enabling the hairpin can time out and the box closes permanently. The probe image is small, so the risk is low. 2. The `boot/ingress` SSM value is seeded by hand, though tofu already knows the addresses and already writes the queue URL. tofu should write it too. 3. The edge's `Requires=nftables.service` means a root nftables restart also restarts the edge without a Task 4 permit, and briefly flushes the hairpin fence. It needs a runbook line: never restart nftables on a group box. 4. The group memory and clock-presence alarms only see the group aggregate. A live member that stops publishing is hidden by the other member's data. **Ledger follow-ups:** none needs fixing before merge. CI not running the tofu and plan-gate tests (T2 P3-1) should be done before switch-on. The main merge already caused one silent plan-gate regression that was caught only by hand. **Checked and sound:** - **Fixed-box identity:** sophie and leo on v0.34.1 see no change to #367 deny generation, units or nft state. Everything hairpin-related does nothing without the group marker. - **Fixed-mode plan:** dev and flagship plans stay byte-identical. The installed OpenTofu 1.12.5 validates the module at the tip. - **Group IAM:** the allow/deny composition holds, including the SSM managed policy. - **Boot ordering:** it runs in the order the brief requires. - **Hairpin invariant:** only TCP 80 and 443 are reachable on an ingress EIP. The fence is in place before any EIP is assigned, the exemption is re-checked before it applies, and it is withdrawn on any failure. - **Integration:** the boundaries with admission, Task 4 permits, metrics and the boot queue match. My scratch copy of the module has been deleted.</result> <usage><subagent_tokens>246603</subagent_tokens><tool_uses>69</tool_uses><duration_ms>983666</duration_ms></usage> </task-notification>
Attributed to this commit: 19.0 g CO₂e (2,355,394 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on region-ha-p3b-build, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.
diff --git a/infra/modules/region-host/group.tf b/infra/modules/region-host/group.tf| index c8db13566..d56876b17 100644 |
| --- a/infra/modules/region-host/group.tf |
| +++ b/infra/modules/region-host/group.tf |
| @@ -244,7 +244,7 @@ resource "aws_autoscaling_group" "group" { |
| aws_iam_role_policy.host_route53, aws_iam_role_policy.host_steering, |
| aws_iam_role_policy.host_metrics, aws_iam_role_policy.host_terminations, |
| aws_iam_role_policy_attachment.host_ssm, aws_sqs_queue_policy.terminations, |
| - aws_cloudwatch_event_target.terminations, aws_ssm_parameter.group_queue, |
| + aws_cloudwatch_event_target.terminations, aws_ssm_parameter.group_queue, aws_ssm_parameter.group_ingress, |
| ] |
| } |
| @@ -256,6 +256,14 @@ resource "aws_ssm_parameter" "group_queue" { |
| tags = local.group_tags |
| } |
| +resource "aws_ssm_parameter" "group_ingress" { |
| + count = local.group_enabled ? 1 : 0 |
| + name = "${local.group_ssm_path}/boot/ingress" |
| + type = "String" |
| + value = jsonencode(values(local.group_ingress.public_ips)) |
| + tags = local.group_tags |
| +} |
| + |
| # Only these fixed resources need addresses changed to support mode selection. |
| moved { |
| from = aws_instance.host |
diff --git a/infra/modules/region-host/group_alarms.tf b/infra/modules/region-host/group_alarms.tf| index 0ef73c423..f2c0967ea 100644 |
| --- a/infra/modules/region-host/group_alarms.tf |
| +++ b/infra/modules/region-host/group_alarms.tf |
| @@ -147,12 +147,38 @@ resource "aws_sns_topic_policy" "group_launch_failed" { |
| arn = aws_sns_topic.alerts[0].arn |
| policy = jsonencode({ |
| Version = "2012-10-17" |
| - Statement = [{ |
| - Sid = "GroupLaunchFailure" |
| - Effect = "Allow" |
| - Principal = { Service = "events.amazonaws.com" } |
| - Action = "sns:Publish" |
| - Resource = aws_sns_topic.alerts[0].arn |
| - }] |
| + Statement = [ |
| + { |
| + Sid = "OwnerAccess" |
| + Effect = "Allow" |
| + Principal = { AWS = "*" } |
| + Action = [ |
| + "sns:GetTopicAttributes", "sns:SetTopicAttributes", "sns:AddPermission", |
| + "sns:RemovePermission", "sns:DeleteTopic", "sns:Subscribe", |
| + "sns:ListSubscriptionsByTopic", "sns:Publish", |
| + ] |
| + Resource = aws_sns_topic.alerts[0].arn |
| + Condition = { StringEquals = { "AWS:SourceOwner" = data.aws_caller_identity.current.account_id } } |
| + }, |
| + { |
| + Sid = "GroupAlarmPublish" |
| + Effect = "Allow" |
| + Principal = { Service = "cloudwatch.amazonaws.com" } |
| + Action = "sns:Publish" |
| + Resource = aws_sns_topic.alerts[0].arn |
| + Condition = { |
| + StringEquals = { "aws:SourceAccount" = data.aws_caller_identity.current.account_id } |
| + ArnLike = { "aws:SourceArn" = "arn:${data.aws_partition.current[0].partition}:cloudwatch:${data.aws_region.current.region}:${data.aws_caller_identity.current.account_id}:alarm:*" } |
| + } |
| + }, |
| + { |
| + Sid = "GroupLaunchFailure" |
| + Effect = "Allow" |
| + Principal = { Service = "events.amazonaws.com" } |
| + Action = "sns:Publish" |
| + Resource = aws_sns_topic.alerts[0].arn |
| + Condition = { ArnEquals = { "aws:SourceArn" = aws_cloudwatch_event_rule.group_launch_failed[0].arn } } |
| + }, |
| + ] |
| }) |
| } |
diff --git a/infra/modules/region-host/outputs.tf b/infra/modules/region-host/outputs.tf| index a59fd62cc..f5a136a36 100644 |
| --- a/infra/modules/region-host/outputs.tf |
| +++ b/infra/modules/region-host/outputs.tf |
| @@ -68,7 +68,7 @@ output "group_boot_parameters" { |
| value = var.mode == "group" ? { |
| bootstrap_object = "${local.group_ssm_path}/boot/bootstrap-object" |
| bootstrap_sha256 = "${local.group_ssm_path}/boot/bootstrap-sha256" |
| - ingress = "${local.group_ssm_path}/boot/ingress" |
| + ingress = aws_ssm_parameter.group_ingress[0].name |
| termination_queue_url = aws_ssm_parameter.group_queue[0].name |
| } : null |
| } |
diff --git a/infra/modules/region-host/tests/group.tftest.hcl b/infra/modules/region-host/tests/group.tftest.hcl| index 1f6342f94..43dfb0936 100644 |
| --- a/infra/modules/region-host/tests/group.tftest.hcl |
| +++ b/infra/modules/region-host/tests/group.tftest.hcl |
| @@ -181,6 +181,16 @@ run "group_shape" { |
| ) |
| error_message = "group launches must use pinned images, public IPv4, IMDSv2 and disposable encrypted roots" |
| } |
| + assert { |
| + condition = try( |
| + length(aws_ssm_parameter.group_ingress) == 1 && |
| + aws_ssm_parameter.group_ingress[0].name == "/carlos/dev/ie/boot/ingress" && |
| + output.group_boot_parameters.ingress == aws_ssm_parameter.group_ingress[0].name && |
| + aws_ssm_parameter.group_ingress[0].type == "String" && |
| + jsondecode(nonsensitive(aws_ssm_parameter.group_ingress[0].value)) == ["198.51.100.10", "198.51.100.11"] && |
| + aws_ssm_parameter.group_ingress[0].tags == tomap({ "carlos:deployment" = "dev", "carlos:region" = "ie" }), false) |
| + error_message = "the group must own boot/ingress as the regional ingress IPv4 JSON array" |
| + } |
| assert { |
| condition = ( |
| aws_sqs_queue.terminations.name == "carlos-dev-ie-group-terminations" && |
| @@ -373,7 +383,7 @@ run "new_ingress_owner" { |
| } |
| } |
| assert { |
| - condition = length(module.group_ingress) == 1 && length(data.aws_lb.group) == 0 && aws_autoscaling_group.group[0].target_group_arns == toset(values(module.group_ingress[0].target_group_arns)) |
| + condition = try(jsondecode(nonsensitive(aws_ssm_parameter.group_ingress[0].value)) == ["198.51.100.10", "198.51.100.11"], false) && length(module.group_ingress) == 1 && length(data.aws_lb.group) == 0 && aws_autoscaling_group.group[0].target_group_arns == toset(values(module.group_ingress[0].target_group_arns)) |
| error_message = "new ingress must have one child owner and attach the group directly" |
| } |
| } |
diff --git a/infra/modules/region-host/tests/group_alarms.tftest.hcl b/infra/modules/region-host/tests/group_alarms.tftest.hcl| index 69db294b3..50bea336a 100644 |
| --- a/infra/modules/region-host/tests/group_alarms.tftest.hcl |
| +++ b/infra/modules/region-host/tests/group_alarms.tftest.hcl |
| @@ -62,7 +62,7 @@ override_resource { |
| run "termination_alarm_default_off" { |
| command = plan |
| assert { |
| - condition = length(aws_cloudwatch_metric_alarm.termination_queue_age) == 0 && length(aws_cloudwatch_metric_alarm.group_capacity) == 0 && length(aws_cloudwatch_metric_alarm.group_memory) == 0 && length(aws_cloudwatch_metric_alarm.group_clock) == 0 && length(aws_cloudwatch_metric_alarm.group_clock_missing) == 0 && length(aws_cloudwatch_event_rule.group_launch_failed) == 0 |
| + condition = length(aws_ssm_parameter.group_ingress) == 0 && length(aws_sns_topic_policy.group_launch_failed) == 0 && length(aws_cloudwatch_metric_alarm.termination_queue_age) == 0 && length(aws_cloudwatch_metric_alarm.group_capacity) == 0 && length(aws_cloudwatch_metric_alarm.group_memory) == 0 && length(aws_cloudwatch_metric_alarm.group_clock) == 0 && length(aws_cloudwatch_metric_alarm.group_clock_missing) == 0 && length(aws_cloudwatch_event_rule.group_launch_failed) == 0 |
| error_message = "fixed plans must not gain a termination queue alarm by default" |
| } |
| } |
| @@ -232,9 +232,56 @@ run "group_alarm_producers" { |
| error_message = "alarm dimensions and metric names must match the actual producers" |
| } |
| assert { |
| - condition = split(":", aws_sns_topic.alerts[0].arn)[3] == data.aws_region.current.region && jsondecode(aws_cloudwatch_event_rule.group_launch_failed[0].event_pattern) == { source = ["aws.autoscaling"], "detail-type" = ["EC2 Instance Launch Unsuccessful"], detail = { AutoScalingGroupName = [aws_autoscaling_group.group[0].name] } } && aws_cloudwatch_event_target.group_launch_failed[0].arn == aws_sns_topic.alerts[0].arn && jsondecode(aws_sns_topic_policy.group_launch_failed[0].policy).Statement[0].Principal.Service == "events.amazonaws.com" |
| + condition = split(":", aws_sns_topic.alerts[0].arn)[3] == data.aws_region.current.region && jsondecode(aws_cloudwatch_event_rule.group_launch_failed[0].event_pattern) == { source = ["aws.autoscaling"], "detail-type" = ["EC2 Instance Launch Unsuccessful"], detail = { AutoScalingGroupName = [aws_autoscaling_group.group[0].name] } } && aws_cloudwatch_event_target.group_launch_failed[0].arn == aws_sns_topic.alerts[0].arn |
| error_message = "launch failures must notify without filtering provider Cause text" |
| } |
| + assert { |
| + condition = try( |
| + length(jsondecode(aws_sns_topic_policy.group_launch_failed[0].policy).Statement) == 3 && |
| + one([for s in jsondecode(aws_sns_topic_policy.group_launch_failed[0].policy).Statement : s if s.Sid == "OwnerAccess"]) == { |
| + Sid = "OwnerAccess" |
| + Effect = "Allow" |
| + Principal = { AWS = "*" } |
| + Action = ["sns:GetTopicAttributes", "sns:SetTopicAttributes", "sns:AddPermission", "sns:RemovePermission", "sns:DeleteTopic", "sns:Subscribe", "sns:ListSubscriptionsByTopic", "sns:Publish"] |
| + Resource = aws_sns_topic.alerts[0].arn |
| + Condition = { StringEquals = { "AWS:SourceOwner" = "123456789012" } } |
| + }, false) |
| + error_message = "alerts must preserve the default account-owner permissions" |
| + } |
| + assert { |
| + condition = try(one([for s in jsondecode(aws_sns_topic_policy.group_launch_failed[0].policy).Statement : s if s.Sid == "GroupAlarmPublish"]) == { |
| + Sid = "GroupAlarmPublish" |
| + Effect = "Allow" |
| + Principal = { Service = "cloudwatch.amazonaws.com" } |
| + Action = "sns:Publish" |
| + Resource = aws_sns_topic.alerts[0].arn |
| + Condition = { |
| + StringEquals = { "aws:SourceAccount" = "123456789012" } |
| + ArnLike = { "aws:SourceArn" = "arn:aws:cloudwatch:eu-west-1:123456789012:alarm:*" } |
| + } |
| + }, false) |
| + error_message = "CloudWatch publish must be limited to this account and region's alarms" |
| + } |
| + assert { |
| + condition = try(one([for s in jsondecode(aws_sns_topic_policy.group_launch_failed[0].policy).Statement : s if s.Sid == "GroupLaunchFailure"]) == { |
| + Sid = "GroupLaunchFailure" |
| + Effect = "Allow" |
| + Principal = { Service = "events.amazonaws.com" } |
| + Action = "sns:Publish" |
| + Resource = aws_sns_topic.alerts[0].arn |
| + Condition = { ArnEquals = { "aws:SourceArn" = aws_cloudwatch_event_rule.group_launch_failed[0].arn } } |
| + }, false) |
| + error_message = "EventBridge publish must be limited to this group's launch-failed rule" |
| + } |
| + assert { |
| + condition = alltrue([ |
| + for s in jsondecode(aws_sns_topic_policy.group_launch_failed[0].policy).Statement : |
| + try(length(s.Condition) > 0 && (can(s.Condition.ArnEquals["aws:SourceArn"]) || can(s.Condition.ArnLike["aws:SourceArn"])), false) |
| + if can(s.Principal.Service) |
| + ]) |
| + error_message = "service principals must not publish without a source ARN condition" |
| + } |
| + |
| } |
| override_data { |
diff --git a/internal/edgesfile/nameauthority.go b/internal/edgesfile/nameauthority.go| index 098a05e56..b3d7b4488 100644 |
| --- a/internal/edgesfile/nameauthority.go |
| +++ b/internal/edgesfile/nameauthority.go |
| @@ -61,7 +61,6 @@ func NameClassOf(role string, alias bool) NameClass { |
| // retains its children when no serving catch-all claims them. |
| func ResolveNameAuthority(name string, local []NameClaim, peers []NameClaim) NameResolution { |
| var exact, fallback []NameClaim |
| - aware := false |
| wildcard := "" |
| if i := strings.IndexByte(name, '.'); i > 0 { |
| wildcard = "*" + name[i:] |
| @@ -73,10 +72,8 @@ func ResolveNameAuthority(name string, local []NameClaim, peers []NameClaim) Nam |
| } |
| if c.Name == name { |
| exact = append(exact, c) |
| - aware = aware || c.AdmissionAware |
| } else if c.Name == wildcard { |
| fallback = append(fallback, c) |
| - aware = aware || c.AdmissionAware |
| } |
| } |
| } |
| @@ -104,6 +101,10 @@ func ResolveNameAuthority(name string, local []NameClaim, peers []NameClaim) Nam |
| if len(claims) == 0 { |
| return NameResolution{} |
| } |
| + aware := false |
| + for _, c := range claims { |
| + aware = aware || c.AdmissionAware |
| + } |
| out := NameResolution{State: NameHeld, AdmissionAware: aware} |
| for _, c := range claims { |
| if c.Class == NameRoute { |
diff --git a/internal/edgesfile/nameauthority_test.go b/internal/edgesfile/nameauthority_test.go| new file mode 100644 |
| index 000000000..26914732a |
| --- /dev/null |
| +++ b/internal/edgesfile/nameauthority_test.go |
| @@ -0,0 +1,25 @@ |
| +package edgesfile |
| + |
| +import "testing" |
| + |
| +func TestLegacyExactAliasIgnoresUnrelatedAwareWildcard(t *testing.T) { |
| + local := NameClaim{Name: "alias.custom.example.com", Class: NameAlias, Account: "owner", App: "app", TargetHost: "app.example.com", Stamp: 1, Eligible: true, Local: true, Box: "x"} |
| + peer := local |
| + peer.Local, peer.Box, peer.Dial, peer.Stamp = false, "y", "192.0.2.2:443", 2 |
| + wildcard := NameClaim{Name: "*.custom.example.com", Class: NameRoute, Account: "other", App: "other", TargetHost: "other.example.com", Stamp: 3, Eligible: true, AdmissionAware: true, Box: "z", Dial: "192.0.2.3:443"} |
| + for _, peers := range [][]NameClaim{{peer}, {peer, wildcard}} { |
| + got := ResolveNameAuthority(local.Name, []NameClaim{local}, peers) |
| + if got.State != NameDialable || got.Serving != local || got.Authority != local || got.AdmissionAware { |
| + t.Fatalf("legacy exact alias changed by wildcard: %+v", got) |
| + } |
| + } |
| + peer.AdmissionAware = true |
| + got := ResolveNameAuthority(local.Name, []NameClaim{local}, []NameClaim{peer, wildcard}) |
| + if !got.AdmissionAware || got.Serving.Box != "y" { |
| + t.Fatalf("deciding exact claim must retain admission-aware ordering: %+v", got) |
| + } |
| + got = ResolveNameAuthority("child.custom.example.com", nil, []NameClaim{wildcard}) |
| + if !got.AdmissionAware || got.Serving != wildcard { |
| + t.Fatalf("deciding wildcard must retain admission awareness: %+v", got) |
| + } |
| +} |
diff --git a/internal/host/edgesfile.go b/internal/host/edgesfile.go| index 9fbac85e4..07b75e09f 100644 |
| --- a/internal/host/edgesfile.go |
| +++ b/internal/host/edgesfile.go |
| @@ -1296,7 +1296,7 @@ func edgesFileLoop(reg *registry.Registry, lifetimes bool, assets *assetPolicy) |
| if err == nil { |
| ident.RolePublishRequired = false |
| } |
| - state.done(now, err == nil) |
| + state.donePublication(now, err) |
| } |
| } |
diff --git a/internal/host/edgesschedule.go b/internal/host/edgesschedule.go| index 34e4df62b..8d3dbc961 100644 |
| --- a/internal/host/edgesschedule.go |
| +++ b/internal/host/edgesschedule.go |
| @@ -1,6 +1,9 @@ |
| package host |
| -import "time" |
| +import ( |
| + "errors" |
| + "time" |
| +) |
| // edgesLoopState is edgesFileLoop's per-tick decision: the registry and |
| // timer schedule, plus, with the asset cache armed, a pass whenever an |
| @@ -39,3 +42,11 @@ func (s *edgesLoopState) done(now time.Time, ok bool) { |
| s.sched.done(now, ok) |
| } |
| } |
| + |
| +func (s *edgesLoopState) donePublication(now time.Time, err error) { |
| + s.done(now, err == nil) |
| + if errors.Is(err, errGroupReadersNotReady) { |
| + s.sched.retryAt = now.Add(min(s.sched.retryAt.Sub(now), 30*time.Second)) |
| + s.sched.backoff = min(s.sched.backoff, 30*time.Second) |
| + } |
| +} |
diff --git a/internal/host/edgesschedule_test.go b/internal/host/edgesschedule_test.go| index f19eace26..bc6923bb2 100644 |
| --- a/internal/host/edgesschedule_test.go |
| +++ b/internal/host/edgesschedule_test.go |
| @@ -1,6 +1,8 @@ |
| package host |
| import ( |
| + "errors" |
| + "github.com/carlosframework/platform/internal/release" |
| "testing" |
| "time" |
| ) |
| @@ -45,3 +47,61 @@ func TestEdgesScheduleAssetPassesObeyTheRetryBackoff(t *testing.T) { |
| t.Fatalf("passes after writes recovered = %v, want an assets pass on every tick within eight minutes", after) |
| } |
| } |
| + |
| +func TestGroupReaderRefusalRetryBound(t *testing.T) { |
| + for _, tc := range []struct { |
| + name string |
| + group, refuseReaders bool |
| + }{ |
| + {"group-reader-refusal", true, true}, |
| + {"group-store-failure", true, false}, |
| + {"fixed-store-failure", false, false}, |
| + } { |
| + t.Run(tc.name, func(t *testing.T) { |
| + a := readyGroupAdmission(t) |
| + a.group = tc.group |
| + a.knownReaders = []string{"missing"} |
| + s := &readerStore{Store: release.NewDirStore(t.TempDir())} |
| + reg := edgesTestRegistry(t) |
| + ident := edgesFile{Box: "self", RoleSource: a, RolePublishRequired: true} |
| + var last []byte |
| + pubErr := edgesFileWriteClaims(t.Context(), s, reg, ident, "192.0.2.1", &last, true, nil, false, nil, nil) |
| + if tc.group && (!errors.Is(pubErr, errGroupReadersNotReady) || s.puts != 0) { |
| + t.Fatalf("group reader refusal = %v, puts=%d", pubErr, s.puts) |
| + } |
| + if !tc.group && pubErr != nil { |
| + t.Fatalf("fixed publication refused: %v", pubErr) |
| + } |
| + if !tc.refuseReaders { |
| + pubErr = errors.New("store unavailable") |
| + } |
| + start := time.Unix(1000, 0) |
| + state := &edgesLoopState{sched: newEdgesFileSchedule(start, func() time.Duration { return 5 * time.Minute })} |
| + var previous time.Time |
| + var longest time.Duration |
| + for now := start; now.Before(start.Add(20 * time.Minute)); now = now.Add(edgesFileWatchInterval) { |
| + if !state.dueWithRole(now, "unchanged", true, false, ident) { |
| + continue |
| + } |
| + if !previous.IsZero() { |
| + longest = max(longest, now.Sub(previous)) |
| + } |
| + previous = now |
| + state.donePublication(now, pubErr) |
| + } |
| + if tc.refuseReaders && longest > 30*time.Second { |
| + t.Fatalf("reader refusal delayed retry %s, want <=30s", longest) |
| + } |
| + if !tc.refuseReaders && longest != 5*time.Minute { |
| + t.Fatalf("ordinary failure cadence changed: %s", longest) |
| + } |
| + if !state.dueWithRole(start.Add(time.Hour), "unchanged", true, false, ident) { |
| + t.Fatal("recovery pass not due") |
| + } |
| + state.donePublication(start.Add(time.Hour), nil) |
| + if !state.sched.retryAt.IsZero() || state.sched.backoff != 0 { |
| + t.Fatal("success did not reset retry") |
| + } |
| + }) |
| + } |
| +} |
diff --git a/internal/host/group_boot.go b/internal/host/group_boot.go| index 2bdf45ec2..1985100a1 100644 |
| --- a/internal/host/group_boot.go |
| +++ b/internal/host/group_boot.go |
| @@ -20,12 +20,12 @@ const groupUnitProtection = "[Unit]\nRequires=nftables.service\nAfter=nftables.s |
| const groupIdentityPath = "/etc/carlos/group-identity.json" |
| func validateGroupSwitches(getenv func(string) string) error { |
| - if getenv("CARLOS_GROUP_ADMISSION") == "1" && (getenv("CARLOS_HIBERNATE_BUCKET") == "" || getenv("CARLOS_HIBERNATE_REGION") == "") { |
| - return hostenv.ErrGroupConfig |
| - } |
| if !groupReferenced(getenv) { |
| return nil |
| } |
| + if getenv("CARLOS_GROUP_ADMISSION") == "1" && (getenv("CARLOS_HIBERNATE_BUCKET") == "" || getenv("CARLOS_HIBERNATE_REGION") == "") { |
| + return hostenv.ErrGroupConfig |
| + } |
| if getenv("CARLOS_GROUP_ADMISSION") != "1" || getenv("CARLOS_REGION_HA") != "true" || getenv("CARLOS_CHANGE_INDEX") != "read" { |
| return hostenv.ErrGroupConfig |
| } |
diff --git a/internal/host/group_fixed_entry_test.go b/internal/host/group_fixed_entry_test.go| new file mode 100644 |
| index 000000000..e2d5011e7 |
| --- /dev/null |
| +++ b/internal/host/group_fixed_entry_test.go |
| @@ -0,0 +1,78 @@ |
| +package host |
| + |
| +import ( |
| + "go/ast" |
| + "go/parser" |
| + "go/token" |
| + "path/filepath" |
| + "testing" |
| +) |
| + |
| +func TestFixedAdmissionNoHibernateEntryPoints(t *testing.T) { |
| + // Exercise the shared startup check and pin its wiring at each entry. |
| + // Running root bootstrap or install-channel would mutate the host. |
| + for _, entry := range []struct{ file, name string }{ |
| + {"agent.go", "RunAgent"}, {"agent.go", "runAgent"}, |
| + {"bootstrap.go", "RunBootstrap"}, {"installchannel.go", "RunSystemInstallChannel"}, |
| + } { |
| + t.Run(entry.name, func(t *testing.T) { |
| + file, err := parser.ParseFile(token.NewFileSet(), entry.file, nil, 0) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + wired := false |
| + for _, decl := range file.Decls { |
| + fn, ok := decl.(*ast.FuncDecl) |
| + if !ok || fn.Name.Name != entry.name { |
| + continue |
| + } |
| + ast.Inspect(fn.Body, func(node ast.Node) bool { |
| + call, ok := node.(*ast.CallExpr) |
| + if !ok { |
| + return true |
| + } |
| + name, ok := call.Fun.(*ast.Ident) |
| + if !ok || name.Name != "loadGroupConfiguration" || len(call.Args) != 1 { |
| + return true |
| + } |
| + arg, ok := call.Args[0].(*ast.SelectorExpr) |
| + if ok { |
| + pkg, ok := arg.X.(*ast.Ident) |
| + wired = ok && pkg.Name == "os" && arg.Sel.Name == "Getenv" |
| + } |
| + return true |
| + }) |
| + } |
| + if !wired { |
| + t.Fatal("entry no longer uses the tested startup check") |
| + } |
| + for _, missing := range []string{"region", "bucket", "both"} { |
| + t.Run(missing, func(t *testing.T) { |
| + env := map[string]string{"CARLOS_GROUP_ADMISSION": "1", "CARLOS_REGION_HA": "true", "CARLOS_CHANGE_INDEX": "read", "CARLOS_HIBERNATE_BUCKET": "data", "CARLOS_HIBERNATE_REGION": "eu-west-1"} |
| + if missing != "bucket" { |
| + delete(env, "CARLOS_HIBERNATE_REGION") |
| + } |
| + if missing != "region" { |
| + delete(env, "CARLOS_HIBERNATE_BUCKET") |
| + } |
| + get := func(k string) string { return env[k] } |
| + cfg, err := loadGroupConfigurationAt(get, filepath.Join(t.TempDir(), "absent.json")) |
| + if cfg != nil || err != nil { |
| + t.Fatalf("fixed startup refused: config=%v err=%v", cfg, err) |
| + } |
| + if a := newFixedAdmission(get, admissionHealth()); a == nil || a.group { |
| + t.Fatal("fixed admission changed") |
| + } |
| + env["CARLOS_BOX_REFERENCE"] = "group" |
| + if validateGroupSwitches(get) == nil { |
| + t.Fatal("group accepted missing hibernation configuration") |
| + } |
| + env["CARLOS_HIBERNATE_BUCKET"], env["CARLOS_HIBERNATE_REGION"] = "data", "eu-west-1" |
| + if err := validateGroupSwitches(get); err != nil { |
| + t.Fatalf("complete group switches refused: %v", err) |
| + } |
| + }) |
| + } |
| + }) |
| + } |
| +} |