Last active
December 3, 2024 18:22
-
-
Save Snawoot/a8019c7f200245627036d49e87a6ec19 to your computer and use it in GitHub Desktop.
dumbproxy HMAC auth on HAProxy 3.0+
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
global | |
log /dev/log local0 | |
log /dev/log local1 notice | |
chroot /var/lib/haproxy | |
stats socket /run/haproxy/admin.sock mode 660 level admin | |
stats timeout 30s | |
user haproxy | |
group haproxy | |
daemon | |
# Default SSL material locations | |
ca-base /etc/ssl/certs | |
crt-base /etc/ssl/private | |
# See: https://ssl-config.mozilla.org/#server=haproxy&server-version=2.0.3&config=intermediate | |
ssl-default-bind-ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384 | |
ssl-default-bind-ciphersuites TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256 | |
ssl-default-bind-options ssl-min-ver TLSv1.2 no-tls-tickets | |
set-var proc.hmac_key str(14Eg31ZAUSfVe4mFJWDGx3sLVeef5XC4ojfkXWE4KA4=) | |
defaults | |
log global | |
mode http | |
option httplog | |
option dontlognull | |
timeout connect 5000 | |
timeout client 50000 | |
timeout server 50000 | |
errorfile 400 /etc/haproxy/errors/400.http | |
errorfile 403 /etc/haproxy/errors/403.http | |
errorfile 408 /etc/haproxy/errors/408.http | |
errorfile 500 /etc/haproxy/errors/500.http | |
errorfile 502 /etc/haproxy/errors/502.http | |
errorfile 503 /etc/haproxy/errors/503.http | |
errorfile 504 /etc/haproxy/errors/504.http | |
frontend main | |
bind :8080 | |
mode http | |
option http-use-proxy-header | |
http-request set-var(txn.raw_auth_expire) http_auth_pass,ub64dec,bytes(0,8) | |
http-request set-var(txn.auth_expire) var(txn.raw_auth_expire),be2hex,hex2i | |
http-request set-var(txn.auth_current_ts) date | |
http-request set-var(txn.auth_tag) http_auth_pass,ub64dec,bytes(8,32) | |
http-request set-var-fmt(txn.hmac_input) "%{+bin}o%[str(dumbproxy grant token v1)]%[http_auth_user]%[var(txn.raw_auth_expire)]" | |
http-request set-var(txn.auth_expected_tag) var(txn.hmac_input),hmac(sha256,proc.hmac_key) | |
acl tag_ok var(txn.auth_tag),secure_memcmp(txn.auth_expected_tag) | |
acl tag_expired var(txn.auth_expire),sub(txn.auth_current_ts) -m int le 0 | |
http-request auth realm "Private Area" unless !tag_expired tag_ok | |
default_backend proxy | |
backend proxy | |
server proxy 127.0.0.1:8181 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Important
Requires HAProxy 3.0+