feat(gateway): Add server-side TLS support (#15052)
This commit is contained in:
@@ -135,6 +135,8 @@ class Router:
|
||||
health_check_endpoint: Health check endpoint path. Default: '/health'
|
||||
model_path: Model path for loading tokenizer (HuggingFace model ID or local path). Default: None
|
||||
tokenizer_path: Explicit tokenizer path (overrides model_path tokenizer if provided). Default: None
|
||||
server_cert_path: Path to server TLS certificate (PEM format). Default: None
|
||||
server_key_path: Path to server TLS private key (PEM format). Default: None
|
||||
"""
|
||||
|
||||
def __init__(self, router: _Router):
|
||||
|
||||
@@ -118,6 +118,9 @@ class RouterArgs:
|
||||
client_cert_path: Optional[str] = None
|
||||
client_key_path: Optional[str] = None
|
||||
ca_cert_paths: List[str] = dataclasses.field(default_factory=list)
|
||||
# Server TLS configuration
|
||||
server_cert_path: Optional[str] = None
|
||||
server_key_path: Optional[str] = None
|
||||
# Trace
|
||||
enable_trace: bool = False
|
||||
otlp_traces_endpoint: str = "localhost:4317"
|
||||
@@ -644,6 +647,19 @@ class RouterArgs:
|
||||
default=[],
|
||||
help="Path(s) to CA certificate(s) for verifying worker TLS certificates. Can specify multiple CAs.",
|
||||
)
|
||||
# Server TLS configuration
|
||||
parser.add_argument(
|
||||
f"--{prefix}tls-cert-path",
|
||||
type=str,
|
||||
default=None,
|
||||
help="Path to server TLS certificate (PEM format)",
|
||||
)
|
||||
parser.add_argument(
|
||||
f"--{prefix}tls-key-path",
|
||||
type=str,
|
||||
default=None,
|
||||
help="Path to server TLS private key (PEM format)",
|
||||
)
|
||||
parser.add_argument(
|
||||
f"--{prefix}enable-trace",
|
||||
action="store_true",
|
||||
@@ -678,6 +694,18 @@ class RouterArgs:
|
||||
elif attr.name in cli_args_dict:
|
||||
args_dict[attr.name] = cli_args_dict[attr.name]
|
||||
|
||||
# Special handling for CLI args with dashes vs dataclass fields with underscores
|
||||
# e.g. --tls-cert-path maps to tls_cert_path in args namespace, but we might want server_cert_path in dataclass
|
||||
# Wait, dataclass fields are server_cert_path/server_key_path
|
||||
# CLI args are tls_cert_path/tls_key_path
|
||||
# We need to manually map them if names don't match
|
||||
|
||||
# Map tls args to server cert/key path
|
||||
if f"{prefix}tls_cert_path" in cli_args_dict:
|
||||
args_dict["server_cert_path"] = cli_args_dict[f"{prefix}tls_cert_path"]
|
||||
if f"{prefix}tls_key_path" in cli_args_dict:
|
||||
args_dict["server_key_path"] = cli_args_dict[f"{prefix}tls_key_path"]
|
||||
|
||||
# parse special arguments and remove "--prefill" and "--decode" from cli_args_dict
|
||||
args_dict["prefill_urls"] = cls._parse_prefill_urls(
|
||||
cli_args_dict.get(f"{prefix}prefill", None)
|
||||
|
||||
@@ -226,6 +226,8 @@ struct Router {
|
||||
client_cert_path: Option<String>,
|
||||
client_key_path: Option<String>,
|
||||
ca_cert_paths: Vec<String>,
|
||||
server_cert_path: Option<String>,
|
||||
server_key_path: Option<String>,
|
||||
enable_trace: bool,
|
||||
otlp_traces_endpoint: String,
|
||||
}
|
||||
@@ -407,6 +409,10 @@ impl Router {
|
||||
self.client_key_path.as_ref(),
|
||||
)
|
||||
.add_ca_certificates(self.ca_cert_paths.clone())
|
||||
.maybe_server_cert_and_key(
|
||||
self.server_cert_path.as_ref(),
|
||||
self.server_key_path.as_ref(),
|
||||
)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
@@ -488,6 +494,8 @@ impl Router {
|
||||
client_cert_path = None,
|
||||
client_key_path = None,
|
||||
ca_cert_paths = vec![],
|
||||
server_cert_path = None,
|
||||
server_key_path = None,
|
||||
enable_trace = false,
|
||||
otlp_traces_endpoint = String::from("localhost:4317"),
|
||||
))]
|
||||
@@ -566,6 +574,8 @@ impl Router {
|
||||
client_cert_path: Option<String>,
|
||||
client_key_path: Option<String>,
|
||||
ca_cert_paths: Vec<String>,
|
||||
server_cert_path: Option<String>,
|
||||
server_key_path: Option<String>,
|
||||
enable_trace: bool,
|
||||
otlp_traces_endpoint: String,
|
||||
) -> PyResult<Self> {
|
||||
@@ -658,6 +668,8 @@ impl Router {
|
||||
client_cert_path,
|
||||
client_key_path,
|
||||
ca_cert_paths,
|
||||
server_cert_path,
|
||||
server_key_path,
|
||||
enable_trace,
|
||||
otlp_traces_endpoint,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user