Repository navigation
fix(cloud): grant ec2:RevokeSecurityGroupEgress so cloud launch can create its security group - #15478
jcjaskula-aws wants to merge 1 commit into
Conversation
The launcher policy printed by `kirocrew cloud iam-policy` grants ec2:AuthorizeSecurityGroupEgress and ec2:RevokeSecurityGroupIngress but not ec2:RevokeSecurityGroupEgress, while kirocrew-ec2.yaml declares an inline SecurityGroupEgress block on the instance security group. CloudFormation must revoke the implicit allow-all egress rule EC2 attaches to a new security group before it can apply a declared egress rule, so every launch calls RevokeSecurityGroupEgress and stops at InstanceSecurityGroup with AccessDenied, rolling the stack back. The grant lands in Ec2ManagedResourceMutateTagged beside its Authorize counterpart, so it stays gated on aws:ResourceTag/kirocrew:managed=true and applies only to security groups this launcher created. The added test reads the template and asserts the pairing, so removing the grant or the declared egress block lands red rather than surfacing as a failed launch.
Design Review (Fable 5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing to check. [DESIGN-REVIEWED] 1483ee5 Description read[DESCRIPTION-READ] 81d4d94064fff1fa8aa0f75727c91b69e4a557b457b85be74b76a8501e87523b That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
First Principles Review (Fable 5, fork) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Verify the manual claim: only the author's live launch shows the stack now passes The defect is confirmed on base: What this change shipsInventory (6 items) — 6 justifiedIntent: FIX — make
[FIRST-PRINCIPLES-REVIEWED] 1483ee5 Description read[DESCRIPTION-READ] 807f105fac5cd565f444333bf4caefd5e0e28664294877ffbd4a0a55b7ea5389 That sha256 names the PR description this verdict read. Recompute it with |
GPT 5.6 Review (fork) —
|
Opus 5 Review (fork) — ✅ no blocking findingsReviewed |
|
Superseded by #15237, merged at 23:22 UTC today, which lands the same fix: Closing as redundant. One assertion here is not covered upstream, in case it is wanted separately: this PR guarded the grant with a check that the template still declares inline |
Problem / Motivation
Goal: Make
kirocrew cloud launchable to create its stack with the launcher policy thatkirocrew cloud iam-policyprints.It cannot today. The launch fails at
InstanceSecurityGroupand rolls the stack back, on every launch, in every account:Ec2ManagedResourceMutateTagged(src/kiro_crew/cloud/iam.py:412) grantsAuthorizeSecurityGroupEgress,AuthorizeSecurityGroupIngressandRevokeSecurityGroupIngress. One half of a symmetric pair is absent.Why it matters
The generated policy is the documented path for anyone launching a remote crew without admin credentials, and this blocks it unconditionally — there is no account, region or option combination where the current policy reaches the
Instanceresource. Each attempt costs a full CloudFormation create-and-rollback cycle, and the error names an action the operator cannot find anywhere in the policy they just applied, so the natural response is to suspect their own setup.Not a goal
iam:PassRolegated onaws:ResourceTag), cloud launch: a GetPolicy denial on the instance boundary is reported as a missing iam:CreatePolicy grant #15474 (aGetPolicydenial reported as a missingiam:CreatePolicygrant), Remote-crew pane cannot embed when the dashboard is served on a non-loopback origin (HTTPS reverse proxy / tunnel), and the error card reports "All checks passed" #15475 (the remote-crew pane on a non-loopback origin).SecurityGroupEgressblock is left exactly as it is; this PR only grants the call it already forces.What changed (motivation → approach → change)
src/kiro_crew/cloud/templates/kirocrew-ec2.yaml:199declares an inlineSecurityGroupEgressblock on the instance security group. EC2 attaches an implicit allow-all egress rule to every new security group, so when a CloudFormation security group declares egress, CloudFormation must revoke that implicit rule before applying the declared one. Every launch therefore callsec2:RevokeSecurityGroupEgress— an action no statement grants.The fix is one action added to
Ec2ManagedResourceMutateTagged, beside itsAuthorizecounterpart. Putting it there rather than in a new statement matters: it inherits that statement'saws:ResourceTag/kirocrew:managed=truecondition, so it applies only to security groups this launcher created — identical scoping to theRevokeSecurityGroupIngressverb next to it, and no new reach.Three files move with it, because the change would otherwise land red or leave the docs wrong:
test/test_cloud_iam.py— the exact set-equality pin on the merged action list (deliberately strict, so action creep on aResource: "*"statement cannot land green) and the destructive-verb tag-scope assertion.test/fixtures/cloud_iam_policy_pre_shrink.json— the permission-neutrality test compares pre-shrink and current policies as tuple sets for equality, so the verb belongs in the fixture'sEc2DestructiveTaggedtoo (sameEffect,ResourceandCondition, so the tuple matches).docs/system-specs/modules/cloud.md:477— the documented destructive-verb list, which had the same blind spot as the code.Backwards compatibility
Compatible: this adds one
Allowaction to an existing tag-conditioned statement. Nothing that works today stops working, and an operator running the previous policy is unaffected until they regenerate it.Tests
test_template_declared_egress_requires_the_egress_revoke(new) — reads the CloudFormation template and asserts that a declaredSecurityGroupEgressblock is paired with the egress revoke grant. Removing either side lands red instead of surfacing as a failed launch in a user's account. It reaches the template throughpathlib.Path(iam.__file__), not the working directory, to satisfy the Working-Directory Path Gate.Ec2ManagedResourceMutateTagged's action list and the destructive-verb tag-scope assertion are updated to include the new verb, so both keep failing on an unintended action rather than silently absorbing it.test/test_cloud_iam.py, including the permission-neutrality tuple comparison and both policy-size gates.Manual verification
Verified against a live launch. With the current policy the stack rolls back at
InstanceSecurityGroupwith the error quoted above; with this action added, the security group, instance role and instance profile all reachCREATE_COMPLETEand the launch proceeds to theInstanceresource — where it then hits #15473, which is why that one is filed separately.Related Issues
Sibling defects from the same pass: #15473, #15474, #15475.
Pattern harvest
Rule candidate: review-prompt
Pattern: an IAM policy grants one half of an
Authorize/Revoke(orCreate/Delete,Put/Get) pair for a resource the same codebase declares, so the paired call is only discovered at runtime asAccessDenied. The generalizable form is to check a generated policy against the calls the shipped infrastructure template forces, rather than against the list of calls the code makes directly — the CloudFormation-implied revoke has no call site in this repository to notice.Checklist