Skip to content
Merged
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ hmac = "0.12"
hex = "0.4"
chacha20poly1305 = "0.10"
regex = "1"
aho-corasick = "1"
# AWS EventStream framing (already in the lock via sqlx/reqwest)
crc = "3"
percent-encoding = "2"
Expand Down
2 changes: 1 addition & 1 deletion control-plane/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ require (
golang.org/x/sys v0.47.0 // indirect
golang.org/x/text v0.41.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20260825221802-da73d73af1c5 // indirect
google.golang.org/grpc v1.83.1 // indirect
google.golang.org/grpc v1.83.2 // indirect
google.golang.org/protobuf v1.36.12 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
)
4 changes: 2 additions & 2 deletions control-plane/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/genproto/googleapis/rpc v0.0.0-20260825221802-da73d73af1c5 h1:1VUiZAXyC+zmiFYi+WLtBzr68Cj8wOofHjjrA/kkizc=
google.golang.org/genproto/googleapis/rpc v0.0.0-20260825221802-da73d73af1c5/go.mod h1:DjtHYE8FKJLivXcBEjGwndXfIC23G0VpXiXKqG179uA=
google.golang.org/grpc v1.83.1 h1:HIO0+BEtBP6soyqvqC8sNUjZ7bTs+0hFQuFF+RAy++Y=
google.golang.org/grpc v1.83.1/go.mod h1:kDyl6SKsiHKt0uylY5gtn5cEjkrIOhQOGDgIc4JGwzQ=
google.golang.org/grpc v1.83.2 h1:EManeRomTObA0BU7I8vXgg/78uE5MJ9M8B39EX2WscU=
google.golang.org/grpc v1.83.2/go.mod h1:YPI1hK3kDked6iHvgX3tR0y+nX/qpMFKhPgFsokw1S8=
google.golang.org/protobuf v1.36.12 h1:pJOKDDOyeXErUroCihFAd5LQuwXBSpVnKGrj5o/fwxc=
google.golang.org/protobuf v1.36.12/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
100 changes: 50 additions & 50 deletions control-plane/web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ serde-saphyr = { workspace = true }
sha2 = { workspace = true }
thiserror = { workspace = true }
regex = { workspace = true }
aho-corasick = { workspace = true }
tracing = { workspace = true }

[lints]
Expand Down
38 changes: 36 additions & 2 deletions crates/config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,13 @@ pub struct ModelConf {
/// capacity.
#[serde(default)]
pub variants: Vec<VariantConf>,
#[serde(skip)]
kind: Option<Protocol>,
}

impl ModelConf {
pub fn protocol(&self) -> Option<Protocol> {
Protocol::from_wire(&self.protocol)
self.kind
}
}

Expand Down Expand Up @@ -388,6 +390,9 @@ pub struct SecurityConf {
/// Blocklist terms; normalized to lower-case (empties dropped) at load.
#[serde(default)]
pub blocklist: Vec<String>,
/// The blocklist as one automaton; `None` when the list is empty.
#[serde(skip)]
pub blocklist_matcher: Option<aho_corasick::AhoCorasick>,
/// What a blocklist hit does (default: block).
#[serde(default)]
pub blocklist_action: Action,
Expand All @@ -413,6 +418,12 @@ pub struct SecurityConf {
}

impl SecurityConf {
/// The policy as load leaves it: blocklist lower-cased and compiled, regexes built.
pub fn compiled(mut self) -> Self {
compile_security(&mut self);
self
}

/// Whether responses must be redacted before leaving — the one predicate
/// the outbound-DLP masking AND the stream-buffering boundary share, so a
/// secrets-only tenant can't stream raw deltas past the masking.
Expand Down Expand Up @@ -764,6 +775,8 @@ pub struct GatewayConfig {
product_idx: HashMap<String, usize>,
#[serde(skip)]
tenant_idx: HashMap<String, usize>,
#[serde(skip)]
account_idx: HashMap<String, usize>,
}

impl GatewayConfig {
Expand All @@ -781,6 +794,7 @@ impl GatewayConfig {
self.model_idx = index_by(&self.models, |m| &m.name);
self.product_idx = index_by(&self.products, |p| &p.name);
self.tenant_idx = index_by(&self.tenants, |t| &t.name);
self.account_idx = index_by(&self.accounts, |a| &a.name);
}

/// Expand provider presets: fill each model's default wire type and
Expand Down Expand Up @@ -870,6 +884,9 @@ impl GatewayConfig {
compile_security(sec);
}
}
for m in &mut self.models {
m.kind = Protocol::from_wire(&m.protocol);
}
Ok(())
}

Expand Down Expand Up @@ -1278,6 +1295,10 @@ impl GatewayConfig {
self.models.get(*self.model_idx.get(name)?)
}

pub fn find_account(&self, name: &str) -> Option<&AccountConf> {
self.accounts.get(*self.account_idx.get(name)?)
}

/// Pricing for a public model name; zero if unlisted.
fn prices_for(&self, name: &str) -> (i64, i64) {
self.find_model(name)
Expand Down Expand Up @@ -1344,7 +1365,7 @@ fn provider_preset(kind: &str) -> Option<ProviderPreset> {
wires: &["gemini", "realtime"],
default_model_wire: "gemini",
},
// OpenAI-protocol vendors: same wire shape, different base URL.
// vendors on the OpenAI protocol share the wire shape and differ by base URL
"deepseek" => ProviderPreset {
endpoint: "https://api.deepseek.com",
wires: &["openai-chat"],
Expand Down Expand Up @@ -1469,6 +1490,19 @@ fn compile_security(sec: &mut SecurityConf) {
.filter(|w| !w.is_empty())
.map(|w| w.to_lowercase())
.collect();
sec.blocklist_matcher = (!sec.blocklist.is_empty())
.then(|| {
aho_corasick::AhoCorasickBuilder::new()
.ascii_case_insensitive(true)
.build(&sec.blocklist)
})
.and_then(|built| match built {
Ok(matcher) => Some(matcher),
Err(e) => {
tracing::error!(error = %e, "blocklist did not compile; the list is ignored");
None
}
});
sec.regexes = sec
.regex_rules
.iter()
Expand Down
5 changes: 2 additions & 3 deletions crates/consts/src/error_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

use crate::ErrCode;

/// One classification from the contract's closed set. `ModelStreamError` is
/// in-stream only and never renders at the HTTP phase.
/// One classification from the contract's closed set.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ErrClass {
Validation,
Expand Down Expand Up @@ -73,7 +72,7 @@ impl ErrClass {
ErrClass::ModelTimeout => 408,
ErrClass::Conflict => 409,
ErrClass::RequestEntityTooLarge => 413,
// ModelStreamError never renders at the HTTP phase; 424 nominal
// the in-stream ModelStreamError never renders at the HTTP phase; 424 nominal
ErrClass::ModelError | ErrClass::ModelStreamError => 424,
ErrClass::Throttling => 429,
ErrClass::InternalServer => 500,
Expand Down
Loading