Skip to content

Commit ff26284

Browse files
committed
Copyedits to webhook and remove basic-auth in database
1 parent 32c5f46 commit ff26284

File tree

2 files changed

+24
-123
lines changed

2 files changed

+24
-123
lines changed

docs/universal-gateway/examples/database-gateway.mdx

Lines changed: 21 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
---
2-
title: "Database gateway"
2+
title: "Database Gateway"
33
description: "Securely expose databases to external clients with strict authentication, rate limiting, and query transformation to prevent runaway costs and data leaks."
4-
sidebar_label: "Database gateway"
4+
sidebar_label: "Database Gateway"
55
---
66

77
import ReserveDomain from "./snippets/_reserve-domain.mdx";
88
import CloudEndpoint from "./snippets/_cloud-endpoint.mdx";
99
import TryOut from "./snippets/_try-out.mdx";
1010
import Back from "./snippets/_back-to-examples.mdx";
11-
import TabItem from "@theme/TabItem";
12-
import Tabs from "@theme/Tabs";
1311

1412
A database gateway provides secure access to databases exposed to external clients. It enforces authentication, rate limiting, and logging before requests reach your database, while optionally transforming queries to prevent costly operations or data exposure.
1513

1614
With this setup, you can:
1715

18-
- Enforce strict authentication (API keys, mTLS) before any database access
16+
- Enforce strict mTLS certificate authentication before any database access
1917
- Rate limit requests per client to prevent abuse and runaway costs
20-
- Log all database access attempts with client attribution for compliance and debugging
21-
- Transform or block dangerous queries to protect sensitive data
18+
- Block dangerous queries to protect sensitive data
2219
- Support secure database replication across clouds without exposing credentials
2320

2421
## 1. Create an endpoint for your database service
@@ -44,106 +41,27 @@ For databases that don't natively support HTTP, consider using a database proxy
4441

4542
## 4. (Optional) Create a vault and secrets
4643

47-
For production environments, store your authentication secrets securely using [Traffic Policy Secrets](/docs/traffic-policy/secrets). This step is optional—you can also use plaintext credentials directly in your policy.
44+
For production environments, store your CA certificate securely using [Traffic Policy Secrets](/docs/traffic-policy/secrets). This step is optional—you can also include the certificate directly in your policy.
4845

49-
Create a vault to store your authentication secrets:
46+
Create a vault to store your CA certificate:
5047

5148
```bash
52-
ngrok api vaults create --name "database-auth" --description "Database gateway authentication secrets"
49+
ngrok api vaults create --name "database-auth" --description "Database gateway CA certificate"
5350
```
5451

55-
Add your credentials to the vault, replacing the names and values, plus changing `$VAULT_ID` to match the vault ID from the response:
52+
Add your CA certificate to the vault using the vault ID from the response:
5653

5754
```bash
58-
# Add API keys for different clients (username:password format)
59-
ngrok api secrets create \
60-
--name "customer-123-key" \
61-
--value "sk_live_abc123" \
62-
--vault-id "$VAULT_ID"
63-
64-
ngrok api secrets create \
65-
--name "partner-456-key" \
66-
--value "sk_live_def456" \
67-
--vault-id "$VAULT_ID"
68-
69-
# Add CA certificate for mTLS (if using certificate authentication)
55+
# Add CA certificate for mTLS authentication
7056
ngrok api secrets create \
7157
--name "client-ca-certificate" \
7258
--value "-----BEGIN CERTIFICATE-----\nYour CA certificate content here\n-----END CERTIFICATE-----" \
73-
--vault-id "$VAULT_ID"
59+
--vault-id "vault_2yNPzuk6GjHrx3mlOCkJK42RsdR"
7460
```
7561

7662
## 5. Apply Traffic Policy to your Cloud Endpoint
7763

78-
While still viewing your new cloud endpoint in the dashboard, copy and paste one of the policies below into the Traffic Policy editor.
79-
80-
<Tabs>
81-
<TabItem value="api-key" label="API key authentication" default>
82-
83-
```yaml
84-
on_http_request:
85-
# Authenticate using API keys (username:password format)
86-
- actions:
87-
- type: basic-auth
88-
config:
89-
credentials:
90-
- "customer-123:${secrets.get('database-auth', 'customer-123-key')}"
91-
- "customer-456:${secrets.get('database-auth', 'customer-456-key')}"
92-
93-
# Different rate limits per client tier
94-
- expressions:
95-
# Premium clients get higher limits
96-
- "actions.ngrok.basic_auth.credentials.username == 'customer-123'"
97-
actions:
98-
- type: rate-limit
99-
config:
100-
name: "Premium client rate limit"
101-
algorithm: "sliding_window"
102-
capacity: 1000
103-
rate: 1h
104-
bucket_key:
105-
- "actions.ngrok.basic_auth.credentials.username"
106-
107-
- expressions:
108-
# Standard clients get lower limits
109-
- "ngrok.auth.basic_auth.username == 'customer-456'"
110-
actions:
111-
- type: rate-limit
112-
config:
113-
name: "Standard client rate limit"
114-
algorithm: "sliding_window"
115-
capacity: 100
116-
rate: "1h"
117-
bucket_key:
118-
- "actions.ngrok.basic_auth.credentials.username"
119-
120-
# Block dangerous SQL operations (example for HTTP-based SQL interfaces)
121-
- expressions:
122-
- "req.url.query.contains('DROP') || req.url.query.contains('DELETE') || req.url.query.contains('TRUNCATE')"
123-
actions:
124-
- type: custom-response
125-
config:
126-
status_code: 403
127-
headers:
128-
content-type: "application/json"
129-
body: |
130-
{
131-
"error": "Forbidden operation detected",
132-
"message": "DROP, DELETE, and TRUNCATE operations are not allowed through this gateway",
133-
"timestamp": "${timestamp(time.now)}"
134-
}
135-
136-
# Forward to database service
137-
- actions:
138-
- type: forward-internal
139-
config:
140-
url: https://database-service.internal
141-
```
142-
143-
**What's happening here?** This policy uses API key authentication in username:password format with client-specific rate limiting tiers. Premium clients get higher request limits, dangerous SQL operations are blocked, and authenticated requests are forwarded to your database service.
144-
145-
</TabItem>
146-
<TabItem value="mtls" label="mTLS certificate authentication">
64+
While still viewing your new cloud endpoint in the dashboard, copy and paste the policy below into the Traffic Policy editor.
14765

