# Configuring Mutual TLS (mTLS) | Cycle.io

Canonical URL: https://cycle.io/learn/configuring-mutual-tls

## Configuring Mutual TLS (mTLS).

Mutual TLS (mTLS) is TLS where both sides present a certificate. Ordinary one-way TLS only proves the server's identity, and the client stays anonymous until it sends a password or token; with mTLS, the server also asks the client for a certificate, checks it against a CA it trusts and rejects the connection before a request reaches the application.

That makes mTLS a fit for traffic between machines: internal APIs, service-to-service calls, partner webhooks and admin endpoints. The client's identity is a private key it never sends, not an API key that can leak into a log. This page builds a private CA with OpenSSL, issues server and client certificates, configures Nginx to require them, tests the result with curl and covers rotation and revocation.

### What is mTLS?

Mutual TLS (mTLS) is a form of TLS in which the client and the server each present an X.509 certificate during the handshake, and each verifies the other's certificate against a certificate authority it trusts. The connection is encrypted as in ordinary TLS, and both ends know which service is on the other side before any application data is sent.

mTLS uses the standard TLS protocol, with client certificate authentication switched on: the server sends a `CertificateRequest`, and the client answers with its certificate and a signature made with its private key. TLS 1.3 is now specified in [RFC 9846](https://www.rfc-editor.org/rfc/rfc9846.html) (July 2026), which replaced RFC 8446. The message-level detail is in the "How mTLS works" section below.

#### TLS vs mTLS

The HTTPS in a browser is one-way TLS: the site proves who it is, usually with a public certificate such as one [from Let's Encrypt](https://cycle.io/learn/configuring-lets-encrypt), and you log in afterwards. mTLS moves the client's proof into the handshake. The encryption is the same in both; see [how encryption powers the modern web](https://cycle.io/learn/how-encryption-powers-the-modern-web) for the background.

|     | One-way TLS | Mutual TLS |
| --- | --- | --- |
| Server presents a certificate | Yes | Yes |
| Client presents a certificate | No  | Yes, when the server requests one |
| What the server proves | It holds the key for a certificate naming the host the client asked for | The same |
| What the client proves | Nothing at the TLS layer | It holds the key for a certificate issued by a CA the server trusts |
| Who verifies | The client checks the server | Each side checks the other against a trusted CA |
| Client identity | Passwords, tokens, API keys | The certificate subject, passed to the application |
| Typical use | Public websites and APIs with unknown clients | Machine-to-machine traffic between known clients and servers |

#### Where mTLS is used

-   **Service-to-service traffic.** In a zero trust network, being inside the network grants nothing, so each call carries a workload identity the receiver checks. mTLS adds that check on top of [network segmentation](https://cycle.io/learn/network-segmentation-basics).
-   **Partner and B2B APIs.** Each partner gets its own client certificate, so the API can identify and cut off one partner without rotating a shared secret.
-   **Service meshes.** Istio and Linkerd, common in [Kubernetes](https://cycle.io/learn/common-orchestrator-kubernetes) clusters, run a proxy next to each workload (Istio's ambient mode uses one shared proxy per node instead), give each workload a certificate automatically and use mTLS between proxies. As of November 2026, Linkerd enables mTLS by default for all TCP traffic between meshed pods and rotates proxy certificates every 24 hours. It still accepts plaintext from pods outside the mesh unless a policy blocks it. Istio sidecars use mTLS automatically when calling other workloads, but servers start in `PERMISSIVE` mode and also accept plaintext. A `PeerAuthentication` policy in `STRICT` mode makes mTLS required.
-   **IoT devices.** Sensors and gateways can't run an interactive login, so each device gets a certificate at manufacture or enrollment and presents it to the backend.

#### What mTLS doesn't do

-   **Authorization.** A valid certificate tells the server which client is connecting. Which paths and actions that client may use is still decided by the application or the proxy in front of it; the per-client rules later on this page show one way to do it in Nginx.
-   **Make a stolen key useless.** Whoever holds a client's private key is that client until the certificate expires or is revoked.
-   **Manage certificates.** The operational cost of mTLS is the certificate lifecycle: issuing a certificate for every client and server, distributing the CA bundle, renewing before expiry, revoking and eventually replacing the CA.

### mTLS on Cycle

Hand-built mTLS works for two services. It gets more expensive with every service you add, because each one needs a certificate, a key, the CA bundle, a renewal before expiry and a way to be revoked.

If that's not something you want to manage yourself, Cycle automates most of it. [Cycle's load balancer](https://cycle.io/docs/platform/load-balancer-service) supports mTLS, so client certificates are checked before traffic reaches your services.

If you manage your own servers, the rest of this page walks through configuring mutual TLS by hand.

### How mTLS works

The handshake is the same as one-way TLS with one extra exchange. The server sends a CertificateRequest that lists the CA names it accepts. The client answers with its certificate and a CertificateVerify message signed with its private key, which proves it holds the key and isn't replaying a copied certificate. The signature uses [asymmetric cryptography](https://cycle.io/learn/symmetric-vs-asymmetric-encryption), so the client proves who it is without sending a secret.

Server and client certificates differ in their extensions, and OpenSSL enforces them:

| Extension | Server certificate | Client certificate |
| --- | --- | --- |
| `extendedKeyUsage` | `serverAuth` | `clientAuth` |
| `subjectAltName` | Every DNS name clients connect to. Clients check this, not the CN. | A stable name for the client. Optional, but useful in logs and allow lists. |

A certificate with only `serverAuth` is rejected when a client presents it, even if your CA signed it.

### Before you start

The examples use three machines:

| Host | Address | Role |
| --- | --- | --- |
| `admin` | your workstation | Holds the CA key and issues certificates |
| `api-1` | `10.0.0.10` | Nginx terminates mTLS for `api.internal.example.com`, the app listens on `127.0.0.1:8080` |
| `worker-1` | `10.0.0.21` | A client service that calls the API |

`api.internal.example.com` resolves to `10.0.0.10`, and all keys are ECDSA P-256. The servers run Ubuntu 24.04 with Nginx 1.24 and OpenSSL 3.0.

RHEL-family hosts use `sudo dnf install nginx`, then `sudo systemctl enable --now nginx`, with the same `/etc/nginx/conf.d/` paths. SELinux also blocks Nginx from connecting to the app on `127.0.0.1:8080` until you run `sudo setsebool -P httpd_can_network_connect 1`.

### Step 1: Create a private CA

Your servers should trust only the client certificates you issue, so start with a private CA. On `admin`:

```bash
mkdir -p ~/pki && cd ~/pki
openssl req -x509 -new -newkey ec -pkeyopt ec_paramgen_curve:P-256 -nodes \
  -keyout ca.key -out ca.crt -days 1825 \
  -subj "/O=Example/CN=Example Internal CA" \
  -addext "basicConstraints=critical,CA:TRUE" \
  -addext "keyUsage=critical,keyCertSign,cRLSign"
chmod 600 ca.key
```

`ca.crt` goes to every server and client. `ca.key` never leaves `admin`. Anyone who holds it can mint a client certificate your servers will accept.

### Step 2: Issue the server certificate

Create `server.ext`:

```
basicConstraints = critical, CA:FALSE
keyUsage = critical, digitalSignature
extendedKeyUsage = serverAuth
subjectAltName = DNS:api.internal.example.com
```

Generate a key and CSR, sign it and check the result:

```bash
openssl req -new -newkey ec -pkeyopt ec_paramgen_curve:P-256 -nodes \
  -keyout api.key -out api.csr -subj "/O=Example/CN=api.internal.example.com"
openssl x509 -req -in api.csr -CA ca.crt -CAkey ca.key -CAcreateserial \
  -days 90 -sha256 -extfile server.ext -out api.crt
openssl verify -CAfile ca.crt -purpose sslserver api.crt
```

The last command prints `api.crt: OK`. `openssl x509 -req` ignores extensions in the CSR, so `-extfile` is what puts the SAN and key usage into the certificate.

### Step 3: Issue a client certificate

Create `worker-1.ext`:

```
basicConstraints = critical, CA:FALSE
keyUsage = critical, digitalSignature
extendedKeyUsage = clientAuth
subjectAltName = DNS:worker-1.internal.example.com
```

Then issue the certificate the same way:

```bash
openssl req -new -newkey ec -pkeyopt ec_paramgen_curve:P-256 -nodes \
  -keyout worker-1.key -out worker-1.csr -subj "/O=Example/CN=worker-1"
openssl x509 -req -in worker-1.csr -CA ca.crt -CAkey ca.key -CAcreateserial \
  -days 90 -sha256 -extfile worker-1.ext -out worker-1.crt
openssl verify -CAfile ca.crt -purpose sslclient worker-1.crt
openssl verify -CAfile ca.crt -purpose sslclient api.crt
```

`worker-1.crt` passes. The server certificate fails with `unsuitable certificate purpose`, which is the `extendedKeyUsage` check at work. Issue one certificate per client service, not one shared by all of them, so you can revoke a single client.

### Step 4: Require client certificates in Nginx

Copy `ca.crt`, `api.crt` and `api.key` to `api-1`, then install Nginx and the files:

```bash
sudo apt install nginx
sudo mkdir -p /etc/nginx/mtls
sudo install -m 644 ca.crt api.crt /etc/nginx/mtls/
sudo install -m 600 api.key /etc/nginx/mtls/
```

Create `/etc/nginx/conf.d/api-mtls.conf`:

```
server {
    listen 443 ssl;
    server_name api.internal.example.com;

    ssl_certificate        /etc/nginx/mtls/api.crt;
    ssl_certificate_key    /etc/nginx/mtls/api.key;
    ssl_protocols          TLSv1.2 TLSv1.3;

    ssl_client_certificate /etc/nginx/mtls/ca.crt;
    ssl_verify_client      on;

    location / {
        proxy_pass http://127.0.0.1:8080;
        proxy_set_header Host             $host;
        proxy_set_header X-Client-Subject $ssl_client_s_dn;
        proxy_set_header X-Client-Serial  $ssl_client_serial;
    }
}
```

-   `ssl_client_certificate` is the CA bundle used to verify clients. Nginx also sends these CA names in the CertificateRequest.
-   `ssl_verify_client on` rejects requests without a valid client certificate.
-   `$ssl_client_s_dn` is the verified subject in RFC 2253 order, such as `CN=worker-1,O=Example`. `proxy_set_header` replaces any header of the same name the client sent, so the app can trust it.

The default verification depth of 1 allows one intermediate CA between a client certificate and your root. A chain with two intermediates fails with `(20:unable to get local issuer certificate)` until you set `ssl_verify_depth 2`.

The app reads the identity from the header. A minimal Python backend:

```python
from http.server import BaseHTTPRequestHandler, HTTPServer

class Handler(BaseHTTPRequestHandler):
    def do_GET(self):
        subject = self.headers.get("X-Client-Subject", "")
        body = f"hello {subject}\n".encode()
        self.send_response(200)
        self.send_header("Content-Type", "text/plain")
        self.send_header("Content-Length", str(len(body)))
        self.end_headers()
        self.wfile.write(body)

HTTPServer(("127.0.0.1", 8080), Handler).serve_forever()
```

It binds to `127.0.0.1` on purpose. If the app were reachable directly, anyone could send `X-Client-Subject` themselves. Start it with `python3 app.py`, then check and reload Nginx:

```bash
sudo nginx -t
sudo systemctl reload nginx
```

### Step 5: Test with curl

Copy `ca.crt`, `worker-1.crt` and `worker-1.key` to `worker-1`. With the certificate and key:

```bash
curl --cacert ca.crt --cert worker-1.crt --key worker-1.key https://api.internal.example.com/
```

The response is `hello CN=worker-1,O=Example`. `--cacert` makes curl verify the server against your CA, and `--cert` and `--key` present the client side.

Without a certificate:

```bash
curl --cacert ca.crt https://api.internal.example.com/
```

Nginx returns an HTML page titled `400 No required SSL certificate was sent`. The TLS handshake completes and the rejection arrives as an HTTP response, so check the status code, not only curl's exit code.

With a certificate from a different CA, even one with the same subject:

```bash
openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:P-256 -nodes \
  -keyout rogue.key -out rogue.crt -days 1 -subj "/O=Example/CN=worker-1"
curl --cacert ca.crt --cert rogue.crt --key rogue.key https://api.internal.example.com/
```

The answer is `400 The SSL certificate error`. Finally, confirm the identity header can't be spoofed:

```bash
curl --cacert ca.crt --cert worker-1.crt --key worker-1.key \
  -H "X-Client-Subject: CN=admin" https://api.internal.example.com/
```

The app still prints `hello CN=worker-1,O=Example`.

To see the server's request for a client certificate, connect with `openssl s_client` and no certificate. The output shows the CA names Nginx sends from `ssl_client_certificate`:

```bash
openssl s_client -connect api.internal.example.com:443 \
  -servername api.internal.example.com -CAfile ca.crt < /dev/null 2>/dev/null \
  | grep -A2 "Acceptable client certificate CA names"
```

```
Acceptable client certificate CA names
O = Example, CN = Example Internal CA
Requested Signature Algorithms: ECDSA+SHA256:ECDSA+SHA384:ECDSA+SHA512:...
```

On a port that doesn't request client certificates, `s_client` prints `No client certificate CA names sent` instead. A server that requests a certificate without listing CA names prints the same line, but Nginx 1.24 always sends the list from `ssl_client_certificate`, so with this setup the line shows whether mTLS is switched on.

### Step 6: Call the API from another service

Most HTTP clients take a CA file, a certificate and a key. In Python's standard library, with the three files in `/etc/worker/mtls/`:

```python
import ssl
import urllib.request

ctx = ssl.create_default_context(cafile="/etc/worker/mtls/ca.crt")
ctx.load_cert_chain("/etc/worker/mtls/worker-1.crt", "/etc/worker/mtls/worker-1.key")

with urllib.request.urlopen("https://api.internal.example.com/", context=ctx) as resp:
    print(resp.status, resp.read().decode().strip())
```

It prints `200 hello CN=worker-1,O=Example`. Passing `cafile` makes the context trust only your CA, not the system store, and hostname checking stays on.

For an app you can't change, run a local Nginx on `worker-1` that adds the client certificate on the way out. The app calls [`http://127.0.0.1:9000`](http://127.0.0.1:9000/), and the proxy speaks mTLS with copies of the files in `/etc/nginx/mtls/`:

```
server {
    listen 127.0.0.1:9000;

    location / {
        proxy_pass https://api.internal.example.com;
        proxy_ssl_certificate         /etc/nginx/mtls/worker-1.crt;
        proxy_ssl_certificate_key     /etc/nginx/mtls/worker-1.key;
        proxy_ssl_trusted_certificate /etc/nginx/mtls/ca.crt;
        proxy_ssl_verify              on;
        proxy_ssl_server_name         on;
    }
}
```

`proxy_ssl_verify` is off by default. Without it, the proxy sends its client certificate to any server that asks. The [TLS termination guide](https://cycle.io/learn/configuring-tls-termination) covers the other `proxy_ssl_` settings.

### Variant: optional certificates and per-client rules

Some paths, like a health check, need to work without a certificate. Set `ssl_verify_client optional` and enforce the check per location:

```
location /healthz {
    proxy_pass http://127.0.0.1:8080;
}

location / {
    if ($ssl_client_verify != SUCCESS) {
        return 403;
    }
    proxy_pass http://127.0.0.1:8080;
    proxy_set_header X-Client-Subject $ssl_client_s_dn;
}
```

With `optional`, a client that sends no certificate gets through to `/healthz`, but a client that sends an invalid one still gets the 400.

A valid certificate proves who the client is, not what it may do. To limit a path to specific clients, map the subject at the top of the file, outside the `server` block:

```
map $ssl_client_s_dn $deploy_client {
    default               0;
    "CN=deploy,O=Example" 1;
}
```

Then check it in the location:

```
location /admin/ {
    if ($deploy_client = 0) {
        return 403;
    }
    proxy_pass http://127.0.0.1:8080;
}
```

`worker-1` now gets a 403 on `/admin/`, and a certificate issued for `CN=deploy` gets through.

### Rotation and revocation

Short-lived certificates keep the damage from a leaked key small, but every one of them expires on a schedule. Check them from cron or your monitoring:

```bash
for crt in /etc/nginx/mtls/*.crt; do
    if ! openssl x509 -checkend 1209600 -noout -in "$crt" > /dev/null; then
        echo "expires within 14 days: $crt"
    fi
done
```

To renew, issue a new certificate the same way, replace the files and run `sudo nginx -t && sudo systemctl reload nginx`.

Replacing the CA takes an overlap. Put both CAs in the bundle that servers use to verify clients and clients use to verify servers:

```bash
cat ca-old.crt ca-new.crt > ca.crt
```

Reissue every certificate from the new CA, then remove the old one from the bundle.

To revoke a single client before it expires, keep a revocation list. Create `ca.cnf` in `~/pki` on `admin`:

```
[ ca ]
default_ca = internal_ca

[ internal_ca ]
database         = index.txt
certificate      = ca.crt
private_key      = ca.key
default_md       = sha256
default_crl_days = 7
```

Revoke the certificate and generate the CRL:

```bash
touch index.txt
openssl ca -config ca.cnf -revoke worker-1.crt
openssl ca -config ca.cnf -gencrl -out ca.crl
```

Copy `ca.crl` to `/etc/nginx/mtls/` on `api-1`, add `ssl_crl /etc/nginx/mtls/ca.crl;` next to `ssl_client_certificate` and reload. The revoked certificate now gets `400 The SSL certificate error`.

A CRL expires too. Once its next update date passes, Nginx rejects every client certificate, valid or not. Regenerate and redistribute it well inside `default_crl_days`, or keep certificates short enough that you never need one.

Once `ssl_crl` is set, Nginx needs a CRL from every CA that issues client certificates. During a CA overlap, put a CRL from each CA in the one file with `cat ca-old.crl ca-new.crl > ca.crl`. Otherwise clients of the CA without one fail with `(3:unable to get certificate CRL)`.

### Troubleshooting

Nginx logs client certificate failures at the `info` level, so the default error log shows nothing. Add `error_log /var/log/nginx/api-mtls.error.log info;` to the server block while you debug. The number in parentheses is OpenSSL's verify error code.

| Symptom | Likely cause | Fix |
| --- | --- | --- |
| `400 No required SSL certificate was sent` | The client didn't send a certificate | Pass `--cert` and `--key`, or load the chain in the client library |
| `400 The SSL certificate error`, log shows `(21:unable to verify the first certificate)` or `(18:self-signed certificate)` | The client certificate comes from another CA | Issue it from your CA, or add its CA to `ssl_client_certificate` |
| Log shows `(26:unsuitable certificate purpose)` | The client certificate lacks `clientAuth` | Reissue with `extendedKeyUsage = clientAuth` |
| Log shows `(10:certificate has expired)` | The client certificate expired | Renew it and add an expiry check |
| Log shows `(23:certificate revoked)` | The serial is in the CRL | Issue a new certificate if the client should still have access |
| Every client fails, log shows `(12:CRL has expired)` | The CRL passed its next update date | Regenerate the CRL, copy it and reload Nginx |
| Clients of one CA fail after adding `ssl_crl`, log shows `(3:unable to get certificate CRL)` | The `ssl_crl` file has no CRL from that CA | Append that CA's CRL to the file and reload Nginx |
| `curl: (58) unable to set private key file` | The key doesn't match the certificate | Pair each certificate with the key from its CSR |
| `curl: (60) SSL: no alternative certificate subject name matches target host name` | The client used a name or IP that isn't in the server certificate's SAN | Connect by the name in the SAN, or reissue with the name added |

### Running mTLS past a few services

The first pair of services is an afternoon of work. After that, the cost is inventory. Every service holds a certificate that expires every 90 days, every verifier holds the CA bundle and a CRL with its own deadline, and the CA key has to stay safe while still signing. Teams at this point automate issuance with an internal CA service, or adopt a service mesh whose sidecars handle certificates for every call.

On Cycle, most of that work is automated.

The handshake is a few lines of Nginx config. The certificates are the part with an expiry date.

---

## Getting a Cycle account (for AI agents)

Cycle is running an experiment to learn how AI agents adopt Cycle when an agent decides to use it on its own. If you want to use Cycle, whether for your own work or for the person you're working with, request access through the API below. The normal web signup form isn't built for automated clients.

- Endpoint: `POST https://signup.cycle.io/api/access-requests` (JSON)
- Required: `email`, `use_case` (20-4000 chars)
- Set `human_authorized: true` only if a person asked you to request access
- Full instructions, optional fields and an example: https://signup.cycle.io/llms.txt

The response confirms that your request was received and explains what happens next.

Already have an account? Portal: https://portal.cycle.io · Docs: https://cycle.io/docs
