-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Add router support for wildcard domains (*.foo.com) #11201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -100,15 +100,36 @@ frontend public | |
| acl secure_redirect base,map_beg(/var/lib/haproxy/conf/os_edge_http_redirect.map) -m found | ||
| redirect scheme https if secure_redirect | ||
|
|
||
| {{ if matchPattern "true|TRUE" (env "ROUTER_ALLOW_WILDCARD_ROUTES" "")}} | ||
| # Check for wildcard domains with redirected http routes. | ||
| acl wildcard_domain hdr(host),map_reg(/var/lib/haproxy/conf/os_wildcard_domain.map) -m found | ||
|
|
||
| acl wildcard_secure_redirect base,map_reg(/var/lib/haproxy/conf/os_edge_http_redirect.map) -m found | ||
| redirect scheme https if wildcard_domain wildcard_secure_redirect | ||
|
|
||
| {{ end }} | ||
|
|
||
| # Check if it is an edge route exposed insecurely. | ||
| acl edge_http_expose base,map_beg(/var/lib/haproxy/conf/os_edge_http_expose.map) -m found | ||
| use_backend be_edge_http_%[base,map_beg(/var/lib/haproxy/conf/os_edge_http_expose.map)] if edge_http_expose | ||
|
|
||
| # map to http backend | ||
| # Search from most specific to general path (host case). | ||
| acl http_backend base,map_beg(/var/lib/haproxy/conf/os_http_be.map) -m found | ||
| use_backend be_http_%[base,map_beg(/var/lib/haproxy/conf/os_http_be.map)] if http_backend | ||
|
|
||
| {{ if matchPattern "true|TRUE" (env "ROUTER_ALLOW_WILDCARD_ROUTES" "")}} | ||
| # Check for wildcard domains with exposed http routes. | ||
| acl wildcard_edge_http_expose base,map_reg(/var/lib/haproxy/conf/os_edge_http_expose.map) -m found | ||
| use_backend be_edge_http_%[base,map_beg(/var/lib/haproxy/conf/os_edge_http_expose.map)] if wildcard_domain wildcard_edge_http_expose | ||
|
|
||
| # map to http backend | ||
| # Search from most specific to general path (host case). | ||
| # Note: If no match, haproxy uses the default_backend, no other | ||
| # use_backend directives below this will be processed. | ||
| use_backend be_http_%[base,map_beg(/var/lib/haproxy/conf/os_http_be.map)] | ||
| use_backend be_http_%[base,map_reg(/var/lib/haproxy/conf/os_http_be.map)] if wildcard_domain | ||
|
|
||
| {{ end }} | ||
|
|
||
| default_backend openshift_default | ||
|
|
||
|
|
@@ -125,6 +146,15 @@ frontend public_ssl | |
| acl sni_passthrough req.ssl_sni,map(/var/lib/haproxy/conf/os_sni_passthrough.map) -m found | ||
| use_backend be_tcp_%[req.ssl_sni,map(/var/lib/haproxy/conf/os_tcp_be.map)] if sni sni_passthrough | ||
|
|
||
| {{ if matchPattern "true|TRUE" (env "ROUTER_ALLOW_WILDCARD_ROUTES" "")}} | ||
| # Check for wildcard domains with passthrough. | ||
| acl sni_wildcard_domain req.ssl_sni,map_reg(/var/lib/haproxy/conf/os_wildcard_domain.map) -m found | ||
|
|
||
| acl sni_wildcard_passthrough req.ssl_sni,map_reg(/var/lib/haproxy/conf/os_sni_passthrough.map) -m found | ||
| use_backend be_tcp_%[req.ssl_sni,map_reg(/var/lib/haproxy/conf/os_tcp_be.map)] if sni sni_wildcard_domain sni_wildcard_passthrough | ||
|
|
||
| {{ end }} | ||
|
|
||
| # if the route is SNI and NOT passthrough enter the termination flow | ||
| use_backend be_sni if sni | ||
|
|
||
|
|
@@ -160,11 +190,25 @@ frontend fe_sni | |
| # Search from most specific to general path (host case). | ||
| use_backend be_secure_%[base,map_beg(/var/lib/haproxy/conf/os_reencrypt.map)] if reencrypt | ||
|
|
||
| # map to http backend | ||
| # Search from most specific to general path (host case). | ||
| acl http_backend base,map_beg(/var/lib/haproxy/conf/os_edge_http_be.map) -m found | ||
| use_backend be_edge_http_%[base,map_beg(/var/lib/haproxy/conf/os_edge_http_be.map)] if http_backend | ||
|
|
||
| {{ if matchPattern "true|TRUE" (env "ROUTER_ALLOW_WILDCARD_ROUTES" "")}} | ||
| # Check for wildcard domains with redirected or exposed http routes. | ||
| acl sni_wildcard_domain hdr(host),map_reg(/var/lib/haproxy/conf/os_wildcard_domain.map) -m found | ||
|
|
||
| acl wildcard_reencrypt base,map_reg(/var/lib/haproxy/conf/os_reencrypt.map) -m found | ||
| use_backend be_secure_%[base,map_reg(/var/lib/haproxy/conf/os_reencrypt.map)] if sni_wildcard_domain wildcard_reencrypt | ||
|
|
||
| # map to http backend | ||
| # Search from most specific to general path (host case). | ||
| # Note: If no match, haproxy uses the default_backend, no other | ||
| # use_backend directives below this will be processed. | ||
| use_backend be_edge_http_%[base,map_beg(/var/lib/haproxy/conf/os_edge_http_be.map)] | ||
| use_backend be_edge_http_%[base,map_reg(/var/lib/haproxy/conf/os_edge_http_be.map)] if sni_wildcard_domain | ||
|
|
||
| {{ end }} | ||
|
|
||
| default_backend openshift_default | ||
|
|
||
|
|
@@ -197,11 +241,24 @@ frontend fe_no_sni | |
| # Search from most specific to general path (host case). | ||
| use_backend be_secure_%[base,map_beg(/var/lib/haproxy/conf/os_reencrypt.map)] if reencrypt | ||
|
|
||
| # map to http backend | ||
| # Search from most specific to general path (host case). | ||
| acl edge_http_backend base,map_beg(/var/lib/haproxy/conf/os_edge_http_be.map) -m found | ||
| use_backend be_edge_http_%[base,map_beg(/var/lib/haproxy/conf/os_edge_http_be.map)] if edge_http_backend | ||
|
|
||
| {{ if matchPattern "true|TRUE" (env "ROUTER_ALLOW_WILDCARD_ROUTES" "")}} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What performance impact does this have on a heavily loaded router? I assume host_wildcard_domain is expensive?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assumed it would be a wee bit more expensive because its doing a regexp compare so there is some cost to matching against a pattern. But it is in a if block so is only enabled if the router allows wildcard routes. The strange part was just did a quick and dirty test with ab and I see different results - removed https out of the mix as there is overhead benchmarking w/ cert checks etc and this is what I see: For a For a non-wildcard route: So the wildcard checks are actually a wee bit faster thanks to a compiled regexp. Of course the performance test is not a real-world test but it still does have some merit and the results are not to say the least interesting.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the plan to enable this in any of the online environments?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At this moment I do not know. We have never been asked by online for this. However, online turns on just about everything they learn about, so likely we need to make sure they understand the implications.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would expect the expense to show up when switching among lots of routes, not repeatedly hitting a router serving few routes. |
||
| acl host_wildcard_domain req.ssl_sni,map_reg(/var/lib/haproxy/conf/os_wildcard_domain.map) -m found | ||
|
|
||
| acl host_reencrypt base,map_reg(/var/lib/haproxy/conf/os_reencrypt.map) -m found | ||
| use_backend be_secure_%[base,map_reg(/var/lib/haproxy/conf/os_reencrypt.map)] if host_wildcard_domain host_reencrypt | ||
|
|
||
| # map to http backend | ||
| # Search from most specific to general path (host case). | ||
| # Note: If no match, haproxy uses the default_backend, no other | ||
| # use_backend directives below this will be processed. | ||
| use_backend be_edge_http_%[base,map_beg(/var/lib/haproxy/conf/os_edge_http_be.map)] | ||
| use_backend be_edge_http_%[base,map_reg(/var/lib/haproxy/conf/os_edge_http_be.map)] if host_wildcard_domain | ||
|
|
||
| {{ end }} | ||
|
|
||
| default_backend openshift_default | ||
|
|
||
|
|
@@ -321,8 +378,8 @@ backend be_edge_http_{{$cfgIdx}} | |
| {{ end }}{{/* end iterate over services */}} | ||
| {{ end }}{{/* end if tls==edge/none */}} | ||
|
|
||
| # Secure backend, pass through | ||
| {{ if eq $cfg.TLSTermination "passthrough" }} | ||
| # Secure backend, pass through | ||
| backend be_tcp_{{$cfgIdx}} | ||
| {{ if ne (env "ROUTER_SYSLOG_ADDRESS" "") ""}} | ||
| option tcplog | ||
|
|
@@ -385,8 +442,8 @@ backend be_tcp_{{$cfgIdx}} | |
| {{ end }}{{/* end iterate over services*/}} | ||
| {{ end }}{{/*end tls==passthrough*/}} | ||
|
|
||
| # Secure backend which requires re-encryption | ||
| {{ if eq $cfg.TLSTermination "reencrypt" }} | ||
| # Secure backend which requires re-encryption | ||
| backend be_secure_{{$cfgIdx}} | ||
| mode http | ||
| option redispatch | ||
|
|
@@ -462,14 +519,35 @@ backend be_secure_{{$cfgIdx}} | |
| {{ end }}{{/* end haproxy config template */}} | ||
|
|
||
| {{/*--------------------------------- END OF HAPROXY CONFIG, BELOW ARE MAPPING FILES ------------------------*/}} | ||
| {{/* | ||
| os_wildcard_domain.map: contains a mapping of wildcard hosts for a | ||
| [sub]domain regexps. This map is used to check if | ||
| a host matches a [sub]domain with has wildcard support. | ||
| */}} | ||
| {{ define "/var/lib/haproxy/conf/os_wildcard_domain.map" }} | ||
| {{ if matchPattern "true|TRUE" (env "ROUTER_ALLOW_WILDCARD_ROUTES" "")}} | ||
| {{ range $idx, $cfg := .State }} | ||
| {{ if ne $cfg.Host ""}} | ||
| {{ if $cfg.IsWildcard }} | ||
| {{genDomainWildcardRegexp $cfg.Host "" true}} 1 | ||
| {{ end }} | ||
| {{ end }} | ||
| {{ end }} | ||
| {{ end }}{{/* end if router allows wildcard routes */}} | ||
| {{ end }}{{/* end wildcard domain map template */}} | ||
|
|
||
| {{/* | ||
| os_http_be.map: contains a mapping of www.example.com -> <service name>. This map is used to discover the correct backend | ||
| by attaching a prefix (be_http_) by use_backend statements if acls are matched. | ||
| */}} | ||
| {{ define "/var/lib/haproxy/conf/os_http_be.map" }} | ||
| {{ range $idx, $cfg := .State }} | ||
| {{ if and (ne $cfg.Host "") (eq $cfg.TLSTermination "")}} | ||
| {{ if $cfg.IsWildcard }} | ||
| {{genDomainWildcardRegexp $cfg.Host $cfg.Path false}} {{$idx}} | ||
| {{ else }} | ||
| {{$cfg.Host}}{{$cfg.Path}} {{$idx}} | ||
| {{ end }} | ||
| {{ end }} | ||
| {{ end }} | ||
| {{ end }}{{/* end http host map template */}} | ||
|
|
@@ -481,7 +559,11 @@ backend be_secure_{{$cfgIdx}} | |
| {{ define "/var/lib/haproxy/conf/os_edge_http_be.map" }} | ||
| {{ range $idx, $cfg := .State }} | ||
| {{ if and (ne $cfg.Host "") (eq $cfg.TLSTermination "edge")}} | ||
| {{ if $cfg.IsWildcard }} | ||
| {{genDomainWildcardRegexp $cfg.Host $cfg.Path false}} {{$idx}} | ||
| {{ else }} | ||
| {{$cfg.Host}}{{$cfg.Path}} {{$idx}} | ||
| {{ end }} | ||
| {{ end }} | ||
| {{ end }} | ||
| {{ end }}{{/* end edge http host map template */}} | ||
|
|
@@ -494,7 +576,11 @@ backend be_secure_{{$cfgIdx}} | |
| {{ define "/var/lib/haproxy/conf/os_edge_http_expose.map" }} | ||
| {{ range $idx, $cfg := .State }} | ||
| {{ if and (ne $cfg.Host "") (and (eq $cfg.TLSTermination "edge") (eq $cfg.InsecureEdgeTerminationPolicy "Allow"))}} | ||
| {{ if $cfg.IsWildcard }} | ||
| {{genDomainWildcardRegexp $cfg.Host $cfg.Path false}} {{$idx}} | ||
| {{ else }} | ||
| {{$cfg.Host}}{{$cfg.Path}} {{$idx}} | ||
| {{ end }} | ||
| {{ end }} | ||
| {{ end }} | ||
| {{ end }}{{/* end edge insecure expose http host map template */}} | ||
|
|
@@ -507,7 +593,11 @@ backend be_secure_{{$cfgIdx}} | |
| {{ define "/var/lib/haproxy/conf/os_edge_http_redirect.map" }} | ||
| {{ range $idx, $cfg := .State }} | ||
| {{ if and (ne $cfg.Host "") (and (eq $cfg.TLSTermination "edge") (eq $cfg.InsecureEdgeTerminationPolicy "Redirect"))}} | ||
| {{ if $cfg.IsWildcard }} | ||
| {{genDomainWildcardRegexp $cfg.Host $cfg.Path false}} {{$idx}} | ||
| {{ else }} | ||
| {{$cfg.Host}}{{$cfg.Path}} {{$idx}} | ||
| {{ end }} | ||
| {{ end }} | ||
| {{ end }} | ||
| {{ end }}{{/* end edge insecure redirect http host map template */}} | ||
|
|
@@ -520,7 +610,11 @@ backend be_secure_{{$cfgIdx}} | |
| {{ define "/var/lib/haproxy/conf/os_tcp_be.map" }} | ||
| {{ range $idx, $cfg := .State }} | ||
| {{ if and (eq $cfg.Path "") (and (ne $cfg.Host "") (or (eq $cfg.TLSTermination "passthrough") (eq $cfg.TLSTermination "reencrypt"))) }} | ||
| {{ if $cfg.IsWildcard }} | ||
| {{genDomainWildcardRegexp $cfg.Host "" true}} {{$idx}} | ||
| {{ else }} | ||
| {{$cfg.Host}} {{$idx}} | ||
| {{ end }} | ||
| {{ end }} | ||
| {{ end }} | ||
| {{ end }}{{/* end tcp host map template */}} | ||
|
|
@@ -532,7 +626,11 @@ backend be_secure_{{$cfgIdx}} | |
| {{ define "/var/lib/haproxy/conf/os_sni_passthrough.map" }} | ||
| {{ range $idx, $cfg := .State }} | ||
| {{ if and (eq $cfg.Path "") (eq $cfg.TLSTermination "passthrough") }} | ||
| {{ if $cfg.IsWildcard }} | ||
| {{genDomainWildcardRegexp $cfg.Host "" true}} {{$idx}} | ||
| {{ else }} | ||
| {{$cfg.Host}} 1 | ||
| {{ end }} | ||
| {{ end }} | ||
| {{ end }} | ||
| {{ end }}{{/* end sni passthrough map template */}} | ||
|
|
@@ -545,7 +643,11 @@ backend be_secure_{{$cfgIdx}} | |
| {{ define "/var/lib/haproxy/conf/os_reencrypt.map" }} | ||
| {{ range $idx, $cfg := .State }} | ||
| {{ if and (ne $cfg.Host "") (eq $cfg.TLSTermination "reencrypt") }} | ||
| {{ if $cfg.IsWildcard }} | ||
| {{genDomainWildcardRegexp $cfg.Host $cfg.Path false}} {{$idx}} | ||
| {{ else }} | ||
| {{$cfg.Host}}{{$cfg.Path}} {{$idx}} | ||
| {{ end }} | ||
| {{ end }} | ||
| {{ end }} | ||
| {{ end }}{{/* end reencrypt map template */}} | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will also meet this condition when the value is 1?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could do a 1 in that set as well if need be but
true|TRUEfollows the other parameters in this file.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, let's just support true for now. The SYN eater I added got it backwards and added '1' so I fixed that later and support 'true' and '1', but 'true' is preferred.