Skip to content

Conversation

shahvrushali22
Copy link
Contributor

Summary

This PR adds in-cluster service proxy support to Headlamp, enables Helm operations with authenticated access, and refactors token validation for consistency. It also ensures namespace scoping in Helm charts and enables secure HTTPS-based readiness and liveness probes.

Changes

  • Added serviceproxy backend module to enable authenticated in-cluster service access.
  • Registered new route /clusters/{cluster}/serviceproxy/{namespace}/{name}.
  • Refactored checkHeadlampBackendToken into a method for consistency.
  • Enabled Helm support via --enable-helm flag and validated tokens using SelfSubjectReview.
  • Forwarded Bearer tokens for secure Helm operations.
  • Updated Helm chart templates:
  • Added namespace scoping to all resources.
  • Enabled HTTPS for liveness/readiness probes and services.
  • Made Helm feature toggleable via values.yaml.
  • Added config test for enableHelm flag and updated expected chart templates.

Steps to Test

  1. Install Headlamp with Helm support enabled
  2. Test in-cluster service proxy route
  3. Test Helm integration in the UI

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jun 26, 2025
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 26, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

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

@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Jun 26, 2025
@illume illume requested a review from Copilot July 2, 2025 10:20
Copy link
Contributor

@Copilot 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

This PR adds authenticated in-cluster service proxy support and enables Helm operations in Headlamp, alongside refactoring token validation and enhancing Helm charts for namespace scoping and HTTPS readiness/liveness probes.

  • Introduce a new serviceproxy backend module and route for in-cluster service access
  • Enable Helm via --enable-helm, forward bearer tokens, and perform a SelfSubjectReview check
  • Update Helm chart templates for namespace scoping, HTTPS probes, and a toggleable Helm feature

Reviewed Changes

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

Show a summary per file
File Description
frontend/src/components/account/Auth.tsx Reload page on successful authentication
frontend/package.json Add npx update-browserslist-db@latest to prebuild
frontend/make-env.js Disable source maps by setting GENERATE_SOURCEMAP: false
charts/headlamp/values.yaml Add enableHelm flag and change default service port to 443
charts/headlamp/templates/serviceaccount.yaml Scope ServiceAccount to release namespace
charts/headlamp/templates/service.yaml Scope Service and switch targetPort to HTTPS
charts/headlamp/templates/deployment.yaml Scope Deployment, add -enable-helm, and enable HTTPS probes
charts/headlamp/templates/secret.yaml Scope Secret to release namespace
charts/headlamp/templates/pvc.yaml Scope PVC to release namespace
charts/headlamp/templates/ingress.yaml Scope Ingress to release namespace
backend/pkg/serviceproxy/service.go Implement service lookup and URL prefix logic
backend/pkg/serviceproxy/http.go Provide HTTPGet helper for proxied requests
backend/pkg/serviceproxy/handler.go Handle proxy requests and enforce no-cache headers
backend/pkg/serviceproxy/connection.go Wrap HTTP calls in a ServiceConnection interface
backend/pkg/helm/release.go Add SelfSubjectReview before Helm install
backend/pkg/config/config.go & config_test.go Add enable-helm flag parsing and tests
backend/cmd/headlamp.go Register serviceproxy route and refactor token check
Comments suppressed due to low confidence (2)

backend/pkg/serviceproxy/service.go:15

  • [nitpick] The constant name HTTPScheme is misleading since it holds the "http" scheme. Rename it to something like HTTPSchemeName or HTTPName and use HTT PSScheme for "https" to avoid confusion.
	HTTPScheme  = "http"

backend/pkg/serviceproxy/service.go:1

  • There are no unit tests for the serviceproxy package. Consider adding tests for getService, getPort, and getServiceURLPrefix to ensure correct behavior and catch regressions.
package serviceproxy

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 6, 2025
Copy link

linux-foundation-easycla bot commented Aug 18, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Aug 18, 2025
@k8s-ci-robot k8s-ci-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Aug 20, 2025
@illume
Copy link
Contributor

illume commented Aug 28, 2025

Thanks for those changes for the copilot comments.

It looks like there's some conflicts with the main branch at the moment. Would you be able to have a look?

@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 16, 2025
@muraliinformal
Copy link

@joaquimrocha @illume Could you please take a look ?

@joaquimrocha
Copy link
Contributor

I will let @illume continue the review.

@muraliinformal muraliinformal force-pushed the add-serviceproxy branch 2 times, most recently from 40d09c2 to 16e1d15 Compare September 22, 2025 19:50
@muraliinformal
Copy link

@illume Could you please review the changes when you get chance ? Thanks

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 25, 2025
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Sep 26, 2025
Copy link
Contributor

@illume illume left a comment

