Skip to content

🔒 fix: audit setCORSHeaders callers to pass explicit methods (#8201)#8212

Merged
clubanderson merged 1 commit intomainfrom
fix/cors-methods-8201
Apr 15, 2026
Merged

🔒 fix: audit setCORSHeaders callers to pass explicit methods (#8201)#8212
clubanderson merged 1 commit intomainfrom
fix/cors-methods-8201

Conversation

@clubanderson
Copy link
Copy Markdown
Collaborator

Summary

Copilot review on merged PR #8198 flagged:

pkg/agent/server_http.go:1976setCORSHeaders still defaults Access-Control-Allow-Methods to "GET, OPTIONS" unless callers pass an explicit method list. There are existing kc-agent handlers that serve POST/DELETE (e.g., /serviceaccounts, and others) which call setCORSHeaders(w) without passing methods, so their preflight responses still advertise only GET/OPTIONS.

This PR audits every setCORSHeaders caller in pkg/agent and updates each non-GET handler to pass an explicit method list. The default of "GET, OPTIONS" is preserved for back-compat and remains correct for read-only handlers.

Handlers Updated

server_http.go

  • handleNamespacesHTTP → GET, POST, DELETE, OPTIONS
  • handleServiceAccountsHTTP → GET, POST, DELETE, OPTIONS (Copilot-flagged)
  • handleServiceExportsHTTP → POST, DELETE, OPTIONS
  • handleRoleBindingsHTTP → GET, POST, DELETE, OPTIONS
  • handleScaleHTTP → POST, OPTIONS (consolidated from inline override)
  • handleDeployWorkloadHTTP → POST, OPTIONS (consolidated from inline override)
  • handleDeleteWorkloadHTTP → POST, OPTIONS (consolidated from inline override)
  • handleAutoUpdateConfig → GET, POST, OPTIONS (was set only inside the OPTIONS branch)
  • handleAutoUpdateTrigger → POST, OPTIONS (was set only inside the OPTIONS branch)
  • handleAutoUpdateCancel → POST, OPTIONS (was set only inside the OPTIONS branch)
  • handleKubeconfigRemoveHTTP → POST, OPTIONS (consolidated from inline override)

server_helm.go

  • handleHelmRollback → POST, OPTIONS
  • handleHelmUninstall → POST, OPTIONS
  • handleHelmUpgrade → POST, OPTIONS

server_gitops.go

  • handleDetectDrift → POST, OPTIONS
  • handleGitopsSync → POST, OPTIONS

server_console_cr.go

  • handleConsoleCRManagedWorkloads → POST, PUT, DELETE, OPTIONS
  • handleConsoleCRClusterGroups → POST, PUT, DELETE, OPTIONS
  • handleConsoleCRWorkloadDeployments → POST, DELETE, OPTIONS
  • handleConsoleCRWorkloadDeploymentStatus → PUT, OPTIONS

server_argocd.go

server_gpu_health.go

  • handleGPUHealthCronJob → POST, DELETE, OPTIONS

server_operations.go

  • handleLocalClusters → GET, POST, DELETE, OPTIONS
  • handleLocalClusterLifecycle → POST, OPTIONS
  • handleVClusterCreate → POST, OPTIONS
  • handleVClusterConnect → POST, OPTIONS
  • handleVClusterDisconnect → POST, OPTIONS
  • handleVClusterDelete → POST, OPTIONS

GET-only handlers (gpu-nodes, nodes, pods, events, deployments, replicasets, statefulsets, daemonsets, cronjobs, ingresses, networkpolicies, services, configmaps, secrets, jobs, hpas, pvcs, roles, resourcequotas, limitranges, resolve-deps, cluster-health, autoUpdateStatus, kagenti/, kagent-crds/, prometheus query, vCluster list/check, cloudCLIStatus, localClusterTools, rbac/permissions, permissions/summary) keep the default and remain correct.

The setCORSHeaders doc comment now carries an explicit audit rule so future handlers serving non-GET methods don't silently regress.

A new regression test TestHandleServiceAccounts_CORSMethodsHeader pins the fix for the specific handler Copilot called out.

Test plan

  • go build ./... passes
  • go vet ./... passes
  • go test ./pkg/agent/ -run "TestSetCORSHeaders|TestHandleCanIHTTP_CORSMethodsHeader|TestHandleServiceAccounts_CORSMethodsHeader" passes
  • cd web && npm run build passes
  • CI build/lint green

Fixes #8201

Copilot review on merged PR #8198 flagged that setCORSHeaders still
defaults Access-Control-Allow-Methods to "GET, OPTIONS" unless callers
pass an explicit method list, and that several existing kc-agent
handlers serving POST/DELETE (e.g. /serviceaccounts) were still calling
setCORSHeaders(w, r) without methods, so their preflight responses
advertised only GET/OPTIONS and browsers rejected cross-origin
POST/DELETE.

This PR audits every setCORSHeaders caller in pkg/agent and updates the
non-GET handlers to pass an explicit method list. The default of
"GET, OPTIONS" is preserved for back-compat and remains correct for the
read-only handlers.

Handlers updated to advertise correct Allow-Methods on preflight:

server_http.go
- handleNamespacesHTTP        GET, POST, DELETE, OPTIONS
- handleServiceAccountsHTTP   GET, POST, DELETE, OPTIONS
- handleServiceExportsHTTP    POST, DELETE, OPTIONS
- handleRoleBindingsHTTP      GET, POST, DELETE, OPTIONS
- handleScaleHTTP             POST, OPTIONS (consolidated from inline)
- handleDeployWorkloadHTTP    POST, OPTIONS (consolidated from inline)
- handleDeleteWorkloadHTTP    POST, OPTIONS (consolidated from inline)
- handleAutoUpdateConfig      GET, POST, OPTIONS (was OPTIONS-only)
- handleAutoUpdateTrigger     POST, OPTIONS (was OPTIONS-only)
- handleAutoUpdateCancel      POST, OPTIONS (was OPTIONS-only)
- handleKubeconfigRemoveHTTP  POST, OPTIONS (consolidated from inline)

server_helm.go
- handleHelmRollback          POST, OPTIONS
- handleHelmUninstall         POST, OPTIONS
- handleHelmUpgrade           POST, OPTIONS

server_gitops.go
- handleDetectDrift           POST, OPTIONS
- handleGitopsSync            POST, OPTIONS

server_console_cr.go
- handleConsoleCRManagedWorkloads        POST, PUT, DELETE, OPTIONS
- handleConsoleCRClusterGroups           POST, PUT, DELETE, OPTIONS
- handleConsoleCRWorkloadDeployments     POST, DELETE, OPTIONS
- handleConsoleCRWorkloadDeploymentStatus PUT, OPTIONS

server_argocd.go
- handleArgoCDSync            POST, OPTIONS (consolidated from inline)

server_gpu_health.go
- handleGPUHealthCronJob      POST, DELETE, OPTIONS

server_operations.go
- handleLocalClusters         GET, POST, DELETE, OPTIONS
- handleLocalClusterLifecycle POST, OPTIONS
- handleVClusterCreate        POST, OPTIONS
- handleVClusterConnect       POST, OPTIONS
- handleVClusterDisconnect    POST, OPTIONS
- handleVClusterDelete        POST, OPTIONS

GET-only handlers (gpu-nodes, nodes, pods, events, deployments,
replicasets, statefulsets, daemonsets, cronjobs, ingresses, services,
configmaps, secrets, jobs, hpas, pvcs, roles, resourcequotas,
limitranges, resolvedeps, clusterhealth, autoupdatestatus, kagenti/*,
kagent-crds/*, prometheus query, vCluster list/check, cloudCLIStatus,
localClusterTools, rbac/permissions, permissions/summary) keep the
default and remain correct.

Also updates the setCORSHeaders doc comment with an explicit audit rule
so future handlers serving non-GET methods don't silently regress.

Adds a regression test (TestHandleServiceAccounts_CORSMethodsHeader)
that pins the fix on the specific handler Copilot called out.

Fixes #8201

Signed-off-by: Andy Anderson <[email protected]>
Copilot AI review requested due to automatic review settings April 15, 2026 19:10
@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 15, 2026
@clubanderson clubanderson added the ai-generated Pull request generated by AI label Apr 15, 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/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Apr 15, 2026
@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 15, 2026

Deploy Preview for kubestellarconsole canceled.

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

@clubanderson clubanderson merged commit e5f37b6 into main Apr 15, 2026
24 of 25 checks passed
@clubanderson clubanderson deleted the fix/cors-methods-8201 branch April 15, 2026 19:12
@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

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

Audits kc-agent HTTP handlers to ensure CORS preflight responses advertise the full set of non-GET methods actually served by each route, preventing browser CORS failures caused by the setCORSHeaders default of "GET, OPTIONS".

Changes:

  • Updated non-GET handlers across agent servers to pass explicit Access-Control-Allow-Methods via setCORSHeaders(..., methods...).
  • Consolidated a few prior inline Access-Control-Allow-Methods overrides into setCORSHeaders calls for consistency.
  • Added a regression test pinning the /serviceaccounts CORS methods header behavior.

Reviewed changes

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

Show a summary per file
File Description
pkg/agent/server_http.go Pass explicit method lists to setCORSHeaders for mutating handlers (namespaces, serviceaccounts, serviceexports, rolebindings, scale/deploy/delete workload, auto-update endpoints, kubeconfig remove) and documents the audit rule.
pkg/agent/server_operations.go Updates local cluster + vCluster mutating endpoints to advertise correct CORS methods (GET/POST/DELETE or POST-only).
pkg/agent/server_helm.go Ensures Helm POST-only endpoints advertise POST in CORS preflight via setCORSHeaders.
pkg/agent/server_gitops.go Ensures GitOps POST-only endpoints advertise POST in CORS preflight via setCORSHeaders.
pkg/agent/server_console_cr.go Ensures Console CR write endpoints advertise POST/PUT/DELETE as appropriate in CORS preflight via setCORSHeaders.
pkg/agent/server_argocd.go Replaces inline CORS methods override with explicit setCORSHeaders method list for POST-only sync.
pkg/agent/server_gpu_health.go Ensures GPU health CronJob install/uninstall advertises POST/DELETE in CORS preflight via setCORSHeaders.
pkg/agent/server_rbac_test.go Adds TestHandleServiceAccounts_CORSMethodsHeader regression test for the audited /serviceaccounts handler.

@github-actions
Copy link
Copy Markdown
Contributor

❌ Post-Merge Verification: failed

Commit: e5f37b675f05f0f872336330c4cd94d3b2e00731
Specs run: smoke.spec.ts
Report: https://github.com/kubestellar/console/actions/runs/24473309995

@github-actions
Copy link
Copy Markdown
Contributor

Post-merge build verification passed

Both Go and frontend builds compiled successfully against merge commit e5f37b675f05f0f872336330c4cd94d3b2e00731.

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/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Copilot Review] 1 comment(s) on merged PR #8198

2 participants