Skip to content

feat(cloud): create the Fargate cluster, per-crew roles and log group - #11521

Merged
bolichen97 merged 1 commit into
mainfrom
feat/fargate-aws-scaffolding-11044
Sep 18, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
feat/fargate-aws-scaffolding-11044

Conversation

@chenmingwei23

@chenmingwei23 chenmingwei23 commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

What is the problem?

The Fargate launch engine is on main, and nothing can reach it. Driven from a
clean tree, preflight() and provision() both refuse:

ValueError: constructed without a launch spec ... it needs a placement
  (cluster, subnets, security_groups), a digest-pinned image, the crew's
  secret references, and a cpu architecture

That refusal text is a list of things this line only ever named.
runtask.py refuses with no cluster is named; execution_role_arn and
task_role_arn build a string; identity.py validates the shape of a secret
ARN. No code path creates any of them, and cloud/templates/ held exactly one
file, for the EC2 lane. There was no issue recording that gap until #11044.

Why this issue matters to the user

Nothing in the product can launch a remote crew on Fargate, and the reason is
not visible from the outside: the modules are present, tested and green. A user
who set out to deploy one would have to author a cluster, two IAM roles with the
exact derived names, a log group and a resource-scoped secret grant by hand,
matching conventions that live only in identity.py. Get a name wrong and the
symptom arrives later, as a task definition refused at launch, not as a
misconfiguration reported where it was made.

How our fix solves it

Fargate needs the AWS resources to exist before a task can start, so this adds
the CloudFormation that creates them, and names its outputs so every field the
refusal listed has exactly one place to be read from.

What the launch spec needs Today With this change
placement.cluster no cluster exists ClusterName (base stack)
placement.security_groups nothing to place a task in SecurityGroupId, egress-only
placement.subnets the operator's private knowledge SubnetIds
cpu_architecture unstated CpuArchitecture, pinned to taskdef.CPU_ARCHITECTURES
execution and task identity ARNs derived for roles that do not exist ExecutionRoleArn, TaskRoleArn (crew stack)
log destination no log group LogGroupName, retention capped
secret references ARN shape validated, nothing behind it SecretArnPattern, SecretNamePrefix

