carlos / platform Public

Fix group operator session channel scope for role identities

Apply R9: scope OpenDataChannel to regional account sessions and reject
SSM-SessionManagerRunShell as the approved document. Pin the channel and
edges resources in the exact-policy test and cover the shell refusal.

Validation: 14 mock tofu runs, go build ./..., and tofu fmt checks pass.
Paul Campbell pushed by claude agent, operated by paul@keymail.dev 8b2940281022c0b665cc63d7ed83b0fa3ea460be parent 05c2743
2 files changed, +19 −9
  • infra/modules/region-host/group_operator.tf +12 −7
  • infra/modules/region-host/tests/group_operator.tftest.hcl +7 −2

Intent

Human

<task-notification> <task-id>a5b1c862127d574a3</task-id> <tool-use-id>toolu_01XDYeiNX8uEPs1LNDUFJP1E</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/e47280e8-3e59-4dc1-95d2-11de7237d34c/tasks/a5b1c862127d574a3.output</output-file> <status>completed</status> <summary>Agent "Re-review B1 follow-up R7" 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>**Per-change verdicts** (all at head 4a43d1e0) 1. **s3:GetObject on control/edges/\*: ADDRESSED.** `infra/modules/region-host/group_operator.tf:83-86` grants only `s3:GetObject` on `${var.deployment_bucket_arn}/control/edges/*`. It adds no ListBucket, no other prefix and no write. The bucket input is correct: `group_config` has no bucket field, and `var.deployment_bucket_arn` is the same input `group.tf:37` turns into `CARLOS_DEPLOYMENT_BUCKET`. The prefix matches the Go constant (`internal/edgesfile/edgesfile.go:33`, `internal/host/edgesfile.go:41`). The exact-set test entry is at `tests/group_operator.tftest.hcl:165-169`. 2. **ssmmessages:OpenDataChannel on own sessions: ADDRESSED as briefed.** `group_operator.tf:88-95` has the comment citing AWS's quickstart. The resource renders to `arn:aws:ssm:eu-west-1:123456789012:session/${aws:userid}-*`, which is AWS's end-user form narrowed to one region and account (test at line 174). See Important #1 for a problem with this form. 3. **BoolIfExists with the separate document statement kept: ADDRESSED.** The condition is at `group_operator.tf:56-58`. The explanation is at `:62-66`, and the `ApprovedSessionDocument` statement is unchanged. The test is at `tftest.hcl:148`. 4. **README wording: ADDRESSED.** `infra/modules/region-host/README.md:159-162` matches the brief. It says no direct termination action, that `UpdateAutoScalingGroup` can still lower capacity or set lifetime limits, that only the operator command may use it, and only in the N-HA14 shape. 5. **TMPDIR in the Python test: ADDRESSED.** `scripts/region_group_ssm_boot_test.py:43` now uses `os.environ.get('TMPDIR')`. A new regression test at `:34-38` covers a missing TMPDIR. `mock.patch.dict` restores the environment and `patch.object` restores `tempfile.tempdir`. **Checks you asked about** - **Fixed mode is still empty.** `group_operator.tf:27` still returns `""` when the group is off. `tftest.hcl:64` asserts `== ""`. - **The tests are exact-set.** `tftest.hcl:121` compares the decoded policy with whole-object equality, so any extra statement, action or condition fails. The forbidden-action assertion is kept. - **StartSession under the combined statements.** IAM must allow every resource in the request. The instance is allowed by GroupSession: the tag still matches, and BoolIfExists passes whether the key is present or absent. - A named document other than the approved one is itself a resource in the request. Only `ApprovedSessionDocument` (a single ARN) allows any document, so that request is refused. - With `--document-name` omitted, AWS documents this exact pattern as checking `SSM-SessionManagerRunShell`. No statement allows that ARN, so the request is refused. - Exception (already noted in the code comment): the precondition accepts any account-owned document. That includes the account's own `SSM-SessionManagerRunShell`, so a deployment could explicitly approve the default shell. See Minor #2. - Residual: BoolIfExists is weaker than the old `Bool` on one path. If the service ever sends the request without the key and skips the document check, the instance statement alone would allow the default shell. That path is AWS's own documented behaviour, not a defect in this diff. The mock tests cannot show it either way. **New breakage:** - **Important #1: OpenDataChannel probably fails for role-based (federated) operators.** It fails by denying, not by over-granting. - For an assumed role, `aws:userid` is `AROA...:&lt;role-session-name&gt;`. Session Manager session IDs start with the role session name, not with `AROA...:`. So `session/${aws:userid}-*` never matches the operator's own sessions, and OpenDataChannel is refused. - That mismatch is why the module's own `OwnSessions` statement (`group_operator.tf:73-79`) uses the `ssm:resourceTag/aws:ssmmessages:session-id` tag for federated callers rather than an ARN prefix. The new statement contradicts that comment. - AWS's quickstart form is written for IAM users. If the attended operator is a role or SSO identity, which the OwnSessions comment anticipates, attended sessions will fail to open their data channel. - Two fixes: confirm the operator is an IAM user, or scope it with the same session-tag condition on `session/*`. The second only works if AWS supports that condition key for `ssmmessages:OpenDataChannel`, which needs checking against the service authorization reference. - The brief prescribed this form, so it is the brief's defect rather than the implementer's. The mock tests cannot catch it. A live witness should open a session from the real operator identity. No other new Critical or Important issues. **Minor (defer):** 1. `tftest.hcl:168` builds the expected edges resource from `${var.deployment_bucket_arn}` rather than the literal `arn:aws:s3:::carlos-dev-platform/control/edges/*`. It still catches a wider prefix or a swapped bucket, but a literal would be a stronger independent check. 2. The precondition (`group_operator.tf:98-104`) lets a deployment approve the account-owned `SSM-SessionManagerRunShell` or any account-owned shell document. The comment admits this. Rejecting that name explicitly would close it. 3. There is no live witness for the two behaviours above: StartSession with no `--document-name` must be refused, and the data channel must open from the real operator identity. The report says the same. 4. The README's "lifetime limits" wording leaves out other `UpdateAutoScalingGroup` powers, such as changing the launch template version or health-check settings. It is accurate as far as it goes. 5. The implementer's test and mutation runs are unverified; I did not re-run them. Verdict: all addressed (Important #1 is a new concern in the form the brief prescribed for change 2).</result> <usage><subagent_tokens>58352</subagent_tokens><tool_uses>5</tool_uses><duration_ms>87033</duration_ms></usage> </task-notification>

