Skip to content

Pass cluster info to exec credential plugins (provideClusterInfo)#1808

Open
mutsaddi-deshaw wants to merge 6 commits into
kubernetes-client:masterfrom
mutsaddi-deshaw:mutsaddi-deshaw-provide-cluster-info
Open

Pass cluster info to exec credential plugins (provideClusterInfo)#1808
mutsaddi-deshaw wants to merge 6 commits into
kubernetes-client:masterfrom
mutsaddi-deshaw:mutsaddi-deshaw-provide-cluster-info

Conversation

@mutsaddi-deshaw

@mutsaddi-deshaw mutsaddi-deshaw commented Jun 17, 2026

Copy link
Copy Markdown

Implements support for provideClusterInfo: true in a kubeconfig user's exec block. Per the exec credential plugin protocol (client.authentication.k8s.io), when this flag is set the client passes the cluster's connection details to the plugin via spec.cluster in KUBERNETES_EXEC_INFO. The provideClusterInfo / installHint fields were added in #620, but forwarding the cluster info was left as a TODO (#618 / #620). This PR completes that.

Forwards server, insecure-skip-tls-verify, certificate-authority-data (resolved from inline data or a CA file path), tls-server-name, and the exec extension config.

Note: the AOT client forwards all scalar cluster fields but not config. The AOT ClusterEndpoint anyway omits Extensions currently.

Copilot AI review requested due to automatic review settings June 17, 2026 06:12
@k8s-ci-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

@linux-foundation-easycla

linux-foundation-easycla Bot commented Jun 17, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

@k8s-ci-robot

Copy link
Copy Markdown
Contributor

Welcome @mutsaddi-deshaw!

It looks like this is your first PR to kubernetes-client/csharp 🎉. 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-client/csharp 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 cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jun 17, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds support for passing cluster details to Kubernetes exec credential plugins (via KUBERNETES_EXEC_INFO.spec.cluster) and ensures CA data can be surfaced consistently (inline or file-resolved), with new unit tests covering cluster mapping/serialization.

Changes:

  • Add CaData to persist base64 CA data resolved from kubeconfig inline data or CA file path.
  • Extend exec credential flow to optionally include spec.cluster in KUBERNETES_EXEC_INFO, with shared ToExecClusterInfo conversion.
  • Add/expand tests validating cluster info mapping, optional field omission, and nested extension serialization.

Reviewed changes

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

