Identity Selectors for Gateway Policies, Groups, and SAML OIDC
How Cloudflare Gateway matches users and IdP groups in DNS, HTTP, network, device, and DLP policies—and which selector to use per identity provider.
This page summarises Cloudflare Zero Trust documentation on identity-based selectors: the identity.* fields you use in Gateway policy expressions to allow, block, or scope traffic and device settings by user, group, or IdP attributes. The same identity shape also appears in device profiles, device IP assignment, DLP policies, and Workers Gateway context.
Identity selectors: what they match in Gateway policies
Section titled “Identity selectors: what they match in Gateway policies”Identity selectors let Gateway policies match attributes from your configured identity provider (IdP)—email, display name, group membership, SAML assertion values, and (in limited cases) OIDC claims—rather than only IP addresses or hostnames.
You can configure access on a per-user or group basis by adding identity-based conditions to your policies. These selectors match against user attributes from your configured identity provider.
— Cloudflare, Common policies
For DNS, HTTP, network, egress, and resolver policies, the Users category exposes the same identity fields; see for example DNS policies — Users, HTTP policies — Users, Network policies — Users, and Egress policies — Users. Evaluation timing for DNS selectors (before, during, or after resolution) is described in DNS policies — Selectors; identity selectors on DNS run before DNS resolution.
Prerequisites: IdP connection and device enrollment
Section titled “Prerequisites: IdP connection and device enrollment”Before identity selectors work in traffic policies, Cloudflare must know who the user is.
Cloudflare Gateway can integrate with your organization’s identity providers (IdPs). Before building a Gateway policy for IdP users or groups, be sure to add the IdP as an authentication method.
— Cloudflare, Identity-based policies
For device profiles and device IP profiles, identity-based selectors apply only when the device was enrolled by logging in through an IdP:
You can configure device profiles to match against the following selectors, or criteria. Identity-based selectors are only available if the user enrolled the device by logging in to an identity provider (IdP).
— Cloudflare, Device profiles — Selectors
Policy design guidance recommends picking one IdP as the source of truth for email and groups, connecting it to Cloudflare, and checking the user registry so group values match what you put in policies.
User email, name, and group selectors (API examples)
Section titled “User email, name, and group selectors (API examples)”The dedicated reference is Identity-based policies. Typical UI names and API expression fragments:
| UI name | API example (from docs) | Typical use |
|---|---|---|
| User Email | identity.email == "user-name@company.com" |
Per-user allow/block |
| User Name | identity.name == "user-name" |
Match IdP username or display name |
| User Group Names | identity.groups.name == "\"finance\"" |
Team- or role-based rules |
| User Group Email | identity.groups.email == "contractors@company.com" |
IdPs that expose group by mailing list |
| User Group IDs | identity.groups.id == "12jf495bhjd7893ml09o" |
Stable group Object IDs (e.g. Entra) |
In list-style policies (DNS, HTTP, network, egress), group matching often uses any() over the groups array, for example any(identity.groups[*].name in {"Engineering"}) as shown in Gateway policy expressions.
SAML Attributes selector: match assertion name–value pairs
Section titled “SAML Attributes selector: match assertion name–value pairs”For SAML IdPs, use a string that encodes attribute name and value:
Specify a value from the SAML Attribute Assertion.
— Cloudflare, Identity-based policies — SAML Attributes
API example from the same page: identity.saml_attributes == "\"group=finance\"". DNS policies document indexed access, e.g. any(identity.saml_attributes["http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name"] in {"Test User"}) in DNS policies — Users. Many Access policies depend on the correct email attribute name in SAML; Generic SAML 2.0 notes that providers may call it Email, e-mail, or emailAddress, which you should confirm from a SAML test assertion.
OIDC Claims selector: Generic OIDC only
Section titled “OIDC Claims selector: Generic OIDC only”Custom OIDC claims work only with the Generic OIDC IdP integration:
This selector is only available for the Generic OIDC identity provider integration. Named OIDC providers such as Okta and Microsoft Entra ID do not support custom OIDC claims in Gateway policies — use the User Group Names or User Group IDs selectors for those providers instead.
— Cloudflare, Identity-based policies — OIDC Claims
Example API value: any(identity.oidc_claims[*] == "\"department=engineering\"".
Which selector to use for your IdP
Section titled “Which selector to use for your IdP”Because IdPs expose groups differently, Cloudflare documents per-provider mappings on Identity-based policies:
| IdP | Recommended selector | Example value |
|---|---|---|
| Microsoft Entra ID | User Group IDs | Object Id, e.g. 61503835-b6fe-4630-af88-de551dd59a2 |
| Microsoft Entra ID (SCIM sync) | User Group Names | SCIM-synchronised group name |
| Okta (OIDC) | User Group Names | e.g. Marketing |
| Okta (SAML) | SAML Attributes | Attribute name groups, value e.g. Marketing |
| Google, GitHub | User Group Names | e.g. Marketing |
| Generic SAML | SAML Attributes | e.g. attribute department, value Marketing |
| Generic OIDC | OIDC Claims | e.g. claim department, value Engineering |
For SaaS OIDC apps, Generic OIDC application describes a Group filter regex to limit which IdP groups are passed to the application (separate from Gateway policy matching, but part of the same identity pipeline).
Combine identity selectors with host and DNS conditions
Section titled “Combine identity selectors with host and DNS conditions”Policies usually mix identity with traffic criteria using and, as in Gateway policy expressions:
http.request.host == "internal.example.com" and identity.email matches ".*@company.com"Another documented pattern is group-based allow: any(identity.groups[*].name in {"Engineering"}). DLP shows a full table-style rule: block uploads/downloads for User Group Names Contractors when content matches a financial DLP profile and file-sharing categories—see Common policies — Block uploads/downloads for specific users.
Device profiles add non-identity selectors (OS, managed network, service token) on the same page as identity fields; see Device profiles — Selectors. Assign device IPs uses the same identity selectors to pin subnets to users or groups.
Gateway identity in Workers (context.identity())
Section titled “Gateway identity in Workers (context.identity())”When a Worker integrates with Gateway, call await context.identity() only when the script needs the Gateway session identity. It returns Promise<GatewayIdentity | null>: an object when the user is identified, null when not, or an error if Gateway cannot retrieve identity.
Fields documented on Available context — Identity:
| Field | Type | Role |
|---|---|---|
email |
optional string | User email |
name |
optional string | Display name |
groups |
optional readonly array | id, email, name per group |
samlAttributes |
optional readonly string[] | SAML-related values |
oidcClaims |
optional readonly string[] | OIDC claim strings (list, not a decoded token) |
Use Gateway-provided identity for user-aware logic. Client-supplied identity headers are not an authoritative substitute.
— Cloudflare, Available context — Identity
Check !identity explicitly if anonymous traffic should be allowed or denied. Cloudflare Access notes that the identity object should match the production Access identity shape for Workers using Access.
DEX rules and other identity-scoped products
Section titled “DEX rules and other identity-scoped products”DEX rules use parallel selector names (user email, group emails, group IDs, group names, OS, managed network, SAML attributes, colos) to define which fleet segment a synthetic test affects—same identity concepts, different product surface.
Outbound email DLP uses sender/recipient selectors rather than identity.* Gateway fields; see Outbound DLP — Selectors.
Common mistakes when writing identity policies
Section titled “Common mistakes when writing identity policies”- Using Access rule group names in DNS, HTTP, or network policies instead of IdP group names or IDs.
- OIDC custom claims on Okta or Entra where only Generic OIDC supports the OIDC Claims selector; use group name or ID selectors instead.
- Expecting identity on devices without IdP-based enrollment (device profiles and device IPs).
- Wrong SAML attribute name for email or groups—preview the assertion as described in Generic SAML 2.0.
- Mismatch between SCIM-synced names and policy values—verify the user registry per Policy design — Identity.
For domains or hostnames with non-Latin characters, policy fields may require a list entry (stored as Punycode) rather than a literal in the selector.
How to check this on your site
Section titled “How to check this on your site”-
In Cloudflare One, confirm your IdP is added as an authentication method and that test users appear in the user registry with the expected groups, following Policy design — Identity.
-
Create a narrow test policy (for example DNS or HTTP) with a single identity selector such as
identity.emailorany(identity.groups[*].name in {"YourGroup"})using examples from Identity-based policies and Gateway policy expressions. -
From a client authenticated as that user (WARP with IdP login where required), trigger traffic that should match the policy and confirm the expected action in Gateway logs for DNS or HTTP policies.
-
If using Workers, log the result of
await context.identity()per Available context and confirm it is non-null for identified users andnullfor anonymous sessions when expected. -
You can check automatically in Answerwell (our tool): https://answerwell.org/workspace
Report an error or ask a question
Section titled “Report an error or ask a question”If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact sentence you are asking about, and we will correct or clarify it.