Skip to content

Commit 135e7f9

Browse files
committed
feat(http): TLS support
While we expect the frontend to be deployed behind a web layer, we still want to support TLS: - The data center might require all internal communications to be encrypted. - For some deployments such as NIM a web layer is not practical. Make a self-signed certificate: ``` openssl genpkey -algorithm Ed25519 -out key.pem openssl req -new -x509 -key key.pem -days 1460 -out cert.pem -subj "/C=US/ST=CA/L=Santa Clara/O=LocalDev/OU=Dynamo/CN=example.com" ``` Start the frontend: ``` python -m dynamo.frontend --http-port 8443 --tls-cert-path /data/certs/cert.pem --tls-key-path /data/certs/key.pem ``` Remember to add `--insecure` to your curl request.
1 parent d177cdf commit 135e7f9

File tree

12 files changed

+415
-31
lines changed

12 files changed

+415
-31
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: 21 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,
@@ -192,6 +209,10 @@ async def async_main():
192209
kwargs["model_name"] = flags.model_name
193210
if flags.model_path:
194211
kwargs["model_path"] = flags.model_path
212+
if flags.tls_cert_path:
213+
kwargs["tls_cert_path"] = flags.tls_cert_path
214+
if flags.tls_key_path:
215+
kwargs["tls_key_path"] = flags.tls_key_path
195216

196217
if is_static:
197218
# 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)]
54+
pub tls_cert_path: Option<PathBuf>,
55+
56+
/// TLS certificate key file
57+
#[arg(long)]
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)