Skip to content

Add application-controlled security policies for kubeconfig exec plugins - #1930

Draft
brendandburns with Copilot wants to merge 7 commits into
masterfrom
copilot/add-security-policy-support
Draft

brendandburns with Copilot wants to merge 7 commits into
masterfrom
copilot/add-security-policy-support

Conversation

Copilot AI commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Untrusted kubeconfigs can launch arbitrary local processes through exec credential plugins. This adds application-controlled authorization without requiring callers to parse and inspect kubeconfig themselves.

  • Policy API: Immutable AllowAll (default), DenyAll, and Allowlist policies across configuration builders, including Classic and AOT. Existing API signatures remain available.
  • Enforcement: Checks initial execution and token refresh before process launch. Denials throw ExecCredentialPluginDeniedException; kubeconfig cannot override the application policy.
  • Allowlist semantics: Match basenames or exact absolute paths, including Windows UNC paths. Empty lists deny all; invalid entries and quoted commands are rejected. Allowlist mode also rejects kubeconfig-supplied environment overrides to prevent command redirection and loader injection.
  • Trust boundaries: Basenames permit any matching executable location. Arguments and executable contents are not restricted; the policy is not a sandbox.
var config = KubernetesClientConfiguration.BuildConfigFromConfigFile(
    kubeConfigPath,
    execCredentialPluginPolicy: ExecCredentialPluginPolicy.DenyAll);

// Or explicitly approve credential plugins:
var config = KubernetesClientConfiguration.BuildConfigFromConfigFile(
    kubeConfigPath,
    execCredentialPluginPolicy: ExecCredentialPluginPolicy.Allowlist(
        "kubelogin",
        @"C:\Program Files\Contoso\trusted-plugin.exe"));

Copilot AI balanced review requested due to automatic review settings October 6, 2026 21:51
@kubernetes-prow kubernetes-prow Bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 6, 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.

Copilot wasn't able to review any files in this pull request. Check if the Files changed in this pull request are included in default exclusions.

@linux-foundation-easycla

linux-foundation-easycla Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

CLA Not Signed

@kubernetes-prow kubernetes-prow Bot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Oct 6, 2026
Copilot AI linked an issue Oct 6, 2026 that may be closed by this pull request
Co-authored-by: brendandburns <5751682+brendandburns@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 6, 2026 22:01
@kubernetes-prow

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Copilot
Once this PR has been reviewed and has the lgtm label, please ask for approval from brendandburns. 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

@kubernetes-prow kubernetes-prow Bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Oct 6, 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.

Copilot review overview

🟡 Changes recommended

Kubeconfig-controlled environment variables can bypass allowlisted command restrictions and still enable arbitrary code execution.

Review effort: Balanced
Findings: 1 High severity

Open (1)

Comment thread src/KubernetesClient/ExecCredentialPluginPolicy.cs Outdated
Co-authored-by: brendandburns <5751682+brendandburns@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 6, 2026 22:22

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.

Copilot review overview

🔵 Needs a closer look

Security-sensitive process execution changes span multiple target variants, while the PR explicitly indicates build and security validation remain incomplete.

Review effort: Balanced
Findings: 1 High severity

Open (1)

Copilot AI changed the title [WIP] Add security policy support for kubeconfig exec credential plugins Add application-controlled security policies for kubeconfig exec plugins Oct 6, 2026
Copilot AI requested a review from brendandburns October 6, 2026 22:28
@brendandburns

Copy link
Copy Markdown
Contributor

@copilot can you add documentation that this is intended for defense in depth and is not a hard security boundary, loading a kubeconfig from an untrusted source is an inherently dangerous activity and should be handled as part of an overall security model, not relying exclusively on this capability.

Co-authored-by: brendandburns <5751682+brendandburns@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 14, 2026 16:03

Copilot AI commented Oct 14, 2026

Copy link
Copy Markdown
Contributor Author

@copilot can you add documentation that this is intended for defense in depth and is not a hard security boundary, loading a kubeconfig from an untrusted source is an inherently dangerous activity and...

