Skip to content

helm: add authentication support to Helm repository operations#5120

Open
Athang69 wants to merge 1 commit into
kubernetes-sigs:mainfrom
Athang69:helm-repo-auth-support
Open

helm: add authentication support to Helm repository operations#5120
Athang69 wants to merge 1 commit into
kubernetes-sigs:mainfrom
Athang69:helm-repo-auth-support

Conversation

@Athang69
Copy link
Copy Markdown
Contributor

@Athang69 Athang69 commented Apr 11, 2026

Summary

This PR adds authentication support to Helm repository add and update operations by extending AddUpdateRepoRequest to include auth fields supported by helm.sh/helm/v3/pkg/repo.Entry.

Changes

  • Extended AddUpdateRepoRequest struct with username, password, insecureSkipTLSverify, and passCredentialsAll fields. certFile, keyFile, and caFile are intentionally omitted as accepting filesystem paths from HTTP clients would allow arbitrary local file reads on the server; these values are preserved from the existing repo entry only.
  • Added Validate() method to AddUpdateRepoRequest to reject empty name or url with HTTP 400.
  • Updated addRepository to accept the full request struct and pass auth fields to repo.Entry.
  • Updated UpdateRepository to accept the full request struct, preserve existing auth fields, and return HTTP 404 if the named repository does not exist.
  • Lowercased updateRepositoryWithRequest to keep it unexported since there are no external callers outside this file.
  • Added applyRequestFields helper to apply optional auth fields to a repo.Entry.
  • Added findRepoEntry helper to look up an existing repo entry by name.
  • Fixed createFileIfNotThere to properly close the file handle and propagate non-IsNotExist errors from os.Stat.
  • Fixed ListRepo and AddRepo handlers to buffer the JSON response before writing headers, preventing malformed responses on encode errors.
  • Fixed log message in RemoveRepository to pass the repository name via structured metadata instead of as the message string.

Steps to Test

  1. Run the backend with Helm enabled: HEADLAMP_CONFIG_ENABLE_HELM=true ./headlamp-server
  2. Send a POST request to the add repo endpoint with username and password fields in the body.
  3. Confirm the repository is added and the credentials are stored in the Helm repo config file.
  4. Send a PUT request to the update repo endpoint without auth fields and confirm the existing credentials are preserved.
  5. Send a PUT request with a repo name that does not exist and confirm a 404 is returned.
  6. Run go test -v -p 1 ./pkg/helm/... and confirm all tests pass.

Notes for the Reviewer

  • All new auth fields are optional. Requests that omit them get zero-value defaults, so there is no breaking change to existing callers.
  • addRepository is unexported so its signature change has no impact outside this file.
  • updateRepositoryWithRequest is unexported. UpdateRepository remains the single exported function and delegates to it.
  • certFile, keyFile, and caFile are not accepted from the HTTP request body. This is a deliberate security decision to prevent server-side path traversal via authenticated API calls.
  • TestListChart was already failing before this PR due to a missing local Helm cache file. This PR does not introduce or fix that failure.

Copilot AI review requested due to automatic review settings April 11, 2026 09:25
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Athang69
Once this PR has been reviewed and has the lgtm label, please assign sniok 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

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Apr 11, 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

This PR extends the backend Helm repository add/update endpoints to support Helm repository authentication and TLS-related settings by plumbing additional request fields through to helm.sh/helm/v3/pkg/repo.Entry.

Changes:

  • Expanded AddUpdateRepoRequest to include username/password and TLS/auth-related fields supported by Helm’s repo.Entry.
  • Updated repository add/update flows to pass the full request through to Helm’s repository entry creation/update.
Comments suppressed due to low confidence (1)

