Validate kubeConfig Namespaces against known Fleet namespaces#5224
Merged
Conversation
Contributor
There was a problem hiding this comment.
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.
weyfonk
reviewed
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.
6e06937 to
1c3139e
Compare
weyfonk
approved these changes
Jun 5, 2026
This was referenced Jun 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 setskubeConfigSecretNamespaceto the cluster namespace.