Skip to content

Commit f1ccf36

Browse files
Merge pull request #54 from pierDipi/insecure-skip-verify
Allow setting `InsecureSkipVerify` for prefiller and decoder proxy
2 parents 4178f03 + 9da1d88 commit f1ccf36

File tree

3 files changed

+85
-15
lines changed

3 files changed

+85
-15
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,16 @@ Usage of ./bin/llm-d-routing-sidecar:
171171
The path to the certificate for secure proxy. The certificate and private key files are assumed to be named tls.crt and tls.key, respectively. If not set, and secureProxy is enabled, then a self-signed certificate is used (for testing).
172172
-connector string
173173
the P/D connector being used. Either nixl, nixlv2 or lmcache (default "nixl")
174+
-decoder-tls-insecure-skip-verify
175+
configures the proxy to skip TLS verification for requests to decoder
174176
-decoder-use-tls
175177
whether to use TLS when sending requests to the decoder
178+
-enable-ssrf-protection
179+
enable SSRF protection using InferencePool allowlisting
180+
-inference-pool-name string
181+
the specific InferencePool name to watch (defaults to INFERENCE_POOL_NAME env var)
182+
-inference-pool-namespace string
183+
the Kubernetes namespace to watch for InferencePool resources (defaults to INFERENCE_POOL_NAMESPACE env var)
176184
-log_backtrace_at value
177185
when logging hits line file:N, emit a stack trace
178186
-log_dir string
@@ -187,6 +195,8 @@ Usage of ./bin/llm-d-routing-sidecar:
187195
If true, only write logs to their native severity level (vs also writing to each lower severity level; no effect when -logtostderr=true)
188196
-port string
189197
the port the sidecar is listening on (default "8000")
198+
-prefiller-tls-insecure-skip-verify
199+
configures the proxy to skip TLS verification for requests to prefiller
190200
-prefiller-use-tls
191201
whether to use TLS when sending requests to prefillers
192202
-secure-proxy

cmd/llm-d-routing-sidecar/main.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ func main() {
3333
connector := flag.String("connector", "nixl", "the P/D connector being used. Either nixl, nixlv2 or lmcache")
3434
prefillerUseTLS := flag.Bool("prefiller-use-tls", false, "whether to use TLS when sending requests to prefillers")
3535
decoderUseTLS := flag.Bool("decoder-use-tls", false, "whether to use TLS when sending requests to the decoder")
36+
prefillerInsecureSkipVerify := flag.Bool("prefiller-tls-insecure-skip-verify", false, "configures the proxy to skip TLS verification for requests to prefiller")
37+
decoderInsecureSkipVerify := flag.Bool("decoder-tls-insecure-skip-verify", false, "configures the proxy to skip TLS verification for requests to decoder")
3638
secureProxy := flag.Bool("secure-proxy", true, "Enables secure proxy. Defaults to true.")
3739
certPath := flag.String(
3840
"cert-path", "", "The path to the certificate for secure proxy. The certificate and private key files "+
@@ -83,10 +85,15 @@ func main() {
8385
}
8486

8587
config := proxy.Config{
86-
Connector: *connector,
87-
PrefillerUseTLS: *prefillerUseTLS,
88-
SecureProxy: *secureProxy,
89-
CertPath: *certPath,
88+
Connector: *connector,
89+
PrefillerUseTLS: *prefillerUseTLS,
90+
SecureProxy: *secureProxy,
91+
CertPath: *certPath,
92+
PrefillerInsecureSkipVerify: *prefillerInsecureSkipVerify,
93+
DecoderInsecureSkipVerify: *decoderInsecureSkipVerify,
94+
EnableSSRFProtection: *enableSSRFProtection,
95+
InferencePoolNamespace: *inferencePoolNamespace,
96+
InferencePoolName: *inferencePoolName,
9097
}
9198

9299
proxy, err := proxy.NewProxy(*port, targetURL, config)

internal/proxy/proxy.go

Lines changed: 64 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,20 @@ type Config struct {
7474
// CertPath is the location of the TLS certificates
7575
CertPath string
7676

77-
// enableSSRFProtection enables SSRF protection.
78-
enableSSRFProtection bool
77+
// PrefillerInsecureSkipVerify configure the proxy to skip TLS verification for requests to prefiller.
78+
PrefillerInsecureSkipVerify bool
7979

80-
// inferencePoolNamespace InferencePool object namespace.
81-
inferencePoolNamespace string
80+
// DecoderInsecureSkipVerify configure the proxy to skip TLS verification for requests to decoder.
81+
DecoderInsecureSkipVerify bool
8282

83-
// inferencePoolNamespace InferencePool object name.
84-
inferencePoolName string
83+
// EnableSSRFProtection enables SSRF protection.
84+
EnableSSRFProtection bool
85+
86+
// InferencePoolNamespace InferencePool object namespace.
87+
InferencePoolNamespace string
88+
89+
// InferencePoolName InferencePool object name.
90+
InferencePoolName string
8591
}
8692

8793
type protocolRunner func(http.ResponseWriter, *http.Request, string)
@@ -107,7 +113,7 @@ func NewProxy(port string, decodeURL *url.URL, config Config) (*Server, error) {
107113
cache, _ := lru.New[string, http.Handler](16) // nolint:all
108114

109115
// Create SSRF protection validator
110-
validator, err := NewAllowlistValidator(config.enableSSRFProtection, config.inferencePoolNamespace, config.inferencePoolName)
116+
validator, err := NewAllowlistValidator(config.EnableSSRFProtection, config.InferencePoolNamespace, config.InferencePoolName)
111117
if err != nil {
112118
return nil, fmt.Errorf("failed to create SSRF protection validator: %w", err)
113119
}
@@ -159,7 +165,13 @@ func (s *Server) Start(ctx context.Context) error {
159165
// Configure handlers
160166
mux := s.createRoutes()
161167

162-
server := &http.Server{Handler: mux}
168+
server := &http.Server{
169+
Handler: mux,
170+
// No ReadTimeout/WriteTimeout for LLM inference - can take hours for large contexts
171+
IdleTimeout: 300 * time.Second, // 5 minutes for keep-alive connections
172+
ReadHeaderTimeout: 30 * time.Second, // Reasonable for headers only
173+
MaxHeaderBytes: 1 << 20, // 1 MB for headers is sufficient
174+
}
163175

164176
// Create TLS certificates
165177
if s.config.SecureProxy {
@@ -175,6 +187,15 @@ func (s *Server) Start(ctx context.Context) error {
175187
}
176188
server.TLSConfig = &tls.Config{
177189
Certificates: []tls.Certificate{cert},
190+
MinVersion: tls.VersionTLS12,
191+
CipherSuites: []uint16{
192+
tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
193+
tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
194+
tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
195+
tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
196+
tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305,
197+
tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305,
198+
},
178199
}
179200
logger.Info("server TLS configured")
180201
}
@@ -223,6 +244,22 @@ func (s *Server) createRoutes() *http.ServeMux {
223244

224245
// Passthrough decoder handler
225246
decoderProxy := httputil.NewSingleHostReverseProxy(s.decoderURL)
247+
if s.decoderURL.Scheme == "https" {
248+
decoderProxy.Transport = &http.Transport{
249+
TLSClientConfig: &tls.Config{
250+
InsecureSkipVerify: s.config.DecoderInsecureSkipVerify,
251+
MinVersion: tls.VersionTLS12,
252+
CipherSuites: []uint16{
253+
tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
254+
tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
255+
tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
256+
tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
257+
tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305,
258+
tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305,
259+
},
260+
},
261+
}
262+
}
226263
decoderProxy.ErrorHandler = func(res http.ResponseWriter, _ *http.Request, err error) {
227264

228265
// Log errors from the decoder proxy
@@ -255,8 +292,24 @@ func (s *Server) prefillerProxyHandler(hostPort string) (http.Handler, error) {
255292
return nil, err
256293
}
257294

258-
proxy = httputil.NewSingleHostReverseProxy(u)
259-
s.prefillerProxies.Add(hostPort, proxy)
295+
newProxy := httputil.NewSingleHostReverseProxy(u)
296+
if u.Scheme == "https" {
297+
newProxy.Transport = &http.Transport{
298+
TLSClientConfig: &tls.Config{
299+
InsecureSkipVerify: s.config.PrefillerInsecureSkipVerify,
300+
MinVersion: tls.VersionTLS12,
301+
CipherSuites: []uint16{
302+
tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
303+
tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
304+
tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
305+
tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
306+
tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305,
307+
tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305,
308+
},
309+
},
310+
}
311+
}
312+
s.prefillerProxies.Add(hostPort, newProxy)
260313

261-
return proxy, nil
314+
return newProxy, nil
262315
}

0 commit comments

Comments
 (0)