Choose a reason for hiding this comment

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

Thanks for those changes.

Seems there's some backend lint/formatting issues and some chart issues. You can run these locally:

make backend-lint
make backend-format
make helm-template-test

I marked some conversations as resolved, and left a few open that need to be addressed.

@illume illume requested a review from Copilot September 26, 2025 18:52
Copy link
Contributor

@Copilot 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

Copilot reviewed 24 out of 24 changed files in this pull request and generated 5 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

})
);
// On successful authentication, reload the page
window.location.reload();
Copy link
Preview

Copilot AI Sep 26, 2025

Choose a reason for hiding this comment

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

Using window.location.reload() forces a full page reload which can be disruptive to user experience. Consider using React state management or router navigation to update the UI state instead of a hard reload.

Suggested change
window.location.reload();
// window.location.reload(); // Removed to avoid full page reload

Copilot uses AI. Check for mistakes.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this window reload really needed? (We seem to be ok without it so far.)

I wonder if there is a way to reproduce any issue where it's not working?

Choose a reason for hiding this comment

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

This is removed

@illume illume requested a review from Copilot October 3, 2025 18:31
Copy link
Contributor

@Copilot 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

Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.


// Get - perform the get request.
func (c *Connection) Get(requestURI string) ([]byte, error) {
uri := fmt.Sprintf("%s/%s", c.URI, requestURI)
Copy link
Preview

Copilot AI Oct 3, 2025

Choose a reason for hiding this comment

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

The requestURI parameter is directly concatenated without validation, which could lead to path traversal attacks. Consider validating and sanitizing the requestURI parameter to prevent malicious paths like '../../../etc/passwd'.

Copilot uses AI. Check for mistakes.

installClient.Description = req.Description
installClient.CreateNamespace = req.CreateNamespace
installClient.ReleaseName, installClient.Namespace = req.Name, req.Namespace
installClient.Description, installClient.CreateNamespace = req.Description, req.CreateNamespace
Copy link
Preview

Copilot AI Oct 3, 2025

Choose a reason for hiding this comment

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

[nitpick] Multiple assignments on a single line reduce readability. Consider splitting these into separate lines for better maintainability.

Suggested change
installClient.Description, installClient.CreateNamespace = req.Description, req.CreateNamespace
installClient.Description = req.Description
installClient.CreateNamespace = req.CreateNamespace

Copilot uses AI. Check for mistakes.

Comment on lines +63 to +69
// TODO - what if both exist?
func getPort(ports []corev1.ServicePort) (*corev1.ServicePort, error) {
for i, port := range ports {
if port.Name == HTTPSScheme || port.Name == HTTPScheme {
return &ports[i], nil
}
}
Copy link
Preview

Copilot AI Oct 3, 2025

Choose a reason for hiding this comment

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

The TODO comment indicates incomplete logic handling. The function should clarify the priority when both 'http' and 'https' ports exist, or implement proper logic to handle this scenario.

Suggested change
// TODO - what if both exist?
func getPort(ports []corev1.ServicePort) (*corev1.ServicePort, error) {
for i, port := range ports {
if port.Name == HTTPSScheme || port.Name == HTTPScheme {
return &ports[i], nil
}
}
// Prefer "https" over "http" if both exist.
func getPort(ports []corev1.ServicePort) (*corev1.ServicePort, error) {
// First, look for "https"
for i, port := range ports {
if port.Name == HTTPSScheme {
return &ports[i], nil
}
}
// Then, look for "http"
for i, port := range ports {
if port.Name == HTTPScheme {
return &ports[i], nil
}
}

Copilot uses AI. Check for mistakes.

}

values := make(map[string]interface{})

Copy link
Preview

Copilot AI Oct 3, 2025

Choose a reason for hiding this comment

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

[nitpick] The values variable is declared after decoding but could be declared closer to its usage for better code organization.

Suggested change

Copilot uses AI. Check for mistakes.

@illume
Copy link
Contributor

illume commented Oct 3, 2025

@muraliinformal theres a few open conversations. Can you please let me know what you think about each of them?

Please see the commit guidelines https://headlamp.dev/docs/latest/contributing#2-follow-commit-guidelines

Could you please squash your changes and rebase against main? If it makes sense to break it up into some smaller independent atomic commits, please do that?

Copy link
Contributor

@illume illume left a comment

Choose a reason for hiding this comment

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

Left a note about the enableHelm chart variable needing documentation.

name: ""
# -- directory to look for plugins
pluginsDir: "/headlamp/plugins"
enableHelm: false
Copy link
Contributor

Choose a reason for hiding this comment

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

We’ll need to add an entry to the documentation for this variable in charts/headlamp/README.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. 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.

5 participants