Skip to content

Commit 209618b

Browse files
grahamkinghhzhang16
authored andcommitted
feat(http): TLS support (#2492)
Signed-off-by: Hannah Zhang <hannahz@nvidia.com>
1 parent bdaee00 commit 209618b

File tree

12 files changed

+433
-34
lines changed

12 files changed

+433
-34
lines changed

Cargo.lock

Lines changed: 71 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,9 @@ Dynamo provides a simple way to spin up a local set of inference components incl
118118
- **Workers** – Set of pre-configured LLM serving engines.
119119

120120
```
121-
# Start an OpenAI compatible HTTP server, a pre-processor (prompt templating and tokenization) and a router:
122-
python -m dynamo.frontend --http-port 8080
121+
# Start an OpenAI compatible HTTP server, a pre-processor (prompt templating and tokenization) and a router.
122+
# Pass the TLS certificate and key paths to use HTTPS instead of HTTP.
123+
python -m dynamo.frontend --http-port 8080 [--tls-cert-path cert.pem] [--tls-key-path key.pem]
123124
124125
# Start the SGLang engine, connecting to NATS and etcd to receive requests. You can run several of these,
125126
# both for the same model and for multiple models. The frontend node will discover them.

components/frontend/src/dynamo/frontend/main.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,15 @@
1616
# Worker example:
1717
# - cd lib/bindings/python/examples/hello_world
1818
# - python server_sglang_static.py
19+
#
20+
# For TLS:
21+
# - python -m dynamo.frontend --http-port 8443 --tls-cert-path cert.pem --tls-key-path key.pem
22+
#
1923

2024
import argparse
2125
import asyncio
2226
import os
27+
import pathlib
2328
import re
2429

2530
import uvloop
@@ -85,6 +90,18 @@ def parse_args():
8590
parser.add_argument(
8691
"--http-port", type=int, default=8080, help="HTTP port for the engine (u16)."
8792
)
93+
parser.add_argument(
94+
"--tls-cert-path",
95+
type=pathlib.Path,
96+
default=None,
97+
help="TLS certificate path, PEM format.",
98+
)
99+
parser.add_argument(
100+
"--tls-key-path",
101+
type=pathlib.Path,
102+
default=None,
103+
help="TLS certificate key path, PEM format.",
104+
)
88105
parser.add_argument(
89106
"--router-mode",
90107
type=str,
@@ -149,6 +166,8 @@ def parse_args():
149166

150167
if flags.static_endpoint and (not flags.model_name or not flags.model_path):
151168
parser.error("--static-endpoint requires both --model-name and --model-path")
169+
if bool(flags.tls_cert_path) ^ bool(flags.tls_key_path): # ^ is XOR
170+
parser.error("--tls-cert-path and --tls-key-path must be provided together")
152171

153172
return flags
154173

@@ -192,6 +211,10 @@ async def async_main():
192211
kwargs["model_name"] = flags.model_name
193212
if flags.model_path:
194213
kwargs["model_path"] = flags.model_path
214+
if flags.tls_cert_path:
215+
kwargs["tls_cert_path"] = flags.tls_cert_path
216+
if flags.tls_key_path:
217+
kwargs["tls_key_path"] = flags.tls_key_path
195218

196219
if is_static:
197220
# out=dyn://<static_endpoint>

launch/dynamo-run/src/flags.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,18 @@ pub struct Flags {
4545
pub model_path_flag: Option<PathBuf>,
4646

4747
/// HTTP port. `in=http` only
48+
/// If tls_cert_path and tls_key_path are provided, this will be TLS/HTTPS.
4849
#[arg(long, default_value = "8080")]
4950
pub http_port: u16,
5051

52+
/// TLS certificate file
53+
#[arg(long, requires = "tls_key_path")]
54+
pub tls_cert_path: Option<PathBuf>,
55+
56+
/// TLS certificate key file
57+
#[arg(long, requires = "tls_cert_path")]
58+
pub tls_key_path: Option<PathBuf>,
59+
5160
/// The name of the model we are serving
5261
#[arg(long)]
5362
pub model_name: Option<String>,

launch/dynamo-run/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub async fn run(
2020
runtime: Runtime,
2121
in_opt: Input,
2222
out_opt: Option<Output>,
23-
flags: Flags,
23+
mut flags: Flags,
2424
) -> anyhow::Result<()> {
2525
//
2626
// Configure
@@ -39,7 +39,9 @@ pub async fn run(
3939
.kv_cache_block_size(flags.kv_cache_block_size)
4040
// Only set if user provides. Usually loaded from tokenizer_config.json
4141
.context_length(flags.context_length)
42-
.http_port(Some(flags.http_port))
42+
.http_port(flags.http_port)
43+
.tls_cert_path(flags.tls_cert_path.take())
44+
.tls_key_path(flags.tls_key_path.take())
4345
.router_config(Some(flags.router_config()))
4446
.request_template(flags.request_template.clone())
4547
.migration_limit(flags.migration_limit)

0 commit comments

Comments
 (0)