What you’ll need
- Ensure you have openssl installed.
1. Generate a cert and key pair
The following command:- Generates a new certificate signing request (CSR) for a 4096-bit RSA key pair.
- The key is saved to
your-key.key.
- The key is saved to
- 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: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 theagent_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.
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, usengrok 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 usesopenssl s_client to initiate an SSL/TLS client connection to your upstream server without a certificate.
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.