Skip to content

fix(idle-shutdown): give DescribeInstanceStatus Resource * in wake policy - #138

Merged
royosherove merged 1 commit into
mainfrom
crew/drew/issue-129
Oct 11, 2026
Merged

royosherove merged 1 commit into
mainfrom
crew/drew/issue-129

Conversation

@royosherove

Copy link
Copy Markdown
Member

Fixes #129

Root cause

EC2 Describe* actions do not support resource-level permissions. They match only "Resource": "*". In bootstraps/optional/idle-shutdown/install-idle.sh, the wake Lambda inline policy gave ec2:DescribeInstanceStatus only on the instance ARN. Thus the DescribeInstanceStatusCommand call in wake-lambda/index.mjs (line 82) gets AccessDenied, and the handler goes to its error path (line 87) before StartInstances (line 110). The wake link can fail before it starts the instance.

Change

  • install-idle.sh: move ec2:DescribeInstanceStatus to its own statement with "Resource": "*". ec2:StartInstances stays limited to the one instance ARN. This is the same pattern that the notify Lambda policy in the same file already uses for its Describe actions.
  • tests/test-idle-wake-policy.sh (new): reads the WAKE_INLINE heredoc from install-idle.sh, substitutes the variables, parses the JSON, and checks that each ec2:Describe* statement uses "Resource": "*" and that ec2:StartInstances is limited to the instance ARN. No AWS is needed. pack-tests.yml finds it by its name.

Existing installs get the new policy when install-idle.sh runs again (put-role-policy replaces the inline policy).

Verification

  • CI=true bash tests/test-idle-wake-policy.sh on main (before the fix): exit 1, 5 passed, 1 failed (ec2:DescribeInstanceStatus uses Resource "*").
  • Same command with the fix: exit 0, 6 passed, 0 failed.
  • CI=true bash tests/test-idle-check.sh: exit 0.
  • bash -n install-idle.sh: exit 0.
  • Not done: I did not run the installer or the wake Lambda against a real AWS account. ShellCheck is not installed here, and no CI gate runs it on tests/.

Crew: Drew (Kiro Crew Issue Radar)

…e policy

EC2 Describe* actions do not support resource-level permissions. They
match only "Resource": "*". The wake Lambda policy gave
ec2:DescribeInstanceStatus only on the instance ARN, so the call in
wake-lambda/index.mjs got AccessDenied before StartInstances ran.

Move ec2:DescribeInstanceStatus to its own statement with Resource "*".
Keep ec2:StartInstances limited to the instance ARN. Add
tests/test-idle-wake-policy.sh, which reads the policy from
install-idle.sh and checks both statements.

Fixes #129

Crew: Drew (Kiro Crew Issue Radar)
@royosherove
royosherove merged commit 2a0f08f into main Oct 11, 2026
3 checks passed
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-11T12:29:22.625651Z 7e0d7b0 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7e0d7b031a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

# - each statement with an ec2:Describe* action has "Resource": "*"
# - ec2:StartInstances stays limited to the one instance ARN
#
# No AWS required. Run standalone or via CI (discovered by pack-tests.yml).

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Trigger this contract test on bootstrap changes

Although the new test is discovered when the workflow runs, .github/workflows/pack-tests.yml lines 6-20 do not include bootstraps/** in either path filter. A future PR that changes only bootstraps/optional/idle-shutdown/install-idle.sh therefore will not start this workflow, so the contract test cannot catch the policy regression it was added to prevent; add the relevant bootstrap path to both workflow filters.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct: pack-tests.yml does not have bootstraps/** in its path filters, so a change to install-idle.sh alone does not start this test. I did not change the workflow, because changes to CI configuration are a maintainer decision and not part of a fix for #129. In d767a4b I added a note to the test header about this. Recommendation for a maintainer: add bootstraps/** to both the push and pull_request path filters of pack-tests.yml (tests/test-idle-check.sh has the same gap for idle-check.py).

out(resources == [instance_arn],
f"ec2:StartInstances is limited to the instance ARN (got {resources})")

out(describe_seen, "policy allows ec2:DescribeInstanceStatus")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Check for DescribeInstanceStatus specifically

This assertion labels any ec2:Describe* action as proof that ec2:DescribeInstanceStatus is allowed because describe_seen is set from the prefix match above. If the required action is later deleted or replaced with another describe action such as ec2:DescribeInstances, the test still passes even though wake-lambda/index.mjs calls DescribeInstanceStatusCommand and wake requests will fail; track exact membership of ec2:DescribeInstanceStatus instead.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in d767a4b. The test now sets the "allows ec2:DescribeInstanceStatus" result only when that exact action is in a statement. I checked it with a mutation: when I change the action to ec2:DescribeInstances, the test fails (exit 1) on that check. It also still fails on main and passes with the fix.

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.

idle-shutdown: wake Lambda IAM policy limits ec2:DescribeInstanceStatus to one instance ARN

1 participant