Pull requests / #3366

#3366 [Other] Let a trusted LAN serve without an API key via STRATA_ALLOW_KEYLESS_BIND env variable

open · @dsenchankau · 0 Kommentare · Auf GitHub

Server & API

Beschreibung

## Problem and result

Since v0.2.0-beta, the server started on `0.0.0.0` refuses with `a non-loopback bind requires an inference API key` and exit 2; Although `0.0.0.0` is not loopback, it's my local network, behind a firewall, and nothing else reaches it.

Now, if you set `STRATA_ALLOW_KEYLESS_BIND=1` in the environment where strata starts, both `strata serve` and `launch` checks let the keyless bind through. The server prints a warning at startup so a stray env var stays visible: `STRATA_ALLOW_KEYLESS_BIND is set: anyone who can reach this port can use the model`. Unset or empty, nothing changes, same refusal, same message.

## Approach

One helper, `keyless_bind_allowed()`, next to `api_key_of` in `serve/server.py`. Both gates call it: the server startup check and `_launch_plan` in `strata_cli/cli.py`, which already imports from `serve.server`. The gate checks the effective host, so it doesn't matter whether the host comes from the run config or from `--host`. It is an env var rather than a flag: the check runs in the process that starts the server, and a flag would need plumbing through launch, the TUI and the app. It is only read when the bind is non-loopback and no key was configured.

## Validation

Passed:

- `.venv/bin/python -m unittest tests.terminal.test_profiles` — 22 tests, `OK`. The new `test_keyless_non_loopback_bind_needs_the_opt_in_env` plans a profile with `host=0.0.0.0`, expects the refusal, and expects the plan to pass with the env var set.
- `.venv/bin/python -m unittest tests.terminal.test_launch` — `OK`.
- `.venv/bin/python -m py_compile serve/server.py strata_cli/cli.py` — no output (compiles).
- `STRATA_ALLOW_KEYLESS_BIND=1 python serve/server.py --engine strata --config <run config> --host 0.0.0.0 --port 1337` — the server started, no `[strata] a non-loopback bind requires an inference API key` error.

Failed:

- None observed.

Not run:

- N/A

## Limits

- The config JSON's `env` field doesn't help: it feeds the engine subprocess, the gate reads the server's own environment at startup.
- If the owner-host daemon starts the server, set the var in the daemon's environment.
- No `--allow-keyless` flag, nothing in the app or TUI.

Mehr auf der Site

Links zu Install, Modellen, Releases.