Add --skip-access-check flag and skipAccessCheck config option#3970
Open
minivolk wants to merge 1 commit intoderailed:masterfrom
Open
Add --skip-access-check flag and skipAccessCheck config option#3970minivolk wants to merge 1 commit intoderailed:masterfrom
minivolk wants to merge 1 commit intoderailed:masterfrom
Conversation
2708e50 to
e375b97
Compare
Author
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.
Summary
Adds an opt-in CLI flag
--skip-access-checkand a corresponding YAML config keyk9s.skipAccessCheckthat disables the pre-flightSelfSubjectAccessReview(SAR) probes k9s issues before every API request. When enabled, k9s relies solely on the API server's response to the actual call, eliminating the SAR round-trip entirely.Default behavior is unchanged (flag/key default to
false).Motivation
k9s currently calls
SelfSubjectAccessReview(via(*APIClient).CanI) before any resource list/get/watch/edit/delete. The result gates whether informers are created, whether menu items are shown, and whether DAO operations even attempt the call. While this is a useful UX optimization on a vanilla Kubernetes cluster, it breaks badly in environments where the SAR result does not reflect whatkubectlwould actually return.Concrete failure case: Teleport (and similar auth proxies)
Teleport's Kubernetes Access proxy applies authorization policy at the proxy layer, not by translating it into RBAC the API server can fully introspect. In particular, Teleport supports per-resource deny rules and label-based filtering that the API server itself is unaware of. The behavior users observe:
kubectl get secretswith a deny rule on one secretSelfSubjectAccessReviewforsecrets/listallowed: falsebecause any deny block exists for the resource typekubectl get secret allowed-onekubectl get secretsworks fine. The same pattern applies to any auth provider that:Other supporting cases
selfsubjectaccessreviews.create. Today k9s breaks; with this flag it works.What changed
New CLI flag
New YAML key (
~/.config/k9s/config.yaml)Precedence
Matches the existing
--readonly/readOnlypattern:falsefalse(default)truetruefalse--skip-access-checktrue(CLI wins when explicitly true)true--skip-access-check=falsetrue(CLI false does not override YAML — same as--readonly)Implementation notes
The change has a single chokepoint:
(*APIClient).CanIininternal/client/client.gois the one place SAR is issued; all 30+ call sites (factory informers, browser UI gates, DAO operations, metrics, cluster info) flow through it. A short-circuit at the top ofCanItherefore covers the entire app without touching any caller. When skipped, errors surface naturally on the actual API call — k9s already handles those.Files changed
internal/config/flags.go—SkipAccessCheck *boolonFlagscmd/root.go— register flag; resolve final value (CLI > YAML) intoclient.Config.SkipAccessCheckafterK9s.Overrideinternal/client/config.go—SkipAccessCheck boolfield onConfiginternal/client/client.go— short-circuitCanI; preserve flag acrossSwitchContextinternal/config/k9s.go— persistedSkipAccessCheckfield, manual override,IsSkipAccessCheck(),Mergepropagationinternal/config/json/schemas/k9s.json— schema entry for YAML validationinternal/client/client_test.go,internal/config/flags_test.go,internal/config/k9s_test.go— unit testsREADME.md— CLI usage and YAML examplesTests
TestCanI_SkipAccessCheck— verifiesCanIshort-circuits without invoking the API server when the flag is set.TestK9sIsSkipAccessCheck— table-driven precedence matrix (default / yaml-only / cli-only / both / cli-false-no-override).TestNewFlagsto assert the new default.How to verify
Backwards compatibility
false. No existing user is affected.additionalProperties: falseis preserved by adding the property explicitly).Risks & tradeoffs