Example scenario
Consider a situation where a you have a fleet of customers comprised of medical clinics. Each of these clinics has a host of services living behind a secure firewall which blocks inbound connections, but you require fine grained access to these critical resources. For the purposes of this example scenario, these resources include a REST API, a patient database, and a clinic operations database for each clinic. This guide will walk you through how to set up remote access to the resources in a single clinic (clinic 1), and the steps can be reproduced for each clinic in the customer fleet.Architectural Reference

Why only one ngrok agent per clinic?
Traditionally, you might assume that every service inside the clinic needs its own ngrok agent, but this isn’t necessary. A single ngrok agent is installed on a network-accessible server inside the clinic, and it:- Acts as a central gateway that can reach any service on the local network, eliminating the need for multiple agents.
- Creates Internal Endpoints so that each API and database is securely exposed inside ngrok, never publicly visible.
- Uses Cloud Endpoints for controlled, granular access. External cloud apps can access only what they need.
- Runs as a background service configured to automatically start on boot, restart after crashes, and log events.
Agent vs SDK vs ngrok Operator - which is right for you?
Tool | Ideal Environment |
---|---|
Agent | Simple, lightweight, and quick deployment to connect to customer services on any platform (cloud, on-prem, VM, or physical server). No code changes or complex network configuration required. |
SDK | Embed ngrok connectivity directly into your application for programmatic control, or when you’re building custom integrations (e.g., device gateways, BYOC architectures). |
ngrok Operator | Customer’s environment is Kubernetes-based and you need to expose services securely from inside their cluster to your network, without configuring low-level networking. |
What you’ll need
- An ngrok account. If you don’t have one, sign up.
- An ngrok agent configured on a customer integrated server. See the getting started guide for instructions on how to install the ngrok agent.
- An ngrok API Key. You’ll need an account first.
1. Create a bot user and authtoken to enable isolated agent management
Create a bot user so that you can create an agent authtoken independent of any user account. A bot user represents a service account, and allows each clinic to have its own authtoken. In the case one authtoken is compromised, only that clinic may be affected rather than all of them.2. Define internal endpoints in ngrok.yml for privatized device access
An internal endpoint enables a service inside the clinic to be reachable within ngrok, without being publicly exposed. They can:- Only receive traffic from cloud endpoints or internal services that explicitly route traffic to them.
- Not be accessed directly from the internet.
- Be used for telemetry APIs, databases, and dashboards.
/path/to/ngrok/ngrok.yml
and the executable in /path/to/ngrok/ngrok
.
3. Reserve a custom wildcard domain
Creating a custom wildcard domain will allow you to create endpoints and receive traffic on any subdomain of your domain. Wildcard domains are available on ngrok pay-as-you-go-plans when you verify with support. It can be helpful to create a separate subdomain for each clinic you wish to bring online and specify which resource the endpoint will point to for that clinic.
4. Reserve a TCP address for your TCP-based cloud endpoint
When you reserve a TCP Address, you can create a TCP cloud endpoint that binds to that domain. Reserved TCP addresses are available on ngrok’s pay-as-you-go plan.5. Create your cloud endpoints for persistent API and database access
A cloud endpoint is a permanent, externally accessible entry point into the clinic that’s also:- Managed centrally via the ngrok API or dashboard.
- Always on, not tied to the lifecycle of the agent.
- Does not forward traffic to the agent by default—it must be configured to route traffic to internal endpoints.
- Used for exposing services to external cloud apps securely.
6. Secure your endpoints with Traffic Policy
There are a variety of traffic policy actions to choose from to layer security on to our endpoints. Listed below are YAML snippets and curl commands below for how to enable IP Restrictions, JWT Validation, and mTLS. There are many other actions to choose from which can be found in Traffic Policy Actions. These actions will be added to the existing traffic policy config, preceding the forward-internal action. As patient data is extremely sensitive, let’s add an extra layer of protection for our TLS cloud endpoint. ngrok’s Traffic Policy is the perfect way to do this in a flexible and robust manner. We’ll also use traffic policy’s forward-internal action to forward traffic from our public cloud endpoints to our internal agent endpoints. Navigate to your newly created TLS cloud endpoint in the endpoints tab on the dashboard, and apply a terminate-tls traffic policy action to require a minimum tls version. Since this is a cloud endpoint, TLS will terminate at the ngrok edge by default, but we can also create an action within our agent configuration file if we wish to terminate TLS at the ngrok agent itself. Our traffic policy file for tls://patientdb-clinic1.clinic-network.com should look like this:TLS Endpoint with Minimum TLS Version
TCP Endpoint with IP Restrictions
HTTPs Endpoint with JWT Validation
Additional ngrok Features
Enable endpoint pooling
You can use endpoint pooling with multiple internal agent endpoints to achieve redundancy and high availability for services inside your network. If desired, you can install a second agent within the customer network as a failover in case agents in the wild go offline. Configure each agent endpoint to use the same ngrok internal URL. This automatically forms an endpoint pool. Incoming traffic to the pooled URL is automatically distributed among all healthy endpoints in the pool. If one endpoint goes offline, traffic is seamlessly routed to the remaining endpoints, ensuring redundancy and failoverCreate a custom connect URL
This provides a white-labeling capability so that your ngrok agents will connect toconnect.example.com
instead of the default connection hostname (connect.ngrok-agent.com). Dedicated IPs that are unique for your account which your agents will connect to are also available. This takes away any danger of rogue agents in your network trying to call home and adds an additional layer of security by specializing your ngrok connectivity. Custom connect URLs are available with ngrok’s pay-as-you-go plan as an additional paid feature.
Install ngrok as a background service
Now, install and start the serviceIn most cases, installing ngrok as a service requires administrator privileges.
Recap
You officially made it! You have now integrated a system that allows you to seamlessly and securely access any and all remote resources within your customer’s network. Let’s recap what you’ve built:- One ngrok agent per clinic and no need for multiple installs.
- Always-online API and databases, securely available via cloud and internal endpoints.
- ngrok runs as a background service, which means it’s reliable and will always auto-restart.
- Granular access with a composable traffic policy offering refined and robust security measures for our endpoints.