Added the README clarification in commit 36876d0: the policy is defense in depth, not a hard security boundary, and untrusted kubeconfigs must be addressed within the application's overall security model.

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.

🔵 Needs a closer look

Basename validation incorrectly rejects valid Unix executable names containing colons.

1 open finding
Previously missed (1)

In code that hasn't changed since last review

Medium severity Rejects valid Unix executable basenames containing colons

src/​KubernetesClient/​ExecCredentialPluginPolicy.cs:93

The unconditional ':' check rejects valid Unix executable basenames such as plugin:v2, even though the API accepts command basenames and colon is only special for Windows drive syntax. Restrict the colon check to Windows so valid Unix basenames can be allowlisted.

🧠 Review effort: Balanced

Co-authored-by: brendandburns <5751682+brendandburns@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 16, 2026 23:47

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.

🟡 Changes recommended

DenyAll can probe untrusted network paths, and Windows casing differences can reject approved executables.

2 open issues
1 resolved since last review

Review effort: Balanced

Comment thread src/KubernetesClient/ExecCredentialPluginPolicy.cs Outdated
Comment on lines +92 to +94
return commands.Any(entry =>
TryResolveCommand(entry, path, out var resolvedEntry) &&
string.Equals(resolvedEntry, resolvedCommand, StringComparison.Ordinal));
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 19, 2026 16:14

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.

🟡 Changes recommended

Executable resolution permits unchecked fallback searches and unapproved network probes, and uses incompatible Windows extension rules.

3 open issues
1 previously missed issue

In code that hasn't changed since last review

Medium severity Respect native Windows extension resolution rules

src/​KubernetesClient/​ExecCredentialPluginPolicy.cs:209

On Windows, PATHEXT controls shell lookup, but CreateRunnableExternalProcess uses UseShellExecute = false. Native process creation appends .exe to an extensionless command; this resolver can instead select a preceding .com, .bat, or .cmd and pin it into FileName. Enabling an allowlist can therefore launch a different executable or fail on a batch shim where the original command would find an .exe. Use native process-creation extension rules and add a Windows test with competing extensions.

1 resolved since last review

Review effort: Balanced

Comment on lines +109 to +111
return TryResolveCommand(command, Environment.GetEnvironmentVariable("PATH"), out var resolvedCommand)
? resolvedCommand
: command;
try
{
var fullPath = Path.GetFullPath(command);
if (!File.Exists(fullPath))
@brendandburns

Copy link
Copy Markdown
Contributor

@copilot There are some common environment variables used for exec (e.g. AWS_PROFILE) so I think that blocking all environment variables won't work. Can you focus on just blocking dangerous ones and allowing others

Co-authored-by: brendandburns <5751682+brendandburns@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 19, 2026 17:40

Copilot AI commented Oct 19, 2026

Copy link
Copy Markdown
Contributor Author

@copilot There are some common environment variables used for exec (e.g. AWS_PROFILE) so I think that blocking all environment variables won't work. Can you focus on just blocking dangerous ones and a...

Allowlist mode now blocks PATH, dynamic-loader variables, and common language-runtime injection variables while allowing ordinary overrides such as AWS_PROFILE. Added coverage and updated the README in commit 0157b92.

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.

🟡 Changes recommended

Unblocked startup environment variables allow code injection through approved credential plugins.

4 open issues

Review effort: Balanced

string.Equals(name, "_JAVA_OPTIONS", StringComparison.OrdinalIgnoreCase) ||
string.Equals(name, "JDK_JAVA_OPTIONS", StringComparison.OrdinalIgnoreCase) ||
string.Equals(name, "CLASSPATH", StringComparison.OrdinalIgnoreCase) ||
string.Equals(name, "DOTNET_STARTUP_HOOKS", StringComparison.OrdinalIgnoreCase));

This branch has not been deployed

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

Labels

cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add security policy support for kubeconfig exec credential plugins

3 participants