@@ -206,18 +206,25 @@ backend openshift_default
206
206
where to send the traffic but should run the be in tcp mode
207
207
3. if the config is terminated at the
208
208
*/}}
209
- {{ range $id , $serviceUnit := .State }}
210
- {{ range $cfgIdx, $cfg := $serviceUnit.ServiceAliasConfigs }}
211
- {{ if or (eq $cfg.TLSTermination "") (eq $cfg.TLSTermination "edge ") }}
212
- {{ if (eq $cfg.TLSTermination "") }}
209
+ {{ range $cfgIdx , $cfg := .State }}
210
+ {{ if or (eq $cfg.TLSTermination "") (eq $cfg.TLSTermination "edge") }}
211
+ {{ if (eq $cfg.TLSTermination "") }}
212
+ # Plain http backend
213
213
backend be_http_{{$cfgIdx}}
214
- {{ else }}
214
+ {{ else }}
215
+ # Plain http backend but request is TLS, terminated at edge
215
216
backend be_edge_http_{{$cfgIdx}}
216
- {{ end }}
217
+ {{ end }}
217
218
mode http
218
219
option redispatch
219
220
option forwardfor
221
+ {{ with $balanceAlgo := index $cfg.Annotations "router.openshift.io/haproxy.balance" }}
222
+ {{ with $matchValue := (matchValues $balanceAlgo "roundrobin" "leastconn" ) }}
223
+ balance {{ $balanceAlgo }}
224
+ {{ end }}
225
+ {{ else }}
220
226
balance leastconn
227
+ {{ end }}
221
228
timeout check 5000ms
222
229
http-request set-header X-Forwarded-Host %[req.hdr(host)]
223
230
http-request set-header X-Forwarded-Port %[dst_port]
@@ -226,41 +233,53 @@ backend be_edge_http_{{$cfgIdx}}
226
233
{{ if (eq $cfg.TLSTermination "") }}
227
234
cookie {{$cfg.RoutingKeyName}} insert indirect nocache httponly
228
235
{{ else }}
229
- cookie {{$cfg.RoutingKeyName}} insert indirect nocache httponly secure
236
+ cookie {{$cfg.RoutingKeyName}} insert indirect nocache httponly secure
230
237
{{ end }}
231
238
http-request set-header Forwarded for=%[src];host=%[req.hdr(host)];proto=%[req.hdr(X-Forwarded-Proto)]
232
- {{ range $idx, $endpoint := endpointsForAlias $cfg $serviceUnit }}
233
- server {{$endpoint.IdHash}} {{$endpoint.IP}}:{{$endpoint.Port}} check inter 5000ms cookie {{$endpoint.IdHash}}
234
- {{ end }}
235
- {{ end }}
236
-
237
- {{ if eq $cfg.TLSTermination "passthrough" }}
239
+ {{ range $serviceUnitName, $weight := $cfg.ServiceUnitNames }}
240
+ {{ with $serviceUnit := index $.ServiceUnits $serviceUnitName }}
241
+ {{ range $idx, $endpoint := endpointsForAlias $cfg $serviceUnit }}
242
+ server {{$endpoint.IdHash}} {{$endpoint.IP}}:{{$endpoint.Port}} check inter 5000ms cookie {{$endpoint.IdHash}} weight {{ $weight }}
243
+ {{ end }}
244
+ {{ end }}
245
+ {{ end }}{{/* end iterate over services */}}
246
+ {{ end }}{{/* end if tls==edge/none */}}
247
+
248
+ # Secure backend, pass through
249
+ {{ if eq $cfg.TLSTermination "passthrough" }}
238
250
backend be_tcp_{{$cfgIdx}}
239
251
{{ if ne (env "ROUTER_SYSLOG_ADDRESS" "") ""}}
240
252
option tcplog
241
253
{{ end }}
242
254
balance {{ env "ROUTER_TCP_BALANCE_SCHEME" "source" }}
243
255
hash-type consistent
244
256
timeout check 5000ms
245
- {{ range $idx, $endpoint := endpointsForAlias $cfg $serviceUnit }}
257
+ {{ range $svcUnitIdx, $serviceUnitName := $cfg.ServiceUnitNames }}
258
+ {{ with $serviceUnit := index $.ServiceUnits $serviceUnitName }}
259
+ {{ range $idx, $endpoint := endpointsForAlias $cfg $serviceUnit }}
246
260
server {{$endpoint.ID}} {{$endpoint.IP}}:{{$endpoint.Port}} check inter 5000ms
247
- {{ end }}
248
- {{ end }}
261
+ {{ end }}
262
+ {{ end }}
263
+ {{ end }}{{/* end iterate over services*/}}
264
+ {{ end }}{{/*end tls==passthrough*/}}
249
265
250
- {{ if eq $cfg.TLSTermination "reencrypt" }}
266
+ # Secure backend which requires re-encryption
267
+ {{ if eq $cfg.TLSTermination "reencrypt" }}
251
268
backend be_secure_{{$cfgIdx}}
252
269
mode http
253
270
option redispatch
254
271
balance leastconn
255
272
timeout check 5000ms
256
273
cookie {{$cfg.RoutingKeyName}} insert indirect nocache httponly secure
257
- {{ range $idx, $endpoint := endpointsForAlias $cfg $serviceUnit }}
274
+ {{ range $svcUnitIdx, $serviceUnitName := $cfg.ServiceUnitNames }}
275
+ {{ with $serviceUnit := index $.ServiceUnits $serviceUnitName }}
276
+ {{ range $idx, $endpoint := endpointsForAlias $cfg $serviceUnit }}
258
277
server {{$endpoint.IdHash}} {{$endpoint.IP}}:{{$endpoint.Port}} ssl check inter 5000ms verify required ca-file {{ $workingDir }}/cacerts/{{$cfgIdx}}.pem cookie {{$endpoint.IdHash}}
259
- {{ end }}
260
- {{ end }}
261
- {{ end }}{{/* $serviceUnit.ServiceAliasConfigs*/ }}
262
- {{ end }}{{/* $serviceUnit */}}
263
-
278
+ {{ end }}
279
+ {{ end }}
280
+ {{ end }}
281
+ {{ end }}{{/* end tls==reencrypt */}}
282
+ {{ end }}{{/* end loop over routes */}}
264
283
{{ end }}{{/* end haproxy config template */}}
265
284
266
285
{{/*--------------------------------- END OF HAPROXY CONFIG, BELOW ARE MAPPING FILES ------------------------*/}}
@@ -269,27 +288,23 @@ backend be_secure_{{$cfgIdx}}
269
288
by attaching a prefix (be_http_) by use_backend statements if acls are matched.
270
289
*/}}
271
290
{{ define "/var/lib/haproxy/conf/os_http_be.map" }}
272
- {{ range $id, $serviceUnit := .State }}
273
- {{ range $idx, $cfg := $serviceUnit.ServiceAliasConfigs }}
291
+ {{ range $idx, $cfg := .State }}
274
292
{{ if and (ne $cfg.Host "") (eq $cfg.TLSTermination "")}}
275
293
{{$cfg.Host}}{{$cfg.Path}} {{$idx}}
276
294
{{ end }}
277
295
{{ end }}
278
- {{ end }}
279
296
{{ end }}{{/* end http host map template */}}
280
297
281
298
{{/*
282
299
os_edge_http_be.map: same as os_http_be.map but allows us to separate tls from non-tls routes to ensure we don't expose
283
300
a tls only route on the unsecure port
284
301
*/}}
285
302
{{ define "/var/lib/haproxy/conf/os_edge_http_be.map" }}
286
- {{ range $id, $serviceUnit := .State }}
287
- {{ range $idx, $cfg := $serviceUnit.ServiceAliasConfigs }}
303
+ {{ range $idx, $cfg := .State }}
288
304
{{ if and (ne $cfg.Host "") (eq $cfg.TLSTermination "edge")}}
289
305
{{$cfg.Host}}{{$cfg.Path}} {{$idx}}
290
306
{{ end }}
291
307
{{ end }}
292
- {{ end }}
293
308
{{ end }}{{/* end edge http host map template */}}
294
309
295
310
{{/*
@@ -298,13 +313,11 @@ backend be_secure_{{$cfgIdx}}
298
313
(http) if acls match for routes with insecure option set to expose.
299
314
*/}}
300
315
{{ define "/var/lib/haproxy/conf/os_edge_http_expose.map" }}
301
- {{ range $id, $serviceUnit := .State }}
302
- {{ range $idx, $cfg := $serviceUnit.ServiceAliasConfigs }}
316
+ {{ range $idx, $cfg := .State }}
303
317
{{ if and (ne $cfg.Host "") (and (eq $cfg.TLSTermination "edge") (eq $cfg.InsecureEdgeTerminationPolicy "Allow"))}}
304
318
{{$cfg.Host}}{{$cfg.Path}} {{$idx}}
305
319
{{ end }}
306
320
{{ end }}
307
- {{ end }}
308
321
{{ end }}{{/* end edge insecure expose http host map template */}}
309
322
310
323
{{/*
@@ -313,13 +326,11 @@ backend be_secure_{{$cfgIdx}}
313
326
if acls match for routes that have the insecure option set to redirect.
314
327
*/}}
315
328
{{ define "/var/lib/haproxy/conf/os_edge_http_redirect.map" }}
316
- {{ range $id, $serviceUnit := .State }}
317
- {{ range $idx, $cfg := $serviceUnit.ServiceAliasConfigs }}
329
+ {{ range $idx, $cfg := .State }}
318
330
{{ if and (ne $cfg.Host "") (and (eq $cfg.TLSTermination "edge") (eq $cfg.InsecureEdgeTerminationPolicy "Redirect"))}}
319
331
{{$cfg.Host}}{{$cfg.Path}} {{$idx}}
320
332
{{ end }}
321
333
{{ end }}
322
- {{ end }}
323
334
{{ end }}{{/* end edge insecure redirect http host map template */}}
324
335
325
336
@@ -328,27 +339,23 @@ backend be_secure_{{$cfgIdx}}
328
339
by attaching a prefix (be_tcp_ or be_secure_) by use_backend statements if acls are matched.
329
340
*/}}
330
341
{{ define "/var/lib/haproxy/conf/os_tcp_be.map" }}
331
- {{ range $id, $serviceUnit := .State }}
332
- {{ range $idx, $cfg := $serviceUnit.ServiceAliasConfigs }}
342
+ {{ range $idx, $cfg := .State }}
333
343
{{ if and (eq $cfg.Path "") (and (ne $cfg.Host "") (or (eq $cfg.TLSTermination "passthrough") (eq $cfg.TLSTermination "reencrypt"))) }}
334
344
{{$cfg.Host}} {{$idx}}
335
345
{{ end }}
336
346
{{ end }}
337
- {{ end }}
338
347
{{ end }}{{/* end tcp host map template */}}
339
348
340
349
{{/*
341
350
os_sni_passthrough.map: contains a mapping of routes that expect to have an sni header and should be passed
342
351
through to the host_be. Driven by the termination type of the ServiceAliasConfigs
343
352
*/}}
344
353
{{ define "/var/lib/haproxy/conf/os_sni_passthrough.map" }}
345
- {{ range $id, $serviceUnit := .State }}
346
- {{ range $idx, $cfg := $serviceUnit.ServiceAliasConfigs }}
354
+ {{ range $idx, $cfg := .State }}
347
355
{{ if and (eq $cfg.Path "") (eq $cfg.TLSTermination "passthrough") }}
348
356
{{$cfg.Host}} 1
349
357
{{ end }}
350
358
{{ end }}
351
- {{ end }}
352
359
{{ end }}{{/* end sni passthrough map template */}}
353
360
354
361
@@ -357,11 +364,9 @@ backend be_secure_{{$cfgIdx}}
357
364
that does specific checks that avoid mitm attacks: http://cbonte.github.io/haproxy-dconv/configuration-1.5.html#5.2-ssl
358
365
*/}}
359
366
{{ define "/var/lib/haproxy/conf/os_reencrypt.map" }}
360
- {{ range $id, $serviceUnit := .State }}
361
- {{ range $idx, $cfg := $serviceUnit.ServiceAliasConfigs }}
367
+ {{ range $idx, $cfg := .State }}
362
368
{{ if and (ne $cfg.Host "") (eq $cfg.TLSTermination "reencrypt") }}
363
369
{{$cfg.Host}}{{$cfg.Path}} {{$idx}}
364
370
{{ end }}
365
371
{{ end }}
366
- {{ end }}
367
372
{{ end }}{{/* end reencrypt passthrough map template */}}
0 commit comments