Access Labels
Put a Cloudflare Zero Trust Access login in front of a hostname with labels.
Access labels add a Cloudflare Access login in front of a hostname. It takes two steps: define a policy, then use it from a tunnel or DNS label.
services:
admin:
image: nginx:alpine
labels:
# 1. Define a policy named "team"
labelgate.access.team.policy.include.emails: "alice@example.com,bob@example.com"
# 2. Use it
labelgate.tunnel.admin.hostname: "admin.example.com"
labelgate.tunnel.admin.service: "http://admin:80"
labelgate.tunnel.admin.access: "team"Only Alice and Bob can now open admin.example.com, after logging in with Cloudflare Access.
Policy labels
Every label has the form labelgate.access.<name>.<property>. The <name> is the policy name you use in access: "<name>". It follows the name rules.
| Property | Required | Default | Example | Meaning |
|---|---|---|---|---|
policy.include.<selector> | for allow and block | - | policy.include.emails | Who the policy applies to. Any one rule is enough. |
policy.require.<selector> | no | - | policy.require.country | Everyone must also match all of these. |
policy.exclude.<selector> | no | - | policy.exclude.emails | Never applies to these. |
policy.decision | no | allow | bypass | What to do. See Decisions. |
policy.name | no | app name | Team only | Policy name shown in Cloudflare. |
app_name | no | labelgate-<name> | Admin panel | Access application name shown in Cloudflare. |
session_duration | no | 24h | 12h | How long a login lasts. Use m or h (30m, 720h); 7d is not accepted. |
Decisions
policy.decision | Meaning |
|---|---|
allow | Matching users get in after logging in. Needs an include rule. |
block | Matching users are blocked. Needs an include rule. |
bypass | Matching requests get in without logging in. |
service_auth | For machines: a service token or client certificate, no login. |
Selectors
Separate several values with commas.
| Selector | Value | Example |
|---|---|---|
emails | Email addresses | alice@example.com,bob@example.com |
emails_ending_in | Email domains | example.com |
ip_ranges | IP addresses or CIDR ranges | 203.0.113.0/24,198.51.100.7 |
country | Country codes | US,GB |
everyone | No value (use "") | "" |
service_token | Service token IDs | <token-id> |
access_groups | Access group IDs | <group-id> |
certificate | No value (use ""); any valid client certificate | "" |
login_methods | Login method (identity provider) IDs | <idp-id> |
Recipes
Everyone with a company email
labels:
labelgate.access.staff.policy.include.emails_ending_in: "example.com"
labelgate.tunnel.wiki.hostname: "wiki.example.com"
labelgate.tunnel.wiki.service: "http://wiki:80"
labelgate.tunnel.wiki.access: "staff"Office network only
labels:
labelgate.access.office.policy.include.ip_ranges: "203.0.113.0/24"
labelgate.tunnel.intranet.hostname: "intranet.example.com"
labelgate.tunnel.intranet.service: "http://intranet:80"
labelgate.tunnel.intranet.access: "office"Public, no login
labels:
labelgate.access.public.policy.decision: "bypass"
labelgate.access.public.policy.include.everyone: ""
labelgate.tunnel.docs.hostname: "docs.example.com"
labelgate.tunnel.docs.service: "http://docs:80"
labelgate.tunnel.docs.access: "public"Machines with a service token
labels:
labelgate.access.machine.policy.decision: "service_auth"
labelgate.access.machine.policy.include.service_token: "<token-id>"
labelgate.tunnel.api.hostname: "api.example.com"
labelgate.tunnel.api.service: "http://api:8080"
labelgate.tunnel.api.access: "machine"Company emails, US only, minus contractors
labels:
labelgate.access.secure.policy.include.emails_ending_in: "example.com"
labelgate.access.secure.policy.require.country: "US"
labelgate.access.secure.policy.exclude.emails: "contractor@example.com"
# use it with: labelgate.tunnel.<name>.access: "secure"One policy for several hostnames
Define the policy once. Any container on the same host can use it.
services:
policies:
image: busybox
command: sleep infinity # must keep running
labels:
labelgate.access.team.policy.include.emails_ending_in: "example.com"
app:
image: nginx:alpine
labels:
labelgate.tunnel.app.hostname: "app.example.com"
labelgate.tunnel.app.service: "http://app:80"
labelgate.tunnel.app.access: "team"Good to know
- Where a policy can live. In the same container, or in any running container on the same host. On an agent, only containers on that agent count.
- Same name twice. A policy in the container itself wins. Otherwise, if two other containers define different policies with that name, you get
access policy "name" is defined differently on several containers of this host. Rename one. - Cleanup. A policy has no
cleanuplabel. Its Access app follows the tunnel or DNS label that uses it. - Changes apply. Edit a label, e.g. remove an email, and Cloudflare is updated on the next sync.
- Existing apps are not touched. If Cloudflare already has an Access app for the hostname that Labelgate did not create, you get
conflict: existing record not owned by labelgate. See Ownership & Conflicts.