Skip to content

Commit 770687a

Browse files
committed
Fixes as per @simo5 review comments.
1 parent d3894ad commit 770687a

File tree

4 files changed

+37
-11
lines changed

4 files changed

+37
-11
lines changed

contrib/completions/bash/oc

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

contrib/completions/zsh/oc

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

images/router/haproxy/conf/haproxy-config.template

+24-10
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,17 @@ frontend fe_sni
231231
# before matching, or any requests containing uppercase characters will never match.
232232
http-request set-header Host %[req.hdr(Host),lower]
233233

234-
{{- if ne (env "ROUTER_MUTUAL_TLS_AUTH" "none") "none" }}
235-
{{- with (env "ROUTER_MUTUAL_TLS_AUTH_CN") }}
236-
# If a mutual TLS auth CN is set, we deny requests if the common name doesn't
237-
# match. A custom template can change this behavior (e.g. set custom headers).
238-
acl cert_cn_matches ssl_c_s_dn(CN) -m sub {{.}}
234+
{{ if ne (env "ROUTER_MUTUAL_TLS_AUTH" "none") "none" }}
235+
{{- with (env "ROUTER_MUTUAL_TLS_AUTH_FILTER") }}
236+
# If a mutual TLS auth subject filter environment variable is set, we deny
237+
# requests if the DN field in the client certificate doesn't match that value.
238+
# Please note that this match is a subset (substring) match.
239+
# Example: For DN set to: /CN=header.test/ST=CA/C=US/O=Security/OU=OpenShift3,
240+
# A. ROUTER_MUTUAL_TLS_AUTH_FILTER="header.test" would match the
241+
# DN field and the request will be passed on to the backend.
242+
# B. ROUTER_MUTUAL_TLS_AUTH_FILTER="legacy-web-client", the request
243+
# will be rejected.
244+
acl cert_cn_matches ssl_c_s_dn -m sub {{.}}
239245
http-request deny unless cert_cn_matches
240246
{{- end }}
241247

@@ -250,6 +256,7 @@ frontend fe_sni
250256
http-request set-header X-SSL-Issuer %{+Q}[ssl_c_i_dn]
251257
http-request set-header X-SSL-Client-NotBefore %{+Q}[ssl_c_notbefore]
252258
http-request set-header X-SSL-Client-NotAfter %{+Q}[ssl_c_notafter]
259+
http-request set-header X-SSL-Client-DER %{+Q}[ssl_c_der,base64]
253260
{{- end }}
254261

255262
# map to backend
@@ -290,11 +297,17 @@ frontend fe_no_sni
290297
# before matching, or any requests containing uppercase characters will never match.
291298
http-request set-header Host %[req.hdr(Host),lower]
292299

293-
{{- if ne (env "ROUTER_MUTUAL_TLS_AUTH" "none") "none" }}
294-
{{- with (env "ROUTER_MUTUAL_TLS_AUTH_CN") }}
295-
# If a mutual TLS auth CN is set, we deny requests if the common name doesn't
296-
# match. A custom template can change this behavior (e.g. set custom headers).
297-
acl cert_cn_matches ssl_c_s_dn(CN) -m sub {{.}}
300+
{{ if ne (env "ROUTER_MUTUAL_TLS_AUTH" "none") "none" }}
301+
{{- with (env "ROUTER_MUTUAL_TLS_AUTH_FILTER") }}
302+
# If a mutual TLS auth subject filter environment variable is set, we deny
303+
# requests if the DN field in the client certificate doesn't match that value.
304+
# Please note that this match is a subset (substring) match.
305+
# Example: For DN set to: /CN=header.test/ST=CA/C=US/O=Security/OU=OpenShift3,
306+
# A. ROUTER_MUTUAL_TLS_AUTH_FILTER="header.test" would match the
307+
# DN field and the request will be passed on to the backend.
308+
# B. ROUTER_MUTUAL_TLS_AUTH_FILTER="legacy-web-client", the request
309+
# will be rejected.
310+
acl cert_cn_matches ssl_c_s_dn -m sub {{.}}
298311
http-request deny unless cert_cn_matches
299312
{{- end }}
300313

