I use Cloudflare Access as an authenticated reverse proxy for my Home Assistant instance, and to simplify my login flow I’ve whitelisted Cloudflare’s IP ranges using the trusted_networks authorization provider as shown below:
In order to make things simpler for other users, and to make this setup more resilient to changes on Cloudflare’s side, I’d like to add a boolean cloudflare_access configuration parameter to trusted_networks that would transparently fetch the latest IP list from Cloudflare and add them to the whitelist.
I had originally considered creating a separate authorization provider to handle this, but as it would be a near duplicate of trusted_networks, it seems like a better solution would be to simply add this functionality to the existing module.
@balloob, I’d be interested to hear your thoughts on this.
It’s taken me an age to figure out my issues with x-forwarded-by and Cloudflare … it seems to me that an opt-in of trusted networks providers would be extremely useful.
For me, this post was extremely useful.
If anyone comes here for answers … I have a cloudflare -> nginx proxy -> HA on TrueNas …
Adding the CloudFlare networks corrected the entire x-forwarded-by … otherwise I just received “Login attempt or request with invalid authentication from 162.158.165.218 (162.158.165.218). See the log for details.” Which was of no use.
FWIW, CloudFlare included their Tunnels feature in the free tier: https://blog.cloudflare.com/tunnel-for-everyone/ So you can set up a tunnel to CloudFlare and not allow any inboud traffic to your server.