Show a summary per file
File Description
tests/KubernetesClient.Tests/ExternalExecutionTests.cs Adds unit tests for exec cluster info mapping and inclusion/omission in KUBERNETES_EXEC_INFO.
src/KubernetesClient/KubernetesClientConfiguration.cs Adds CaData property to retain resolved base64 CA data.
src/KubernetesClient/KubernetesClientConfiguration.ConfigFile.cs Resolves/records CaData, adds cluster injection for exec plugins, and introduces ToExecClusterInfo.
src/KubernetesClient/Authentication/ExecTokenProvider.cs Threads optional cluster info through token refresh exec calls.
src/KubernetesClient.Aot/KubernetesClientConfiguration.ConfigFile.cs Mirrors exec cluster injection and ToExecClusterInfo for AOT build (without extensions).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/KubernetesClient/Authentication/ExecTokenProvider.cs Outdated
Comment thread src/KubernetesClient/KubernetesClientConfiguration.ConfigFile.cs Outdated
Comment thread src/KubernetesClient/KubernetesClientConfiguration.ConfigFile.cs Outdated
Comment thread src/KubernetesClient.Aot/KubernetesClientConfiguration.ConfigFile.cs Outdated
Comment thread src/KubernetesClient.Aot/KubernetesClientConfiguration.ConfigFile.cs Outdated
Comment thread src/KubernetesClient/KubernetesClientConfiguration.ConfigFile.cs
Comment thread src/KubernetesClient/KubernetesClientConfiguration.ConfigFile.cs Outdated
Comment thread src/KubernetesClient/KubernetesClientConfiguration.ConfigFile.cs
@mutsaddi-deshaw mutsaddi-deshaw force-pushed the mutsaddi-deshaw-provide-cluster-info branch from e6c77d0 to 3749bdf Compare June 17, 2026 06:30
- Omit spec.cluster key when ProvideClusterInfo is false (don't emit null)
- Omit insecure-skip-tls-verify when false (omitempty per spec)
- Resolve CA from file path (mirroring client-go's dataFromSliceOrFile)
- Use resolved Host/TlsServerName/CaData instead of raw kubeconfig values
- Preserve binary compatibility via method overloads
- Guard against cluster=null when ProvideClusterInfo=true
- Add nested extension and edge-case tests
Copilot AI review requested due to automatic review settings June 17, 2026 08:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 5 out of 5 changed files in this pull request and generated 2 comments.

Comment on lines +507 to +516
var execExtension = cluster.Extensions?
.FirstOrDefault(e => e.Name == "client.authentication.k8s.io/exec");
if (execExtension != null)
{
object extConfig = execExtension.Extension;
if (extConfig != null)
{
node["config"] = JsonNode.Parse(JsonSerializer.Serialize(extConfig));
}
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Dictionary<object, object> serialization with System.Text.Json is officially supported with default options when the runtime key type is a supported type. See Supported key types

Comment thread src/KubernetesClient/KubernetesClientConfiguration.cs Outdated
@mutsaddi-deshaw mutsaddi-deshaw requested a review from Copilot June 17, 2026 09:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 5 out of 5 changed files in this pull request and generated 2 comments.

Comment on lines +511 to +515
object extConfig = execExtension.Extension;
if (extConfig != null)
{
node["config"] = JsonNode.Parse(JsonSerializer.Serialize(extConfig));
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Same as #1808 (comment)

Comment thread src/KubernetesClient.Aot/KubernetesClientConfiguration.ConfigFile.cs Outdated
@mutsaddi-deshaw mutsaddi-deshaw requested a review from Copilot June 17, 2026 10:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 5 out of 5 changed files in this pull request and generated 5 comments.

Comment thread src/KubernetesClient.Aot/KubernetesClientConfiguration.ConfigFile.cs Outdated
Comment thread src/KubernetesClient/KubernetesClientConfiguration.ConfigFile.cs
Comment thread src/KubernetesClient/KubernetesClientConfiguration.ConfigFile.cs
Comment thread src/KubernetesClient/KubernetesClientConfiguration.ConfigFile.cs Outdated
Copilot AI review requested due to automatic review settings June 18, 2026 12:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 5 out of 5 changed files in this pull request and generated 1 comment.

Comment on lines +326 to +330
var caPath = GetFullPath(k8SConfig, clusterDetails.ClusterEndpoint.CertificateAuthority);
CertificateAuthorityData = Convert.ToBase64String(File.ReadAllBytes(caPath));

// File-path loaders auto-detect cert format (PEM/DER/PFX), which the
// byte-based APIs do not reliably do on pre-.NET 9. The second read is

@mutsaddi-deshaw mutsaddi-deshaw Jun 18, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Can a non-PEM CA file can realistically occur? kubeconfig CA files are PEM per spec, and I think such a file wouldn't work with kubectl or client-go either. client-go appears to forward the raw bytes unchanged and the non-AOT C# client also seems to assume PEM (CertUtils.LoadPemFileCert). Do we have a real scenario that produces a DER/PFX CA in a kubeconfig? If not, I'd rather not add handling for input the spec disallows.

@tg123

tg123 commented Jun 22, 2026

Copy link
Copy Markdown
Member

@mutsaddi-deshaw clean up git commit author

@kubernetes-prow kubernetes-prow Bot 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 Jun 22, 2026
@mutsaddi-deshaw

Copy link
Copy Markdown
Author

@mutsaddi-deshaw clean up git commit author

@tg123 happy to fix, but could you clarify what you'd like cleaned up on the commit author?

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.

4 participants