Update: support tcp-mode (in frontend/backend)
This commit is contained in:
parent
869fdead3d
commit
f5b097616e
3 changed files with 30 additions and 3 deletions
14
README.md
14
README.md
|
|
@ -80,6 +80,7 @@ Important: easyhaproxy needs to be in the same network of the containers or othe
|
||||||
| Tag | Description |
|
| Tag | Description |
|
||||||
|---------------------------------------------|---------------------------------------------------------------------------------------------------------|
|
|---------------------------------------------|---------------------------------------------------------------------------------------------------------|
|
||||||
| com.byjg.easyhaproxy.definitions | A Comma delimited list with the definitions. Each name requires the definition of the parameters below. |
|
| com.byjg.easyhaproxy.definitions | A Comma delimited list with the definitions. Each name requires the definition of the parameters below. |
|
||||||
|
| com.byjg.easyhaproxy.mode.[definition] | (Optional) Is this http or tcp mode in HAProxy. (Defaults to http) |
|
||||||
| com.byjg.easyhaproxy.port.[definition] | (Optional) What is the port that the HAProxy will listen to. (Defaults to 80) |
|
| com.byjg.easyhaproxy.port.[definition] | (Optional) What is the port that the HAProxy will listen to. (Defaults to 80) |
|
||||||
| com.byjg.easyhaproxy.localport.[definition] | (Optional) What is the port that the container is listening. (Defaults to 80) |
|
| com.byjg.easyhaproxy.localport.[definition] | (Optional) What is the port that the container is listening. (Defaults to 80) |
|
||||||
| com.byjg.easyhaproxy.host.[definition] | What is the host that the HAProxy will listen to. |
|
| com.byjg.easyhaproxy.host.[definition] | What is the host that the HAProxy will listen to. |
|
||||||
|
|
@ -126,6 +127,19 @@ docker run \
|
||||||
some/myimage
|
some/myimage
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### TLS passthrough
|
||||||
|
|
||||||
|
Used to pass on SSL-termination to a backend:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker run \
|
||||||
|
-l com.byjg.easyhaproxy.defintions=tcp-service \
|
||||||
|
-l com.byjg.easyhaproxy.mode.tcp-service=tcp \
|
||||||
|
-l com.byjg.easyhaproxy.port.tcp-service=443
|
||||||
|
.... \
|
||||||
|
some/tcp-service
|
||||||
|
```
|
||||||
|
|
||||||
### Redirect Example:
|
### Redirect Example:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|
|
||||||
2
swarm.py
2
swarm.py
|
|
@ -36,6 +36,7 @@ for line in lineList:
|
||||||
if "com.byjg.easyhaproxy.host." + definition not in d:
|
if "com.byjg.easyhaproxy.host." + definition not in d:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
mode = d["com.byjg.easyhaproxy.mode." + definition] if "com.byjg.easyhaproxy.mode." + definition in d else "http"
|
||||||
port = d["com.byjg.easyhaproxy.port." + definition] if "com.byjg.easyhaproxy.port." + definition in d else "80"
|
port = d["com.byjg.easyhaproxy.port." + definition] if "com.byjg.easyhaproxy.port." + definition in d else "80"
|
||||||
hash = hashlib.md5(d["com.byjg.easyhaproxy.sslcert." + definition].encode('utf-8')).hexdigest() if "com.byjg.easyhaproxy.sslcert." + definition in d else ""
|
hash = hashlib.md5(d["com.byjg.easyhaproxy.sslcert." + definition].encode('utf-8')).hexdigest() if "com.byjg.easyhaproxy.sslcert." + definition in d else ""
|
||||||
|
|
||||||
|
|
@ -43,6 +44,7 @@ for line in lineList:
|
||||||
|
|
||||||
if key not in easymapping:
|
if key not in easymapping:
|
||||||
easymapping[key] = {
|
easymapping[key] = {
|
||||||
|
"mode": mode,
|
||||||
"port": port,
|
"port": port,
|
||||||
"hosts": dict(),
|
"hosts": dict(),
|
||||||
"redirect": dict(),
|
"redirect": dict(),
|
||||||
|
|
|
||||||
|
|
@ -39,10 +39,17 @@ backend srv_stats
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% for o in data["easymapping"] %}
|
{% for o in data["easymapping"] %}
|
||||||
|
{% set mode = o["mode"] or "http" %}
|
||||||
{% set salt = loop.index %}
|
{% set salt = loop.index %}
|
||||||
frontend http_in_{{ o["port"] }}_{{ salt }}
|
frontend {{ mode }}_in_{{ o["port"] }}_{{ salt }}
|
||||||
bind *:{{ o["port"] }} {{ " ssl crt " + o["ssl_cert"] if "ssl_cert" in o else "" }}
|
bind *:{{ o["port"] }} {{ " ssl crt " + o["ssl_cert"] if "ssl_cert" in o else "" }}
|
||||||
mode http
|
mode {{ mode }}
|
||||||
|
|
||||||
|
{% if mode == "tcp" -%}
|
||||||
|
option tcplog
|
||||||
|
tcp-request inspect-delay 5s
|
||||||
|
tcp-request content accept if { req.ssl_hello_type 1 }
|
||||||
|
{% endif -%}
|
||||||
|
|
||||||
{% for k in o["redirect"] -%}
|
{% for k in o["redirect"] -%}
|
||||||
redirect prefix {{ o["redirect"][k] }} code 301 if { hdr(host) -i {{ k }} }
|
redirect prefix {{ o["redirect"][k] }} code 301 if { hdr(host) -i {{ k }} }
|
||||||
|
|
@ -59,10 +66,14 @@ frontend http_in_{{ o["port"] }}_{{ salt }}
|
||||||
{% set host = k.replace(".", "_") + "_{0}_{1}".format(o["port"], salt) %}
|
{% set host = k.replace(".", "_") + "_{0}_{1}".format(o["port"], salt) %}
|
||||||
backend srv_{{ host }}
|
backend srv_{{ host }}
|
||||||
balance roundrobin
|
balance roundrobin
|
||||||
mode http
|
mode {{ mode }}
|
||||||
|
|
||||||
|
{% if mode == "http" %}
|
||||||
option forwardfor
|
option forwardfor
|
||||||
http-request set-header X-Forwarded-Port %[dst_port]
|
http-request set-header X-Forwarded-Port %[dst_port]
|
||||||
http-request add-header X-Forwarded-Proto https if { ssl_fc }
|
http-request add-header X-Forwarded-Proto https if { ssl_fc }
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
server srv {{ o["hosts"][k] }} check weight 1
|
server srv {{ o["hosts"][k] }} check weight 1
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue