carlos / platform Public

ingresshealth: refuse a malformed box account or region before comparing

Astra task 8 review, fix round 1. hostenv's Seed and Assemble take the
expected account and region from CARLOS_INGRESS_TARGET_GROUPS itself, so
equality alone passed a malformed ARN that agreed with itself (account
"abc"). ParseTargetGroups now requires a 12-digit account and an AWS
region code before using them; one validator for hostenv and the drain.

Tests: ingresshealth malformed account and region cases; hostenv seed
(zero writes) and assembly refusals for malformed fields.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 580c5bb79c8408d9e80693a697633e710b5c1841 parent 2657b58
4 files changed, +40 −3
  • internal/hostenv/hostenv.go +4 −2
  • internal/hostenv/hostenv_test.go +7 −0
  • internal/ingresshealth/ingresshealth.go +17 −1
  • internal/ingresshealth/ingresshealth_test.go +12 −0

Intent

Human

<task-notification> <task-id>ad045bc75bb93dab3</task-id> <tool-use-id>toolu_01NGENZSoYrigPp9aEZ4Uvxp</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/a373aecd-faa9-4b83-8736-ff726fb2d3af/tasks/ad045bc75bb93dab3.output</output-file> <status>completed</status> <summary>Agent "Implement W6 Task 8 (tofu+hostenv)" 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>Status: DONE. Nothing was applied live, and I didn't touch internal/host. Commits: 2657b58e on w6-ingress-drain. Git printed a `packed-refs.lock` warning during the commit, but the branch points at 2657b58e and it holds only my 10 files. Tests: all pass on OpenTofu 1.13.9, the pinned version, which I downloaded to scratch with its checksum checked. Region-host 113, managed_fleets 34, ingress 17, fixed-targets 2; `tofu validate` is clean; `go test ./internal/hostenv` passes in full, with RED before GREEN recorded in the report. Concerns: - **The module can't write the host-env key.** It doesn't own a fixed box's host-env, so it outputs the value (`ingress_target_groups`) for the operator's stack to write later. That keeps the key a separate step after the role and attributes. This differs from the brief's wording. - **Resource `"*"` is verified.** The AWS service authorization page (list_elbv2.html) lists no resource type for DescribeTargetHealth or DescribeTargetGroupAttributes. - **The hostenv check is partly shape-only.** Assemble and Seed don't know the box's account or region, so they check shape and that all entries agree with each other. AssembleGroup checks against the group config's account and region. - **Census not run.** The infra files and internal/hostenv are in census scope; that's Task 11. - **Group boxes can carry the key.** If a region is seeded from a fixed box's host.env, group boxes get it too; they never arm the drain, so it's harmless. Report: /home/paulca/amadan.net/carlos/platform/.claude/worktrees/w6-build/.superpowers/sdd/2026-11-10-fixed-edge-ingress-drain/task-8-report.md (`.superpowers/` is git-excluded, so it isn't committed).</result> <usage><subagent_tokens>148820</subagent_tokens><tool_uses>78</tool_uses><duration_ms>1436993</duration_ms></usage> </task-notification>

Attributed to this commit: 7.62 g CO₂e (985,306 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on w6-ingress-drain, 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/internal/hostenv/hostenv.go b/internal/hostenv/hostenv.go
index 7eba8d39b..d9d6e5c87 100644
--- a/internal/hostenv/hostenv.go
+++ b/internal/hostenv/hostenv.go
@@ -258,8 +258,10 @@ const ingressTargetGroups = "CARLOS_INGRESS_TARGET_GROUPS"
// empty or absent value is no drain and passes. account and region are
// the box's when the caller knows them (a group box's config); when it
// does not (Assemble and Seed run without the box's identity), the first
-// entry's account and region stand in, so the check is the value's shape
-// and that every entry names the same account and region. The drain
+// entry's account and region stand in. ParseTargetGroups checks their own
+// form (12 digits, a region code) before comparing, so the check is the
+// value's shape, well-formed account and region fields, and that every
+// entry names the same account and region. The drain
// checks them against the box itself when it is asked to run. The error
// is ErrValue and names the variable only, like every refusal here.
func validateIngressTargetGroups(env map[string]string, account, region string) error {
diff --git a/internal/hostenv/hostenv_test.go b/internal/hostenv/hostenv_test.go
index 46a4079cf..21d9bd89f 100644
--- a/internal/hostenv/hostenv_test.go
+++ b/internal/hostenv/hostenv_test.go
@@ -578,6 +578,13 @@ func TestIngressTargetGroupsRefusedWhenNotTargetGroupARNs(t *testing.T) {
"twoAccounts": ingressTG80 + "," + otherAccount,
"twoRegions": ingressTG80 + "," + otherRegion,
"onlyASeparator": ",",
+ // A malformed account or region agrees with itself, so it must be
+ // refused on its own form, not only by comparing entries.
+ "accountNotDigits": strings.Replace(ingressTG80, "123456789012", "abc", 1),
+ "accountTooShort": strings.Replace(ingressTG80, "123456789012", "12345678901", 1),
+ "regionMalformed": strings.Replace(ingressTG80, "eu-west-1", "EU_WEST", 1),
+ "regionEmpty": strings.Replace(ingressTG80, "eu-west-1", "", 1),
+ "bothMalformedPair": strings.Replace(strings.Replace(ingressTG80, "123456789012", "x", 1), "eu-west-1", "y", 1) + "," + strings.Replace(strings.Replace(ingressTG443, "123456789012", "x", 1), "eu-west-1", "y", 1),
} {
t.Run(name, func(t *testing.T) {
env := today()
diff --git a/internal/ingresshealth/ingresshealth.go b/internal/ingresshealth/ingresshealth.go
index b0a2338c7..8a7fa98cb 100644
--- a/internal/ingresshealth/ingresshealth.go
+++ b/internal/ingresshealth/ingresshealth.go
@@ -203,6 +203,11 @@ var (
// targetGroupResource is ELB's target group resource: a name of 1 to
// 32 letters, digits and hyphens, and a 16-hex-digit id.
targetGroupResource = regexp.MustCompile(`^targetgroup/[A-Za-z0-9-]{1,32}/[0-9a-f]{16}$`)
+ // awsAccount is an AWS account id: exactly 12 digits.
+ awsAccount = regexp.MustCompile(`^[0-9]{12}$`)
+ // awsRegion is an AWS region code such as eu-west-1, us-gov-west-1 or
+ // cn-north-1: lower-case words joined by hyphens, ending in a number.
+ awsRegion = regexp.MustCompile(`^[a-z]{2}(-[a-z]+)+-[0-9]+$`)
)
// ParseTargetGroups parses CARLOS_INGRESS_TARGET_GROUPS: a comma-separated
@@ -210,7 +215,8 @@ var (
// refuses the whole value on an empty entry (so an empty value is refused;
// callers treat a missing key as "no drain" before calling), a repeated
// entry, or any entry that is not an Elastic Load Balancing target group
-// ARN in account and region. Spaces around entries are ignored.
+// ARN in account and region. account must be 12 digits and region an AWS
+// region code, or nothing is accepted. Spaces around entries are ignored.
func ParseTargetGroups(value, account, region string) ([]string, error) {
if account == "" {
return nil, fmt.Errorf("ingress target groups: the box's account is unknown")
@@ -218,6 +224,16 @@ func ParseTargetGroups(value, account, region string) ([]string, error) {
if region == "" {
return nil, fmt.Errorf("ingress target groups: the box's region is unknown")
}
+ // Checked on their own form before they are the expected values: a
+ // caller without the box's identity (hostenv at write and seed) takes
+ // them from the value itself, and equality alone would then pass a
+ // malformed ARN that agrees with itself.
+ if !awsAccount.MatchString(account) {
+ return nil, fmt.Errorf("ingress target groups: the box's account %q is not a 12-digit AWS account", account)
+ }
+ if !awsRegion.MatchString(region) {
+ return nil, fmt.Errorf("ingress target groups: the box's region %q is not an AWS region", region)
+ }
var out []string
seen := map[string]int{}
for i, raw := range strings.Split(value, ",") {
diff --git a/internal/ingresshealth/ingresshealth_test.go b/internal/ingresshealth/ingresshealth_test.go
index 8db745493..21cc09d66 100644
--- a/internal/ingresshealth/ingresshealth_test.go
+++ b/internal/ingresshealth/ingresshealth_test.go
@@ -120,6 +120,10 @@ func TestParseTargetGroups(t *testing.T) {
if _, err := ParseTargetGroups(cn, acct, "cn-north-1"); err != nil {
t.Fatalf("aws-cn partition refused: %v", err)
}
+ gov := "arn:aws-us-gov:elasticloadbalancing:us-gov-west-1:123456789012:targetgroup/edge/0123456789abcdef"
+ if _, err := ParseTargetGroups(gov, acct, "us-gov-west-1"); err != nil {
+ t.Fatalf("aws-us-gov partition refused: %v", err)
+ }
for _, c := range []struct{ name, value, account, region, want string }{
{"empty value", "", acct, region, "entry 1 is empty"},
@@ -141,6 +145,14 @@ func TestParseTargetGroups(t *testing.T) {
{"inner space", "arn:aws:elasticloadbalancing:eu-west-1:123456789012:targetgroup/edge 80/0123456789abcdef", acct, region, "not a target group"},
{"no box account", tg80, "", region, "the box's account is unknown"},
{"no box region", tg80, acct, "", "the box's region is unknown"},
+ // The box's own account and region are checked before they are used
+ // as the expected values, so a caller that takes them from the
+ // value itself (hostenv, which has no box identity) cannot pass a
+ // malformed ARN through.
+ {"box account not 12 digits", strings.Replace(tg80, acct, "abc", 1), "abc", region, "the box's account \"abc\" is not a 12-digit AWS account"},
+ {"box account 11 digits", strings.Replace(tg80, acct, "12345678901", 1), "12345678901", region, "is not a 12-digit AWS account"},
+ {"box region malformed", strings.Replace(tg80, region, "EU_WEST", 1), acct, "EU_WEST", "the box's region \"EU_WEST\" is not an AWS region"},
+ {"box region no number", strings.Replace(tg80, region, "eu-west", 1), acct, "eu-west", "is not an AWS region"},
} {
t.Run(c.name, func(t *testing.T) {
got, err := ParseTargetGroups(c.value, c.account, c.region)