mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 15:05:27 +00:00
Support more auth strategies in kubeadm join
with discovery file (#110553)
* Add support for client-go credential plugins * Add support for authprovider authentication * Add support for TokenFile authentication
This commit is contained in:
parent
03b18bf138
commit
4a542609aa
@ -124,7 +124,7 @@ func HasAuthenticationCredentials(config *clientcmdapi.Config) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// token authentication
|
// token authentication
|
||||||
if len(authInfo.Token) != 0 {
|
if len(authInfo.Token) != 0 || len(authInfo.TokenFile) != 0 {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,6 +139,16 @@ func HasAuthenticationCredentials(config *clientcmdapi.Config) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// exec authentication
|
||||||
|
if authInfo.Exec != nil && len(authInfo.Exec.Command) != 0 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// authprovider authentication
|
||||||
|
if authInfo.AuthProvider != nil && len(authInfo.AuthProvider.Name) != 0 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,6 +176,14 @@ func EnsureAuthenticationInfoAreEmbedded(config *clientcmdapi.Config) error {
|
|||||||
authInfo.ClientKeyData = clientKey
|
authInfo.ClientKeyData = clientKey
|
||||||
authInfo.ClientKey = ""
|
authInfo.ClientKey = ""
|
||||||
}
|
}
|
||||||
|
if len(authInfo.Token) == 0 && len(authInfo.TokenFile) != 0 {
|
||||||
|
tokenBytes, err := os.ReadFile(authInfo.TokenFile)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "error while reading token file defined in kubeconfig")
|
||||||
|
}
|
||||||
|
authInfo.Token = string(tokenBytes)
|
||||||
|
authInfo.TokenFile = ""
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -313,6 +313,24 @@ func TestHasCredentials(t *testing.T) {
|
|||||||
},
|
},
|
||||||
expected: true,
|
expected: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "exec authentication credentials",
|
||||||
|
config: &clientcmdapi.Config{
|
||||||
|
CurrentContext: "kubernetes",
|
||||||
|
Contexts: map[string]*clientcmdapi.Context{"kubernetes": {AuthInfo: "kubernetes"}},
|
||||||
|
AuthInfos: map[string]*clientcmdapi.AuthInfo{"kubernetes": {Exec: &clientcmdapi.ExecConfig{Command: "command"}}},
|
||||||
|
},
|
||||||
|
expected: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "authprovider authentication credentials",
|
||||||
|
config: &clientcmdapi.Config{
|
||||||
|
CurrentContext: "kubernetes",
|
||||||
|
Contexts: map[string]*clientcmdapi.Context{"kubernetes": {AuthInfo: "kubernetes"}},
|
||||||
|
AuthInfos: map[string]*clientcmdapi.AuthInfo{"kubernetes": {AuthProvider: &clientcmdapi.AuthProviderConfig{Name: "A"}}},
|
||||||
|
},
|
||||||
|
expected: true,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for _, rt := range testCases {
|
for _, rt := range testCases {
|
||||||
t.Run(rt.name, func(t *testing.T) {
|
t.Run(rt.name, func(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user