Skip to content

backend: headlamp: Add pkce support #3692

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

k-airos
Copy link

@k-airos k-airos commented Jul 26, 2025

Summary

Add PKCE support for OIDC authentication flow

Related Issue

Fixes #3137

Changes

  • Added PKCE configuration: Newflag (default: true) to enable/disable PKCE
  • Updated Config struct: Added OidcUsePKCE field to support PKCE configuration
  • Implemented PKCE cryptographic functions
  • Enhanced OauthConfig struct: Added field to store PKCE verifier

Copy link

linux-foundation-easycla bot commented Jul 26, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Jul 26, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: k-airos
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.

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 requested review from ashu8912 and skoeva July 26, 2025 10:03
@k8s-ci-robot
Copy link
Contributor

Welcome @k-airos!

It looks like this is your first PR to kubernetes-sigs/headlamp 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/headlamp has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jul 26, 2025
@k-airos k-airos force-pushed the pkce_extention_support branch from 76a41bf to eb171ed Compare July 26, 2025 10:12
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Jul 26, 2025
@illume
Copy link
Contributor

illume commented Jul 27, 2025

Thanks @k-airos !

I asked in the issue for feedback, and ran the CI checks.

We'd need to documentation into the headlamp helm chart at some point (README.md, values.yaml and values.schema. Let me know if you'd like to add it in this PR, or we can do it after this is merged.

@k-airos
Copy link
Author

k-airos commented Jul 27, 2025

Thanks! I've added the documentation to README.md, updated values.yaml and values.schema.json accordingly.
Let me know if anything else should be adjusted!

@illume
Copy link
Contributor

illume commented Jul 28, 2025

@k-airos much appreciated.

I see Erik from the issue gave a thumbs up. Let's wait a little bit to see if anyone else from that issue has feedback.

I see there's an error in CI:

Testing Helm chart templates against expected output...
Error: parse error at (headlamp/templates/deployment.yaml:227): undefined variable "$usePKCE"

Use --debug flag to render out invalid YAML

To test this locally you can run:
make helm-template-test

@illume illume requested review from yolossn and Copilot and removed request for skoeva July 28, 2025 07:03
Copy link

@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 PKCE (Proof Key for Code Exchange) support to the OIDC authentication flow in Headlamp, enhancing security for OAuth 2.0 authorization code flows. PKCE is particularly important for public clients and helps mitigate authorization code interception attacks.

  • Added PKCE configuration option with default value of false
  • Implemented cryptographic functions for PKCE code verifier and challenge generation
  • Updated OIDC flow to conditionally use PKCE parameters during authorization and token exchange

Reviewed Changes

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

Show a summary per file
File Description
charts/headlamp/values.yaml Added usePKCE configuration option with default false
charts/headlamp/values.schema.json Added schema definition for usePKCE boolean field
charts/headlamp/templates/secret.yaml Added usePKCE to secret template
charts/headlamp/templates/deployment.yaml Added OIDC_USE_PKCE environment variable handling
charts/headlamp/README.md Updated documentation to include usePKCE configuration
backend/pkg/config/config.go Added OidcUsePKCE field and flag definition
backend/cmd/server.go Added oidcUsePKCE to server configuration
backend/cmd/headlamp.go Implemented PKCE cryptographic functions and updated OAuth flow
Comments suppressed due to low confidence (1)

backend/cmd/headlamp.go:264

  • [nitpick] The default value for PKCE should be true rather than false. PKCE is a security enhancement recommended by RFC 7636 and OAuth 2.1, and there's no significant downside to enabling it by default. Consider changing the default to improve security posture.
		case strings.HasPrefix(r.Host, "localhost:") || r.TLS == nil:

@@ -213,6 +224,10 @@ spec:
# Check if useAccessToken is non false either from env or oidc.config
- "-oidc-use-access-token=$(OIDC_USE_ACCESS_TOKEN)"
{{- end }}
{{- if or (ne ($oidc.usePKCE | toString) "false") (ne $usePKCE "") }}
Copy link
Preview

Copilot AI Jul 28, 2025

Choose a reason for hiding this comment

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

The variable $usePKCE is referenced but not defined in this context. This appears to be a copy-paste error from the useAccessToken logic above. It should likely be ($oidc.usePKCE | toString) or the environment variable check should be removed.

Suggested change
{{- if or (ne ($oidc.usePKCE | toString) "false") (ne $usePKCE "") }}
{{- if or (ne ($oidc.usePKCE | toString) "false") (ne $usePKCE "false") }}

Copilot uses AI. Check for mistakes.

oauth2Token, err = oauthConfig.Config.Exchange(
oauthConfig.Ctx,
r.URL.Query().Get("code"),
oauth2.SetAuthURLParam("code_verifier", oauthConfig.CodeVerifier),
Copy link
Preview

Copilot AI Jul 28, 2025

Choose a reason for hiding this comment

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

The oauth2.SetAuthURLParam function is being used incorrectly for token exchange. For PKCE token exchange, you should use oauth2.SetAuthURLParam with the Exchange method, but the parameter should be passed as an option to Exchange, not as an auth URL parameter. Use oauth2.SetAuthURLParam("code_verifier", oauthConfig.CodeVerifier) as an option to the Exchange call.

Copilot uses AI. Check for mistakes.

@illume
Copy link
Contributor

illume commented Jul 28, 2025

@yolossn @ashu8912 When you get a chance, can you please review?

@illume illume added kind/feature Categorizes issue or PR as related to a new feature. oidc Issue related to OIDC labels Jul 28, 2025
Copy link
Contributor

@yolossn yolossn left a comment

Choose a reason for hiding this comment

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

I tried testing this in in-cluster and the app doesn't work without the client-secret because of this client-secret check. We have to make client-secret optional in the kubconfig.OidcConfig for the user to make headlamp work without client-secret.

if oidcClientID != "" && oidcClientSecret != "" && oidcIssuerURL != "" && oidcScopes != "" {

@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 8, 2025
@k8s-ci-robot
Copy link
Contributor

PR needs rebase.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

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. kind/feature Categorizes issue or PR as related to a new feature. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. oidc Issue related to OIDC 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.

Enable Headlamp to use Public OIDC Client
4 participants