feat: add as, as-group and as-uid as available arguments - #39
Open
carlottostromstedt wants to merge 2 commits into
Open
feat: add as, as-group and as-uid as available arguments#39carlottostromstedt wants to merge 2 commits into
carlottostromstedt wants to merge 2 commits into
Conversation
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.
What
Adds
--as,--as-group, and--as-uidto let the whole session run as another Kubernetes identity, matching the equivalentkubectlflags.For example:
This is useful when you need to access objects your normal kubeconfig identity cannot, such as deleting something that requires cluster-admin privileges.
--as-groupcan be specified multiple times.How
The flags are turned into a
k8s.Impersonationinmain.goand passed throughclientcmdusing the sameAuthInfo.Impersonate,ImpersonateGroups, andImpersonateUIDoverrides thatkubectluses.From there, the identity ends up on
rest.Config.Impersonate. All clients and transports ininternal/k8sare built from that same config, including the clientset, dynamic and discovery clients, exec, port-forward, and WebSocket transports. That means individual call sites don't need to know anything about impersonation.Impersonation.Validatealso catches invalid combinations up front, such as specifying a group or UID without a user.clientcmdwould reject these too, but validating them when the session starts gives a more useful error tied directly to the flags the user provided.The identity is stored on
App, soswitchContextCmdcarries it over when rebuilding the client. It is never persisted tostate.json.Behavior
aschip appears in the header while impersonation is active. It shows the impersonated user and group count.Ccommand preview includes the impersonation flags, so the generatedkubectlcommand matches the session.--as-groupand--as-uidare only shown when--asis present, sincekubectldoesn't accept them on their own.--checkincludes anas:line showing the active identity.c, because the rebuilt client keeps the same identity.--editis passed orShift+Eis pressed.Testing
Added coverage for:
internal/k8s/impersonate_test.go:Active,Validate,String, kubeconfig →rest.Configimpersonation, and preserving impersonation across context overrides.main_test.go: repeatable--as-group, empty groups, and flag validation.internal/ui/impersonate_test.go: chip rendering, chip labels, context switches, and chip overflow.internal/ui/command_view_test.go: impersonation flags in generated commands, omission when unset, and requiring--as.internal/ui/help_view_test.go: wrapping the mode note without widening the modal.make testandmake vetboth pass.