Skip to content

Validate kubeConfig Namespaces against known Fleet namespaces#5224

Merged
thardeck merged 1 commit into
mainfrom
validate_kubeconfig_ns
Jun 5, 2026
Merged

Validate kubeConfig Namespaces against known Fleet namespaces#5224
thardeck merged 1 commit into
mainfrom
validate_kubeconfig_ns

Conversation

@thardeck
Copy link
Copy Markdown
Collaborator

@thardeck thardeck commented Jun 3, 2026

Restrict kubeconfig secret reads to Fleet-managed namespaces and preserve same-namespace behavior for explicit or empty values.

Keep legacy namespace entries for now because migration code paths still reference LegacyDefaultNamespace, and Rancher manager-initiated registration sets kubeConfigSecretNamespace to the cluster namespace.

@thardeck thardeck self-assigned this Jun 3, 2026
Copilot AI review requested due to automatic review settings June 3, 2026 07:40
@thardeck thardeck requested a review from a team as a code owner June 3, 2026 07:40
@thardeck thardeck added this to Fleet Jun 3, 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

Adds validation for Cluster.Spec.KubeConfigSecretNamespace so the controller only reads kubeconfig secrets from a restricted set of Fleet-related namespaces, while keeping the existing behavior that an empty field falls back to the Cluster object’s own namespace.

Changes:

  • Introduces allowedKubeConfigSecretNamespace() and uses it in indexing, config-change detection, and cluster import flows.
  • Skips indexing / config-change checks when the namespace is disallowed (logs and continues), and errors out during import when disallowed.
  • Adds unit tests for disallowed namespaces and for the namespace allowlist helper.

Reviewed changes

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

File Description
internal/cmd/controller/agentmanagement/controllers/cluster/import.go Replaces direct namespace selection with an allowlist-based helper and wires it into secret indexing + reads.
internal/cmd/controller/agentmanagement/controllers/cluster/import_test.go Adds coverage for skipping disallowed namespaces and validates allowlist behavior.

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

@thardeck thardeck moved this to 👀 In review in Fleet Jun 3, 2026
@thardeck thardeck requested a review from Copilot June 3, 2026 08:02
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 2 comments.

Comment thread internal/cmd/controller/agentmanagement/controllers/cluster/import_test.go Outdated
@thardeck thardeck requested review from weyfonk and removed request for a team June 3, 2026 10:04
Restrict kubeconfig secret reads to Fleet-managed namespaces and
preserve same-namespace behavior for explicit or empty values.

Keep legacy namespace entries for now because migration code paths
still reference LegacyDefaultNamespace, and Rancher
manager-initiated registration sets kubeConfigSecretNamespace to the
cluster namespace.
@thardeck thardeck force-pushed the validate_kubeconfig_ns branch from 6e06937 to 1c3139e Compare June 5, 2026 08:25
@thardeck thardeck requested a review from weyfonk June 5, 2026 08:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

3 participants