Repository navigation
Real IP of the users behind reverse proxies and Cloudflare, and Apache log settings - #435
Merged
Merged
Conversation
… other processes With a DAEMON_COMMAND_* or a cron job, supervise.sh sent SIGQUIT to apache2-fpm-foreground, which bash ignores in its background jobs: the container was killed after the stop timeout (exit code 137 after 10 s). SIGTERM stops Apache and PHP-FPM gracefully too.
APACHE_TRUSTED_PROXIES lists the proxies in front of the container: host names (resolved every 30 seconds), IPs and CIDR ranges. APACHE_TRUSTED_CLOUDFLARE=1 trusts the ranges of Cloudflare (downloaded every day, a copy being shipped in the image), and "only" also refuses the requests that did not go through Cloudflare. mod_remoteip only trusts the X-Forwarded-For hops added by these proxies, and CF-Connecting-IP only when the previous hop is a Cloudflare address, even when the proxy replaced X-Forwarded-For: the container does not rely on the configuration of the proxy. Requests of a trusted proxy with X-Forwarded-Proto: https get HTTPS=on. APACHE_LOG_FORMAT sets the format of the access log (combined, detailed, json or a format of mod_log_config). APACHE_LOG_OUTPUT=file writes the logs in /var/log/apache2, rotated every day and at APACHE_LOG_MAX_SIZE by rotatelogs, gzipped and deleted after APACHE_LOG_RETENTION_DAYS days. The logs are now set at the server level: the default virtual host no longer sets its own. New reverse proxy guide: a configurator for Traefik, nginx, Kubernetes and Cloudflare, with the path of a request and of a forged one, the configuration of the proxy and of the application, and the logs.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Behind Traefik, nginx, a Kubernetes ingress or Cloudflare, Apache and PHP see the address of the proxy instead of the one of the users. Trusting
X-Forwarded-FororCF-Connecting-IPblindly is worse: any client chooses its IP. This PR makes the container find the real IP by itself, without relying on the configuration of the proxy.mod_remoteiponly skips the hops added by the listed proxies.CF-Connecting-IPis only used when the previous hop is a Cloudflare address, even when Traefik or ingress-nginx replacedX-Forwarded-For, so a request sent to the IP of the server cannot forge it.APACHE_TRUSTED_CLOUDFLARE=only: a 403 for the requests of the proxy that did not go through Cloudflare, with the same up-to-date list. No IP list to maintain in Traefik or in a firewall.HTTPS=onfor the requests the proxy received in HTTPS, the access log,Require ipandREMOTE_ADDRall get the client IP: the trusted proxies of Symfony or Laravel can stay empty.Logs, while at it:
APACHE_LOG_FORMAT:combined(default),detailed(+ response time and proxy),json, or any format of mod_log_config.APACHE_LOG_OUTPUT=file: files in/var/log/apache2(a directory of the server or a volume), a new file every day and atAPACHE_LOG_MAX_SIZE, gzipped, deleted afterAPACHE_LOG_RETENTION_DAYSdays. stdout stays the default.The reverse proxy guide (online once merged) builds the configuration of the proxy and of the application for Traefik, nginx or Kubernetes, with or without Cloudflare, in the compose file of the project or in a separate ingress stack, and shows how a legit and a forged request are resolved. It also explains why the trusted proxies of the frameworks are not recommended.
The PR also fixes
docker stopof the fpm variant with its built-in Apache when it runs other processes (cron,DAEMON_COMMAND_*, here the watcher of the proxies): bash ignoresSIGQUITin its background jobs, the container was killed after 10 s.Tested on PHP 8.2 to 8.5, apache and fpm slim images: new
apache-trusted-proxies.shandapache-logs.shsuites, and the existing Apache, fpm, daemon and user suites.