backend/pkg/helm/repository.go:141

  • This PR introduces persisted credentials (e.g., Password, TLS key material) in the Helm repo config, but the file is written with defaultNewConfigFileMode (currently 0644). That makes credentials world-readable on multi-user systems. Use a restrictive mode (e.g., 0600) when writing/creating the repo config (and consider tightening the directory mode as well).
	repoFile.Update(newRepo)

	err = repoFile.WriteFile(settings.RepositoryConfig, defaultNewConfigFileMode)
	if err != nil {

Comment thread backend/pkg/helm/repository.go Outdated
Comment thread backend/pkg/helm/repository.go
Comment thread backend/pkg/helm/repository.go Outdated
Comment thread backend/pkg/helm/repository.go Outdated
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Apr 11, 2026
@Athang69 Athang69 changed the title helm: add authentication support to repository add and update helm: add authentication support add update to repository Apr 11, 2026
@Athang69 Athang69 requested a review from Copilot April 11, 2026 17:50
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

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

Comment thread backend/pkg/helm/repository.go Outdated
Comment thread backend/pkg/helm/repository_test.go Outdated
Comment thread backend/pkg/helm/repository_test.go Outdated
Comment thread backend/pkg/helm/repository_test.go Outdated
Comment thread backend/pkg/helm/repository.go
@Athang69
Copy link
Copy Markdown
Contributor Author

@sniok @illume
In the copilot reviews the nolint:gosec directive is intentional. gosec G117 flags json.Marshal because the struct contains a Password field. These are test-only credentials used to verify that auth fields are correctly passed through to the Helm repo entry. There are no real secrets here.

@Athang69
Copy link
Copy Markdown
Contributor Author

@sniok @illume I’d appreciate your review of this PR, especially to confirm whether the approach looks good to you.

Copy link
Copy Markdown
Contributor

@skoeva skoeva left a comment

Choose a reason for hiding this comment

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

hi, could you squash the linting fixes into one atomic commit? and make sure to address the failing test in the CI

@Athang69 Athang69 force-pushed the helm-repo-auth-support branch 2 times, most recently from 85f7e4f to b76c7f8 Compare April 15, 2026 16:39
@Athang69 Athang69 requested a review from skoeva April 15, 2026 16:55
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 17, 2026
@Athang69 Athang69 force-pushed the helm-repo-auth-support branch from b76c7f8 to 3c1ffc7 Compare April 17, 2026 04:47
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 17, 2026
@Athang69 Athang69 requested a review from Copilot April 17, 2026 04:47
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

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

Comment thread backend/pkg/helm/repository_test.go Outdated
Comment thread backend/pkg/helm/repository_test.go Outdated
Comment thread backend/pkg/helm/repository.go
@Athang69 Athang69 force-pushed the helm-repo-auth-support branch 2 times, most recently from ad7b353 to 655ad01 Compare April 17, 2026 05:21
@Athang69
Copy link
Copy Markdown
Contributor Author

Hi @skoeva I’ve squashed the linting fixes into a single atomic commit as requested and also fixed the failing CI test
Please take a look at the changes and let me know if you'd like me to change anything further.
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 May 13, 2026
@Athang69
Copy link
Copy Markdown
Contributor Author

@illume Resolved the copilot's review PTAL.
Thanks!!

@Athang69
Copy link
Copy Markdown
Contributor Author

@illume For the flaky fuzz test I have raised #5683 PTAL.
Thankss!

@Athang69 Athang69 force-pushed the helm-repo-auth-support branch 2 times, most recently from 062d4cd to b2ef92f Compare May 16, 2026 10:54
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels May 16, 2026
@illume illume requested a review from Copilot May 16, 2026 14:54
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

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

Comment thread backend/pkg/helm/repository.go Outdated
Comment thread backend/pkg/helm/repository.go
Comment thread backend/pkg/helm/repository.go Outdated
@Athang69 Athang69 force-pushed the helm-repo-auth-support branch from b2ef92f to 00b3af9 Compare May 16, 2026 15:10
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels May 16, 2026
@illume illume requested a review from Copilot May 17, 2026 06:41
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

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

Comment thread backend/pkg/helm/repository.go Outdated
Comment thread backend/pkg/helm/repository.go
Comment thread backend/pkg/helm/repository.go
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

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

Copy link
Copy Markdown
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 working on this.

Would you mind addressing the open Copilot review comments? Please mark each comment as resolved after addressing it.

@Athang69
Copy link
Copy Markdown
Contributor Author

Athang69 commented May 17, 2026

@illume The exported UpdateRepository function is only called from its own HTTP handler within the same file with no external callers in the codebase, so no deprecation cycle is needed. The godoc has been updated to document the new 404 behavior explicitly so any future external caller is aware
All other copilot reviews are fixed PTAL.
Thanks!!

@Athang69 Athang69 requested a review from illume May 17, 2026 10:31
Copy link
Copy Markdown
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.

Thank you.

It's looking very good now.

Just left a few notes about some missing function docs. I think after that it looks good to go.

Comment thread backend/pkg/helm/repository.go
Comment thread backend/pkg/helm/repository.go
Comment thread backend/pkg/helm/repository_test.go
Signed-off-by: Athang69 <athangkali21@gmail.com>
@Athang69 Athang69 force-pushed the helm-repo-auth-support branch from 18d980a to a91fcfa Compare May 18, 2026 04:03
@Athang69 Athang69 requested a review from illume May 18, 2026 04:04
@Athang69
Copy link
Copy Markdown
Contributor Author

@illume Added doc comments PTAL.
Thanks!!

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

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

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