Repository navigation
Expand file tree
/
Copy pathconfig.example.yaml
More file actions
177 lines (151 loc) · 7.16 KB
/
Copy pathconfig.example.yaml
File metadata and controls
177 lines (151 loc) · 7.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# Roxy Proxy Configuration Example
# Copy to config.yaml and customize
listen: "0.0.0.0:8080"
# Hot reload: check for config file changes every N seconds (0 = disabled, default: 5)
reload_interval_secs: 5
# TLS/MITM configuration (optional)
# tls:
# ca_cert: "./ca.crt"
# ca_key: "./ca.key"
# cert_cache_size: 1000
# Skip TLS certificate verification for upstream servers (default: false).
# WARNING: Disables ALL upstream certificate validation. Self-signed and
# invalid certificates will be accepted. Only use in trusted networks
# or development environments where upstream servers use self-signed certs.
# unsafe_skip_verify: true
# Connection pool settings (optional)
# Limits prevent unbounded memory growth and mitigate DoS attacks.
# All fields below are optional with sane defaults shown.
pool:
max_idle_per_host: 10 # Maximum idle connections per upstream host
idle_timeout_secs: 30 # Seconds before idle connections are closed
# HTTP/2 client keep-alive: PING pooled h2 connections to detect dead peers.
# Without this, h2 connections to silently-dead upstreams accumulate until
# idle_timeout_secs elapses (which only triggers when truly idle, which an
# h2 socket with stuck streams is not). Set interval to 0 to disable.
http2_keep_alive_interval_secs: 20
http2_keep_alive_timeout_secs: 10
http2_keep_alive_while_idle: true
# Inbound server timeouts (optional). NOT hot-reloadable: changes require restart.
# Without these, inbound sockets from misbehaving / dead clients accumulate
# indefinitely (this is the root cause of socket/RSS growth observed in
# long-running deployments).
server_timeouts:
# HTTP/1 header-read timeout — kills slow-loris clients that open a socket
# and send headers extremely slowly (or never). Set to 0 to disable.
http1_header_read_timeout_secs: 15
# HTTP/2 server-side keep-alive PINGs detect h2 peers that are dead at the
# application protocol level even though TCP still looks established.
# Keep this enabled for dead-peer detection; max_connection_age_secs below
# is what bounds healthy idle peers that ACK PINGs forever.
http2_keep_alive_interval_secs: 20
http2_keep_alive_timeout_secs: 10 # must be < interval when interval > 0
# Bound multiplexing fan-out per h2 connection (0 = unbounded).
http2_max_concurrent_streams: 256
# Vendored hudsucker InternalProxy/accept-loop deadline knobs.
# max_connection_age_secs is the hard cap that prevents healthy-but-idle h2
# clients from holding sockets forever by ACKing every PING. On expiry roxy
# asks hyper to gracefully drain, then force-closes after the grace window.
max_connection_age_secs: 1800 # 30 minutes, 0 = disabled
max_connection_age_grace_secs: 30 # must be < max_connection_age_secs
# CONNECT-specific gaps in upstream hudsucker 0.24.0 now covered by roxy's
# vendored proxy path.
connect_initial_read_timeout_secs: 15
tls_handshake_timeout_secs: 15
# Kernel TCP keepalive applied to the listening socket (Linux inherits onto
# every accepted client connection). Tunes how long the OS waits before
# declaring a silent peer dead.
#
# Defaults (60/30/4) give ~3 min worst-case dead-peer detection,
# set `enabled: false` to skip SO_KEEPALIVE entirely (peers will then
# only be detected as dead via real TCP errors / RST). `retries` is Linux-only.
tcp_keepalive:
enabled: true
time_secs: 60 # TCP_KEEPIDLE — idle seconds before first probe
interval_secs: 30 # TCP_KEEPINTVL — seconds between probes
retries: 4 # TCP_KEEPCNT — unACK'd probes before kill (Linux only)
# Optional runtime metrics (NOT hot-reloadable). Logs tokio alive-task and
# worker count every N seconds; useful for verifying that connection leak
# fixes are taking effect. Omit / set interval_secs to 0 to disable.
# runtime_metrics:
# interval_secs: 30
# Rate limit settings (optional)
rate_limit:
cleanup_interval_secs: 60
# Access control rules
rules:
# Block requests to internal networks
- name: "block-internal"
rule: 'host("*.internal") || host("*.local") || host("10.*") || host("192.168.*") = block'
# Block specific user agents
- name: "block-bad-ua"
rule: 'header("User-Agent~*curl*") && !header("X-Allowed:true") = block : pass'
# Require auth header for API
- name: "require-auth"
rule: 'host("api.example.com") && !header("X-Auth") = block : pass'
# Rate limit API requests
- name: "api-rate-limit"
rule: 'host("api.*") && path("/v1/*") = rate_limit(100/s, header(X-Customer-Id))'
# Rate limit by IP for public endpoints
- name: "public-rate-limit"
rule: 'path("/public/*") = rate_limit(10/m, ip)'
# Credit-based rate limiting (fixed budget with scheduled reset)
# Periods: /d (daily), /w (weekly), /M (monthly)
- name: "api-credits"
rule: 'host("api.*") && path("/v2/*") = credit(1000/d, header(X-Customer-Id))'
# Composite: rate limit (burst) + credit (budget) on the same rule
# Rate limit enforces per-second burst protection; credit enforces daily budget.
# Both must pass for the request to proceed.
- name: "api-protected"
rule: 'host("api.*") && path("/v3/*") = rate_limit(50/s, header(X-Customer-Id)) + credit(5000/d, header(X-Customer-Id))'
- name: "premium-credits"
rule: 'host("api.*") && header("X-Plan:premium") = credit(50000/M, header(X-Customer-Id))'
# Mangle headers for backend requests
- name: "backend-headers"
rule: 'host("backend.*") = mangle'
# Allow only specific methods
- name: "allowed-methods"
rule: '!(method(GET) || method(POST) || method(HEAD) || method(CONNECT)) = block'
# Per-rule log level (optional). Accepted: trace, debug, info (default), warn, error, off.
# Use `off` to silence the matched-rule log entry for noisy but expected traffic.
- name: "allow-healthcheck"
rule: 'path("/health") && method(GET) = pass'
log_level: off
# Header manipulation
headers:
- rules: ["backend-headers"]
add:
- name: "X-Proxy-Processed"
value: "true"
- name: "X-Forwarded-By"
value: "roxy"
remove:
- "X-Internal-Debug"
# Throttle config: progressive delay (soft limit) for rate_limit rules
# Delay ramps linearly from 0ms at soft_limit to max_delay_ms at the hard limit
throttle:
- rule: "api-rate-limit"
soft_limit: 80 # Start throttling at 80 req/s (hard limit is 100)
max_delay_ms: 2000 # Max delay when approaching hard limit
- rule: "api-protected"
soft_limit: 40 # Start throttling at 40 req/s (hard limit is 50)
max_delay_ms: 1500
# Credit system config
# Credits are a fixed budget that resets on a schedule (daily/weekly/monthly)
# Formats: "daily@HH:MM", "weekly@Day-HH:MM", "monthly@DD-HH:MM" (UTC)
credits:
- rule: "api-credits"
soft_limit: 800 # Start throttling at 800/1000 credits used
max_delay_ms: 2000
reset_schedule: "daily@00:00"
message: "API credit exhausted. Resets at {reset_time}."
- rule: "premium-credits"
soft_limit: 40000
max_delay_ms: 3000
reset_schedule: "monthly@01-00:00"
message: "Monthly credit limit reached. Resets at {reset_time}."
- rule: "api-protected"
soft_limit: 4000
max_delay_ms: 2000
reset_schedule: "daily@00:00"
message: "API budget exhausted. Resets at {reset_time}."