Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions agent/agent-mutual-tls-termination.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ Using the CA certificate generated in the previous step, you can specify the `mu

```yaml policy.yml
on_tcp_connect:
- actions:
- type: terminate-tls
- actions:
- type: terminate-tls
config:
mutual_tls_certificate_authorities:
- -----BEGIN CERTIFICATE-----
... certificate ...
-----END CERTIFICATE-----
... certificate ...
-----END CERTIFICATE-----
```

```json policy.json
Expand Down
8 changes: 4 additions & 4 deletions getting-started/_secure-your-app.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,17 @@ First, create a new file called `traffic-policy.yml` in the root of your project

```yaml policy.yml
on_http_request:
- name: OAuth
- name: OAuth
actions:
- type: oauth
- type: oauth
config:
auth_id: oauth
provider: google
- name: bad email
- name: bad email
expressions:
- actions.ngrok.oauth.identity.email != '[email protected]'
actions:
- type: custom-response
- type: custom-response
config:
body: Hey, no auth for you ${actions.ngrok.oauth.identity.name}!
status_code: 400
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
"scripts": {
"build": "mint build",
"dev": "mint dev --port 3333",
"fmt:check": "biome check . --diagnostic-level=error && prettier --check .",
"fmt": "biome check . --write --diagnostic-level=error --organize-imports-enabled=true && prettier --write .",
"verify-redirects": "node snippets/custom-scripts/check-redirect-conflicts.js",
"test-links": "mint broken-links"
},
Expand Down
20 changes: 10 additions & 10 deletions traffic-policy/examples/a-b-tests.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ This rule:

```yaml policy.yml
on_http_request:
- expressions:
- expressions:
- rand.double() <= 0.5
actions:
- type: forward-internal
- type: forward-internal
config:
url: https://a.internal
- actions:
- type: forward-internal
config:
url: https://b.internal
- actions:
- type: forward-internal
config:
url: https://b.internal
```

```json policy.json
Expand Down Expand Up @@ -77,15 +77,15 @@ You can also send the traffic to a different route using url rewrites.

```yaml policy.yml
on_http_request:
- expressions:
- expressions:
- rand.double() <= 0.5
actions:
- type: url-rewrite
- type: url-rewrite
config:
from: /path/to/test
to: /path/to/test-b
- actions:
- type: forward-internal
- actions:
- type: forward-internal
config:
url: https://b.internal
```
Expand Down
8 changes: 4 additions & 4 deletions traffic-policy/examples/add-and-remove-headers.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ This rule adds multiple headers to the request, including the client's IP addres

