fix: POST /api/plan panics when ATLANTIS_ENABLE_POLICY_CHECKS=true#6484
Open
Abzaek wants to merge 1 commit into
Open
fix: POST /api/plan panics when ATLANTIS_ENABLE_POLICY_CHECKS=true#6484Abzaek wants to merge 1 commit into
Abzaek wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Attempts to fix the panic in POST /api/plan (and symmetrically /api/apply) that occurs when ATLANTIS_ENABLE_POLICY_CHECKS=true. The root cause is that BuildPlanCommands returns 2×N ProjectContexts (Plan + PolicyCheck) while cc only has N CommentCommands, so indexing cc[i] panics. The patch guards the access with a length check and passes nil when out of range.
Changes:
- Adds a bounds check around
cc[i]in theapiPlanloop, passingnilto pre/post hook runners when the index overflows. - Applies the same guard in
apiApplyfor symmetry.
600a786 to
8ffa1bc
Compare
When ATLANTIS_ENABLE_POLICY_CHECKS=true, BuildPlanCommands can add policy-check contexts in addition to plan contexts. Keep API workflow hooks tied to real plan comment commands, load existing pull status so sticky policy approvals are preserved, route policy checks through the policy-check runner, and include policy-check failures in the API plan result. For branch-only API requests, return policy-check results without PR comment, status, or database side effects. For /api/apply, refresh PR and pull status after the plan phase, then stop before building apply commands if the plan phase reports failed policy checks. Fixes runatlantis#6449 Assisted-by: OpenAI <noreply@openai.com> Signed-off-by: Rui Chen <rui@chenrui.dev>
8ffa1bc to
3b4fd50
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes a panic (index out of range) in POST /api/plan when ATLANTIS_ENABLE_POLICY_CHECKS=true.
Root cause: getCommands() returns cmds (project contexts) and cc (comment commands). When policy checks are enabled, BuildPlanCommands appends a PolicyCheck context alongside Plan context for each project, so cmds has 2xN entries while cc has N entries. The loop indexes both slices with the same variable i, causing panic.
Fix: guard cc[i] with bounds check. Same fix applied to apiApply for consistency.
Fixes #6449