Skip to content

www/caddy: add possibility to import proxy_protocol #5583

Description

@jhubee

Important notices
Before you add a new report, we ask you kindly to acknowledge the following:

Is your feature request related to a problem? Please describe.
Since caddy v2.7.0 proxy_protocol directive inside the global server -> listener_wrappers block is merged into caddy core. See https://caddyserver.com/docs/caddyfile/options#proxy-protocol
Don't mix up with the "layer4" module proxy_protocol matcher/handler.
The core module can terminate and utilize the proxy_protocol header e.g. set client_ip placeholder to real client IP instead upstream (SNI) proxy ip.

With current setup of the caddy plugin, it's not possible to import custom configs to the global servers or inside servers -> listen_wrappers block. It's only possible to add custom configs inside the layer4 block.

Describe the solution you'd like
Add import directive to listen_wrappers block after layer4 module block but before "tls".

servers {
protocols {{ generalSettings.HttpVersions.split(',') | join(' ') }}
{% if accessList %}
trusted_proxies static {{ accessList.clientIps.split(',') | join(' ') }}
{% endif %}
{% if generalSettings.ClientIpHeaders %}
{% for header_uuid in generalSettings.ClientIpHeaders.split(',') %}
{% set header = helpers.toList('Pischem.caddy.reverseproxy.header') | selectattr('@uuid', 'equalto', header_uuid) | first %}
{% if header and header.HeaderType %}
client_ip_headers {{ header.HeaderType }}
{% endif %}
{% endfor %}
{% endif %}
{% if generalSettings.LogCredentials|default("0") == "1" %}
log_credentials
{% endif %}
{% if generalSettings.timeout_read_body or
generalSettings.timeout_read_header or
generalSettings.timeout_write or
generalSettings.timeout_idle %}
timeouts {
{% if generalSettings.timeout_read_body %}
read_body {{ generalSettings.timeout_read_body }}s
{% endif %}
{% if generalSettings.timeout_read_header %}
read_header {{ generalSettings.timeout_read_header }}s
{% endif %}
{% if generalSettings.timeout_write %}
write {{ generalSettings.timeout_write }}s
{% endif %}
{% if generalSettings.timeout_idle %}
idle {{ generalSettings.timeout_idle }}s
{% endif %}
}
{% endif %}
{% if generalSettings.EnableLayer4|default("0") == "1" %}
listener_wrappers {
layer4 {
import /usr/local/etc/caddy/caddy.d/*.layer4listener
{% set context_var = "listener_wrappers" %}
{% include "OPNsense/Caddy/includeLayer4" %}
}
{# Route all other traffic to HTTP App #}
tls
}
{% endif %}
}

Before "{# Route all other traffic to HTTP App #}" add e.g.:
import /usr/local/etc/caddy/caddy.d/*.listenerwrappers

Describe alternatives you've considered
Alternatively make proxy_protocol configurable via ui.

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureAdding new functionalityhelp wantedContributor missing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions