Skip to main content
Agent TLS termination enables you to secure your traffic with end-to-end encryption without needing to reconfigure your server.
If your service doesn’t support TLS termination, you can still use Agent TLS termination with Zero-Knowledge TLS.
The following instructions will guide you through setting up Agent TLS termination with ngrok.

What you’ll need

  • Ensure you have openssl installed.

1. Generate a cert and key pair

The following command:
  1. Generates a new certificate signing request (CSR) for a 4096-bit RSA key pair.
    • The key is saved to your-key.key.
  2. Creates a self-signed certificate which:
    • Is in x509 format and uses the SHA-256 hash algorithm.
    • Is valid for 365 days.
    • Is saved to your-cert.crt.

2. Configure your endpoint

You can configure your endpoint with an agent configuration file. To create a new configuration file with your generated cert and key pair, run the following command:
Your generated configuration file should resemble the following:
You can run ngrok config edit to open the configuration file in your default text editor. Learn more about the ngrok config command.

Optional: require client certificates (mTLS) at the agent

To make the agent authenticate clients as part of the TLS handshake, add one or more Certificate Authorities to the agent_tls_termination block with mutual_tls_certificate_authorities. The agent will reject any client whose certificate isn’t signed by one of the listed CAs.
See agent_tls_termination.mutual_tls_certificate_authorities for the full reference.
This is different from mTLS terminated at the ngrok edge via the terminate-tls Traffic Policy action. With agent-side mTLS, the client certificate is validated by your agent; traffic between the ngrok edge and your agent is still carried over the agent’s secure TLS connection to ngrok, but client-certificate authentication is not performed on that hop.

3. Start your endpoint

Next, use ngrok start endpoint_name_here in the terminal to start an endpoint using the settings in your agent configuration file, as shown below:

4. Start your upstream server

Start an upstream server on the specified port (for example, 12345) to handle incoming requests. The following example uses Python, but you can use any language or framework depending on your requirements.

5. Try connecting to your endpoint

The following example uses openssl s_client to initiate an SSL/TLS client connection to your upstream server without a certificate.
The following example uses openssl s_client to initiate an SSL/TLS client connection to your upstream server with a certificate.
The extra arguments added to the command suppress most of the output so that only the data exchanged with the server will be displayed.