mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 12:15:52 +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
|
||||
if len(authInfo.Token) != 0 {
|
||||
if len(authInfo.Token) != 0 || len(authInfo.TokenFile) != 0 {
|
||||
return true
|
||||
}
|
||||
|
||||
@ -139,6 +139,16 @@ func HasAuthenticationCredentials(config *clientcmdapi.Config) bool {
|
||||
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
|
||||
}
|
||||
|
||||
@ -166,6 +176,14 @@ func EnsureAuthenticationInfoAreEmbedded(config *clientcmdapi.Config) error {
|
||||
authInfo.ClientKeyData = 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
|
||||
}
|
||||
|
@ -313,6 +313,24 @@ func TestHasCredentials(t *testing.T) {
|
||||
},
|
||||
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 {
|
||||
t.Run(rt.name, func(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user