@@ -159,6 +159,10 @@ pub struct Config {
159
159
// TODO Actually support proxy or create an example with custom client
160
160
/// Optional proxy URL.
161
161
pub proxy_url : Option < http:: Uri > ,
162
+ /// If set, apiserver certificate will be validated to contain this string
163
+ ///
164
+ /// If not set, the `cluster_url` is used instead
165
+ pub tls_server_name : Option < String > ,
162
166
}
163
167
164
168
impl Config {
@@ -180,6 +184,7 @@ impl Config {
180
184
accept_invalid_certs : false ,
181
185
auth_info : AuthInfo :: default ( ) ,
182
186
proxy_url : None ,
187
+ tls_server_name : None ,
183
188
}
184
189
}
185
190
@@ -213,20 +218,20 @@ impl Config {
213
218
214
219
/// Load an in-cluster Kubernetes client configuration using
215
220
/// [`Config::incluster_env`].
216
- #[ cfg( not( feature = "rustls-tls" ) ) ]
217
- pub fn incluster ( ) -> Result < Self , InClusterError > {
218
- Self :: incluster_env ( )
219
- }
220
-
221
- /// Load an in-cluster Kubernetes client configuration using
222
- /// [`Config::incluster_dns`].
223
221
///
224
- /// The `rustls-tls` feature is currently incompatible with
225
- /// [`Config::incluster_env`]. See
226
- /// <https://github.com/kube-rs/kube/issues/1003>.
227
- #[ cfg( feature = "rustls-tls" ) ]
222
+ /// # Rustls-specific behavior
223
+ /// Rustls does not support validating IP addresses (see
224
+ /// <https://github.com/kube-rs/kube/issues/1003>).
225
+ /// To work around this, when rustls is configured, this function automatically appends
226
+ /// `tls-server-name = "kubernetes.default.svc"` to the resulting configuration.
227
+ /// Overriding or unsetting `Config::tls_server_name` will avoid this behaviour.
228
228
pub fn incluster ( ) -> Result < Self , InClusterError > {
229
- Self :: incluster_dns ( )
229
+ let mut cfg = Self :: incluster_env ( ) ?;
230
+ if cfg ! ( all( not( feature = "openssl-tls" ) , feature = "rustls-tls" ) ) {
231
+ // openssl takes precedence when both features present, so only do it when only rustls is there
232
+ cfg. tls_server_name = Some ( "kubernetes.default.svc" . to_string ( ) ) ;
233
+ }
234
+ Ok ( cfg)
230
235
}
231
236
232
237
/// Load an in-cluster config using the `KUBERNETES_SERVICE_HOST` and
@@ -236,9 +241,7 @@ impl Config {
236
241
/// `/var/run/secrets/kubernetes.io/serviceaccount/`.
237
242
///
238
243
/// This method matches the behavior of the official Kubernetes client
239
- /// libraries, but it is not compatible with the `rustls-tls` feature . When
240
- /// this feature is enabled, [`Config::incluster_dns`] should be used
241
- /// instead. See <https://github.com/kube-rs/kube/issues/1003>.
244
+ /// libraries and is the default for both TLS stacks.
242
245
pub fn incluster_env ( ) -> Result < Self , InClusterError > {
243
246
let uri = incluster_config:: try_kube_from_env ( ) ?;
244
247
Self :: incluster_with_uri ( uri)
@@ -251,7 +254,9 @@ impl Config {
251
254
/// `/var/run/secrets/kubernetes.io/serviceaccount/`.
252
255
///
253
256
/// This behavior does not match that of the official Kubernetes clients,
254
- /// but this approach is compatible with the `rustls-tls` feature.
257
+ /// but this approach is compatible with the `rustls-tls` feature
258
+ /// without setting `tls_server_name`.
259
+ /// See <https://github.com/kube-rs/kube/issues/1003>.
255
260
pub fn incluster_dns ( ) -> Result < Self , InClusterError > {
256
261
Self :: incluster_with_uri ( incluster_config:: kube_dns ( ) )
257
262
}
@@ -275,6 +280,7 @@ impl Config {
275
280
..Default :: default ( )
276
281
} ,
277
282
proxy_url : None ,
283
+ tls_server_name : None ,
278
284
} )
279
285
}
280
286
@@ -333,6 +339,7 @@ impl Config {
333
339
accept_invalid_certs,
334
340
proxy_url : loader. proxy_url ( ) ?,
335
341
auth_info : loader. user ,
342
+ tls_server_name : loader. cluster . tls_server_name ,
336
343
} )
337
344
}
338
345
0 commit comments