Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4,728 changes: 4,728 additions & 0 deletions examples/envoy-sandbox-proxy/Cargo.lock

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions examples/envoy-sandbox-proxy/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

[workspace]

[package]
name = "openshell-envoy-proxy"
version = "0.0.0"
edition = "2024"
rust-version = "1.95"
license = "Apache-2.0"
description = "Example Envoy dynamic module for OpenShell L4 TLS passthrough via ORIGINAL_DST"
publish = false

[lib]
name = "openshell_envoy_proxy"
crate-type = ["cdylib", "rlib"]

[dependencies]
envoy-proxy-dynamic-modules-rust-sdk = { git = "https://github.com/envoyproxy/envoy", rev = "9e5580933739775e8bce696a57a2e1bc99368f23" }
openshell-core = { path = "../../crates/openshell-core" }
openshell-crypto = { path = "../../crates/openshell-crypto" }
openshell-sdk = { path = "../../crates/openshell-sdk" }
rustls = { version = "0.23", default-features = false, features = ["std", "logging", "tls12"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tokio = { version = "1.53.3", features = ["full"] }
tokio-stream = { version = "0.1", features = ["net", "sync"] }
tonic = "0.14"
url = "2"

[dev-dependencies]
envoy-proxy-dynamic-modules-rust-sdk = { git = "https://github.com/envoyproxy/envoy", rev = "9e5580933739775e8bce696a57a2e1bc99368f23", features = ["mock"] }
9 changes: 9 additions & 0 deletions examples/envoy-sandbox-proxy/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

# Package the Linux module built with the glibc-compatible target in README.md.
FROM envoyproxy/envoy:v1.40.0@sha256:459f2a6404c340fe6afccd69d85527012d47f3c036765493e6f8f3113fa384de
COPY deploy/docker/.build/prebuilt-binaries/amd64/libopenshell_envoy_proxy.so /usr/local/lib/libopenshell_envoy_proxy.so
ENV ENVOY_DYNAMIC_MODULES_SEARCH_PATH=/usr/local/lib
USER 65532:65532
ENTRYPOINT ["/usr/local/bin/envoy"]
98 changes: 98 additions & 0 deletions examples/envoy-sandbox-proxy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# Envoy discovery proxy example

A reference discovery consumer that routes application TLS through Envoy directly
to shared supervisors. A Rust dynamic module watches `openshell.v1.ServiceDiscovery`
and maps exact SNI hostnames to advertised supervisor IPs and ports. Envoy's
`tls_inspector`, `ORIGINAL_DST` cluster, and `tcp_proxy` relay the application bytes;
application certificates and private keys remain on the supervisor.

Based on [the Envoy prototype](https://github.com/ai-openshell/openshell/tree/dc8a34a4d8826125a07d3291ff9434ec99ca99d0/crates/openshell-envoy-proxy)
using the Rust SDK and the service discovery API.

## Discovery and route lifetime

Select one `workspace`, a finite `workspaces` array, or `all_workspaces: true`.
Use HTTPS with `gateway_ca` and either `discovery_client_cert` /
`discovery_client_key` or `discovery_token_file`. Credential files are reread when
the watch reconnects. The watch begins with a complete snapshot, so initialization
does not perform a separate snapshot RPC.

Route withdrawal, installation-version changes, and endpoint changes close active
connections. Authorization failures and invalid discovery data clear the view.
Timely lease renewals preserve existing connections. Deadlines use the gateway's
absolute expiry and a monotonic clock anchor; clock rollback cannot extend a lease.

By default, lease expiry also closes active connections. Set
`retain_stale_routes: true` to keep previously accepted installations during
transient discovery outages. Expired data cannot introduce a new installation.
Explicit withdrawals,
owner changes, and authorization failures still revoke routes.

## Configuration

The module receives JSON through `filter_config` in `envoy.yaml`.

| Field | Default | Purpose |
| --- | --- | --- |
| `gateway_endpoint` | required | HTTPS gateway origin |
| `workspace` / `workspaces` / `all_workspaces` | exactly one | Discovery workspace selection |
| `gateway_ca` | system trust | Gateway CA bundle path |
| `discovery_client_cert` / `discovery_client_key` | none | Discovery mTLS identity paths |
| `discovery_token_file` | none | Bearer token path; exclusive with mTLS |
| `retain_stale_routes` | `false` | Retain previously accepted installations during outages |
| `max_connections_per_host` | `64` | Concurrent connections per hostname |
| `max_routes` | `4096` | Routes allowed in one complete view |
| `max_lease_secs` | `15` | Local upper bound on an accepted fresh lease |
| `readiness_address` | none | Optional HTTP endpoint reporting first valid view / hard error state |
| `allow_insecure_gateway` | `false` | Credential-free loopback HTTP for the mock harness |

The readiness endpoint stays ready through normal watch reconnects and transient
outages. It becomes unready on hard discovery errors until a valid view arrives.
Keep this endpoint private. Envoy's admin listener is loopback-only.

Size Envoy's global downstream resource monitor, network connection limit, and
upstream circuit breaker along with the module's per-host limit. Operators can
mount a custom bootstrap file to configure listeners, limits, and deployment
settings independently of the image.

## Build and validate

The module SDK is pinned to Envoy commit
`9e5580933739775e8bce696a57a2e1bc99368f23`, matching the pinned Envoy v1.40.0
image's v0.2.0 module ABI. Build for a libc compatible with the runtime's glibc
2.35. The example image packages the prebuilt Linux module.

From the repository root:

```shell
cargo test --manifest-path examples/envoy-sandbox-proxy/Cargo.toml --lib
CARGO_TARGET_DIR=target cargo zigbuild \
--manifest-path examples/envoy-sandbox-proxy/Cargo.toml \
--target x86_64-unknown-linux-gnu.2.35 --release --lib
mkdir -p deploy/docker/.build/prebuilt-binaries/amd64
cp target/x86_64-unknown-linux-gnu/release/libopenshell_envoy_proxy.so \
deploy/docker/.build/prebuilt-binaries/amd64/
mise run example:envoy-proxy:image -- REGISTRY/envoy-sandbox-proxy:TAG
```

The standalone harness runs the real Envoy image against mock discovery and two
backends. Keeping its manifest separate lets it link without Envoy's host symbols.

```shell
cargo run --manifest-path examples/envoy-sandbox-proxy/e2e/Cargo.toml -- \
--image REGISTRY/envoy-sandbox-proxy:TAG
```

It checks unknown SNI rejection, verbatim ClientHello passthrough, lease renewal,
owner takeover, and withdrawal.

Mount the bootstrap and a directory containing the gateway CA and discovery
client certificate/key when starting the image. Edit `gateway_endpoint` and
workspace selection in the mounted bootstrap for your installation.

```shell
docker run --rm -p 18443:18443 \
-v "$PWD/examples/envoy-sandbox-proxy/envoy.yaml:/etc/envoy/envoy.yaml:ro" \
-v "$DISCOVERY_CERT_DIR:/etc/openshell/discovery:ro" \
REGISTRY/envoy-sandbox-proxy:TAG -c /etc/envoy/envoy.yaml
```
13 changes: 13 additions & 0 deletions examples/envoy-sandbox-proxy/build-image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
set -euo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")/../.."
image="${1:?usage: build-image.sh IMAGE:TAG}"
module=deploy/docker/.build/prebuilt-binaries/amd64/libopenshell_envoy_proxy.so
if [[ ! -f "$module" ]]; then
echo "Build and stage the Linux module as described in examples/envoy-sandbox-proxy/README.md" >&2
exit 1
fi
source tasks/scripts/container-engine.sh
ce_build --platform linux/amd64 --load -f examples/envoy-sandbox-proxy/Dockerfile -t "$image" .
Loading
Loading