Skip to content

Commit 060ea5c

Browse files
committed
add openssl commands
1 parent d815b62 commit 060ea5c

File tree

1 file changed

+118
-15
lines changed

1 file changed

+118
-15
lines changed

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

Lines changed: 118 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ To enforce mTLS authentication for an application:
4848
-----END CERTIFICATE-----
4949
```
5050

51+
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.
52+
5153
5. In **Associated hostnames**, enter the fully-qualified domain names (FQDN) that will use this certificate.
5254

5355
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.
@@ -77,7 +79,7 @@ To enforce mTLS authentication for an application:
7779

7880
15. Save the application.
7981

80-
Next, [test mTLS authentication](#test-mtls) to your application.
82+
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).
8183

8284
## Test mTLS
8385

@@ -125,9 +127,114 @@ Assuming your browser uses the macOS system store, you can now connect to the mT
125127

126128
## Generate mTLS certificates
127129

130+
You can use open source private key infrastructure (PKI) tools to generate certificates to test the mTLS feature in Cloudflare Access.
131+
132+
### OpenSSL
133+
134+
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.
135+
136+
#### Generate the root CA
137+
138+
1. Generate the root CA private key:
139+
140+
```sh
141+
openssl genrsa -aes256 -out rootCA.key 4096
142+
```
143+
144+
When prompted, enter a password to use with `rootCA.key`.
145+
146+
2. Create a self-signed root certificate called `rootCA.pem`:
147+
148+
```sh
149+
openssl req -x509 -new -nodes -key rootCA.key -sha256 -days 3650 -out rootCA.pem
150+
```
151+
152+
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.
153+
154+
#### Generate an intermediate certificate
155+
156+
1. Generate the intermediate CA private key:
157+
158+
```sh
159+
openssl genrsa -aes256 -out intermediate.key 4096
160+
```
161+
162+
When prompted, enter a password to use with `intermediate.key`.
163+
164+
2. Create a certificate signing request (CSR) for the intermediate certificate:
165+
166+
```sh
167+
openssl req -new -sha256 -key intermediate.key -out intermediate.csr
168+
```
169+
170+
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.
171+
172+
3. Create a CA Extension file called `v3_intermediate_ca.ext`. For example,
173+
174+
```txt
175+
subjectKeyIdentifier = hash
176+
authorityKeyIdentifier = keyid:always,issuer
177+
basicConstraints = critical, CA:true
178+
keyUsage = critical, cRLSign, keyCertSign
179+
```
180+
181+
Make sure that `basicConstraints` includes the `CA:true` property. This property allows the intermediate certificate to act as a CA and sign client certificates.
182+
183+
4. Sign the intermediate certificate with the root CA:
184+
185+
```sh
186+
openssl x509 -req -in intermediate.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out intermediate.pem -days 1825 -sha256 -extfile v3_intermediate_ca.ext
187+
```
188+
189+
#### Create a CA chain file
190+
191+
1. Combine the intermediate and root certificates into a single file:
192+
193+
```sh
194+
cat intermediate.pem rootCA.pem > ca-chain.pem
195+
```
196+
197+
The intermediate certificate should be at the top of the file, followed by its signing certificate.
198+
199+
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).
200+
201+
#### Generate a client certificate
202+
203+
1. Generate a private key for the client:
204+
205+
```sh
206+
openssl genrsa -out client.key 2048
207+
```
208+
209+
2. Create a CSR for the client certificate:
210+
211+
```sh
212+
openssl req -new -key client.key -out client.csr
213+
```
214+
215+
You will be prompted to fill in some optional fields. For testing purposes, you can set **Common Name** to something like `John Doe`.
216+
217+
3. Sign the client certificate with the intermediate certificate:
218+
219+
```sh
220+
openssl x509 -req -in client.csr -CA intermediate.pem -CAkey intermediate.key -CAcreateserial -out client.pem -days 365 -sha256
221+
```
222+
223+
4. Validate the client certificate against the certificate chain:
224+
225+
```sh
226+
openssl verify -CAfile ca-chain.pem client.pem
227+
```
228+
229+
```sh output
230+
client.pem: OK
231+
```
232+
233+
You can now use the client certificate (`client.pem`) and its key (`client.key`) to [test mTLS](#test-mtls).
234+
128235
### Cloudflare PKI
129236

130-
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.
237+
This guide uses [Cloudflare's PKI toolkit](https://github.com/cloudflare/cfssl) to generate a root CA and client certificates from JSON files.
131238

132239
#### 1. Install dependencies
133240

@@ -139,9 +246,9 @@ The process requires two packages from Cloudflare's PKI toolkit:
139246
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.
140247
Use the instructions under Installation to install the toolkit, and ensure that you install all of the utility programs in the toolkit.
141248

142-
#### 2. Generate the Root CA
249+
#### 2. Generate the root CA
143250

144-
1. Create a new directory to store the Root CA.
251+
1. Create a new directory to store the root CA.
145252

146253
2. Within that directory, create two new files:
147254

@@ -188,27 +295,27 @@ Use the instructions under Installation to install the toolkit, and ensure that
188295
}
189296
```
190297

191-
3. Now, run the following command to generate the Root CA with those files.
298+
3. Now, run the following command to generate the root CA with those files.
192299

193300
```sh
194301
cfssl gencert -initca ca-csr.json | cfssljson -bare ca
195302
```
196303

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

199306
```sh
200307
ls
201308
```
202309

203-
The output should now return the following content:
204-
205-
```sh
310+
```sh output
206311
ca-config.json ca-csr.json ca-key.pem ca.csr ca.pem
207312
```
208313

314+
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).
315+
209316
#### 3. Generate a client certificate
210317

211-
Returning to the terminal, generate a client certificate that will authenticate against the Root CA uploaded.
318+
To generate a client certificate that will authenticate against the uploaded root CA:
212319

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

@@ -238,11 +345,7 @@ Returning to the terminal, generate a client certificate that will authenticate
238345
cfssl gencert -ca=ca.pem -ca-key=ca-key.pem -config=ca-config.json -profile=client client-csr.json | cfssljson -bare client
239346
```
240347

241-
3. You can now test the client certificate with the following `cURL` command.
242-
243-
```sh
244-
curl -v --cert client.pem --key client-key.pem https://iot.widgetcorp.tech
245-
```
348+
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).
246349

247350
#### Create a certificate revocation list
248351

0 commit comments

Comments
 (0)