allow or deny traffic from that range.
You can manage IP Policies in the ngrok dashboard or via the IP Policies API.
Creating and managing IP Policies
In the dashboard
- Go to Security, then IP Policies in the ngrok dashboard.
- Click New IP Policy to create a policy.
- Add rules to your policy by specifying a CIDR range (such as
203.0.113.0/24) and choosingallowordeny. - Save your policy.
You’ll get a policy ID (for example,
ipp_...) that you can reference in your Traffic Policy.
Via the API
You can also create and manage IP Policies using the ngrok API. Refer to the IP Policy Rules API to add or remove rules from existing policies.Applying IP Policies to Endpoints
To enforce an IP Policy on your endpoints, use therestrict-ips Traffic Policy action.
This action lets you reference one or more IP Policy IDs, and ngrok will allow or deny traffic based on the rules in those policies.
There are two ways to apply a Traffic Policy to an Agent Endpoint:
- Standalone policy file: Create a separate
policy.ymlorpolicy.jsonfile and pass it to ngrok with the--traffic-policy-fileflag. The policy phases (such ason_http_request) are at the top level of the file. - Agent config file: Define the policy inline inside your ngrok agent config file (for example,
ngrok.yml). In this case, the policy phases must be nested under thetraffic_policy:key inside the endpoint configuration.
When embedding a Traffic Policy in your agent config file, the
on_http_request (and other phase) blocks must be placed under traffic_policy: inside the endpoint definition—not at the top level of the config file.Using a standalone policy file
Create apolicy.yml or policy.json file with the following contents:
--traffic-policy-file flag:
Using the agent config file
To embed the same policy in your ngrok agent config file, nest the policy block undertraffic_policy: inside the endpoint definition:
ngrok.yml
Using a Cloud Endpoint
To use a Cloud Endpoint, visit the Endpoints section in the ngrok dashboard and select the Cloud Endpoint. You’ll be taken to the Traffic Policy editor where you can enter the policy directly. The editor uses the standalone policy format. Enter the phase blocks (such ason_http_request) at the top level:
Referencing an existing IP Policy by ID
You can also reference an existing IP Policy by its ID instead of listing CIDRs directly:traffic_policy: when using the agent config file.
For a full reference of all configuration options, behavior, and examples for the restrict-ips action, see the Restrict IPs action reference.
Applying account-wide IP Policies
To apply account-wide IP Policies, you can use the IP Restrictions feature in the ngrok dashboard. In the dashboard UI, you can apply IP Restrictions to users trying to sign in to your ngrok dashboard, traffic trying to access your API or Endpoints, and source IPs trying to start Agent Endpoints on your account. You can define the IP Policies that make up your restrictions in the dashboard UI.Related resources
- Restrict IPs Traffic Policy action: Full reference for the
restrict-ipsaction, including all configuration options and examples. - IP Policies API reference: Manage IP Policies programmatically via the ngrok API.
- IP Policy Rules API reference: Add or remove rules from your IP Policies via the ngrok API.