-
-
Couldn't load subscription status.
- Fork 68
Access Policy Best Practices.md
DockFlare provides powerful tools to manage Cloudflare Access policies, but following best practices ensures your services remain secure and manageable. This guide covers key strategies for a robust Zero Trust setup.
The single most important best practice for any Cloudflare Access setup is to create a "catch-all" or wildcard policy. This acts as a safety net, ensuring that no service can be accidentally exposed to the public.
Why it's essential: Without a wildcard policy, if you create a new DNS record (manually or via DockFlare) but forget to assign an Access Policy, that endpoint will be publicly accessible. A wildcard policy ensures that by default, everything is denied access unless you explicitly allow it.
How to create a *.yourdomain.com policy:
- Navigate to the Cloudflare Zero Trust Dashboard.
- Go to Access -> Applications and click Add an application.
- Choose Self-hosted.
- In the "Application Domain" field, enter your wildcard domain, for example:
*.example.com. - Give the policy a name, like "Default Deny" or "My Personal Access".
- Create a policy rule. A good starting point is an Allow rule for your personal email address.
- Crucially, Cloudflare automatically adds a "Deny" rule at the end for everyone else. This is the safety net.
- Save the application.
Now, any subdomain like random-app.example.com will automatically be protected and require a login.
To grant access to users, you need to connect Cloudflare to an Identity Provider (IdP). This can be a social provider like Google or GitHub, or a corporate one like Microsoft Entra ID.
How to add an IdP (high-level):
- In the Cloudflare Zero Trust Dashboard, go to Settings -> Authentication.
- Under the "Login methods" card, click Add new.
- Select your desired provider (e.g., Google, GitHub, SAML, OIDC).
- The dashboard will provide step-by-step instructions. This usually involves:
- Going to the developer portal of your chosen provider (e.g., Google Cloud Console, GitHub Developer Settings).
- Creating a new OAuth application.
- Copying the Client ID and Client Secret from the provider into Cloudflare.
- Copying the callback URL from Cloudflare into the provider's application settings.
- Save the configuration in both Cloudflare and the provider.
For detailed, official guides, please refer to the Cloudflare Zero Trust documentation.
DockFlare is designed to work seamlessly with these best practices, giving you both declarative security and interactive flexibility.
You can instruct DockFlare to rely on your wildcard "safety net" for any specific rule.
-
Label: Use
dockflare.access.policy=default_tld. -
Behavior: When this label is used, DockFlare will not create a specific Access Application for that hostname. It assumes your wildcard policy (
*.yourdomain.com) will cover it. This is perfect for internal tools that you only want accessible to yourself.
You can define the entire security posture of a service directly in your docker-compose.yml.
-
bypass: Creates a public application, explicitly overriding the wildcard deny policy. Use this for services you truly want open to the public. -
authenticate: Creates a specific application requiring a login. This is useful if you want different access rules for a specific app than your general wildcard policy provides. -
custom_rules: For advanced scenarios, you can define precise JSON-based rules on a label.
While labels are great for defining the initial state, the Web UI is perfect for managing exceptions and daily operations.
-
Quick Policy Changes: Instantly change a service's policy from
authenticatetobypassfor a temporary test without editing any files. - Persistent Overrides: Changes made in the UI are saved and take precedence over labels, so your interactive changes are not lost on a container restart. The "UI Override" badge makes it clear which rules are in this state.
-
Revert to Code: The "Revert to Labels" button gives you a simple way to return to your declarative, code-based configuration, ensuring your
docker-compose.ymlremains the source of truth when you want it to be.
By combining a strong, default-deny wildcard policy in Cloudflare with DockFlare's flexible label and UI-based controls, you can build a secure, manageable, and easily understood Zero Trust environment for all your self-hosted services.