Repository navigation
fix(cloud): shrink launcher IAM policy under IAM's 6144-char cap - #13029
Conversation
GPT 5.6 Review — ✅ no blocking findingsGPT 5.6 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
c06e63a to
c295f25
Compare
GPT 5.6 Review —
|
Design Review (Fable 5) — ✅ PASSDesign-level review of Design-Verdict: PASS Verify once against live AWS that Suggestions
[DESIGN-REVIEWED] 5488b80 |
First Principles Review (Fable 5) — 🟡 CONCERNSPremise-level review of First-Principles-Verdict: CONCERNS The 383-line pre-shrink fixture and byte-for-byte equivalence test are a one-shot proof guaranteed to go red on #3355 — the feature this PR reserves headroom for. Not justified as shipped
What this change shipsInventory (8 items) — 7 justifiedIntent: make the printed launcher IAM policy applicable again by a non-admin operator (it exceeded AWS's 6,144-char cap) — a FIX, with provenance (the new size test fails on base).
[FIRST-PRINCIPLES-REVIEWED] 5488b80 |
Opus 5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
The `kirocrew cloud iam-policy` output was 6467 characters whitespace-free, over AWS's non-adjustable 6,144-char managed-policy quota, so applying the printed JSON failed with LimitExceeded for any non-admin operator. Shrink to 5818 whitespace-free by merging statements that share Effect + Resource + Condition (permission-neutral by construction): - Ec2SecurityGroupRulesTagged + Ec2DestructiveTagged + Ec2LifecycleTagged -> Ec2ManagedResourceMutateTagged (Resource "*", managed-tag condition) - IamPutRolePolicyForInstance + IamTagRoleOnManaged -> IamPutRolePolicyAndTagRoleOnManaged (role ARN, managed-tag condition) - CloudFormationRead + TagDiscovery + Ec2Discovery + Route53DnsPreflight -> CloudFormationAndResourceDiscovery (Resource "*", no condition) The effective permission set is identical before and after: a new test flattens the pre-shrink policy (kept as a fixture) and the current policy into canonical (Effect, Action, Resource-form, Resource, Condition) tuple sets and asserts equality. A size-gate test asserts the whitespace-free length is at most 6144 (citing the AWS quota) and at most 5900 for headroom so EC2 Spot (#3355, roughly +152 chars) still fits. Sid-pinning tests updated to the merged statement names; no assertions dropped.
c295f25 to
d270b09
Compare
UX Review (Fable 5) — ⏭️ skippedRevision |
0d6556f to
18f22f1
Compare
Remove test/test_knowledge.py from .github/black-baseline.txt: the file graduated to black-clean on main, so the baselined-file gate fails until the stale entry is pruned (0 new offenders, 1 graduated entry). Same base-defect fix applied to the other wave-3 PRs. Also tighten two assertions on the merged IamPutRolePolicyAndTagRoleOnManaged statement to full set-equality (was subset `in`), per a-ratchet-may-only-tighten: a future third verb on that role-ARN statement now reds the test instead of landing un-caught. Test-only, permission-neutral.
18f22f1 to
5488b80
Compare
…odotdev#13029) * fix(cloud): shrink launcher IAM policy under IAM's 6144-char cap The `kirocrew cloud iam-policy` output was 6467 characters whitespace-free, over AWS's non-adjustable 6,144-char managed-policy quota, so applying the printed JSON failed with LimitExceeded for any non-admin operator. Shrink to 5818 whitespace-free by merging statements that share Effect + Resource + Condition (permission-neutral by construction): - Ec2SecurityGroupRulesTagged + Ec2DestructiveTagged + Ec2LifecycleTagged -> Ec2ManagedResourceMutateTagged (Resource "*", managed-tag condition) - IamPutRolePolicyForInstance + IamTagRoleOnManaged -> IamPutRolePolicyAndTagRoleOnManaged (role ARN, managed-tag condition) - CloudFormationRead + TagDiscovery + Ec2Discovery + Route53DnsPreflight -> CloudFormationAndResourceDiscovery (Resource "*", no condition) The effective permission set is identical before and after: a new test flattens the pre-shrink policy (kept as a fixture) and the current policy into canonical (Effect, Action, Resource-form, Resource, Condition) tuple sets and asserts equality. A size-gate test asserts the whitespace-free length is at most 6144 (citing the AWS quota) and at most 5900 for headroom so EC2 Spot (kirodotdev#3355, roughly +152 chars) still fits. Sid-pinning tests updated to the merged statement names; no assertions dropped. * chore: prune black baseline entries the gate flags Remove test/test_knowledge.py from .github/black-baseline.txt: the file graduated to black-clean on main, so the baselined-file gate fails until the stale entry is pruned (0 new offenders, 1 graduated entry). Same base-defect fix applied to the other wave-3 PRs. Also tighten two assertions on the merged IamPutRolePolicyAndTagRoleOnManaged statement to full set-equality (was subset `in`), per a-ratchet-may-only-tighten: a future third verb on that role-ARN statement now reds the test instead of landing un-caught. Test-only, permission-neutral. --------- Co-authored-by: iamwhatever <iamwhatever@users.noreply.github.com>
Problem / Motivation
kirocrew cloud iam-policyprints a customer-managed IAM policy for a non-adminoperator to apply. That policy on
mainwas 6467 characters counted withoutwhitespace — over AWS's hard cap of 6,144 characters for a customer-managed
policy (whitespace not counted). Applying the printed JSON therefore failed with
LimitExceeded, so every operator who is not already an admin could not createthe launcher policy at all.
Why it matters
The generated policy is the only supported way a least-privilege operator
stands up the
kirocrew cloudlauncher. Over the cap it is unusable, whichblocks the entire non-admin launch path. It is also prep for #3355 (EC2 Spot),
which adds ~152 characters and cannot fit while
mainis already over.What changed (motivation → approach → change)
Root cause: the policy accumulated statements that are individually
least-privilege but collectively push the compact JSON over the quota. The fix
shrinks by merging statements that share the same Effect + Resource +
Condition — a merge that is permission-neutral by construction (the effective
Effect × Action × Resource × Conditiontuple set is unchanged) — plus no otherchange. Three merges:
Ec2SecurityGroupRulesTagged+Ec2DestructiveTagged+Ec2LifecycleTagged→
Ec2ManagedResourceMutateTagged(allResource: "*"+aws:ResourceTag/kirocrew:managed=true).IamPutRolePolicyForInstance+IamTagRoleOnManaged→IamPutRolePolicyAndTagRoleOnManaged(both thekirocrew-ec2-*role ARN +the managed-tag condition).
CloudFormationRead+TagDiscovery+Ec2Discovery+Route53DnsPreflight→
CloudFormationAndResourceDiscovery(allResource: "*", no Condition;all read-only).
Result: 6467 → 5818 characters whitespace-free (29 → 23 statements), under
the 6,144 hard cap and under a self-imposed 5,900 headroom target so #3355 fits.
The security rationale of every merged statement is preserved in the combined
comments (the tag-gate reasoning, the
iam:TagRolenon-spoofable-distinguisherargument, the DNS-preflight note, the exclusion of
ListCommandInvocationsetc.). No condition, resource scope, or action was added or dropped.
Missing-
Resourcestatement: the task flagged a statement onmainreportedly missing a
Resourcekey. I did not find one — every statement inpolicy_document()carries exactly one ofResource/NotResource(the existingtest_is_valid_policy_shapeasserts this and passes both before and after). Thesingle
Deny(DenyStartSessionOutsideTheLane) usesNotResource, which iscorrect and intentional. Nothing to fix here.
CHANGELOG: deliberately not touched. This repo's
docs/build/changelog.mdand the
check_changelog_history.pygate state that a feature/fix PR does nottouch
CHANGELOG.md— the release PR writes the section,[Unreleased]andper-PR entries are refused, and shipped sections are immutable. The commit
subject is the record until a version bump. Adding an entry here would either
fail the gate's intent or freeze an unreleased section; the correct action under
this repo's own rule is to leave it out. (This is a deliberate deviation from the
literal "add a CHANGELOG entry" instruction, driven by the repo's documented
gate.)
Backwards compatibility
Compatible: the effective permission set is byte-for-byte identical before and
after (proven by
test_shrink_preserved_the_permission_set_byte_for_byte, whichcompares canonical tuple sets of the pre-shrink fixture vs. the new policy — 118
tuples, equal). Statement
Sids changed, butSidis a human label with noauthorization effect; the only in-repo consumers of these
Sids are thismodule's own tests, updated in the same commit.
Tests
test_shrink_preserved_the_permission_set_byte_for_byte(new): flattensthe pre-shrink policy (kept as fixture
test/fixtures/cloud_iam_policy_pre_shrink.json)and the current policy into canonical
(Effect, Action, Resource-form, Resource, Condition)tuple sets and asserts equality; also asserts the fixturereally was over 6144 (so it is the genuine pre-shrink state).
test_policy_fits_iam_managed_policy_limit(new): asserts thewhitespace-free length is
<= 6144(docstring cites the AWS IAM"Managed policy size" quota, non-adjustable) and
<= 5900for feat(cloud): support EC2 Spot Instances in kirocrew cloud launch (--spot) #3355 headroom.(
test_authorize_security_group_is_tag_gated,test_lifecycle_is_tag_scoped,test_destructive_ec2_verbs_tag_scoped,test_put_role_policy_is_tag_scoped,test_tag_role_gated_on_existing_managed_tag,test_put_role_policy_scoped_no_dead_boundary_condition,test_put_role_policy_and_passrole_not_tag_scoped_regression,test_cloudformation_mutation_scoped_to_kirocrew_stacks) — every assertionretained.
Manual verification
N/A — unit coverage sufficient. The change is text + tests only, no AWS calls;
equivalence and size are both machine-checked. Ran locally: full
test/test_cloud_*.pysuite (1073 passed),flake8,isort --check,black --check,mypyon both files (all clean), and the changelog-history gateagainst the merge base (shipped sections intact).
Related Issues
Prep for #3355 (EC2 Spot launch).
Pattern harvest
Rule candidate: review-prompt
Pattern: an IAM/JSON policy generator that grows near a hard size quota should
carry a size-gate test AND an equivalence-against-fixture test, so statements can
be merged for size without silently changing the permission set.
Checklist
fix: ...)