Skip to content

Commit 6b442c7

Browse files
committed
Move Access up one level
1 parent f97696d commit 6b442c7

File tree

12 files changed

+769
-6
lines changed

12 files changed

+769
-6
lines changed

public/__redirects

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2387,7 +2387,7 @@
23872387
/cloudflare-one/policies/gateway/* /cloudflare-one/traffic-policies/:splat 301
23882388
/cloudflare-one/policies/browser-isolation/* /cloudflare-one/remote-browser-isolation/:splat 301
23892389
/cloudflare-one/policies/data-loss-prevention/* /cloudflare-one/data-loss-prevention/:splat 301
2390-
/cloudflare-one/policies/access/* /cloudflare-one/access-controls/policies/access/:splat 301
2390+
/cloudflare-one/policies/access/* /cloudflare-one/access-controls/policies/:splat 301
23912391
/cloudflare-one/api-terraform/* /cloudflare-one/access-controls/policies/api-terraform/:splat 301
23922392

23932393
# Learning paths
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
---
2+
pcx_content_type: concept
3+
title: Application paths
4+
sidebar:
5+
order: 5
6+
7+
---
8+
9+
Application paths define the URLs protected by an Access policy. When adding a self-hosted application to Access, you can choose to protect the entire website by entering its apex domain, or alternatively, protect specific subdomains and paths.
10+
11+
## Policy inheritance
12+
13+
Cloudflare Zero Trust allows you to create unique rules for parts of an application that share a root path. Imagine an example application is deployed at `dashboard.com/eng` that anyone on the engineering team should be able to access. However, a tool deployed at `dashboard.com/eng/exec` should only be accessed by the executive team.
14+
15+
When multiple rules are set for a common root path, the more specific rule takes precedence. For example, when setting rules for `dashboard.com/eng` and `dashboard.com/eng/exec` separately, the more specific rule for `dashboard.com/eng/exec` takes precedence, and no rule is inherited from `dashboard.com/eng`. If no separate, specific rule is set for `dashboard.com/eng/exec`, it will inherit any rules set for `dashboard.com/eng`.
16+
17+
## Wildcards
18+
19+
When you create an application for a specific subdomain or path, you can use asterisks (`*`) as wildcards. Wildcards allow you to extend the application you are creating to multiple subdomains or paths in a given apex domain.
20+
21+
### Examples
22+
23+
#### Match all subdomains of an apex domain
24+
25+
A wildcard in the **Subdomain** field only matches that specific subdomain level. It does not cover the apex domain or multiple levels of the subdomain. If you want to cover multiple subdomain levels, you can use multiple wildcards.
26+
27+
| Application | Covers | Does not cover |
28+
| --------------- | -------------------------------------------- | -------------- |
29+
| `*.example.com` | `alpha.example.com` <br/> `beta.example.com` | `example.com` <br/> `foo.bar.example.com` |
30+
31+
#### Match all paths of an apex domain
32+
33+
To protect an apex domain and all of the paths under it, leave the **Path** field empty. Alternatively, use a wildcard in the **Path** field.
34+
35+
| Application | Covers | Does not cover |
36+
| -------------------------------------- | ---------------------------------------------------------------- | ------------------- |
37+
| `example.com` <br/> or `example.com/*` | `example.com` <br/> `example.com/alpha` <br/> `example.com/beta` | `alpha.example.com` |
38+
39+
#### Match multi-level subdomains
40+
41+
Using a wildcard in the **Subdomain** field does not cover the parent subdomain nor the apex domain.
42+
43+
| Application | Covers | Does not cover |
44+
| -------------------- | ------------------------------------------------------ | --------------------------------------- |
45+
| `*.test.example.com` | `alpha.test.example.com` <br/> `beta.test.example.com` | `test.example.com` <br/> `example.com` |
46+
47+
#### Partially match subdomains
48+
49+
Using a wildcard at the beginning or end of the **Subdomain** field does not cover multiple levels of the subdomain.
50+
51+
| Application | Covers | Does not cover |
52+
| ------------------- | ------------------------------------------------ | ----------------------- |
53+
| `*test.example.com` | `test.example.com` <br/> `alphatest.example.com` | `beta.test.example.com` |
54+
55+
#### Match multi-level paths
56+
57+
Using a wildcard in the **Path** field does not cover the parent path nor the apex domain.
58+
59+
| Application | Covers | Does not cover |
60+
| --------------------- | ----------------------------------------------------- | --------------------------------------- |
61+
| `example.com/alpha/*` | `example.com/alpha/one` <br/> `example.com/alpha/two` | `example.com/alpha` <br/> `example.com` |
62+
63+
#### Partially match paths
64+
65+
Using a wildcard in the middle of the **Path** field covers multiple segments of the URL.
66+
67+
| Application | Covers |
68+
| ---------------------- | ------------------------------------------------------------------------------------ |
69+
| `example.com/foo*/bar` | `example.com/foo/bar`<br/> `example.com/food/bar` <br/> `example.com/food/stuff/bar` |
70+
71+
### Limitations
72+
73+
* At most one wildcard in between each dot in the **Subdomain**. For example, `foo*bar*baz.example.com` is not allowed.
74+
* At most one wildcard in between each slash in the **Path**. For example, `example.com/foo*bar*baz` is not allowed.
75+
76+
## Subdomain setups
77+
78+
[Subdomain setups](/dns/zone-setups/subdomain-setup/) allow you to manage a child domain separately from its parent domain. In Access application paths, your configured child domains will appear in the **Domain** dropdown menu. If you [split out a subdomain](/dns/zone-setups/subdomain-setup/setup/) which already has an Access application, you will need to re-save the Access application to associate it with the new child domain.
79+
80+
## Unsupported URLs
81+
82+
### Port numbers
83+
84+
Port numbers are not supported in Access application paths. If a request includes a port number in the URL, Access will strip the port number and redirect the request to the default HTTP/HTTPS port.
85+
86+
### Query strings
87+
88+
Query strings (such as`?foo=bar`) are not supported in Access application paths.
89+
90+
### Anchor links
91+
92+
Since anchor links are processed by the browser and not the server, Access applications do not support `#` characters in the URL. For example, requests to `dashboard.com/#settings` will redirect to `dashboard.com`.
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
---
2+
pcx_content_type: how-to
3+
title: External Evaluation rules
4+
sidebar:
5+
order: 4
6+
---
7+
8+
import { GlossaryTooltip, Example, WranglerConfig, DashButton } from "~/components";
9+
10+
With Cloudflare Access, you can create Allow or Block policies which evaluate the user based on custom criteria. This is done by adding an **External Evaluation** rule to your policy. The **External Evaluation** selector requires two values:
11+
12+
- **Evaluate URL** — the API endpoint containing your business logic.
13+
- **Keys URL** — the key that Access uses to verify that the response came from your API
14+
15+
After the user authenticates with your identity provider, Access sends the user's identity to the external API at **Evaluate URL**. The external API returns a True or False response to Access, which will then allow or deny access to the user. To protect against man-in-the-middle attacks, Access signs all requests with your Access account key and checks that responses are signed by the key at **Keys URL**.
16+
17+
You can set up External Evaluation rules using any API service, but to get started quickly we recommend using [Cloudflare Workers](/workers/).
18+
19+
## Set up external API and key with Cloudflare Workers
20+
21+
### Prerequisites
22+
23+
- [Workers account](/workers/get-started/guide/)
24+
- Install [npm](https://docs.npmjs.com/getting-started)
25+
- Install [Node.js](https://nodejs.org/en/)
26+
- Application protected by Access
27+
28+
### 1. Create a new Worker
29+
30+
1. Open a terminal and clone our example project.
31+
32+
```sh
33+
npm create cloudflare@latest my-worker -- --template https://github.com/cloudflare/workers-access-external-auth-example
34+
```
35+
36+
2. Go to the project directory.
37+
38+
```sh
39+
cd my-worker
40+
```
41+
42+
3. Create a [Workers KV namespace](/kv/concepts/kv-namespaces/) to store the key. The binding name should be `KV` if you want to run the example as written.
43+
44+
```sh
45+
npx wrangler kv namespace create "KV"
46+
```
47+
48+
The command will output the binding name and KV namespace ID, for example
49+
50+
```txt
51+
[[kv_namespaces]]
52+
binding = "KV"
53+
id = "YOUR_KV_NAMESPACE_ID"
54+
```
55+
56+
4. Open the [Wrangler configuration file](/workers/wrangler/configuration/) in an editor and insert the following:
57+
58+
- `[[kv_namespaces]]`: Add the output generated in the previous step.
59+
- `<TEAM_NAME>`: your Cloudflare Zero Trust <GlossaryTooltip term="team name">team name</GlossaryTooltip>.
60+
61+
<WranglerConfig>
62+
63+
```toml
64+
name = "my-worker"
65+
workers_dev = true
66+
compatibility_date = "2024-08-06"
67+
main = "index.js"
68+
69+
70+
[[kv_namespaces]]
71+
binding = "KV"
72+
id = "YOUR_KV_NAMESPACE_ID"
73+
74+
[vars]
75+
TEAM_DOMAIN="<TEAM_NAME>.cloudflareaccess.com"
76+
DEBUG=false
77+
```
78+
</WranglerConfig>
79+
80+
### 2. Program your business logic
81+
82+
1. Open `index.js` and modify the `externalEvaluation` function to perform logic on any identity-based data sent by Access.
83+
84+
:::note
85+
86+
- Sample code is available in our [GitHub repository](https://github.com/cloudflare/workers-access-external-auth-example).
87+
- To view a list of identity-based data fields, log in to your Access application and append `/cdn-cgi/access/get-identity` to the URL. For example, if `www.example.com` is behind Access, visit `https://www.example.com/cdn-cgi/access/get-identity`.
88+
:::
89+
90+
2. Deploy the Worker to Cloudflare's global network.
91+
92+
```sh
93+
npx wrangler deploy
94+
```
95+
96+
The Worker will be deployed to your `*.workers.dev` subdomain at `my-worker.<YOUR_SUBDOMAIN>.workers.dev`.
97+
98+
### 3. Generate a key
99+
100+
To generate an RSA private/public key pair:
101+
102+
1. Open a browser and go to `https://my-worker.<YOUR_SUBDOMAIN>.workers.dev/keys`.
103+
104+
2. (Optional) Verify that the key has been stored in the `KV` namespace:
105+
1. In the Cloudflare dashboard, go to the **Workers KV** page.
106+
<DashButton url="/?to=/:account/workers/kv/namespaces" />
107+
2. Select **View** next to `my-worker-KV`.
108+
109+
Other key formats (such as DSA) are not supported at this time.
110+
111+
### 4. Create an External Evaluation rule
112+
113+
1. In [Zero Trust](https://one.dash.cloudflare.com/), go to **Access** > **Policies**.
114+
115+
2. Edit an existing policy or select **Add a policy**.
116+
117+
3. Add the following rule to your policy:
118+
119+
| Rule Type | Selector | Evaluate URL | Keys URL |
120+
| --------- | ------------------- | ------------------------------------------------- | ------------------------------------------------------ |
121+
| Include | External Evaluation | `https://my-worker.<YOUR_SUBDOMAIN>.workers.dev/` | `https://my-worker.<YOUR_SUBDOMAIN>.workers.dev/keys/` |
122+
123+
4. Save the policy.
124+
125+
5. Go to **Access** > **Applications** and edit the application for which you want to apply the External Evaluation rule.
126+
127+
6. In the **Policies** tab, add the policy that contains the External Evaluation rule.
128+
129+
7. Select **Save application**.
130+
131+
When a user logs in to your application, Access will now check their email, device, location, and other identity-based data against your business logic.
132+
133+
### Troubleshooting the Worker
134+
135+
To debug your External Evaluation rule:
136+
137+
1. Go to your Worker directory.
138+
139+
```sh
140+
cd my-worker
141+
```
142+
143+
2. Open the [Wrangler configuration file](/workers/wrangler/configuration/) in an editor and set the `debug` variable to `TRUE`.
144+
145+
3. Deploy your changes.
146+
147+
```sh
148+
npx wrangler deploy
149+
```
150+
151+
4. Next, start a session to output realtime logs from your Worker.
152+
153+
```sh
154+
wrangler tail -f pretty
155+
```
156+
157+
5. Log in to your Access application.
158+
159+
The session logs should show an incoming and outgoing JWT. The incoming JWT was sent by Access to the Worker API, while the outgoing JWT was sent by the Worker back to Access.
160+
161+
6. To decode the contents of a JWT, you can copy the token into [jwt.io](https://jwt.io/).
162+
163+
The incoming JWT should contain the user's identity data. The outgoing JWT should look similar to:
164+
165+
```js
166+
{
167+
"success": true,
168+
"iat": 1655409315,
169+
"exp": 1655409375,
170+
"nonce": "9J2E9Xg6wYj8tlnA5MV4Zgp6t8rzmS0Q"
171+
}
172+
```
173+
174+
Access checks the outgoing JWT for all of the following criteria:
175+
176+
- Token was signed by **Keys URL**.
177+
- Expiration date has not elapsed.
178+
- API returns `"success": true`.
179+
- `nonce` is unchanged from the incoming JWT. The `nonce` value is unique per request.
180+
181+
If any condition fails, the External Evaluation rule evaluates to false.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
pcx_content_type: concept
3+
title: Rule groups
4+
sidebar:
5+
order: 2
6+
---
7+
8+
import { Render } from "~/components";
9+
10+
A rule group is a collection of Access rules that can be configured once and then quickly applied across many Access policies. Rule groups use the same [rule types](/cloudflare-one/access-controls/policies/#rule-types) and [selectors](/cloudflare-one/access-controls/policies/#selectors) shown in the Access policy builder.
11+
12+
:::note
13+
Rule groups are distinct from groups in your identity provider, like Okta groups. Rule groups can contain a mix of individual users, groups from identity providers, and service authentication options like service tokens.
14+
:::
15+
16+
## Create a rule group
17+
18+
<Render file="access/rule-group" product="cloudflare-one" />
19+
20+
## Use cases
21+
22+
### IP-based rules
23+
24+
We recommend using rule groups to define any IP address-based rules you configure in policies. Keeping IP addresses in one place allows you to modify or remove addresses once, rather than in each policy, and reduces the potential for mistakes.
25+
26+
:::note
27+
If adding more than one IP address or range to a rule group, use an Include rule for the IPs. If you do not use an Include rule, the policy will require traffic to originate from all ranges.
28+
:::
29+
30+
### Country requirements
31+
32+
You can create a rule group that consists of countries to allow or block. Access will treat the countries in the Include rule with an OR logical operator. When building policies for an Access application, you can assign this rule group to a Require policy to require at least one of the countries inside of the group. For an example policy, refer to [Require rules with OR operators](/cloudflare-one/access-controls/policies/#require-rules-with-or-operators).

0 commit comments

Comments
 (0)