Skip to content

fix: address Copilot review on PR #6031#6080

Merged
clubanderson merged 1 commit intomainfrom
fix/6075-copilot-followup
Apr 10, 2026
Merged

fix: address Copilot review on PR #6031#6080
clubanderson merged 1 commit intomainfrom
fix/6075-copilot-followup

Conversation

@clubanderson
Copy link
Copy Markdown
Collaborator

Summary

Two cleanups flagged by Copilot on the merged security bundle PR #6031.

1. exec.go race window

Where: `pkg/api/handlers/exec.go` (around the original line 393)

Problem: the exec context + registry registration happened only AFTER reading the init message, looking up the k8s client + REST config, and building the SPDY executor. If the user logged out during that ~hundreds-of-ms window, `CancelUserExecSessions` had nothing to cancel — the about-to-start exec session leaked past logout.

Fix: move `execCtx, execCancel := context.WithCancel(...)` and the `registerExecSession()` call to immediately after JWT validation, before any of the long-running setup. Registration now happens essentially synchronously with the first byte the handler receives, so a follow-up `Logout` always finds and cancels the in-flight session.

2. gitops_test.go missing argocd-sync coverage

Where: `pkg/api/handlers/gitops_test.go:148`

Problem: `gitopsMutationCases` covered `sync`, `helm-upgrade`, `helm-uninstall`, `helm-rollback` but NOT `/api/gitops/argocd/sync`, even though `TriggerArgoSync` was gated by `requireEditorOrAdmin` in PR #6031 (#6022).

Fix: added an `argocd-sync` entry. Adding the case surfaced a pre-existing ordering bug in `TriggerArgoSync`: the k8s client nil check ran BEFORE body parsing and required-field validation, so a request with valid auth + valid body shape would 503 instead of returning the 400 the matrix expects. Reordered `TriggerArgoSync` to: body-parse → required-fields → `validateK8sName` → `k8sClient` check — matching the `Sync` / `UpgradeHelmRelease` conventions.

Verification

```
go build ./...
go vet ./...
go test ./pkg/... -count=1 # all pass including the new argocd-sync RBAC matrix
```

Fixes #6075

Two cleanups flagged on the merged security bundle PR.

1. exec.go race window — close the gap where /ws/exec could outlive
   logout. Previously the exec context was created and registered
   in the per-user registry only AFTER reading the init message,
   looking up the k8s client + REST config, and building the SPDY
   executor. If the user logged out during that ~hundreds-of-ms
   window, CancelUserExecSessions had nothing to cancel — the
   about-to-start exec session leaked past logout.

   Move execCtx + registerExecSession() to immediately after JWT
   validation, before any of the long-running setup. Registration
   now happens essentially synchronously with the first byte the
   handler receives, so a follow-up Logout always finds and cancels
   the in-flight session.

2. gitops_test.go — add /api/gitops/argocd/sync to gitopsMutationCases
   so TriggerArgoSync is exercised by the editor/admin/viewer RBAC
   matrix the same way the helm-* and sync handlers are.

   Adding the test surfaced a pre-existing ordering bug in
   TriggerArgoSync: the k8sClient nil check ran BEFORE body parsing
   and required-field validation, so a request with valid auth and
   a valid body shape would 503 instead of returning the 400 the
   matrix expects. Reordered to body-parse → required-fields →
   validateK8sName → k8sClient check, matching Sync /
   UpgradeHelmRelease conventions.

Fixes #6075

Signed-off-by: Andrew Anderson <[email protected]>
Copilot AI review requested due to automatic review settings April 10, 2026 12:58
@kubestellar-prow
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign mikespreitzer for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubestellar-prow kubestellar-prow Bot added the dco-signoff: yes Indicates the PR's author has signed the DCO. label Apr 10, 2026
@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 10, 2026

Deploy Preview for kubestellarconsole canceled.

Name Link
🔨 Latest commit b799989
🔍 Latest deploy log https://app.netlify.com/projects/kubestellarconsole/deploys/69d8f401a8742700082d7489

@clubanderson clubanderson added the ai-generated Pull request generated by AI label Apr 10, 2026
@github-actions
Copy link
Copy Markdown
Contributor

👋 Hey @clubanderson — thanks for opening this PR!

🤖 This project is developed exclusively using AI coding assistants.

Please do not attempt to code anything for this project manually.
All contributions should be authored using an AI coding tool such as:

This ensures consistency in code style, architecture patterns, test coverage,
and commit quality across the entire codebase.


This is an automated message.

@kubestellar-prow kubestellar-prow Bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Apr 10, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Follow-up hardening for the previously-merged security bundle (#6031), addressing two Copilot-raised gaps: an exec-session cancellation race on logout and missing RBAC matrix coverage for ArgoCD sync.

Changes:

  • Register /ws/exec sessions immediately after JWT validation so logout can reliably cancel in-flight exec setup.
  • Add RBAC test coverage for POST /api/gitops/argocd/sync.
  • Reorder TriggerArgoSync validation to return consistent 400s for invalid bodies before failing on missing Kubernetes client config.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
pkg/api/handlers/exec.go Moves exec context creation + session registry registration earlier to eliminate the logout race window.
pkg/api/handlers/gitops.go Reorders TriggerArgoSync to parse/validate request fields before checking h.k8sClient availability.
pkg/api/handlers/gitops_test.go Extends mutation RBAC test matrix with an argocd-sync case.

@clubanderson clubanderson merged commit 10d2ec4 into main Apr 10, 2026
26 of 27 checks passed
@kubestellar-prow kubestellar-prow Bot deleted the fix/6075-copilot-followup branch April 10, 2026 13:42
@github-actions
Copy link
Copy Markdown
Contributor

Thank you for your contribution! Your PR has been merged.

Check out what's new:

Stay connected: Slack #kubestellar-dev | Multi-Cluster Survey

@github-actions
Copy link
Copy Markdown
Contributor

Post-merge build verification passed

Both Go and frontend builds compiled successfully against merge commit 10d2ec44df04ae8b4b52512e3f417366ec6723b0.

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

Labels

ai-generated Pull request generated by AI dco-signoff: yes Indicates the PR's author has signed the DCO. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Copilot Review] 2 comment(s) on merged PR #6031

2 participants