LiteLLM hat Guardrails als Katalog fertiger Dienste. Für diesen Router wäre das die
falsche Form: welche Inhalte durchgehen, weiß der Betreiber, nicht das Binary. Also
gibt es einen Haken und keine Meinung:
guard request cmd "/usr/local/share/junction/hooks/guard.sh"
Das Skript bekommt JUNCTION_PATH, JUNCTION_MODEL, JUNCTION_VKEY, JUNCTION_BODY_FILE
und JUNCTION_BODY_BYTES. Exit 0 lässt durch, alles andere lehnt mit 403 guard_refused
ab, und stdout wird die Begründung — im Rumpf und im Log. Schweigt das Skript, nennt
die Ablehnung seinen Exit-Code (guard_exit_3), statt eine leere Begründung zu erfinden.
Drei Entscheidungen, die Absicht sind:
- Der Rumpf liegt in einer Datei, nicht auf stdin. Ein Skript, das nur die erste Zeile
liest, hinge sonst beim Schreiben in eine volle Pipe — eine Datei kann nicht deadlocken.
- Der Wächter läuft VOR dem Routing: eine abgelehnte Anfrage belegt keinen Endpunkt,
keinen Warteschlangenplatz und kein Budget.
- Nur die Anfrage wird geprüft. Eine Antwort zu prüfen hieße, jeden Stream zu puffern —
genau das, was dieser Router nicht tut. Das steht so im README, statt es zu verschweigen.
Sichtbar: guard_pass/guard_refused im Log je Anfrage, guard_refused in /status,
junction_guard_refused_total in /metrics.
Tests (tests/guard.sh, Abschnitt 30): ein Skript, das ein Wort ablehnt (Begründung im
Rumpf, Zähler in /metrics, Logzeile), eines, das stumm mit 3 endet (Exit-Code wird zur
Begründung), und eine Anfrage, die durchgeht und als guard_pass geloggt wird.
make test: PASS, 186 Prüfungen. Live: Binary installiert, Dienst neu gestartet, kein
Wächter eingetragen — es gibt keine Regel von Konrad, und eine zu erfinden wäre genau
das, was dieses Feature nicht tut.
147 lines
5.8 KiB
Plaintext
147 lines
5.8 KiB
Plaintext
# junction.conf — pf.conf-style. keyword, arguments, braces. '#' starts a comment.
|
||
# Double quotes group words. Unknown keywords are a hard error with a line number.
|
||
|
||
# Plain listener:
|
||
listen 0.0.0.0:8090
|
||
# ... or TLS (https clients without a proxy in front):
|
||
# listen 0.0.0.0:8443 tls /etc/junction/tls/cert.pem /etc/junction/tls/key.pem
|
||
|
||
connect_timeout_ms 1500
|
||
offline_hold_s 20
|
||
max_body_bytes 67108864
|
||
|
||
# How many upstream requests may run at once; the rest wait in line. A waiting
|
||
# streaming caller gets SSE comments explaining the wait, a plain one waits silently.
|
||
max_inflight 4
|
||
queue_timeout 300
|
||
|
||
# Retry before failover: 429/408/5xx are tried again on the SAME endpoint, because such
|
||
# a state usually clears in seconds while the next link may cost money or context.
|
||
# 0 disables it. retry_backoff is per attempt (attempt n waits n × this).
|
||
retry_num 1
|
||
retry_backoff 0.5
|
||
|
||
# If the WHOLE chain is offline or cooling down, wait this many seconds for it to come
|
||
# back instead of answering 503 at once (0 = never wait). The wait happens before a
|
||
# queue slot is taken, so a waiting request holds no upstream place.
|
||
# offline_wait 20
|
||
|
||
# One JSON line per request that reported usage: time, key, model, endpoint, tokens,
|
||
# cost. The per-key monthly budgets are recomputed from it at startup — without it a
|
||
# budget would be full again after every restart. Empty = no log.
|
||
# spend_log /var/lib/junction/spend.jsonl
|
||
|
||
# A guard sees every request before it is routed and decides: exit 0 = pass, anything
|
||
# else = 403 with the script's stdout as the reason. junction brings no policy of its
|
||
# own. The body is handed over as a file (JUNCTION_BODY_FILE), not on stdin.
|
||
# guard request cmd "/usr/local/share/junction/hooks/guard.sh"
|
||
|
||
# Response cache (memory only). ttl 0 disables it. Only complete, non-streamed 200
|
||
# answers are stored, keyed on method + path + model + body.
|
||
# Only /metrics, only read-only. A Prometheus in a container or on another host can
|
||
# scrape the numbers here without reaching the model port (and /admin) at all.
|
||
# metrics tcp 192.168.1.148:9180
|
||
|
||
cache_ttl 300
|
||
cache_entries 128
|
||
cache_bytes 33554432
|
||
|
||
# --------------------------------------------------------------------- endpoints
|
||
endpoint peer1 {
|
||
base http://192.0.2.10:8081/v1
|
||
kind remote
|
||
context 64000
|
||
priority 20
|
||
timeout 600
|
||
idle_timeout 60
|
||
cooldown 120
|
||
hook /opt/junction/hooks/check-http.sh
|
||
}
|
||
|
||
endpoint peer2 {
|
||
base http://192.0.2.10:8082/v1
|
||
kind remote
|
||
context 64000
|
||
priority 20
|
||
timeout 600
|
||
idle_timeout 60
|
||
cooldown 120
|
||
hook /opt/junction/hooks/check-http.sh
|
||
}
|
||
|
||
endpoint workstation {
|
||
base http://192.0.2.20:8080/v1
|
||
kind local
|
||
context 128000
|
||
priority 10
|
||
timeout 1800
|
||
idle_timeout 30
|
||
cooldown 60
|
||
hook_retry 180
|
||
hook_backoff 5
|
||
wake /opt/junction/hooks/wake-wol.sh
|
||
hook /opt/junction/hooks/check-http.sh
|
||
hook /opt/junction/hooks/check-budget.sh
|
||
}
|
||
|
||
endpoint cloud {
|
||
base https://api.example.com/v1
|
||
kind cloud
|
||
# Rückfall, keine Wahrheit: die Grenzen der Modelle holt junction beim Start aus
|
||
# der Modellliste des Endpunkts (GET /models → limit.context / limit.output).
|
||
# Diese Zahl gilt nur, wenn der Abruf scheitert oder das Modell dort fehlt.
|
||
context 200000
|
||
priority 90
|
||
timeout 900
|
||
idle_timeout 120
|
||
cache off # never store cloud answers
|
||
api_key_env EXAMPLE_API_KEY
|
||
# Zweites Konto, zweites Kontingent: die Zeile darf mehrfach stehen. Jeder Versuch
|
||
# nimmt den nächsten Schlüssel, ein 429 auf dem ersten wird also mit dem zweiten
|
||
# beantwortet, statt den Endpunkt aufzugeben.
|
||
# api_key_env EXAMPLE_API_KEY_2
|
||
tls_verify on # off only for a self-signed internal endpoint
|
||
# tls_ca /etc/junction/tls/internal-ca.pem
|
||
header "X-Title: olivia" # static header sent with every request here
|
||
}
|
||
|
||
# --------------------------------------------------------------------------- mcp
|
||
#
|
||
# junction wird dadurch selbst zum MCP-Server: ein Agent verbindet sich mit
|
||
# http://127.0.0.1:8090/mcp und sieht die Werkzeuge aller hier eingetragenen
|
||
# Server, mit dem Servernamen als Präfix ("tasksd__task_create"). Ein toter
|
||
# Server wird übersprungen, die übrigen Werkzeuge kommen trotzdem.
|
||
#
|
||
# mcp tasksd url http://127.0.0.1:8781/mcp
|
||
# mcp skilld url http://127.0.0.1:8790/mcp header "Authorization: Bearer CHANGE_ME"
|
||
# mcp_cache_ttl 60
|
||
|
||
# A virtual key is a token junction mints: the client sends it, the real upstream key
|
||
# never leaves the process. allow/endpoints restrict what the key may use; rpm and
|
||
# budget (USD per calendar month) limit what it may consume. Both optional.
|
||
# vkey "webui" token_env VKEY_WEBUI allow "deepseek-*" endpoints "cloud,peer1" rpm 60 budget 10
|
||
|
||
# A caller without a key is routed as before - a vkey is accounting, not a door.
|
||
|
||
# ------------------------------------------------------------------------- rules
|
||
# First matching rule wins. Rules may use:
|
||
# for <model-glob> need >N | <N | N path <glob>
|
||
# check hooks|none retry <seconds>
|
||
# pass <endpoint>[,<endpoint>...] [as <model>] | block
|
||
|
||
# A client that DECLARES more output than the peers can hold goes to the big box.
|
||
# 'need' reads max_tokens from the request; there is no character counting and no
|
||
# default, so a request that states nothing is not sized by guesswork.
|
||
req need >64000 pass workstation, cloud
|
||
|
||
# Coding work: prefer the workstation, wake it, wait up to 5 minutes for the hooks,
|
||
# and hand it the model name it actually serves.
|
||
req for "*coder*" check hooks retry 300 pass workstation as "Qwen3.8-Flash-Next-GSQ-RCO-IQ1_M"
|
||
req for "Qwen3.8-Flash-Next*" check hooks retry 60 pass workstation, peer1, peer2
|
||
|
||
# Cheap metadata calls never need a model at all.
|
||
req path "/v1/models" check none pass peer1, peer2, cloud
|
||
|
||
# Anything unseen is refused rather than silently sent to the cloud.
|
||
req for "*" block
|