14866
```yaml
14967
on_tcp_connect:
@@ -153,6 +71,7 @@ on_tcp_connect:
15371
config:
15472
mutual_tls_certificate_authorities:
15573
- "${secrets.get('database-auth', 'client-ca-certificate')}"
74+
mutual_tls_verification_strategy: "require-and-verify"
15675

15776
on_http_request:
15877
# Rate limit per client certificate subject
@@ -162,9 +81,8 @@ on_http_request:
16281
name: "Database access rate limiting per certificate"
16382
algorithm: "sliding_window"
16483
capacity: 500
165-
rate: 1h
166-
bucket_key:
167-
- "actions.ngrok.terminate_tls.client.subject"
84+
rate: "1h"
85+
bucket_key: ["actions.ngrok.terminate_tls.client.subject"]
16886

16987
# Block dangerous SQL operations
17088
- expressions:
@@ -208,45 +126,28 @@ openssl x509 -req -in client.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out c
208126
Add the contents of `ca.crt` to your vault as `client-ca-certificate`.
209127
:::
210128

211-
</TabItem>
212-
</Tabs>
213-
214129
## 6. Try out your endpoint
215130

216131
<TryOut />
217132

218-
Test the authentication and rate limiting:
219-
220-
**For API key authentication:**
133+
Test the mTLS authentication and rate limiting:
221134

222135
```bash
223-
# Base64 encode your credentials first (customer-123:sk_live_abc123)
224-
echo -n "customer-123:sk_live_abc123" | base64
225-
# Returns: Y3VzdG9tZXItMTIzOnNrX2xpdmVfYWJjMTIz
226-
227-
# Make requests with the Authorization header
228-
curl -H "Authorization: Basic Y3VzdG9tZXItMTIzOnNrX2xpdmVfYWJjMTIz" \
136+
# Use client certificates (after generating them with the commands above)
137+
curl --cert client.crt --key client.key \
229138
"https://$NGROK_DOMAIN/api/users?limit=10"
230139

231140
# This should be rate limited after exceeding the configured threshold
232-
for i in {1..150}; do
233-
curl -H "Authorization: Basic Y3VzdG9tZXItMTIzOnNrX2xpdmVfYWJjMTIz" \
141+
for i in {1..600}; do
142+
curl --cert client.crt --key client.key \
234143
"https://$NGROK_DOMAIN/api/users?limit=1"
235144
done
236145
```
237146

238-
**For mTLS authentication:**
239-
240-
```bash
241-
# Use client certificates (after generating them with the commands above)
242-
curl --cert client.crt --key client.key \
243-
"https://$NGROK_DOMAIN/api/users?limit=10"
244-
```
245-
246147
## What's next?
247148

248-
- Learn more about [basic authentication](/docs/traffic-policy/actions/basic-auth) including credential management and security best practices
249-
- Explore [mTLS certificate authentication](/docs/traffic-policy/actions/terminate-tls) for high-security environments
149+
- Learn more about [mTLS certificate authentication](/docs/traffic-policy/actions/terminate-tls) for high-security environments
150+
- For token-based authentication, explore [JWT validation](/docs/traffic-policy/actions/jwt-validation) as a scalable alternative to basic authentication
250151
- Set up [comprehensive logging](/docs/traffic-policy/actions/log) to send database access events to your SIEM or monitoring platform
251152
- Use [URL rewriting](/docs/traffic-policy/actions/url-rewrite) to transform database queries or add security constraints
252153
- View database access patterns in [Traffic Inspector](https://dashboard.ngrok.com/traffic-inspector) to identify potential security issues

docs/universal-gateway/examples/webhook-gateway.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
2-
title: "Webhook gateway"
2+
title: "Webhook Gateway"
33
description: "Centralize webhook validation and routing from third-party providers like Stripe, Twilio, and Slack to secure your integrations and eliminate repetitive implementation."
4-
sidebar_label: "Webhook gateway"
4+
sidebar_label: "Webhook Gateway"
55
---
66

77
import ReserveDomain from "./snippets/_reserve-domain.mdx";
@@ -11,7 +11,7 @@ import Back from "./snippets/_back-to-examples.mdx";
1111
import TabItem from "@theme/TabItem";
1212
import Tabs from "@theme/Tabs";
1313

14-
Instead of implementing webhook validation and routing logic separately in every service, a webhook gateway provides a single, secure entry point for all third-party webhooks from providers like Stripe, Twilio, Slack, and GitHub. This centralized approach validates webhook signatures, prevents tampering, and routes authenticated requests to the appropriate internal services.
14+
Instead of implementing webhook validation and routing logic separately in every service, a webhook gateway provides a single, secure entry point for all third-party webhooks from providers like Stripe, Twilio, Slack, and GitHub. This centralized approach validates webhook signatures, prevents tampering, and routes authenticated requests to the appropriate internal services in production environments.
1515

1616
With this setup, you can:
1717

0 commit comments

Comments
 (0)