```yaml policy.yml
on_http_request:
- actions:
- type: add-headers
- actions:
- type: add-headers
config:
headers:
x-is-ngrok: 1
Expand Down Expand Up @@ -66,8 +66,8 @@ This rule removes the `X-Powered-By` header.

```yaml policy.yml
on_http_request:
- actions:
- type: remove-headers
- actions:
- type: remove-headers
config:
headers:
- X-Powered-By
Expand Down
38 changes: 19 additions & 19 deletions traffic-policy/examples/add-authentication.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,27 @@ This rule adds key-based rate limiting to your endpoints based on your consumers
on_http_request:
- name: Add JWT authentication and rate limiting
actions:
- type: rate-limit
- type: rate-limit
config:
name: Only allow 30 requests per minute
- me: Only allow 30 requests per minute
algorithm: sliding_window
capacity: 30
rate: 60s
bucket_key:
- req.headers['x-api-key']
- type: jwt-validation
- type: jwt-validation
config:
issuer:
- suer:
allow_list:
- value: https://<YOUR-AUTH-PROVIDER>
audience:
allow_list:
al- st:
- value: <YOUR-NGROK-DOMAIN>
http:
tokens:
to-
- type: jwt
method: header
name: Authorization
- : Authorization
prefix: Bearer
jws:
allowed_algorithms:
Expand Down Expand Up @@ -130,25 +130,25 @@ This rule grants conditional access to a page using the following ngrok [OAuth a
on_http_request:
- name: OAuth
actions:
- type: oauth
- type: oauth
config:
auth_id: oauth
- th_id: oauth
provider: google
- name: good email
- name: good email
expressions:
- actions.ngrok.oauth.identity.email.endsWith('@ngrok.com')
- actions.ngrok.oauth.identity.email.endsWith('@ngrok.com')
actions:
- type: custom-response
config:
body: Welcome ${actions.ngrok.oauth.identity.name}!
- dy: Welcome ${actions.ngrok.oauth.identity.name}!
status_code: 200
- name: bad email
- name: bad email
expressions:
- !actions.ngrok.oauth.identity.email.endsWith('@ngrok.com')
- !actions.ngrok.oauth.identity.email.endsWith('@ngrok.com')
actions:
- type: custom-response
config:
body: Hey, no auth for you ${actions.ngrok.oauth.identity.name}!
- dy: Hey, no auth for you ${actions.ngrok.oauth.identity.name}!
status_code: 400
```

Expand Down Expand Up @@ -215,9 +215,9 @@ This rule uses the `actions.ngrok.oidc.identity_token` [OIDC action result varia
on_http_request:
- name: OIDC
actions:
- type: openid-connect
- type: openid-connect
config:
issuer_url: https://accounts.google.com
- suer_url: https://accounts.google.com
client_id: <your-oidc-client-id>
client_secret: <your-oidc-client-secret>
scopes:
Expand All @@ -226,9 +226,9 @@ on_http_request:
- email
- name: Headers
actions:
- type: add-headers
- type: add-headers
config:
headers:
- aders:
id-token: ${actions.ngrok.oidc.identity_token}
```

Expand Down
36 changes: 18 additions & 18 deletions traffic-policy/examples/block-unwanted-requests.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ This rule uses the [connection variables](/traffic-policy/variables/connection/)

```yaml policy.yml
on_http_request:
- expressions:
- essions:
- ('proxy.anonymous.tor' in conn.client_ip.categories)
actions:
- type: deny
- : deny
config:
status_code: 403
```
Expand Down Expand Up @@ -59,11 +59,11 @@ This rule returns a custom response with a [`robots.txt` file](https://developer

```yaml policy.yml
on_http_request:
- name: Add `robots.txt` to deny all bots and crawlers
- : Add `robots.txt` to deny all bots and crawlers
expressions:
- req.url.contains('/robots.txt')
actions:
- type: custom-response
- : custom-response
config:
status_code: 200
body: User-agent: *
Expand Down Expand Up @@ -105,11 +105,11 @@ You can extend this example to create specific rules for crawlers based on their

```yaml policy.yml
on_http_request:
- name: Add `robots.txt` to deny specific bots and crawlers
- : Add `robots.txt` to deny specific bots and crawlers
expressions:
- req.url.contains('/robots.txt')
actions:
- type: custom-response
- : custom-response
config:
status_code: 200
body: User-agent: ChatGPT-User\r\nDisallow: /
Expand Down Expand Up @@ -152,11 +152,11 @@ You can also take action on incoming requests that contain specific strings in [

```yaml policy.yml
on_http_request:
- name: Block specific bots by user agent
- : Block specific bots by user agent
expressions:
- req.user_agent.name in ('ChatGPT-User', 'GPTBot', 'OAI-SearchBot')
actions:
- type: deny
- : deny
config:
status_code: 404
```
Expand Down Expand Up @@ -208,10 +208,10 @@ This rule denies all inbound traffic that is not a GET request.

```yaml policy.yml
on_http_request:
- expressions:
- essions:
- req.method != 'GET'
actions:
- type: deny
- : deny
```

```json policy.json
Expand Down Expand Up @@ -241,10 +241,10 @@ This rule sends a custom response with status code `401` and body `Unauthorized`

```yaml policy.yml
on_http_request:
- expressions:
- essions:
- !('authorization' in req.headers)
actions:
- type: custom-response
- : custom-response
config:
status_code: 401
body: Unauthorized
Expand Down Expand Up @@ -284,11 +284,11 @@ Sometimes you may need to block requests originating from one or more countries

```yaml policy.yml
on_http_request:
- expressions:
- essions:
- conn.geo.country_code in ['<COUNTRY-01>', '<COUNTRY-02>']
name: Block traffic from unwanted countries
actions:
- type: custom-response
- : custom-response
config:
status_code: 401
body: Unauthorized request due to country of origin.
Expand Down Expand Up @@ -330,12 +330,12 @@ This rule demonstrates how to prevent excessively large user uploads, like text

```yaml policy.yml
on_http_request:
- name: Block large POST/PUT requests.
- : Block large POST/PUT requests.
expressions:
- req.method == 'POST' || req.method == 'PUT'
- req.content_length >= 1000
actions:
- type: custom-response
- : custom-response
config:
status_code: 400
body: Error: You can't upload content larger than 1MB.
Expand Down Expand Up @@ -374,10 +374,10 @@ In this example, the Algolia web crawler is exempted from any rate limiting we h

```yaml policy.yml
on_http_request:
- expressions:
- essions:
- !('com.algolia.crawler' in conn.client_ip.categories)
actions:
- type: rate-limit
- : rate-limit
config:
name: Only allow 30 requests per minute
algorithm: sliding_window
Expand Down
4 changes: 2 additions & 2 deletions traffic-policy/examples/compress-json-responses.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ If your upstream service already handles compression, ngrok skips this step.

```yaml policy.yml
on_http_response:
- name: Add compression
- name: Add compression
actions:
- type: compress-response
- type: compress-response
config:
algorithms:
- gzip
Expand Down
4 changes: 2 additions & 2 deletions traffic-policy/examples/enforce-tls.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ This rule:

```yaml policy.yml
on_http_request:
- name: Reject requests using old TLS versions
- name: Reject requests using old TLS versions
expressions:
- conn.tls.version < '1.3'
actions:
- type: custom-response
- type: custom-response
config:
status_code: 401
body: Unauthorized: TLS version too old
Expand Down
8 changes: 4 additions & 4 deletions traffic-policy/examples/event-logging.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ This rule:

```yaml policy.yml
on_http_request:
- actions:
- type: custom-response
- actions:
- type: custom-response
config:
status_code: 503
body: <html><body><h1>Service Unavailable</h1><p>Our servers are currently down for maintenance. Please check back later.</p></body></html>
headers:
content-type: text/html
on_http_response:
- name: Log unsuccessful requests
- name: Log unsuccessful requests
expressions:
- res.status_code < '200' && res.status_code >= '300'
actions:
- type: log
- type: log
config:
metadata:
message: Unsuccessful request
Expand Down
Loading