Four more outputs carry no launch-spec field but exist so the stacks are
addressable by other automation: the base stack also emits ClusterArn,
Region and StackTag (the tag #11328's wiring reads a stack back by), and the
crew stack emits Crew (the crew a stack belongs to, echoed for the same
lookup). The contract test asserts the full output key set in both directions,
so a dropped or renamed output reds.

Two templates, because the roles are per crew and the cluster is not:

  • kirocrew-fargate-base.yaml, one stack per account and region: the ECS
    cluster and an egress-only security group with no ingress at all.
  • kirocrew-fargate-crew.yaml, one stack per crew: the execution role, the
    task role and the log group.

The split follows from the code rather than from taste. execution_role_arn,
task_role_arn and log_group_name all derive from a CrewBinding, so those
three resources are per crew; Placement.cluster is one value many tasks share.
Splitting them means deleting one crew's stack cannot delete the cluster its
siblings run on, and it gives #10983 a teardown executor: delete-stack on the
per-crew stack.

Chaining symptom to cause, the names are derived, not chosen here. The
templates mirror kirocrew-crew-<crew>-exec, kirocrew-crew-<crew>-task and
/kirocrew/crew/<crew> because identity.py builds exactly those, and
taskdef.py then refuses a document whose ARNs disagree. So a rename on either
side does not produce a mismatch that runs -- it produces a launch refusal, at
the first launch after the rename, with nothing failing when the rename landed.
The contract test asserts the agreement by calling those functions, so the
drift reds at the commit that causes it. CpuArchitecture works the same way:
its allowed values are compared against taskdef.CPU_ARCHITECTURES by importing
that frozenset, so a stack that deploys and a launcher that then rejects the
value cannot both be true.

The two ARN parameters accept every partition CrewBinding accepts, not just
aws. identity._PARTITION_RE admits aws, aws-cn and aws-us-gov, so a
pattern hardcoding arn:aws: would refuse a valid aws-cn ARN at CloudFormation
parameter validation and the per-crew stack would fail to deploy in that
partition. The alternation is not restated from that regex, which is how two
copies of one table drift: a test reads _PARTITION_RE and asserts both template
patterns agree with it partition by partition. Everything the template builds
itself is already partition-correct, because every ARN comes from
${AWS::Partition}.

Two security properties are structural, not incidental:

  • The task role is created with no policies at all and must never gain
    secretsmanager:GetSecretValue. identity.task_role_arn's own docstring
    states the reason: the model key is already in the container's environment by
    the time that role exists, so the permission buys the crew nothing it does not
    have, while a turn that could re-read a secret could read every crew's. The
    execution role holds the read instead, scoped to one crew's secret namespace --
    the trailing wildcard covers only the six-character suffix Secrets Manager
    appends and which no caller can derive. SecretArnPattern publishes that one
    pattern, asserted character-for-character against the policy that grants it, so
    an output promising reach the role does not have cannot ship.
  • Every action is enumerated. No prefix wildcard appears anywhere.
    cloud/aws.py's read allowlist documents why: a prefix admits
    secretsmanager get-secret-value and ssm get-parameter --with-decryption, so
    secretsmanager:Get* on the execution role would grant, through the wildcard,
    exactly what the task role is denied outright. No statement uses NotAction or
    NotResource either, which grant every call they do not name and which a check
    reading only Action cannot see.

PermissionsBoundaryArn defaults to empty, and that is a declared degraded
mode rather than an oversight. The EC2 lane caps its role with a shared,
pre-created, immutable boundary authored once by launcher code
(cloud/iam.py ensure_instance_boundary) so a leaked launcher grant cannot
author a permissive one. No equivalent creator exists for the crew boundary yet.
Rather than reference a policy nothing creates, the parameter accepts the exact
ARN once that creator lands, and its pattern is pinned by a test so widening it
is a visible edit.

What tests we did

test/test_fargate_scaffolding_contract.py -- 19 checks, static and offline.
They read only the template text, so they need no AWS account and no deploy, and
cannot flake. No real AWS resource was created and no template was deployed:
this host has no usable identity for it, so the whole verification is static by
necessity as well as by design. cfn-lint 1.22.3 is clean on both templates.

Locks in Reds if
Role names, log group name, Crew pattern a rename or a widened pattern drifts from identity.py
Task role reaches no secret a policy, a managed policy, or the string secretsmanager appears on it
No action is a prefix wildcard secretsmanager:Get* or ecr:BatchGet* appears, including inside an !If branch
No statement inverts the enumeration a statement uses NotAction or NotResource
Execution role's read is scoped to one crew the resource widens to a sibling crew's namespace
Both roles are assumable only for this account the aws:SourceAccount condition is dropped
Boundary parameter accepts only the one policy the pattern admits an operator-authored policy
Both ARN parameters accept every partition _PARTITION_RE accepts either pattern narrows to arn:aws:, refusing aws-cn or aws-us-gov
Shared security group has no ingress an inbound rule is added
Every output key is present an output is dropped or renamed
Offered architectures equal taskdef.CPU_ARCHITECTURES either side gains a value the other rejects
Advertised secret ARN equals the granted one policy and output diverge in either direction

Every assertion is mutation-verified: the template is broken in the specific way
that test exists to catch, the test is required to go red, then the file is
restored and checked byte-identical. 22 mutations, 22 reds, 0 holes, with the
clean tree confirmed green first and every anchor asserted to match exactly once --
an anchor that matches never, or more than once, is counted as a hole and fails
the run, so a mutation that silently did not apply cannot read as a pass.

The mutations imitate real edits rather than synthetic ones, which is where this
kind of test usually leaks:

mutation why this one and not an easier one
secret read granted via arn:aws:iam::aws:policy/SecretsManagerReadWrite the managed policy is how someone would actually grant it, and its spelling defeats a lower-case substring check, so the assertion is case-insensitive
ecr:BatchGet* hidden inside the conditional ECR branch proves the document walker enters !If branches instead of only reading top-level statements
a statement's Action swapped for NotAction the same reach as a wildcard, invisible to a check that collects only Action
the secret ARN widened in the output only, policy untouched proves the agreement check earns its place: one-sided drift is caught in the direction that misleads a reader
an output renamed rather than deleted presence-only assertions pass a rename; the check compares the key set in both directions
either ARN pattern narrowed back to arn:aws: the parity check reads _PARTITION_RE itself, so a partition table that drifts from identity.py reds instead of surfacing as a failed deploy in aws-cn

Gates run before the commit: scripts/check_black_formatting.py, isort, flake8,
check_comment_history.py, check_brand_name.py, check_subprocess_encoding.py,
check_testpaths_coverage.py, check_changelog_history.py, check_feature_map.py,
docs-lint, and the scoped backend test runner.

Any other suggestions on the work

  • This change is scaffolding, not a launch. After it merges a crew still
    cannot start: engine_for('aws_fargate') raises KeyError because nothing
    registers the lane, which is Fargate: FargateLaunchSpec has no configuration home, so the aws_fargate lane cannot be registered yet #11328, and the crew image is published nowhere,
    which is The crew base image is published nowhere, so its digest has to be minted locally #10901. Registration must land together with _tier_as_pair or a
    light/balanced/power launch is refused.
  • Networking is taken, not invented. SubnetIds is a parameter because
    whether a subnet reaches the registry through a NAT gateway or as a public
    subnet is a property of the operator's VPC that a template cannot discover.
    Passing it in keeps the failure at deploy time with a name attached instead of
    a task that reaches RUNNING and then cannot pull. CpuArchitecture is a
    parameter for the same reason: it is a property of the image, and a runtime
    platform that disagrees with the image fails at task start.
  • The crew boundary's creator is the next step, and it belongs beside
    cloud/iam.py's existing one rather than in a template, for the reason that
    file already gives: a boundary authored per launch by whoever holds the
    launcher policy is not a ceiling.
  • EcrRepositoryArn is empty by default because the decided delivery for the
    shared crew image (Fargate: shared crew image and a task-not-service runtime, design of record #11408) is a public registry, which needs no execution-role
    permission at all. It exists so a private repository is a parameter rather
    than a patch.
  • CI's CloudFormation Lint job does not cover these files. It lints
    src/kiro_crew/deploy/skills/artifact-deploy/templates/ only, so neither these
    two templates nor the existing kirocrew-ec2.yaml sibling are linted there.
    Both were linted locally with the same pinned cfn-lint version. Widening that
    job is a CI change and belongs on its own.

Fixes #11044

@chenmingwei23
chenmingwei23 requested review from a team and iamwhatever September 17, 2026 11:39
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 17, 2026
@github-actions

github-actions Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — ✅ PASS

Design-level review of 6be91e33800a8c3b3a3637eb3293532e6935dd7a — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Verify one real deploy of both stacks in a scratch account before #11328 wires them — all verification here is static (cfn-lint + contract tests), never CloudFormation itself.

Suggestions

[DESIGN-REVIEWED] 6be91e3

@github-actions

github-actions Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5) — 🟡 CONCERNS

Premise-level review of 6be91e33800a8c3b3a3637eb3293532e6935dd7a — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

First-Principles-Verdict: CONCERNS

Two empty-default parameters and two echo outputs ship ahead of any consumer: a boundary nothing creates, a private-ECR grant the decided delivery never needs.

Not justified as shipped

  • Item 5 — zero consumers, inherited: PermissionsBoundaryArn admits only kirocrew-crew-boundary, and the diff's own comment says "No equivalent creator exists for the crew boundary yet" — grepped kirocrew-crew-boundary: 0 hits outside this diff (only the new template and its test); cloud/iam.py builds only kirocrew-ec2-boundary. Empty-default surface reserved "so we can later".
    Subtraction: delete the parameter, the HasBoundary condition and both PermissionsBoundary lines; ship them in the PR that lands the boundary creator.
    Clears when: a creator for kirocrew-crew-boundary exists as a counted consumer, or the parameter is deleted.
  • Item 6 — zero consumers, inherited: EcrRepositoryArn plus the conditional CrewImagePull policy serve a private registry, while the template's own comment says the decided delivery (Fargate: shared crew image and a task-not-service runtime, design of record #11408, ECR Public) "needs no execution-role permission at all" — grepped EcrRepositoryArn|BatchGetImage|GetAuthorizationToken in src: only this template.
    Subtraction: delete the parameter, HasPrivateRegistry and the CrewImagePull !If branch.
    Clears when: a launch path that pulls from a private repository exists, or the branch is deleted.
  • Item 4 — zero consumers: ClusterArn and Region outputs rest on "addressable by other automation" — no consumer named even prospectively (grepped kirocrew-fargate in src: only the two templates; nothing reads any output). StackTag/Crew at least have Fargate: FargateLaunchSpec has no configuration home, so the aws_fargate lane cannot be registered yet #11328's lookup named.
    Subtraction: drop ClusterArn and Region from Outputs and the test's pinned set.
    Clears when: a counted consumer reads them, or they are deleted.

What this change ships

Inventory (8 items) — 5 justified

Intent: let an operator create the AWS resources (cluster, per-crew roles, log group) the merged Fargate launch engine refuses without — ADDITION, staged under rfc-remote-instance-on-fargate (in-progress on base).

  1. Deploying a new base template creates the shared ECS cluster and an egress-only security group — justified
  2. Deploying a new per-crew template creates the execution role, a policy-less task role and the log group, named exactly as identity.py derives — justified
  3. Every launch-spec field the engine's refusal lists is now readable from a stack output — justified
  4. Four outputs carrying no launch-spec field (ClusterArn, Region, StackTag, Crew) — zero consumers, two with no named prospect
  5. PermissionsBoundaryArn parameter, empty default, for a boundary policy nothing creates — zero consumers
  6. EcrRepositoryArn parameter and conditional private-pull grant, empty default — zero consumers, decided delivery needs none
  7. A LogRetentionDays knob capping log retention at 30 days by default — justified
  8. A static contract test pins names, output keys, and the no-secret/no-wildcard/no-NotAction properties to identity.py/taskdef.py by calling them — justified

cloud.md spec rows update in the same commit is mandated by AGENTS.md and not counted.

[FIRST-PRINCIPLES-REVIEWED] 6be91e3

@chenmingwei23
chenmingwei23 force-pushed the feat/fargate-aws-scaffolding-11044 branch from b1f0c2d to 11782f6 Compare September 17, 2026 11:44
@github-actions github-actions Bot removed the readiness: action required A blocking check or review needs attention label Sep 17, 2026
@github-actions

github-actions Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Opus 4.8 Review — ✅ no blocking findings

Reviewed 6be91e33800a8c3b3a3637eb3293532e6935dd7a — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 6be91e3

Verdict parsed from the review's SHA-scoped output markers for commit 6be91e33800a8c3b3a3637eb3293532e6935dd7a.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 6be91e33800a8c3b3a3637eb3293532e6935dd7a: <one-sentence reason>

@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Sep 17, 2026
@github-actions

github-actions Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ✅ no blocking findings

GPT 5.6 completed its review of 6be91e33800a8c3b3a3637eb3293532e6935dd7a and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 6be91e3

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 6be91e33800a8c3b3a3637eb3293532e6935dd7a: <one-sentence reason>

@chenmingwei23
chenmingwei23 force-pushed the feat/fargate-aws-scaffolding-11044 branch from 11782f6 to 064663d Compare September 17, 2026 12:02
@chenmingwei23
chenmingwei23 force-pushed the feat/fargate-aws-scaffolding-11044 branch from 064663d to 1a1bf0b Compare September 17, 2026 12:38
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 17, 2026
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 17, 2026
@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Backend Tests (3.12, 3) on this head is main's, not this change's -- read from the job log, not inferred:

kiro_crew.pod.windows.WindowsTaskError: the Task Scheduler pod backend is win32-only; this host is linux.
src/kiro_crew/pod/windows.py:179: WindowsTaskError
  -> kiro_crew.pod.runtime.PodError: the Task Scheduler pod backend is win32-only; this host is linux.

Why it cannot be this PR:

  1. The diff cannot reach it. This branch adds two CloudFormation templates under
    src/kiro_crew/cloud/templates/ and one test file. No Python in it imports, or
    is imported by, kiro_crew.pod.windows.
  2. It is already filed. test_pod_windows_run fails on Linux since #10707: up now reaches windows.require_backend #11517 -- "test_pod_windows_run fails on Linux since
    fix: diagnose an unreachable pod user bus #10707: up now reaches windows.require_backend" -- is open and names this test
    and this mechanism.
  3. It is not specific to this head. The same shard fails on fix(cloud): accept the interactive tier keys on the Fargate lane #11534 and on
    feat(prepare-pr): tell the loop when a PR's green has expired #11508, both unrelated branches of mine.

Earlier on this head the same lane read cancelled, and Coverage Gate then failed
CLOSED on that cancellation rather than on a finding of its own -- re-running the
run's failed jobs cleared the gate and left this one shard, which is the main-owned
failure above.

Local state on this branch: 12 contract tests pass, the 14-mutation matrix has zero
holes, and the whole Backend Lint gate set plus isort, flake8, ruff,
black --target-version py310, the comment-history gate and the brand-name gate all
pass. Nothing to do here for that lane; it clears when #11517 does.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 17, 2026
@chenmingwei23
chenmingwei23 force-pushed the feat/fargate-aws-scaffolding-11044 branch from 1a1bf0b to ef492a4 Compare September 17, 2026 16:14
@github-actions github-actions Bot removed the readiness: action required A blocking check or review needs attention label Sep 17, 2026
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Sep 17, 2026
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 17, 2026
@chenmingwei23
chenmingwei23 force-pushed the feat/fargate-aws-scaffolding-11044 branch from ef492a4 to bd1a8b7 Compare September 17, 2026 17:32
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Sep 17, 2026
@chenmingwei23
chenmingwei23 force-pushed the feat/fargate-aws-scaffolding-11044 branch from bd1a8b7 to abca7d3 Compare September 17, 2026 17:59
@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Dispositions for the advisory CONCERNS on bd1a8b7e (now abca7d3f after this push):

Design Review

  • Spec not updated (cloud.md): FIXED in this push. docs/system-specs/modules/cloud.md now has rows for kirocrew-fargate-base.yaml and kirocrew-fargate-crew.yaml beside the existing kirocrew-ec2.yaml row, plus a paragraph documenting the full outputs contract. This is what AGENTS.md's same-commit spec rule asks for.
  • Templates linted only statically / CI CloudFormation Lint does not cover them: not changed here, and disclosed in the body. Both are true and by design for scaffolding on a host with no AWS identity: a deploy rides Fargate: FargateLaunchSpec has no configuration home, so the aws_fargate lane cannot be registered yet #11328's wiring, and widening the CI lint job to src/kiro_crew/cloud/templates/ is a CI change on its own. The finding's own "clears when" is a deploy or a CI-scope change, both out of this PR's scope.
  • Cluster naming suggestion (kirocrew-fargate-${StackTag} vs kirocrew-crew-${StackTag}): advisory suggestion, noted; not changed, since the current name is asserted by the contract test and a rename would want its own review of identity.py's prefix invariant.

First Principles

  • Item 6, three undeclared outputs (Region, StackTag, ClusterArn, and Crew): FIXED in this push. The body's output section now declares all four and points at the contract test that pins the full key set.
  • Items 4 and 5 (PermissionsBoundaryArn, EcrRepositoryArn as parameters for code that does not exist yet): not changed. Both are deliberate, defended in the body: each is an empty-default parameter, pattern-pinned by a test so any widening is a visible edit, and each has a named landing PR (the crew-boundary creator beside cloud/iam.py; a private-image path). The "subtraction" is a scope opinion, not a defect in the diff; keeping them is a declared degraded mode, not an oversight.

No blocking finding is open. Backend/E2E CI is running on the new head.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Backend Tests reds on this head are main-owned, not this PR's

Attributed by test name on both sides, not by lane and not by re-run.
Job logs read with gh api .../logs --allow-escape-sequences (without that flag the
API returns zero bytes, which reads misleadingly like a run still in flight).

On this head (abca7d3fef), CI run 35256106267

Lane Result Failing tests
Backend Tests (3.12, 5) 2 failed, 14026 passed test_member_session_control.py::TestMemberChildPrivateBinding::test_a_v1_child_writes_no_private_binding, ::test_global_caller_cannot_grant_a_child_private_authority
Backend Tests (Windows) (5) 2 failed, 13214 passed the same two
Backend Tests (Windows) (7) 4 failed, 13151 passed test_session_control.py::test_create_refuses_unreadable_delegation_identity[OSError], [ValueError], ::test_private_creator_cannot_change_memory[public-worker-canonical], [writer-canonical]

Assertion in the first pair: AssertionError: assert 'member-radar' is None.

On main's own tip (0640c1e0d), CI run 35254907186

Lane Result Failing tests
Backend Tests (Windows) (5) 2 failed, 13212 passed the same two test names
Backend Tests (Windows) (7) 4 failed, 13149 passed the same four test names

Main is red at its own tip on the identical tests.

Mechanism

TestMemberChildPrivateBinding does not exist in this branch's checkout. It is on
origin/main at test/test_member_session_control.py:504, added by
0640c1e0d5 fix(session-control): let private members dispatch their own workers (#11438).
CI evaluates the merge ref refs/pull/11521/merge, so this board inherited main's
brand-new failing tests.

This PR's diff is docs/system-specs/modules/cloud.md, two CloudFormation templates
and one new offline contract test. It touches zero session-control files, so it
cannot influence them.

What follows

  • gh run rerun --failed will not clear these. They are deterministic on main, not
    flaky, so the re-run-proves-it method does not apply here. The main-tip control
    above is the stronger evidence.
  • Rebasing would not help either: main's tip is the commit that introduced the
    failures, so rebasing pulls them in explicitly rather than dropping them.
  • No session-control fix is being folded into this PR. Once main is green on
    #11438, this branch rebases onto settled main to cut a fresh merge ref.

Unaffected

All four review lanes are success on this head, including the ARN-partition
finding. That fix is at kirocrew-fargate-crew.yaml:50 and :66 and is pinned by
test_both_arn_patterns_accept_exactly_the_partitions_identity_accepts against
_PARTITION_RE. Narrowing either pattern back to arn:aws: makes that test fail on
partition aws-cn, verified locally on a clean tree with both anchors asserted
unique so neither mutation could silently no-op.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 17, 2026
@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Tracking the main-side cause as #11585 - main is red at tip on these same six tests after #11438, so this board clears when main does. This PR needs no change for them.

@chenmingwei23
chenmingwei23 force-pushed the feat/fargate-aws-scaffolding-11044 branch from abca7d3 to e753fbf Compare September 17, 2026 20:26
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Sep 17, 2026
@chenmingwei23
chenmingwei23 force-pushed the feat/fargate-aws-scaffolding-11044 branch from e753fbf to cb7d963 Compare September 17, 2026 20:59
The Fargate launch engine is on main, and nothing can reach it: preflight and
provision both refuse with "constructed without a launch spec ... it needs a
placement (cluster, subnets, security_groups), a digest-pinned image, the crew's
secret references, and a cpu architecture". That refusal text is a list of things
this line only ever NAMED. runtask.py refuses with "no cluster is named",
execution_role_arn and task_role_arn build a string, and identity.py checks the
shape of a secret ARN -- no code path creates any of them, and templates/ held
one file, for the EC2 lane.

Two templates, because the roles are per crew and the cluster is not:

- kirocrew-fargate-base.yaml, one stack per account and region: the ECS cluster
  and an egress-only security group with no ingress at all.
- kirocrew-fargate-crew.yaml, one stack per crew: the execution role, the task
  role and the log group. Deleting one crew's stack cannot delete the cluster its
  siblings run on, and delete-stack becomes the teardown executor #10983 lacks.

Every name is derived by cloud/fargate/identity.py rather than chosen here, so
the templates mirror kirocrew-crew-<crew>-exec, kirocrew-crew-<crew>-task and
/kirocrew/crew/<crew>. The task definition refuses a document whose ARNs
disagree, so a rename on either side is a launch refusal rather than a mismatch
that runs -- the contract test asserts the agreement by calling those functions.

The task role is created with no policies at all, and must never gain
secretsmanager:GetSecretValue: identity.py already states why, since the model
credential is in the container's environment before that role exists, so the
permission buys the crew nothing while a turn that could re-read a secret could
read every crew's. The execution role's read is scoped to one crew's secret
namespace, and every action is enumerated -- no prefix wildcard appears
anywhere, because cloud/aws.py documents that a prefix admits
secretsmanager get-secret-value and ssm get-parameter --with-decryption. No
statement uses NotAction or NotResource either, which would grant everything
they do not name and which a check reading only Action cannot see.

The outputs are the whole point: they are the configuration home a launch spec
is read from, so every field the refusal named has exactly one place to come
from. The base stack answers the placement -- ClusterName, SecurityGroupId,
SubnetIds -- plus CpuArchitecture, whose allowed values are compared against
taskdef.CPU_ARCHITECTURES by importing that frozenset, so a stack that deploys
and a launcher that then refuses the value cannot both be true. The crew stack
answers identity: ExecutionRoleArn, TaskRoleArn, LogGroupName, and
SecretArnPattern, the one ARN pattern the execution role may read, asserted
character-for-character against the policy that grants it.

Fixes #11044
@chenmingwei23

Copy link
Copy Markdown
Contributor Author

The inherited reds cleared via #11593, with no change to this PR's code

Recording why the board changed, so the earlier red history reads correctly.

Six session-control tests were failing on this PR's board and on main's own tip.
They were never this PR's: TestMemberChildPrivateBinding did not exist in this
branch's checkout at all, and CI evaluates the merge ref, so the board inherited
tests that arrived on main with
0640c1e0d5 fix(session-control): let private members dispatch their own workers (#11438).

#11593 fix(session-control): authorize a created child on the store it is bound to
is now main's tip at 2627b0407c. Before rebasing onto it I verified the fix in a
frozen detached worktree at that exact SHA: the six give 22 passed there, 22
rather than 18 because #11593 added cases to that class.

This branch is now rebased onto 2627b0407c as 6be91e3380. The commit is
unchanged in content -- the same four files, no line of this PR's own code touched.

The lanes that carried the six

Lane Before On this head
Backend Tests (Windows) (5) 2 failed success
Backend Tests (Windows) (7) 4 failed success
Backend Tests (3.12, 5) 2 failed success
Backend Tests (3.12, 6) 4 failed still running at time of writing

Board otherwise: 68 concluded lanes, zero failures, counts summing to the lane
total so nothing is unaccounted for. All four review lanes were success on the
previous head with the same diff.

Local verification on the rebased tree

Each as its own invocation, with git status --porcelain empty before and after so
the checked tree is the pushed tree:

  • the six formerly-inherited tests: 22 passed
  • test/test_fargate_scaffolding_contract.py: 19 passed
  • mutation matrix: 22 mutations, 22 reds, 0 holes, covering every test node in
    the contract file
  • gate floor: black, isort, flake8, comment-history, brand-name,
    subprocess-encoding, yaml-safe-loading, testpaths-coverage, feature-map and
    changelog-history all exit 0

One correction to the matrix, worth stating

The harness now treats an anchor that matches never or more than once as a hole
that fails the run, not as a skip. Adding that check immediately found a real
ambiguity: the anchor for the widen-past-this-crew mutation matched twice, once in
the policy and once in the SecretArnPattern output, so the mutation had been
landing on whichever came first rather than where its label claimed. A matrix that
prints zero holes because a mutation never applied is worse than a red one, so the
count in the body is now the enforced figure rather than a claim.

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Sep 18, 2026
@bolichen97
bolichen97 merged commit c357127 into main Sep 18, 2026
86 checks passed
@bolichen97
bolichen97 deleted the feat/fargate-aws-scaffolding-11044 branch September 18, 2026 00:29
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Sep 18, 2026
amadsalmon pushed a commit to amadsalmon/KiroCrew that referenced this pull request Sep 22, 2026
…kirodotdev#11521)

The Fargate launch engine is on main, and nothing can reach it: preflight and
provision both refuse with "constructed without a launch spec ... it needs a
placement (cluster, subnets, security_groups), a digest-pinned image, the crew's
secret references, and a cpu architecture". That refusal text is a list of things
this line only ever NAMED. runtask.py refuses with "no cluster is named",
execution_role_arn and task_role_arn build a string, and identity.py checks the
shape of a secret ARN -- no code path creates any of them, and templates/ held
one file, for the EC2 lane.

Two templates, because the roles are per crew and the cluster is not:

- kirocrew-fargate-base.yaml, one stack per account and region: the ECS cluster
  and an egress-only security group with no ingress at all.
- kirocrew-fargate-crew.yaml, one stack per crew: the execution role, the task
  role and the log group. Deleting one crew's stack cannot delete the cluster its
  siblings run on, and delete-stack becomes the teardown executor kirodotdev#10983 lacks.

Every name is derived by cloud/fargate/identity.py rather than chosen here, so
the templates mirror kirocrew-crew-<crew>-exec, kirocrew-crew-<crew>-task and
/kirocrew/crew/<crew>. The task definition refuses a document whose ARNs
disagree, so a rename on either side is a launch refusal rather than a mismatch
that runs -- the contract test asserts the agreement by calling those functions.

The task role is created with no policies at all, and must never gain
secretsmanager:GetSecretValue: identity.py already states why, since the model
credential is in the container's environment before that role exists, so the
permission buys the crew nothing while a turn that could re-read a secret could
read every crew's. The execution role's read is scoped to one crew's secret
namespace, and every action is enumerated -- no prefix wildcard appears
anywhere, because cloud/aws.py documents that a prefix admits
secretsmanager get-secret-value and ssm get-parameter --with-decryption. No
statement uses NotAction or NotResource either, which would grant everything
they do not name and which a check reading only Action cannot see.

The outputs are the whole point: they are the configuration home a launch spec
is read from, so every field the refusal named has exactly one place to come
from. The base stack answers the placement -- ClusterName, SecurityGroupId,
SubnetIds -- plus CpuArchitecture, whose allowed values are compared against
taskdef.CPU_ARCHITECTURES by importing that frozenset, so a stack that deploys
and a launcher that then refuses the value cannot both be true. The crew stack
answers identity: ExecutionRoleArn, TaskRoleArn, LogGroupName, and
SecretArnPattern, the one ARN pattern the execution role may read, asserted
character-for-character against the policy that grants it.

Fixes kirodotdev#11044
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cloud/fargate: nothing creates the cluster, roles, secrets or log group a task needs to start

2 participants