-
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathwebsocket.kdl
More file actions
254 lines (215 loc) · 5.84 KB
/
websocket.kdl
File metadata and controls
254 lines (215 loc) · 5.84 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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
// Example: WebSocket Proxy Configuration
//
// WebSocket proxying with:
// - Frame inspection for security
// - Rate limiting (messages per second)
// - Connection limits per IP
// - Ping/pong keepalive
// - Token authentication
system {
worker-threads 0
max-connections 50000
graceful-shutdown-timeout-secs 30
}
listeners {
listener "http" {
address "0.0.0.0:8080"
protocol "http"
request-timeout-secs 60
}
listener "https" {
address "0.0.0.0:8443"
protocol "https"
tls {
cert-file "/etc/zentinel/certs/ws.crt"
key-file "/etc/zentinel/certs/ws.key"
}
}
}
// =============================================================================
// Agents for WebSocket inspection
// =============================================================================
agents {
// WebSocket frame inspector for security
agent "ws-inspector" {
type "websocket"
grpc address="http://localhost:50051"
events "request_headers" "request_body"
timeout-ms 50
failure-mode "open"
}
// Authentication agent
agent "auth" {
type "auth"
grpc address="http://localhost:50052"
events "request_headers"
timeout-ms 100
failure-mode "closed"
}
}
// =============================================================================
// Filters (agent-backed)
// =============================================================================
filters {
filter "auth" {
type "agent"
agent "auth"
timeout-ms 100
failure-mode "closed"
}
filter "ws-inspector" {
type "agent"
agent "ws-inspector"
timeout-ms 50
failure-mode "open"
}
}
// =============================================================================
// Routes
// =============================================================================
routes {
// WebSocket endpoint with frame inspection
route "websocket" {
priority "high"
matches {
path-prefix "/ws"
}
upstream "ws-backend"
filters "auth" "ws-inspector"
websocket {
enabled #true
ping-interval-secs 30
ping-timeout-secs 10
max-message-size-bytes 65536
max-connections-per-ip 10
}
policies {
timeout-secs 3600 // Long timeout for persistent connections
failure-mode "closed"
}
}
// Socket.io endpoint (HTTP + WebSocket)
route "socketio" {
priority "high"
matches {
path-prefix "/socket.io"
}
upstream "socketio-backend"
filters "auth"
websocket {
enabled #true
ping-interval-secs 25
ping-timeout-secs 10
max-message-size-bytes 1048576 // 1MB for larger payloads
}
policies {
timeout-secs 3600
}
}
// Chat application endpoint
route "chat" {
priority "high"
matches {
path-prefix "/chat"
}
upstream "chat-backend"
filters "auth" "ws-inspector"
websocket {
enabled #true
ping-interval-secs 30
ping-timeout-secs 10
max-message-size-bytes 16384
max-connections-per-ip 5
}
policies {
timeout-secs 7200 // 2 hour sessions
}
}
// Health check
route "health" {
priority "critical"
matches {
path "/health"
}
builtin-handler "health"
}
}
// =============================================================================
// Upstreams
// =============================================================================
upstreams {
upstream "ws-backend" {
target "127.0.0.1:3000" weight=1
target "127.0.0.1:3001" weight=1
load-balancing "ip-hash" // Session affinity for WebSocket
health-check {
type "http" {
path "/health"
expected-status 200
}
interval-secs 10
timeout-secs 5
healthy-threshold 2
unhealthy-threshold 3
}
connection-pool {
max-connections 1000
max-idle 100
}
}
upstream "socketio-backend" {
target "127.0.0.1:3010" weight=1
target "127.0.0.1:3011" weight=1
load-balancing "ip-hash"
health-check {
type "http" {
path "/socket.io/health"
}
interval-secs 10
timeout-secs 5
healthy-threshold 2
unhealthy-threshold 3
}
}
upstream "chat-backend" {
target "127.0.0.1:3020" weight=1
load-balancing "round-robin"
health-check {
type "http" {
path "/health"
}
interval-secs 10
timeout-secs 5
healthy-threshold 2
unhealthy-threshold 3
}
}
}
// =============================================================================
// Observability
// =============================================================================
observability {
metrics {
enabled #true
address "0.0.0.0:9090"
path "/metrics"
// WebSocket-specific metrics:
// - zentinel_websocket_connections_active
// - zentinel_websocket_messages_total
// - zentinel_websocket_frames_inspected_total
// - zentinel_websocket_frames_blocked_total
}
logging {
level "info"
format "json"
access-log {
enabled #true
file "/var/log/zentinel/websocket-access.log"
}
}
}
limits {
max-header-size-bytes 8192
max-header-count 100
max-body-size-bytes 1048576
}