We are using Cloudflare Access to control who has access to our staging environment. We use a simple Google Auth to identify users on our team.
The policy defined is like this for URL *.mydomain.com
:
@myteam.com
The issue is that on the URL in question we're using a wildcard because we have various apps running like:
dashboard.mydomain.com
client.mydomain.com
And that causes a problem when say one app is communicating with the other via a REST API. The requests made from client.mydomain.com
to dashboard.mydomain.com/api
are being held up by Cloudflare, ie. redirecting to the auth page.
I've tried add another policy for dashboard.mydomain.com/api
and allow EVERYONE (just to try out) and it didn't work:
Is my idea of how to set this up correct?
Your configuration looks alright, I believe what is probably happening is the authentication (cookie) isn't being passed to your second subdomain during the API request. This can usually be traced back to a CORS issue.
https://developers.cloudflare.com/cloudflare-one/policies/zero-trust/cors/
Specifically, your API subdomain may not have the Access-Control-Allow-Credentials
properly set to allow sending cookies. Before enabling, you'll want to ensure you'll also want to ensure the other CORS headers are properly setup to restrict which sites can allow requests (reduce risk of XSS attack now that you are allowing authenticated requests).