--as-uid flag in kubectl and kubeconfigs.

This corresponds to previous work to allow impersonating UIDs:
* Introduce Impersonate-UID header: #99961
* Add UID to client-go impersonation config #104483

Signed-off-by: Margo Crawford <margaretc@vmware.com>

Kubernetes-commit: 7e079f5144474cae05802771f604df2b748d781f
This commit is contained in:
Margo Crawford
2021-10-19 16:12:31 -07:00
committed by Kubernetes Publisher
parent 9b0b23a8ad
commit 5fca705b7d
8 changed files with 135 additions and 6 deletions

View File

@@ -217,6 +217,43 @@ func TestTLSServerNameClearsWhenServerNameSet(t *testing.T) {
matchStringArg("", actualCfg.ServerName, t)
}
func TestFullImpersonateConfig(t *testing.T) {
config := createValidTestConfig()
config.Clusters["clean"] = &clientcmdapi.Cluster{
Server: "https://localhost:8443",
}
config.AuthInfos["clean"] = &clientcmdapi.AuthInfo{
Impersonate: "alice",
ImpersonateUID: "abc123",
ImpersonateGroups: []string{"group-1"},
ImpersonateUserExtra: map[string][]string{"some-key": {"some-value"}},
}
config.Contexts["clean"] = &clientcmdapi.Context{
Cluster: "clean",
AuthInfo: "clean",
}
config.CurrentContext = "clean"
clientBuilder := NewNonInteractiveClientConfig(*config, "clean", &ConfigOverrides{
ClusterInfo: clientcmdapi.Cluster{
Server: "http://something",
},
}, nil)
actualCfg, err := clientBuilder.ClientConfig()
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
matchStringArg("alice", actualCfg.Impersonate.UserName, t)
matchStringArg("abc123", actualCfg.Impersonate.UID, t)
matchIntArg(1, len(actualCfg.Impersonate.Groups), t)
matchStringArg("group-1", actualCfg.Impersonate.Groups[0], t)
matchIntArg(1, len(actualCfg.Impersonate.Extra), t)
matchIntArg(1, len(actualCfg.Impersonate.Extra["some-key"]), t)
matchStringArg("some-value", actualCfg.Impersonate.Extra["some-key"][0], t)
}
func TestMergeContext(t *testing.T) {
const namespace = "overridden-namespace"
@@ -808,6 +845,12 @@ func matchByteArg(expected, got []byte, t *testing.T) {
}
}
func matchIntArg(expected, got int, t *testing.T) {
if expected != got {
t.Errorf("Expected %d, got %d", expected, got)
}
}
func TestNamespaceOverride(t *testing.T) {
config := &DirectClientConfig{
overrides: &ConfigOverrides{