1. The problem I’m having:
Unable to get “X-Forwarded-For” to show correct IP on a whoami webpage, also unable to get client_ip to show correctly. It is showing Cloudflare IP despite building Caddy with the Cloudflare Module, and amending the Caddyfile to include what I believe are the correct elements.
2. Error messages and/or full log output:
{"level":"info","ts":1723413883.4145572,"logger":"http.log.access.log7","msg":"handled request","request":{"remote_ip":"172.71.26.33","remote_port":"34842","client_ip":"172.71.26.33","proto":"HTTP/2.0","method":"GET","host":"whoami.allthatlab.xyz","uri":"/","headers":{"Accept-Encoding":["gzip, br"],"Cf-Ray":["8b1b85e30fed71e1-LHR"],"X-Forwarded-Proto":["https"],"Accept":["*/*"],"Cf-Ipcountry":["GB"],"X-Forwarded-For":["82.132.236.243"],"Cf-Visitor":["{\"scheme\":\"https\"}"],"User-Agent":["iCurlHTTP/1.17 libcurl/7.83.1 OpenSSL/1.1.1o zlib/1.2.11 nghttp2/1.47.0"],"Cf-Connecting-Ip":["82.132.236.243"],"Cdn-Loop":["cloudflare"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"whoami.allthatlab.xyz"}},"bytes_read":0,"user_id":"","duration":0.002957776,"size":567,"status":200,"resp_headers":{"Content-Encoding":["gzip"],"Content-Type":["text/plain; charset=utf-8"],"Date":["Sun, 11 Aug 2024 22:04:43 GMT"],"Vary":["Accept-Encoding"],"Server":["Caddy"],"Alt-Svc":["h3=\":443\"; ma=2592000"]}}
3. Caddy version:
v2.8.4
4. How I installed and ran Caddy:
a. System environment:
Unraid, Docker
b. Build:
FROM caddy:2.8-builder AS builder
RUN xcaddy build \
--with github.com/caddy-dns/cloudflare \
--with github.com/hslatman/caddy-crowdsec-bouncer/crowdsec \
--with github.com/WeidiDeng/caddy-cloudflare-ip
FROM caddy:2.8
COPY --from=builder /usr/bin/caddy /usr/bin/caddy
c. Service/unit/compose file:
docker run
-d
--name='caddy'
--net='farrosphere'
--pids-limit 2048
-e TZ="Europe/London"
-e HOST_OS="Unraid"
-e HOST_HOSTNAME="farrosphere"
-e HOST_CONTAINERNAME="caddy"
-e 'CERT_EMAIL'='admin@allthatlab.xyz'
-e 'CF_API_TOKEN'=''
-e 'CROWDSEC_API'=''
-l net.unraid.docker.managed=dockerman
-l net.unraid.docker.icon='https://d1q6f0aelx0por.cloudfront.net/product-logos/library-caddy-logo.png'
-p '2080:80/tcp'
-p '2443:443/tcp'
-p '2443:443/udp'
-v '/mnt/user/appdata/caddy/data':'/data':'rw'
-v '/mnt/user/appdata/caddy/config':'/config':'rw'
-v '/mnt/user/appdata/caddy/config/Caddyfile':'/etc/caddy/Caddyfile':'rw'
-v '/mnt/user/dmz/crowdsec':'/var/log/crowdsec':'rw' 'caddy-allthatlab'
d. My complete Caddy config:
{
acme_dns cloudflare {env.CF_API_TOKEN}
email {env.CERT_EMAIL}
debug
crowdsec {
api_key {env.CROWDSEC_API}
api_url http://crowdsec:8080
}
servers {
trusted_proxies cloudflare
trusted_proxies static private_ranges 100.64.0.0/10
client_ip_headers Cf-Connecting-Ip X-Forwarded-For
}
admin :2019
}
(essentials) {
encode gzip
tls {
dns cloudflare {env.CF_API_TOKEN}
resolvers 1.1.1.1
}
log {
output file /var/log/crowdsec/caddy.log
}
}
(security_headers) {
header_up Strict-Transport-Security "max-age=31536000;"
header_up X-XSS-Protection "1; mode=block"
header_up X-Frame-Options "SAMEORIGIN"
header_up X-Robots-Tag "noindex, nofollow"
header_up X-Content-Type-Options "nosniff"
header_up -Server
header_up -X-Powered-By
header_up Referrer-Policy "same-origin"
}
(authelia) {
forward_auth authelia:9091 {
uri /api/authz/forward-auth
copy_headers Remote-User Remote-Groups Remote-Email Remote-Name
import security_headers
}
}
import /config/*.caddy
---
# Whoami (Auth)
whoami.allthatlab.xyz {
import essentials
import authelia
log {
output file /var/log/crowdsec/whoami.log
}
reverse_proxy whoami:80 {
import security_headers
}
}
5. Links to relevant resources:
Curl Response:
Name: All That Lab
Hostname: 565671e3cbf7
IP: 127.0.0.1
IP: ::1
IP: 172.19.0.60
RemoteAddr: 172.19.0.77:36238
GET / HTTP/1.1
Host: whoami.allthatlab.xyz
User-Agent: iCurlHTTP/1.17 libcurl/7.83.1 OpenSSL/1.1.1o zlib/1.2.11 nghttp2/1.47.0
Accept: */*
Accept-Encoding: gzip, br
Cdn-Loop: cloudflare
Cf-Connecting-Ip: 82.132.236.243
Cf-Ipcountry: GB
Cf-Ray: 8b1b85e30fed71e1-LHR
Cf-Visitor: {"scheme":"https"}
Referrer-Policy: same-origin
Remote-Email: {http.reverse_proxy.header.Remote-Email}
Remote-Groups: {http.reverse_proxy.header.Remote-Groups}
Remote-Name: {http.reverse_proxy.header.Remote-Name}
Remote-User: {http.reverse_proxy.header.Remote-User}
Strict-Transport-Security: max-age=31536000;
X-Content-Type-Options: nosniff
X-Forwarded-For: 172.71.26.33
X-Forwarded-Host: whoami.allthatlab.xyz
X-Forwarded-Proto: https
X-Frame-Options: SAMEORIGIN
X-Robots-Tag: noindex, nofollow
X-Xss-Protection: 1; mode=block