@@ -36,8 +36,9 @@ type Proxy struct {
36
36
tokenAuther * tokenreview.TokenReview
37
37
secureServingInfo * server.SecureServingInfo
38
38
39
- restConfig * rest.Config
40
- clientTransport http.RoundTripper
39
+ restConfig * rest.Config
40
+ clientTransport http.RoundTripper
41
+ noAuthClientTransport http.RoundTripper
41
42
}
42
43
43
44
func New (restConfig * rest.Config , oidcAuther * bearertoken.Authenticator ,
@@ -51,31 +52,29 @@ func New(restConfig *rest.Config, oidcAuther *bearertoken.Authenticator,
51
52
}
52
53
53
54
func (p * Proxy ) Run (stopCh <- chan struct {}) (<- chan struct {}, error ) {
54
- klog .Infof ("waiting for oidc provider to become ready..." )
55
-
56
- // get golang tls config to the API server
57
- tlsConfig , err := rest .TLSConfigFor (p .restConfig )
55
+ clientRT , err := p .roundTripperForRestConfig (p .restConfig )
58
56
if err != nil {
59
57
return nil , err
60
58
}
59
+ p .clientTransport = clientRT
61
60
62
- // create tls transport to request
63
- tlsTransport := & http.Transport {
64
- TLSClientConfig : tlsConfig ,
65
- }
66
-
67
- // get kube transport config form rest client config
68
- restTransportConfig , err := p .restConfig .TransportConfig ()
69
- if err != nil {
70
- return nil , err
71
- }
61
+ // No auth round tripper for no impersonation
62
+ if p .tokenAuther != nil {
63
+ noAuthClientRT , err := p .roundTripperForRestConfig (& rest.Config {
64
+ APIPath : p .restConfig .APIPath ,
65
+ Host : p .restConfig .Host ,
66
+ Timeout : p .restConfig .Timeout ,
67
+ TLSClientConfig : rest.TLSClientConfig {
68
+ CAFile : p .restConfig .CAFile ,
69
+ CAData : p .restConfig .CAData ,
70
+ },
71
+ })
72
+ if err != nil {
73
+ return nil , err
74
+ }
72
75
73
- // wrap golang tls config with kube transport round tripper
74
- clientRT , err := transport .HTTPWrappersForConfig (restTransportConfig , tlsTransport )
75
- if err != nil {
76
- return nil , err
76
+ p .noAuthClientTransport = noAuthClientRT
77
77
}
78
- p .clientTransport = clientRT
79
78
80
79
// get API server url
81
80
url , err := url .Parse (p .restConfig .Host )
@@ -89,6 +88,7 @@ func (p *Proxy) Run(stopCh <-chan struct{}) (<-chan struct{}, error) {
89
88
proxyHandler .ErrorHandler = p .Error
90
89
91
90
// wait for oidc auther to become ready
91
+ klog .Infof ("waiting for oidc provider to become ready..." )
92
92
time .Sleep (10 * time .Second )
93
93
94
94
waitCh , err := p .serve (proxyHandler , stopCh )
@@ -127,8 +127,9 @@ func (p *Proxy) RoundTrip(req *http.Request) (*http.Response, error) {
127
127
if tkErr == nil && ok {
128
128
klog .V (4 ).Infof ("passing request with valid token through (%s)" ,
129
129
req .RemoteAddr )
130
- // don't set impersonation headers
131
- return p .clientTransport .RoundTrip (req )
130
+ // Don't set impersonation headers and pass through without proxy auth
131
+ // and headers still set
132
+ return p .noAuthClientTransport .RoundTrip (req )
132
133
}
133
134
134
135
if tkErr != nil {
@@ -231,3 +232,30 @@ func (p *Proxy) Error(rw http.ResponseWriter, r *http.Request, err error) {
231
232
http .Error (rw , "" , http .StatusInternalServerError )
232
233
}
233
234
}
235
+
236
+ func (p * Proxy ) roundTripperForRestConfig (config * rest.Config ) (http.RoundTripper , error ) {
237
+ // get golang tls config to the API server
238
+ tlsConfig , err := rest .TLSConfigFor (config )
239
+ if err != nil {
240
+ return nil , err
241
+ }
242
+
243
+ // create tls transport to request
244
+ tlsTransport := & http.Transport {
245
+ TLSClientConfig : tlsConfig ,
246
+ }
247
+
248
+ // get kube transport config form rest client config
249
+ restTransportConfig , err := config .TransportConfig ()
250
+ if err != nil {
251
+ return nil , err
252
+ }
253
+
254
+ // wrap golang tls config with kube transport round tripper
255
+ clientRT , err := transport .HTTPWrappersForConfig (restTransportConfig , tlsTransport )
256
+ if err != nil {
257
+ return nil , err
258
+ }
259
+
260
+ return clientRT , nil
261
+ }
0 commit comments