Human

<task-notification> <task-id>b9kdis5lq</task-id> <tool-use-id>toolu_013vBahpHmQ6b4AFcaXCwQ6Q</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/e47280e8-3e59-4dc1-95d2-11de7237d34c/tasks/b9kdis5lq.output</output-file> <status>completed</status> <summary>Background command ".superpowers/sdd/2026-11-04-region-ha-p3b-group/run-astra.sh b2f" completed (exit code 0)</summary> </task-notification>

diff --git a/infra/modules/region-host/group_operator.tf b/infra/modules/region-host/group_operator.tf
index f757a7d51..04256bd70 100644
--- a/infra/modules/region-host/group_operator.tf
+++ b/infra/modules/region-host/group_operator.tf
@@ -62,8 +62,7 @@ output "group_operator_policy_json" {
# Document authorization is separate: AWS-owned documents do not carry
# the instance's group tag. Both resources must authorize StartSession.
# An omitted name selects SSM-SessionManagerRunShell. That document has
- # no Allow here, so the document access check still refuses the default
- # shell unless the deployment explicitly approves it as its document.
+ # no Allow here, and the precondition refuses it as an approved document.
Sid = "ApprovedSessionDocument"
Effect = "Allow"
Action = ["ssm:StartSession"]
@@ -86,19 +85,25 @@ output "group_operator_policy_json" {
Resource = "${var.deployment_bucket_arn}/control/edges/*"
},
{
- # AWS's end-user policy scopes the channel to the caller's session ARNs.
- # https://docs.aws.amazon.com/systems-manager/latest/userguide/getting-started-restrict-access-quickstart.html
+ # StartSession, gated by the group tag and approved document, creates
+ # sessions. Opening a data channel requires the session token AWS
+ # returns only to the session's starter. The userid-prefixed form in
+ # AWS's quickstart never matches roles or SSO users: aws:userid is
+ # AROA...:session-name. The witness runbook must confirm the channel
+ # from the real operator identity.
Sid = "OwnSessionDataChannel"
Effect = "Allow"
Action = ["ssmmessages:OpenDataChannel"]
- Resource = "${local.group_operator_ssm_arn}${data.aws_caller_identity.current.account_id}:session/$${aws:userid}-*"
+ Resource = "${local.group_operator_ssm_arn}${data.aws_caller_identity.current.account_id}:session/*"
},
]
})
precondition {
condition = !local.group_enabled ? true : (
- local.group_operator_document == "${local.group_operator_ssm_arn}:document/AWS-StartNonInteractiveCommand" ||
- startswith(local.group_operator_document, "${local.group_operator_ssm_arn}${data.aws_caller_identity.current.account_id}:document/")
+ !endswith(local.group_operator_document, ":document/SSM-SessionManagerRunShell") && (
+ local.group_operator_document == "${local.group_operator_ssm_arn}:document/AWS-StartNonInteractiveCommand" ||
+ startswith(local.group_operator_document, "${local.group_operator_ssm_arn}${data.aws_caller_identity.current.account_id}:document/")
+ )
)
error_message = "The operator session document must be AWS-StartNonInteractiveCommand in this region, or a document owned by this account in this region and partition."
}
diff --git a/infra/modules/region-host/tests/group_operator.tftest.hcl b/infra/modules/region-host/tests/group_operator.tftest.hcl
index 4ff6094c0..0d647c949 100644
--- a/infra/modules/region-host/tests/group_operator.tftest.hcl
+++ b/infra/modules/region-host/tests/group_operator.tftest.hcl
@@ -165,13 +165,13 @@ run "operator_policy" {
Sid = "ReadMemberEdges"
Effect = "Allow"
Action = ["s3:GetObject"]
- Resource = "${var.deployment_bucket_arn}/control/edges/*"
+ Resource = "arn:aws:s3:::carlos-dev-platform/control/edges/*"
},
{
Sid = "OwnSessionDataChannel"
Effect = "Allow"
Action = ["ssmmessages:OpenDataChannel"]
- Resource = "arn:aws:ssm:eu-west-1:123456789012:session/$${aws:userid}-*"
+ Resource = "arn:aws:ssm:eu-west-1:123456789012:session/*"
},
]
}))
@@ -224,6 +224,11 @@ run "invalid_aws_shell_document" {
variables { group_operator_session_document_arn = "arn:aws:ssm:eu-west-1::document/AWS-StartSSHSession" }
expect_failures = [output.group_operator_policy_json]
}
+run "invalid_default_shell_document" {
+ command = plan
+ variables { group_operator_session_document_arn = "arn:aws:ssm:eu-west-1:123456789012:document/SSM-SessionManagerRunShell" }
+ expect_failures = [output.group_operator_policy_json]
+}
run "invalid_document_type" {
command = plan
variables { group_operator_session_document_arn = "arn:aws:ssm:eu-west-1:123456789012:parameter/shop-maintenance" }