Skip to content

Commit 566489c

Browse files
authored
[ZT] update mTLS instructions for Access (#23879)
* update mTLS Access steps * fix indent * add openssl commands * add prereqs
1 parent 4616091 commit 566489c

File tree

4 files changed

+207
-80
lines changed

4 files changed

+207
-80
lines changed

src/content/docs/cloudflare-one/connections/connect-devices/user-side-certificates/manual-deployment.mdx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,7 @@ To install a Cloudflare certificate in macOS, you can use either the Keychain Ac
119119
<TabItem label="Keychain Access">
120120

121121
1. Download a Cloudflare certificate.
122-
2. Open the `.crt` file in Keychain Access. If prompted, enter your local password.
123-
3. In **Keychain**, choose the access option that suits your needs and select **Add**.
124-
4. In the list of certificates, locate the newly installed certificate. Keychain Access will mark this certificate as not trusted. Right-click the certificate and select **Get Info**.
125-
5. Select **Trust**. Under **When using this certificate**, select _Always Trust_.
122+
<Render file="keychain-access" params={{ cert: ".crt" }} />
126123

127124
The root certificate is now installed and ready to be used.
128125

src/content/docs/cloudflare-one/identity/devices/access-integrations/mutual-tls-authentication.mdx

Lines changed: 187 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ sidebar:
55
order: 3
66
---
77

8-
import { AvailableNotifications, Render } from "~/components";
8+
import { AvailableNotifications, Render, Example } from "~/components";
99

1010
:::note
11-
1211
Only available on Enterprise plans.
1312
:::
1413

@@ -18,84 +17,229 @@ With a root certificate authority (CA) in place, Access only allows requests fro
1817

1918
![mTLS handshake diagram](~/assets/images/cloudflare-one/identity/devices/mtls.png)
2019

21-
## Add mTLS authentication to your Access configuration
22-
2320
:::caution[Important]
2421

2522
The mTLS certificate is used only to verify the client certificate. It does not control the SSL certificate presented during the [server hello](https://www.cloudflare.com/learning/ssl/what-happens-in-a-tls-handshake/).
2623

27-
mTLS is checked on a per host basis. Access sets a flag for when a client certificate was presented and successfully completed mTLS authentication. However, to actually enforce mTLS, you need an Access policy in place, and Access policies are both host and path specific. If you want to enforce mTLS on a specific path, you need to make sure your Access policies are configured accordingly.
28-
2924
:::
3025

31-
To enforce mTLS authentication from [Zero Trust](https://one.dash.cloudflare.com):
26+
## Enforce mTLS authentication
27+
28+
### Prerequisites
29+
30+
- An [Access application](/cloudflare-one/applications/configure-apps/self-hosted-public-app/) for the hostname that you would like to secure with mTLS.
31+
- A CA that issues client certificates for your devices.
32+
<Render file="byo-ca-mtls-cert-requirements" product="ssl" />
3233

33-
1. Go to **Access** > **Service auth** > **Mutual TLS**.
34+
### Add mTLS to your Access application
35+
36+
1. In [Zero Trust](https://one.dash.cloudflare.com/), go to **Access** > **Service auth** > **Mutual TLS**.
3437

3538
2. Select **Add mTLS Certificate**.
3639

37-
3. Give the Root CA any name.
40+
3. Enter any name for the root CA.
3841

39-
4. Paste the content of the `ca.pem` file into the **Certificate content** field.
42+
4. In **Certificate content**, paste the contents of your root CA.
4043

41-
<Render file="byo-ca-mtls-cert-requirements" product="ssl" />
44+
If the client certificate is directly signed by the root CA, you only need to upload the root. If the client certificate is signed by an intermediate certificate, you must upload the entire CA chain (intermediate and root). For example:
45+
```txt
46+
-----BEGIN CERTIFICATE-----
47+
<intermediate.pem>
48+
-----END CERTIFICATE-----
49+
-----BEGIN CERTIFICATE-----
50+
<rootCA.pem>
51+
-----END CERTIFICATE-----
52+
```
53+
54+
Do not include any SSL/TLS server certificates; Access only uses the CA chain to verify the connection between the user's device and Cloudflare.
4255

4356
5. In **Associated hostnames**, enter the fully-qualified domain names (FQDN) that will use this certificate.
4457

4558
These FQDNs will be the hostnames used for the resources being protected in the [Access policy](/cloudflare-one/policies/access/). You must associate the Root CA with the FQDN that the application being protected uses.
4659

47-
6. Select **Save**.
60+
6. Save the policy.
4861

49-
If your zone is using an intermediate certificate in addition to the root certificate, upload the entire chain.
62+
9. Go to **Access** > **Policies**.
5063

51-
7. Next, go to **Access** > **Applications**.
64+
10. [Create an Access policy](/cloudflare-one/policies/access/policy-management/#create-a-policy) using one of the following [selectors](/cloudflare-one/policies/access/#selectors):
65+
- **Valid Certificate**: Any client certificate that can authenticate with the Root CA will be allowed to proceed.
66+
- **Common Name**: Only client certificates with a specific common name will be allowed to proceed.
5267

53-
8. Find the application you would like to enforce mTLS on and select **Configure**. The application must be included in the **Associated hostnames** list from Step 5.
68+
11. If this is for a client who does not need to log in through an IdP, set the policy **Action** to _Service Auth_.
5469

55-
9. Create a new (or amend an existing) [Access policy](/cloudflare-one/policies/access/).
70+
<Example>
71+
**Example mTLS policy**
72+
| Action | Rule type | Selector | Value |
73+
| ------ | --------- | -------- | ----------------- |
74+
| Service Auth | Include | Common Name | `John Doe` |
75+
</Example>
5676

57-
If this is for a client who does not need to log in through an IdP, set the policy **Action** to _Service Auth_.
77+
12. Save the policy, then go to **Access** > **Applications**.
5878

59-
10. Add an mTLS authentication rule using the following selectors:
79+
13. Select the application you would like to enforce mTLS on and select **Configure**. The application must be included in the **Associated hostnames** list from Step 5.
6080

61-
| Selector | Description |
62-
| --------------------- | ----------------------------------------------------------------------------------------- |
63-
| **Common Name** | Only client certificates with a specific common name will be allowed to proceed. |
64-
| **Valid Certificate** | Any client certificate that can authenticate with the Root CA will be allowed to proceed. |
81+
14. In the **Policies** tab, add your mTLS policy.
6582

66-
11. Save the policy.
83+
15. Save the application.
6784

68-
:::caution
85+
You can now authenticate to the application using a client certificate. For instructions on how to present a client certificate, refer to [Test mTLS](#test-mtls).
6986

70-
Cloudflare Gateway cannot inspect traffic to mTLS-protected domains. If a device has the WARP client turned on and passes HTTP requests through Gateway, access will be blocked unless you [bypass HTTP inspection](/cloudflare-one/policies/gateway/http-policies/#do-not-inspect) for the domain.
71-
:::
87+
## Test mTLS
7288

73-
## Test mTLS using cURL
89+
### Test using cURL
7490

7591
To test the application protected by an mTLS policy:
7692

7793
1. First, attempt to curl the site without a client certificate.
78-
This curl command example is for the site `example.com` that has an [Access policy](/cloudflare-one/policies/access/) set for `https://auth.example.com`:
94+
This curl command example is for the site `example.com` that has an [Access application and policy](#add-mtls-to-your-access-application) set for `https://auth.example.com`:
7995

8096
```sh
8197
curl -sv https://auth.example.com
8298
```
8399

84100
Without a client certificate in the request, a `403 forbidden` response displays and the site cannot be accessed.
85101

86-
2. Now, add your client certificate information to the request:
102+
2. Now, add your client certificate and key to the request:
87103

88104
```sh
89105
curl -sv https://auth.example.com --cert example.pem --key key.pem
90106
```
91107

92108
When the authentication process completes successfully, a `CF_Authorization Set-Cookie` header returns in the response.
93109

94-
## Test mTLS using Cloudflare PKI
110+
:::caution
111+
112+
Cloudflare Gateway cannot inspect traffic to mTLS-protected domains. If a device has the WARP client turned on and passes HTTP requests through Gateway, access will be blocked unless you [bypass HTTP inspection](/cloudflare-one/policies/gateway/http-policies/#do-not-inspect) for the domain.
113+
:::
114+
115+
### Test in a browser
116+
117+
To access an mTLS-protected application in a browser, the client certificate must be imported into your browser's certificate manager. Instructions vary depending on the browser. Your browser may use the operating system's root store or its own internal trust store.
118+
119+
The following example demonstrates how to add a client certificate to the macOS system keychain:
120+
121+
:::caution[Important]
122+
123+
The command adds the client certificate to the trusted store on your device. Only proceed if you are comfortable doing so and intend to keep these testing certificates safeguarded.
124+
:::
125+
126+
1. Navigate to the directory containing the client certificate and key.
127+
<Render file="keychain-access" params={{ cert: "client.pem" }} />
128+
129+
Assuming your browser uses the macOS system store, you can now connect to the mTLS application through the browser.
130+
131+
## Generate mTLS certificates
132+
133+
You can use open source private key infrastructure (PKI) tools to generate certificates to test the mTLS feature in Cloudflare Access.
134+
135+
### OpenSSL
136+
137+
This section covers how to use [OpenSSL](https://www.openssl.org/) to generate a root and intermediate certificate, and then issue client certificates that can authenticate against the CA chain.
138+
139+
#### Generate the root CA
140+
141+
1. Generate the root CA private key:
142+
143+
```sh
144+
openssl genrsa -aes256 -out rootCA.key 4096
145+
```
146+
147+
When prompted, enter a password to use with `rootCA.key`.
148+
149+
2. Create a self-signed root certificate called `rootCA.pem`:
150+
151+
```sh
152+
openssl req -x509 -new -nodes -key rootCA.key -sha256 -days 3650 -out rootCA.pem
153+
```
154+
155+
You will be prompted to enter your private key password and fill in some optional fields. For testing purposes, you can leave the optional fields blank.
156+
157+
#### Generate an intermediate certificate
158+
159+
1. Generate the intermediate CA private key:
160+
161+
```sh
162+
openssl genrsa -aes256 -out intermediate.key 4096
163+
```
164+
165+
When prompted, enter a password to use with `intermediate.key`.
166+
167+
2. Create a certificate signing request (CSR) for the intermediate certificate:
95168

96-
You can use Cloudflare's open source tools for private key infrastructure (PKI) to test the mTLS feature in Cloudflare Access. This guide details the process to generate a Root Client Authority (CA), add it to the Cloudflare dashboard, and issue client certificates that can authenticate against the root CA and reach a protected resource.
169+
```sh
170+
openssl req -new -sha256 -key intermediate.key -out intermediate.csr
171+
```
97172

98-
### 1. Install dependencies
173+
You will be prompted to enter your private key password and fill in some optional fields. For testing purposes, you can leave the optional fields blank.
174+
175+
3. Create a CA Extension file called `v3_intermediate_ca.ext`. For example,
176+
177+
```txt
178+
subjectKeyIdentifier = hash
179+
authorityKeyIdentifier = keyid:always,issuer
180+
basicConstraints = critical, CA:true
181+
keyUsage = critical, cRLSign, keyCertSign
182+
```
183+
184+
Make sure that `basicConstraints` includes the `CA:true` property. This property allows the intermediate certificate to act as a CA and sign client certificates.
185+
186+
4. Sign the intermediate certificate with the root CA:
187+
188+
```sh
189+
openssl x509 -req -in intermediate.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out intermediate.pem -days 1825 -sha256 -extfile v3_intermediate_ca.ext
190+
```
191+
192+
#### Create a CA chain file
193+
194+
1. Combine the intermediate and root certificates into a single file:
195+
196+
```sh
197+
cat intermediate.pem rootCA.pem > ca-chain.pem
198+
```
199+
200+
The intermediate certificate should be at the top of the file, followed by its signing certificate.
201+
202+
2. Upload the contents of `ca.pem` to Cloudflare Access. For instructions, refer to [Add mTLS to your Access application](#add-mtls-to-your-access-application).
203+
204+
#### Generate a client certificate
205+
206+
1. Generate a private key for the client:
207+
208+
```sh
209+
openssl genrsa -out client.key 2048
210+
```
211+
212+
2. Create a CSR for the client certificate:
213+
214+
```sh
215+
openssl req -new -key client.key -out client.csr
216+
```
217+
218+
You will be prompted to fill in some optional fields. For testing purposes, you can set **Common Name** to something like `John Doe`.
219+
220+
3. Sign the client certificate with the intermediate certificate:
221+
222+
```sh
223+
openssl x509 -req -in client.csr -CA intermediate.pem -CAkey intermediate.key -CAcreateserial -out client.pem -days 365 -sha256
224+
```
225+
226+
4. Validate the client certificate against the certificate chain:
227+
228+
```sh
229+
openssl verify -CAfile ca-chain.pem client.pem
230+
```
231+
232+
```sh output
233+
client.pem: OK
234+
```
235+
236+
You can now use the client certificate (`client.pem`) and its key (`client.key`) to [test mTLS](#test-mtls).
237+
238+
### Cloudflare PKI
239+
240+
This guide uses [Cloudflare's PKI toolkit](https://github.com/cloudflare/cfssl) to generate a root CA and client certificates from JSON files.
241+
242+
#### 1. Install dependencies
99243

100244
The process requires two packages from Cloudflare's PKI toolkit:
101245

@@ -105,9 +249,9 @@ The process requires two packages from Cloudflare's PKI toolkit:
105249
You can install these packages from the [Cloudflare SSL GitHub repository](https://github.com/cloudflare/cfssl). You will need a working installation of Go, version 1.12 or later. Alternatively, you can [download the packages](https://github.com/cloudflare/cfssl) directly.
106250
Use the instructions under Installation to install the toolkit, and ensure that you install all of the utility programs in the toolkit.
107251

108-
### 2. Generate the Root CA
252+
#### 2. Generate the root CA
109253

110-
1. Create a new directory to store the Root CA.
254+
1. Create a new directory to store the root CA.
111255

112256
2. Within that directory, create two new files:
113257

@@ -154,27 +298,27 @@ Use the instructions under Installation to install the toolkit, and ensure that
154298
}
155299
```
156300

157-
3. Now, run the following command to generate the Root CA with those files.
301+
3. Now, run the following command to generate the root CA with those files.
158302

159303
```sh
160304
cfssl gencert -initca ca-csr.json | cfssljson -bare ca
161305
```
162306

163-
4. Within the directory, check its content to confirm the output was successful.
307+
4. The command will output a root certificate (`ca.pem`) and its key (`ca-key.pem`).
164308

165309
```sh
166310
ls
167311
```
168312

169-
The output should now return the following content:
170-
171-
```sh
313+
```sh output
172314
ca-config.json ca-csr.json ca-key.pem ca.csr ca.pem
173315
```
174316

175-
### 3. Generate a client certificate
317+
5. Upload the contents of `ca.pem` to Cloudflare Access. For instructions, refer to [Add mTLS to your Access application](#add-mtls-to-your-access-application).
318+
319+
#### 3. Generate a client certificate
176320

177-
Returning to the terminal, generate a client certificate that will authenticate against the Root CA uploaded.
321+
To generate a client certificate that will authenticate against the uploaded root CA:
178322

179323
1. Create a file named `client-csr.json` and add the following JSON blob:
180324

@@ -204,31 +348,9 @@ Returning to the terminal, generate a client certificate that will authenticate
204348
cfssl gencert -ca=ca.pem -ca-key=ca-key.pem -config=ca-config.json -profile=client client-csr.json | cfssljson -bare client
205349
```
206350

207-
3. You can now test the client certificate with the following `cURL` command.
208-
209-
```sh
210-
curl -v --cert client.pem --key client-key.pem https://iot.widgetcorp.tech
211-
```
212-
213-
### Test in the browser
214-
215-
The instructions here cover usage with a computer running macOS.
216-
217-
1. In the same working directory, run the following command to add the client certificate into the macOS Keychain.
218-
219-
:::caution[Important]
220-
221-
The command adds the client certificate to the trusted store on your device. Only proceed if you are comfortable doing so and intend to keep these testing certificates safeguarded.
222-
:::
223-
224-
```sh
225-
open client.pem
226-
security import client-key.pem -k ~/Library/Keychains/login.keychain-db
227-
```
228-
229-
2. Select the certificate in the Keychain list to set the certificate to trusted. Confirm that the certificate is listed in **My Certificates**.
351+
The command will output a client certificate file (`client.pem`) and its key (`client-key.pem`). You can now use these files to [test mTLS](#test-mtls).
230352

231-
### Create a CRL
353+
#### Create a certificate revocation list
232354

233355
You can use the Cloudflare PKI toolkit to generate a certificate revocation list (CRL), as well. This list will contain client certificates that are revoked.
234356

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
params:
3+
- cert
4+
---
5+
6+
2. Open the <code>{props.cert}</code> file in Keychain Access. If prompted, enter your local password.
7+
3. In **Keychain**, choose the access option that suits your needs and select **Add**.
8+
4. In the list of certificates, locate the newly installed certificate. Keychain Access will mark this certificate as not trusted. Right-click the certificate and select **Get Info**.
9+
5. Select **Trust**. Under **When using this certificate**, select _Always Trust_.

0 commit comments

Comments
 (0)