@@ -309,6 +322,7 @@ frontend fe_no_sni
309322
http-request set-header X-SSL-Issuer %{+Q}[ssl_c_i_dn]
310323
http-request set-header X-SSL-Client-NotBefore %{+Q}[ssl_c_notbefore]
311324
http-request set-header X-SSL-Client-NotAfter %{+Q}[ssl_c_notafter]
325+
http-request set-header X-SSL-Client-DER %{+Q}[ssl_c_der,base64]
312326
{{- end }}
313327

314328
# map to backend

pkg/oc/admin/router/router.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,10 @@ type RouterConfig struct {
248248
// MutualTLSAuthCRL contains the certificate revocation list used to
249249
// verify a client's certificate.
250250
MutualTLSAuthCRL string
251+
252+
// MutualTLSAuthFilter contains the value to filter requests based on
253+
// a client certificate subject field substring match.
254+
MutualTLSAuthFilter string
251255
}
252256

253257
const (
@@ -333,6 +337,7 @@ func NewCmdRouter(f *clientcmd.Factory, parentName, name string, out, errout io.
333337
cmd.Flags().StringVar(&cfg.MutualTLSAuth, "mutual-tls-auth", cfg.MutualTLSAuth, "Controls access to the router using mutually agreed upon TLS configuration (ala client certificates). You can choose one of 'required', 'optional', or 'none'. The default is none.")
334338
cmd.Flags().StringVar(&cfg.MutualTLSAuthCA, "mutual-tls-auth-ca", cfg.MutualTLSAuthCA, "Optional path to a file containing one or more CA certificates used for mutual TLS authentication. The CA certificate[s] are used by the router to verify a client's certificate.")
335339
cmd.Flags().StringVar(&cfg.MutualTLSAuthCRL, "mutual-tls-auth-crl", cfg.MutualTLSAuthCRL, "Optional path to a file containing the certificate revocation list used for mutual TLS authentication. The certificate revocation list is used by the router to verify a client's certificate.")
340+
cmd.Flags().StringVar(&cfg.MutualTLSAuthFilter, "mutual-tls-auth-filter", cfg.MutualTLSAuthFilter, "Optional value to filter the client certificates. If the client certificate subject field does _not_ contain (substring match) this value, requests will be rejected by the router.")
336341

337342
cfg.Action.BindForOutput(cmd.Flags())
338343
cmd.Flags().String("output-version", "", "The preferred API versions of the output objects")
@@ -347,7 +352,7 @@ func generateMutualTLSSecretName(prefix string) string {
347352

348353
// generateSecretsConfig generates any Secret and Volume objects, such
349354
// as SSH private keys, that are necessary for the router container.
350-
func generateSecretsConfig(cfg *RouterConfig, namespace string, certName string, defaultCert, mtlsAuthCA, mtlsAuthCRL []byte) ([]*kapi.Secret, []kapi.Volume, []kapi.VolumeMount, error) {
355+
func generateSecretsConfig(cfg *RouterConfig, namespace, certName string, defaultCert, mtlsAuthCA, mtlsAuthCRL []byte) ([]*kapi.Secret, []kapi.Volume, []kapi.VolumeMount, error) {
351356
var secrets []*kapi.Secret
352357
var volumes []kapi.Volume
353358
var mounts []kapi.VolumeMount
@@ -782,6 +787,9 @@ func RunCmdRouter(f *clientcmd.Factory, cmd *cobra.Command, out, errout io.Write
782787
if len(mtlsAuthCRL) > 0 {
783788
env["ROUTER_MUTUAL_TLS_AUTH_CRL"] = path.Join(clientCertConfigDir, clientCertConfigCRL)
784789
}
790+
if len(cfg.MutualTLSAuthFilter) > 0 {
791+
env["ROUTER_MUTUAL_TLS_AUTH_FILTER"] = strings.Replace(cfg.MutualTLSAuthFilter, " ", "\\ ", -1)
792+
}
785793
}
786794

787795
env.Add(secretEnv)

0 commit comments

Comments
 (0)