Score:0

Use Apache remote IP, but require proxy IP to be in range

in flag

I put my locally hosted sites behind Cloudflare for an added layer of performance.

To restore the original connecting IP, I use mod_remoteip, set up with all of Cloudflare's IP ranges.

I also want to set up a site purely for access through Cloudflare Access, restricting access to anyone attempting to connect bypassing Cloudflare Access.

I've read online that you can do this with rules such as Require ip xx.xx.xx.xx/24 (etc), but these only work in my situation if I am checking against the original proxy IP, but this has already been overwritten by mod_remoteip.

Is there any way to enforce the original proxy IP address or require that the request has had the IP rewritten, or anything of the sort that would do what I need?

Score:0
kr flag
Bob

Simply set up some form of IP-based access control outside of Apache, in a firewall or security group or similar. Allow only the CloudFlare IP-ranges https://www.cloudflare.com/ips/ to access your web server ports and you won’t have detect any requests that by-bass cloud flare in Apache.

More complex Apache only :

Ensure that only requests from CloudFlare are parsed by mod_remoteip :

mod_remoteip offers the RemoteIPTrustedProxyList where you can easily load the text version of the list of CloudFlare IP’s

Once you have ensured that mod__remoteip only activates for CloudFlare IP’s you can maybe use the following tidbit hidden in the documentation :

The underlying client IP of the connection is available in the %{c}a format string.

And then potentially base an access control on the presence of that format string. Untested:

<If "! %{c}a}”>

    Require all denied
</If>
David Wheatley avatar
in flag
Thanks for your reply! I tried out your second solution, as it seemed it'd be easier to implement. I added to one of my `<VirtualHost>` entries, but it complained that `Variable 'c' does not exist.`. Any ideas why this might be?
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.