mirror of
https://github.com/kubernetes/client-go.git
synced 2025-06-26 07:02:01 +00:00
Merge pull request #91745 from Bisnode/gh-87369
Presence of bearer token should cancel exec action Kubernetes-commit: fe43b104ba28271f06cae81100e9baf38bc26391
This commit is contained in:
commit
cf11d9b71a
@ -237,6 +237,15 @@ type credentials struct {
|
||||
// UpdateTransportConfig updates the transport.Config to use credentials
|
||||
// returned by the plugin.
|
||||
func (a *Authenticator) UpdateTransportConfig(c *transport.Config) error {
|
||||
// If a bearer token is present in the request - avoid the GetCert callback when
|
||||
// setting up the transport, as that triggers the exec action if the server is
|
||||
// also configured to allow client certificates for authentication. For requests
|
||||
// like "kubectl get --token (token) pods" we should assume the intention is to
|
||||
// use the provided token for authentication.
|
||||
if c.HasTokenAuth() {
|
||||
return nil
|
||||
}
|
||||
|
||||
c.Wrap(func(rt http.RoundTripper) http.RoundTripper {
|
||||
return &roundTripper{a, rt}
|
||||
})
|
||||
|
@ -651,6 +651,27 @@ func TestRoundTripper(t *testing.T) {
|
||||
get(t, http.StatusOK)
|
||||
}
|
||||
|
||||
func TestTokenPresentCancelsExecAction(t *testing.T) {
|
||||
a, err := newAuthenticator(newCache(), &api.ExecConfig{
|
||||
Command: "./testdata/test-plugin.sh",
|
||||
APIVersion: "client.authentication.k8s.io/v1alpha1",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// UpdateTransportConfig returns error on existing TLS certificate callback, unless a bearer token is present in the
|
||||
// transport config, in which case it takes precedence
|
||||
cert := func() (*tls.Certificate, error) {
|
||||
return nil, nil
|
||||
}
|
||||
tc := &transport.Config{BearerToken: "token1", TLS: transport.TLSConfig{Insecure: true, GetCert: cert}}
|
||||
|
||||
if err := a.UpdateTransportConfig(tc); err != nil {
|
||||
t.Error("Expected presence of bearer token in config to cancel exec action")
|
||||
}
|
||||
}
|
||||
|
||||
func TestTLSCredentials(t *testing.T) {
|
||||
now := time.Now()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user