Merge "Use Haproxy PROXY Protocol with Gitea"

This commit is contained in:
Zuul authored and Gerrit Code Review committed 2026-08-14 17:36:16 +00:00
commit 95419a64e4
5 files changed
+52 -3

No files matched your search

+22 -1
View File
@@ -23,26 +23,47 @@ gitea_lb_listeners:
check_method: 'check'
- name: balance_git_https
bind:
- ':::443'
# Native v4 + v6-only sockets, not a single dual-stack ':::443'. On a
# dual-stack socket the kernel presents IPv4 peers as IPv4-mapped IPv6
# (::ffff:A.B.C.D), so haproxy send-proxy emits `PROXY TCP6 ::ffff:...`,
# which released Apache mod_remoteip rejects (AH03500: its TCP6 address
# charset has no '.') and aborts the connection. Native sockets make
# haproxy emit `PROXY TCP4 A.B.C.D` for v4 clients, which it accepts.
- '0.0.0.0:443'
- ':::443 v6only'
# proxy_string is 'send-proxy' only -- deliberately NOT 'ssl send-proxy'.
# The bind above has no 'ssl'/'crt', so in mode tcp haproxy relays the
# byte stream and TLS is end-to-end client <-> gitea's Apache. Adding
# 'ssl' here would open a second TLS session to the backend and write the
# client's already-encrypted bytes into it, so Apache would decrypt the
# outer layer and read the client's ClientHello as a plaintext request.
# check-ssl below is unaffected: it governs the health check, not the
# data path.
servers:
- name: 'gitea09.opendev.org'
address: '38.108.68.113:3081'
check_method: 'check check-ssl verify none'
proxy_string: 'send-proxy'
- name: 'gitea10.opendev.org'
address: '38.108.68.77:3081'
check_method: 'check check-ssl verify none'
proxy_string: 'send-proxy'
- name: 'gitea11.opendev.org'
address: '38.108.68.215:3081'
check_method: 'check check-ssl verify none'
proxy_string: 'send-proxy'
- name: 'gitea12.opendev.org'
address: '38.108.68.229:3081'
check_method: 'check check-ssl verify none'
proxy_string: 'send-proxy'
- name: 'gitea13.opendev.org'
address: '38.74.51.139:3081'
check_method: 'check check-ssl verify none'
proxy_string: 'send-proxy'
- name: 'gitea14.opendev.org'
address: '38.108.68.205:3081'
check_method: 'check check-ssl verify none'
proxy_string: 'send-proxy'
iptables_extra_public_tcp_ports:
- 443
- 80
@@ -30,7 +30,7 @@ listen {{ listener.name }}
option httpchk GET /api/healthz
{% for server in listener.servers %}
server {{ server.name }} {{ server.address }} {{ server.check_method }}
server {{ server.name }} {{ server.address }} {{ server.check_method }} {{ server.proxy_string | default('') }}
{% endfor %}
{% endfor %}
+1
View File
@@ -15,6 +15,7 @@
- proxy_http
- ssl
- headers
- remoteip
- name: Copy apache config
template:
@@ -19,6 +19,27 @@ Listen 3081
ServerAdmin infra-root@opendev.org
DocumentRoot /var/www/opendev.org
# Process PROXY Protocol Headers from our haproxy load balancer so
# mod_remoteip can recover the real client address. haproxy runs in
# mode tcp and terminates no TLS, so it cannot inject X-Forwarded-For
# itself; the PROXY header is the only way to carry the client address.
# Except localhost over both IPv4 and IPv6: functional test connections
# reach this vhost directly (e.g. `git clone https://localhost:3081`)
# and so carry no PROXY header. The haproxy load balancer itself must
# NOT be excepted here or mod_remoteip would stop recovering the client
# address for proxied traffic; haproxy health checks still succeed
# because `send-proxy` also prepends the PROXY header to httpchk
# connections.
#
# No RemoteIPTrustedProxy is set: that directive only gates the
# header-based path (RemoteIPHeader, e.g. X-Forwarded-For), which we do
# not use. RemoteIPProxyProtocol trusts any peer not listed in
# RemoteIPProxyProtocolExceptions, so the exceptions list is what
# restricts this. Access to port 3081 is already limited to the
# gitea-lb group by iptables_extra_allowed_groups.
RemoteIPProxyProtocol On
RemoteIPProxyProtocolExceptions 127.0.0.1 ::1
<Directory /var/www/opendev.org/>
Require all granted
Order allow,deny
@@ -8,8 +8,14 @@ gitea_lb_listeners:
check_method: "check"
- name: balance_git_https
bind:
- ":::443"
# Split v4/v6 (see inventory/service/group_vars/gitea-lb.yaml): native
# sockets make haproxy emit `PROXY TCP4 ...` for v4 clients -- including
# the testinfra curl to 127.0.0.1 -- instead of `PROXY TCP6 ::ffff:...`,
# which Apache mod_remoteip rejects with AH03500 and aborts.
- "0.0.0.0:443"
- ":::443 v6only"
servers:
- name: "gitea99.opendev.org"
address: "{{ (hostvars['gitea99.opendev.org'] | default({})).get('nodepool', {}).get('public_ipv4', '') }}:3081"
check_method: "check check-ssl ca-file /usr/local/etc/haproxy/ca.crt"
proxy_string: "send-proxy"