Skip to content

feat: support minimal permission by allowing token/url auth#394

Open
AftAb-25 wants to merge 1 commit intokarmada-io:mainfrom
AftAb-25:fix/issue-272-minimal-permission
Open

feat: support minimal permission by allowing token/url auth#394
AftAb-25 wants to merge 1 commit intokarmada-io:mainfrom
AftAb-25:fix/issue-272-minimal-permission

Conversation

@AftAb-25
Copy link
Copy Markdown

Fixes #272

What does this PR do?

This PR implements minimal permission support by allowing the Karmada Dashboard API to authenticate using a direct API Server URL and Bearer Token, as an alternative to relying solely on a kubeconfig file.

Why are these changes needed?

Currently, the dashboard requires a full kubeconfig which can imply broader permissions than necessary. By allowing token-based authentication, we enable running the dashboard with restricted, minimal permissions (e.g., using a specific ServiceAccount token), significantly enhancing security context.

@karmada-bot karmada-bot added the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label Jan 26, 2026
@karmada-bot
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 rainbowmango 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

@karmada-bot
Copy link
Copy Markdown
Contributor

Welcome @AftAb-25! It looks like this is your first PR to karmada-io/dashboard 🎉

@karmada-bot karmada-bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jan 26, 2026
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @AftAb-25, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the security and flexibility of the Karmada Dashboard's API authentication. By introducing the ability to connect to Kubernetes API servers using a direct URL and a bearer token, it moves away from the potentially overly broad permissions often associated with kubeconfig files. This change allows administrators to configure the dashboard with more granular, minimal permissions, thereby bolstering the overall security context of the application.

Highlights

  • Enhanced Authentication Flexibility: Introduced support for authenticating with Kubernetes API servers using a direct API server URL and a bearer token, providing an alternative to kubeconfig files.
  • Improved Security Posture: Enabled the Karmada Dashboard to operate with minimal, restricted permissions by leveraging token-based authentication, thereby reducing the security surface area compared to full kubeconfig access.
  • New Command-Line Options: Added new command-line flags (--kube-apiserver-url, --kube-token, --karmada-apiserver-url, --karmada-token) to configure the API server URL and bearer token for both host and Karmada clusters.
  • Refactored Client Initialization: Updated the internal client configuration logic to prioritize token/URL authentication when provided, falling back to kubeconfig if these new parameters are not specified.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a valuable feature by adding support for token and URL-based authentication, which enhances security by allowing for minimal permission setups. The implementation is generally well-done. My review includes a couple of suggestions for pkg/client/init.go to improve maintainability by reducing code duplication and replacing hardcoded strings with constants.

Comment on lines +145 to +147
if len(in.kubeconfigPath) == 0 && (len(in.masterURL) == 0 || len(in.token) == 0) {
return nil, errors.New("must specify kubeconfig or masterURL and token")
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

This validation logic is duplicated from buildRestConfig (lines 112-114). The branching logic on line 149 (if len(in.masterURL) > 0 && len(in.token) > 0) is also duplicated from line 118.

To improve maintainability and avoid this duplication, consider extracting these checks into unexported helper methods on configBuilder that can be reused in both buildRestConfig and buildAPIConfig.

Comment on lines +150 to +169
return &clientcmdapi.Config{
Clusters: map[string]*clientcmdapi.Cluster{
"cluster": {
Server: in.masterURL,
InsecureSkipTLSVerify: in.insecure,
},
},
AuthInfos: map[string]*clientcmdapi.AuthInfo{
"user": {
Token: in.token,
},
},
Contexts: map[string]*clientcmdapi.Context{
"context": {
Cluster: "cluster",
AuthInfo: "user",
},
},
CurrentContext: "context",
}, nil
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The strings "cluster", "user", and "context" are hardcoded here. This can make the code harder to maintain and can lead to typos.

It's recommended to define these as constants, similar to how DefaultCmdConfigName is used in pkg/client/auth.go. Using constants would also improve consistency within the package.

@AftAb-25 AftAb-25 force-pushed the fix/issue-272-minimal-permission branch 4 times, most recently from 96dcdcb to a273af5 Compare January 26, 2026 21:15
@karmada-bot karmada-bot removed the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label Jan 26, 2026
@karmada-bot karmada-bot 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 Feb 13, 2026
This change allows the Karmada Dashboard API to authenticate using
a direct API Server URL and Bearer Token as an alternative to
kubeconfig. This enables minimal permission setups where you only
need to specify the masterURL and token for authentication.

Fixes karmada-io#272

Signed-off-by: Aftab <aftab123215@gmail.com>
@AftAb-25 AftAb-25 force-pushed the fix/issue-272-minimal-permission branch from 68d58d2 to 432eda3 Compare February 20, 2026 05:46
@karmada-bot karmada-bot added the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label Feb 20, 2026
@karmada-bot
Copy link
Copy Markdown
Contributor

Keywords which can automatically close issues and at(@) or hashtag(#) mentions are not allowed in commit messages.

The list of commits with invalid commit messages:

  • 432eda3 feat: support minimal permission by allowing token/url auth
Details

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. I understand the commands that are listed here.

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

Labels

do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. 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.

Minimal permission for karmada dashboard

2 participants