mTLS with Application Security
-
Go to your Cloudflare dashboard and select your account and domain.
-
Go to SSL/TLS > Client Certificates tab and select Edit to add the Hosts (hostnames) you want to enable mTLS for.
Example host:
mtls-test.example.com
-
Select Create Certificate and fill in the required fields. You can choose one of the following options:
- Generate a private key (usually referred to as Private Certificate) and Certificate Signing Request (CSR) with Cloudflare (which includes the Public Certificate).
- Use your own private key and CSR which allows you to also label client certificates.
To generate and use your own CSR, you can run a command like the following:
Or use a script like this one from GitHub ↗.
Do not forget to copy the values shown when creating the certificate as they become unavailable after creation.
In order for a client to utilize the Client Certificate you created, it must be on the devices that you want to use them on. You will want to place them in the same directory as your process / script that targets your APIs / hostnames.
We generally recommended using one Client Certificate per device. Configuring your system to actually use the Public and Private Certificates is especially important.
An example is to add both certificates to the Keychain ↗ on a MacBook laptop.
Another example is to generate a PKCS12 (P12) certificate ↗ file and then add it to your browser ↗:
Use the values from the previous step.
Example using cURL command:
Use the values from the previous step.
mTLS is verified and checked in the Cloudflare WAF phase. This is done by creating WAF Custom Rules using the dynamic fields.
All Client Certificate details can be found in the cf.tls_*
dynamic fields in the Cloudflare Ruleset Engine.
Example WAF Custom Rule with action block:
With the Public and Private Certificates in the same directory, with this cURL command, we will gain access:
Without the certificates, the terminal will display the following: