@@ -18,8 +18,7 @@ package authn
18
18
19
19
import (
20
20
"errors"
21
- "fmt"
22
- "io/ioutil"
21
+ "net/http"
23
22
"time"
24
23
25
24
"k8s.io/apiserver/pkg/authentication/authenticator"
@@ -28,27 +27,23 @@ import (
28
27
authenticationclient "k8s.io/client-go/kubernetes/typed/authentication/v1"
29
28
)
30
29
30
+ type DelegatingAuthenticator struct {
31
+ dynamicClientCA * dynamiccertificates.DynamicFileCAContent
32
+ requestAuthenticator authenticator.Request
33
+ }
34
+
31
35
// NewDelegatingAuthenticator creates an authenticator compatible with the kubelet's needs
32
- func NewDelegatingAuthenticator (client authenticationclient.TokenReviewInterface , authn * AuthnConfig ) (authenticator. Request , error ) {
36
+ func NewDelegatingAuthenticator (client authenticationclient.TokenReviewInterface , authn * AuthnConfig ) (* DelegatingAuthenticator , error ) {
33
37
if client == nil {
34
38
return nil , errors .New ("tokenAccessReview client not provided, cannot use webhook authentication" )
35
39
}
36
40
37
41
var (
38
- p authenticatorfactory. CAContentProvider
42
+ p * dynamiccertificates. DynamicFileCAContent
39
43
err error
40
44
)
41
45
if len (authn .X509 .ClientCAFile ) > 0 {
42
- if len (authn .X509 .ClientCAFile ) == 0 {
43
- return nil , fmt .Errorf ("missing filename for ca bundle" )
44
- }
45
-
46
- caBundle , err := ioutil .ReadFile (authn .X509 .ClientCAFile )
47
- if err != nil {
48
- return nil , err
49
- }
50
-
51
- p , err = dynamiccertificates .NewStaticCAContent (authn .X509 .ClientCAFile , caBundle )
46
+ p , err = dynamiccertificates .NewDynamicCAContentFromFile ("client-ca" , authn .X509 .ClientCAFile )
52
47
if err != nil {
53
48
return nil , err
54
49
}
@@ -63,5 +58,26 @@ func NewDelegatingAuthenticator(client authenticationclient.TokenReviewInterface
63
58
}
64
59
65
60
authenticator , _ , err := authenticatorConfig .New ()
66
- return authenticator , err
61
+ if err != nil {
62
+ return nil , err
63
+ }
64
+
65
+ return & DelegatingAuthenticator {requestAuthenticator : authenticator , dynamicClientCA : p }, nil
66
+ }
67
+
68
+ func (a * DelegatingAuthenticator ) AuthenticateRequest (req * http.Request ) (* authenticator.Response , bool , error ) {
69
+ return a .requestAuthenticator .AuthenticateRequest (req )
70
+ }
71
+
72
+ func (a * DelegatingAuthenticator ) RunOnce () error {
73
+ if a .dynamicClientCA != nil {
74
+ return a .dynamicClientCA .RunOnce ()
75
+ }
76
+ return nil
77
+ }
78
+
79
+ func (a * DelegatingAuthenticator ) Run (workers int , stopCh <- chan struct {}) {
80
+ if a .dynamicClientCA != nil {
81
+ a .dynamicClientCA .Run (workers , stopCh )
82
+ }
67
83
}
0 commit comments