Open-source inference server and production cluster for all the models your agent needs.
Python bgecolbertdata-pipelinedeep-learningembeddingsinferenceinference-serverinformation-retrievalllmmlmlopsnatural-language-processingnlppythonrerankingretrievalretrieval-augmented-generationsemantic-searchspladevector-search
fix(helm): require worker auth capability before startup
Attila Laszlo Nagy1e8f5615c2bd
diff --git a/deploy/helm/sie-cluster/README.md b/deploy/helm/sie-cluster/README.mdindex 88e433607..9ff8048ae 100644--- a/deploy/helm/sie-cluster/README.md+++ b/deploy/helm/sie-cluster/README.md@@ -1708,10 +1708,25 @@ health mode the gateway reaches the workers only through NATS. The Rust worker(`engine: candle`) serves only probes over HTTP and receives no token, and theworker sidecars do not serve the worker API.-Worker auth needs `sie-server` and `sie-gateway` images from this chart's-release (its `appVersion`) or later. Images of 0.10.1 and earlier ignore these-variables, so their workers serve without a token. A post-install and-post-upgrade hook Job, `<fullname>-worker-auth-test-<revision>`, checks this+Worker auth needs a `sie-server` image that supports+`serve --require-auth-mode=token|none` and a `sie-gateway` image that presents+`SIE_WORKER_AUTH_TOKEN`. The chart passes `--require-auth-mode=token` to every+Python worker while enforcing auth and `--require-auth-mode=none` during the+upgrade step. The worker asserts its resolved authentication mode before+creating a token or starting the server; the option does not override its+environment. Older worker CLIs reject the unknown option before serving,+including when a lane starts after scaling from zero. Auth-disabled workers+do not receive this option.++An image tag, including this chart's default `appVersion`, does not establish+these capabilities. The published v0.10.1 images predate worker auth; use+images built from source containing the required worker assertion and gateway+token forwarding before enabling it. A worker without the assertion will fail+startup, and a gateway without token forwarding cannot establish WebSocket+health against enforcing workers. No released minimum version is asserted.++A post-install and post-upgrade hook Job,+`<fullname>-worker-auth-test-<revision>`, additionally checks enforcementwhile the workers require the token: once a worker of each lane's currentStatefulSet revision is ready, it sends `GET /v1/models` without a token andfails the release when a worker answers with anything but `401`, when a ready@@ -1723,10 +1738,8 @@ minutes (a cold start longer than that) is skipped with a warning. The check isbest effort: a skipped lane is not checked until a later release finds itrunning. The Job stays for a day after it finishes, so its log(`kubectl logs -n <namespace> job/<fullname>-worker-auth-test-<revision>`)-shows which workers it checked and which lanes it skipped. Keep the image tags-at the chart default, or override `workers.common.image.tag` only with a tag of-the same release or later: with `workers.auth.enabled`, the render fails when-that tag is a version older than the chart's `appVersion`.+shows which workers it checked and which lanes it skipped. The startup+assertion remains required even when this best-effort hook skips a lane.With `workers.auth.tokenSecretName` empty, the chart creates`<fullname>-worker-token` holding a random 64-character token under@@ -1764,8 +1777,9 @@ helm upgrade sie-cluster oci://ghcr.io/superlinked/charts/sie-cluster \--set workers.auth.allowUnauthenticated=true```-This step rolls only the gateway. Once every gateway pod has restarted,-require the token:+This step rolls the gateway and the Python workers, adding the startup+capability assertion while workers still accept unauthenticated requests.+Wait for both rollouts to finish successfully, then require the token:```bashhelm upgrade sie-cluster oci://ghcr.io/superlinked/charts/sie-cluster \diff --git a/deploy/helm/sie-cluster/templates/_helpers.tpl b/deploy/helm/sie-cluster/templates/_helpers.tplindex 327409f53..f86c05e32 100644--- a/deploy/helm/sie-cluster/templates/_helpers.tpl+++ b/deploy/helm/sie-cluster/templates/_helpers.tpl@@ -1060,10 +1060,6 @@ two-step upgrade and needs workers.auth.enabled.{{- if and $allowUnauthenticated (not (include "sie-cluster.workers.authEnabled" .)) -}}{{- fail "workers.auth.allowUnauthenticated=true needs workers.auth.enabled=true: it is the first step of the two-step upgrade, in which the gateway presents the worker token and the workers do not require it yet. Set workers.auth.enabled=true with it, or remove it." -}}{{- end -}}-{{- $tag := toString (dig "common" "image" "tag" "" (.Values.workers | default dict)) -}}-{{- if and (include "sie-cluster.workers.authEnabled" .) .Chart.AppVersion (regexMatch "^v?[0-9]+\\.[0-9]+\\.[0-9]+$" $tag) (semverCompare (printf "<%s" .Chart.AppVersion) $tag) -}}-{{- fail (printf "workers.auth.enabled needs sie-server images from this chart's release (%s) or later, which enforce the worker token; workers.common.image.tag=%s is older, so its workers would serve without a token. Remove the tag override or set a tag of this release or later." .Chart.AppVersion $tag) -}}-{{- end -}}{{- end }}{{/*diff --git a/deploy/helm/sie-cluster/templates/hooks/worker-auth-test.yaml b/deploy/helm/sie-cluster/templates/hooks/worker-auth-test.yamlindex 85bd14d80..1f4db2658 100644--- a/deploy/helm/sie-cluster/templates/hooks/worker-auth-test.yaml+++ b/deploy/helm/sie-cluster/templates/hooks/worker-auth-test.yaml@@ -146,7 +146,7 @@ spec:unreached=$((unreached + 1)) ;;*)echo "FAILED: $lane $address answered GET /v1/models without a token (HTTP $code)."- echo "Its sie-server image does not enforce workers.auth. Use worker images from the same release as the chart."+ echo "Its sie-server image does not enforce workers.auth. Use worker images that support serve --require-auth-mode=token."exit 1 ;;esacdonediff --git a/deploy/helm/sie-cluster/templates/worker-statefulset.yaml b/deploy/helm/sie-cluster/templates/worker-statefulset.yamlindex 6be727df8..2dfc87d12 100644--- a/deploy/helm/sie-cluster/templates/worker-statefulset.yaml+++ b/deploy/helm/sie-cluster/templates/worker-statefulset.yaml@@ -332,6 +332,9 @@ spec:imagePullPolicy: {{ $root.Values.workers.common.image.pullPolicy }}args:- serve+ {{- if include "sie-cluster.workers.authEnabled" $root }}+ - --require-auth-mode={{ ternary "token" "none" (not (empty $workerAuthEnforced)) }}+ {{- end }}- --host=0.0.0.0- --port={{ $workerPort }}- --bundle={{ $bundle }}diff --git a/deploy/helm/sie-cluster/values.yaml b/deploy/helm/sie-cluster/values.yamlindex 453b581d1..b72af4176 100644--- a/deploy/helm/sie-cluster/values.yaml+++ b/deploy/helm/sie-cluster/values.yaml@@ -911,10 +911,12 @@ workers:# -- Worker API authentication. When enabled, the gateway presents the# worker token (SIE_WORKER_AUTH_TOKEN) and each worker container that serves# the worker API requires it (SIE_AUTH_MODE=token, SIE_AUTH_TOKEN) on every- # route except the probes /healthz, /livez, and /readyz. It needs sie-server- # and sie-gateway images from this chart's release (appVersion) or later:- # images of 0.10.1 and earlier ignore these variables and serve without a- # token. A post-install and post-upgrade hook Job fails the release when a+ # route except the probes /healthz, /livez, and /readyz. The sie-server+ # image must support serve --require-auth-mode=token|none; the gateway must+ # present SIE_WORKER_AUTH_TOKEN. Image version tags do not prove support.+ # Published v0.10.1 images predate these capabilities. Unsupported worker+ # CLIs reject the required option before serving, including after scale-up+ # from zero. A post-install and post-upgrade hook Job fails the release when a# ready worker of the current revision answers GET /v1/models without a# token or does not answer; the worker NetworkPolicies admit that Job's pod.# With worker auth off, the chart sets SIE_AUTH_MODE=none on those@@ -925,7 +927,8 @@ workers:enabled: false# -- With enabled, the gateway presents the token but the workers do not# require it yet (a boolean). A temporary aid for the two-step upgrade:- # once every gateway pod has restarted, upgrade again with+ # this step rolls the gateway and Python workers. Once both rollouts+ # complete successfully, upgrade again with# `--set workers.auth.allowUnauthenticated=false`; `--reuse-values` and# `--reset-then-reuse-values` keep it on. It fails the render without# enabled.diff --git a/packages/sie_server/src/sie_server/cli.py b/packages/sie_server/src/sie_server/cli.pyindex ab7987419..ad9b2b1d7 100644--- a/packages/sie_server/src/sie_server/cli.py+++ b/packages/sie_server/src/sie_server/cli.py@@ -27,6 +27,7 @@ import hashlibimport loggingimport shlexfrom collections.abc import Iterable+from enum import StrEnumfrom pathlib import Pathfrom typing import Annotated@@ -151,6 +152,11 @@ _SECURE_DEFAULTS_RELEASE = "0.13.0"SERVER_HOST_ENV = "SIE_SERVER_HOST"+class RequiredAuthMode(StrEnum):+ NONE = "none"+ TOKEN = "token" # noqa: S105 - an authentication mode, not a credential++def _stderr_is_terminal() -> bool:return sys.stderr.isatty()@@ -179,7 +185,9 @@ def _echo_generated_token(stored: StoredToken, port: int) -> None:typer.echo("\n".join([rule, *lines, rule]), err=True)-def _prepare_auth(*, host: str, port: int, host_is_default: bool) -> AuthMode:+def _prepare_auth(+ *, host: str, port: int, host_is_default: bool, require_auth_mode: RequiredAuthMode | None = None+) -> AuthMode:"""Resolve the server's auth mode, provision its token, and warn about exposure."""exposed = not is_loopback_host(host)requested = requested_mode(os.environ)@@ -192,6 +200,10 @@ def _prepare_auth(*, host: str, port: int, host_is_default: bool) -> AuthMode:typer.echo(f"Error: {exc}", err=True)raise typer.Exit(1) from None+ if require_auth_mode is not None and mode != require_auth_mode.value:+ typer.echo("Error: resolved authentication mode does not match --require-auth-mode", err=True)+ raise typer.Exit(1)+if mode == "token" and tokens:typer.echo(f"Auth: every route except /healthz, /livez and /readyz requires one of {len(tokens)} token(s)")elif mode == "token":@@ -503,6 +515,13 @@ def serve(),),] = None,+ require_auth_mode: Annotated[+ RequiredAuthMode | None,+ typer.Option(+ "--require-auth-mode",+ help="Require the resolved authentication mode without changing its configuration.",+ ),+ ] = None,) -> None:"""Start the SIE inference server."""from sie_sdk.storage import is_cloud_path@@ -744,6 +763,7 @@ def serve(host=host,port=port,host_is_default=_parameter_source("host") in (None, ParameterSource.DEFAULT),+ require_auth_mode=require_auth_mode,)typer.echo(f"Starting SIE server on {host}:{port}")diff --git a/packages/sie_server/tests/test_cli_auth.py b/packages/sie_server/tests/test_cli_auth.pyindex cce53beec..82f6f28d1 100644--- a/packages/sie_server/tests/test_cli_auth.py+++ b/packages/sie_server/tests/test_cli_auth.py@@ -6,6 +6,7 @@ import osfrom collections.abc import Iteratorfrom pathlib import Pathfrom typing import Any+from unittest.mock import Mockimport pytestfrom sie_server import cli@@ -14,6 +15,7 @@ from sie_server.core.server_auth import token_pathfrom typer.testing import CliRunnerTOKEN = "s3cret-token-value" # noqa: S105 - test credential+EXPOSED_HOST = "0.0.0.0" # noqa: S104 - no server is started@pytest.fixture(autouse=True)@@ -250,3 +252,141 @@ def test_auth_modes_are_case_sensitive_as_on_the_gateway(assert result.exit_code == 1assert "lowercase" in result.outputassert not started+++ ("mode", "token", "host", "required", "generated"),+ [+ (None, None, EXPOSED_HOST, "none", False),+ ("none", None, EXPOSED_HOST, "none", False),+ (None, TOKEN, EXPOSED_HOST, "token", False),+ ("token", TOKEN, EXPOSED_HOST, "token", False),+ ("static", TOKEN, EXPOSED_HOST, "token", False),+ ("auto", TOKEN, "127.0.0.1", "token", False),+ ("auto", None, "127.0.0.1", "none", False),+ ("auto", None, EXPOSED_HOST, "token", True),+ ("token", None, "127.0.0.1", "token", True),+ ("static", None, "127.0.0.1", "token", True),+ ],+)+def test_required_auth_mode_matches_existing_resolution(+ started: dict[str, Any],+ monkeypatch: pytest.MonkeyPatch,+ tmp_path: Path,+ mode: str | None,+ token: str | None,+ host: str,+ required: str,+ generated: bool,+) -> None:+ if mode is not None:+ monkeypatch.setenv("SIE_AUTH_MODE", mode)+ if token is not None:+ monkeypatch.setenv("SIE_AUTH_TOKEN", token)+ monkeypatch.setattr(cli, "_stderr_is_terminal", lambda: False)++ result = serve("--host", host, "--require-auth-mode", required)++ assert result.exit_code == 0, result.output+ assert resolved_mode(started) == required+ assert token_path(tmp_path / "data").exists() is generated+ assert os.environ.get("SIE_AUTH_MODE") == mode+ assert os.environ.get("SIE_AUTH_TOKEN") == token+ assert TOKEN not in result.output+++def no_token_provisioning(monkeypatch: pytest.MonkeyPatch) -> Iterator[None]:+ directory = Mock(side_effect=AssertionError("unexpected token directory resolution"))+ token = Mock(side_effect=AssertionError("unexpected token provisioning"))+ monkeypatch.setattr(cli, "resolve_data_dir", directory)+ monkeypatch.setattr(cli, "load_or_create_token", token)+ yield+ directory.assert_not_called()+ token.assert_not_called()+++ ("mode", "token", "host", "required"),+ [+ (None, None, EXPOSED_HOST, "token"),+ ("none", None, EXPOSED_HOST, "token"),+ ("token", None, "127.0.0.1", "none"),+ ("static", None, "127.0.0.1", "none"),+ (None, TOKEN, "127.0.0.1", "none"),+ ("auto", None, EXPOSED_HOST, "none"),+ ("auto", None, "127.0.0.1", "token"),+ ],+)[email protected]("no_token_provisioning")+def test_required_auth_mode_mismatch_stops_before_provisioning_or_serving(+ started: dict[str, Any],+ monkeypatch: pytest.MonkeyPatch,+ tmp_path: Path,+ mode: str | None,+ token: str | None,+ host: str,+ required: str,+) -> None:+ if mode is not None:+ monkeypatch.setenv("SIE_AUTH_MODE", mode)+ if token is not None:+ monkeypatch.setenv("SIE_AUTH_TOKEN", token)++ result = serve("--host", host, "--require-auth-mode", required)++ assert result.exit_code == 1+ assert "resolved authentication mode does not match --require-auth-mode" in result.output+ assert not started+ assert not (tmp_path / "data").exists()+ assert os.environ.get("SIE_AUTH_MODE") == mode+ assert os.environ.get("SIE_AUTH_TOKEN") == token+ assert TOKEN not in result.output++[email protected]("required", ["", "auto", "static", "TOKEN", "None", " token", "unknown"])[email protected]("no_token_provisioning")+def test_required_auth_mode_rejects_invalid_option_before_auth_resolution(+ started: dict[str, Any], monkeypatch: pytest.MonkeyPatch, required: str+) -> None:+ prepare = Mock(side_effect=AssertionError("unexpected auth resolution"))+ monkeypatch.setattr(cli, "_prepare_auth", prepare)++ result = serve("--require-auth-mode", required)++ assert result.exit_code == 2+ assert "Invalid value" in result.output+ prepare.assert_not_called()+ assert not started++[email protected]("name", ["SIE_AUTH_TOKEN", "SIE_AUTH_TOKENS"])[email protected]("value", ["", " ", ","])[email protected]("required", ["token", "none"])[email protected]("no_token_provisioning")+def test_required_auth_mode_does_not_bypass_blank_token_refusal(+ started: dict[str, Any], monkeypatch: pytest.MonkeyPatch, name: str, value: str, required: str+) -> None:+ monkeypatch.setenv(name, value)++ result = serve("--require-auth-mode", required)++ assert result.exit_code == 1+ assert "holds no token" in result.output+ assert not started++[email protected]("required", ["token", "none"])[email protected]("no_token_provisioning")+def test_required_auth_mode_does_not_override_auth_off_with_token_refusal(+ started: dict[str, Any], monkeypatch: pytest.MonkeyPatch, required: str+) -> None:+ monkeypatch.setenv("SIE_AUTH_MODE", "none")+ monkeypatch.setenv("SIE_AUTH_TOKEN", TOKEN)++ result = serve("--require-auth-mode", required)++ assert result.exit_code == 1+ assert "SIE_AUTH_MODE=none turns authentication off" in result.output+ assert TOKEN not in result.output+ assert not starteddiff --git a/tools/ci/tests/test_helm_render.py b/tools/ci/tests/test_helm_render.pyindex 3a156ff69..e8210cb99 100644--- a/tools/ci/tests/test_helm_render.py+++ b/tools/ci/tests/test_helm_render.py@@ -3893,13 +3893,14 @@ def older_version(version: str) -> str:return f"v{major}.{minor}.{patch - 1}" if patch else f"v{major}.{minor - 1}.0" if minor else f"v{major - 1}.0.0"-def test_worker_auth_refuses_a_worker_image_tag_older_than_the_chart(tmp_path: Path) -> None:- tag = older_version(chart_app_version())- workers = {"auth": {"enabled": True}, "common": {"image": {"tag": tag}}, **L4_POOL["workers"]}- error = render_error(tmp_path, {"workers": workers})- assert f"workers.common.image.tag={tag} is older" in error- workers["auth"]["allowUnauthenticated"] = True- assert f"workers.common.image.tag={tag} is older" in render_error(tmp_path, {"workers": workers})+def worker_auth_requirements(docs: list[dict]) -> dict[str, list[str]]:+ return {+ f"{doc['metadata']['name']}/{container['name']}": requirements+ for doc in docs+ if doc["kind"] in {"Deployment", "StatefulSet"}+ for container in doc["spec"]["template"]["spec"]["containers"]+ if (requirements := [arg for arg in container.get("args", []) if arg.startswith("--require-auth-mode=")])+ }@pytest.mark.parametrize(@@ -3909,13 +3910,89 @@ def test_worker_auth_refuses_a_worker_image_tag_older_than_the_chart(tmp_path: P({"enabled": True}, "same"),({"enabled": True}, "v99.0.0"),({"enabled": True}, "main"),+ ({"enabled": True}, "older"),({}, "older"),],)-def test_worker_image_tags_that_enforce_or_cannot_be_compared_render(+def test_worker_auth_requires_runtime_capability_independently_of_image_tag(tmp_path: Path, auth: dict, tag: str | None) -> None:version = chart_app_version()tags = {"same": version, "older": older_version(version)}common = {"image": {"tag": tags.get(tag, tag)}} if tag else {}- rendered_documents(tmp_path, {"workers": {"auth": auth, "common": common, **L4_POOL["workers"]}})+ docs = rendered_documents(tmp_path, {"workers": {"auth": auth, "common": common, **L4_POOL["workers"]}})+ expected = {L4_WORKER: ["--require-auth-mode=token"]} if auth.get("enabled") else {}+ assert worker_auth_requirements(docs) == expected++[email protected]("tag", [None, "v0.10.1"], ids=["default-image", "explicit-v0.10.1"])[email protected]("allow_unauthenticated", [False, True], ids=["enforced", "upgrade-step"])+def test_worker_auth_requires_capability_for_default_and_legacy_image_tags(+ tmp_path: Path, tag: str | None, allow_unauthenticated: bool+) -> None:+ common = {"image": {"tag": tag}} if tag is not None else {}+ workers = {+ "auth": {"enabled": True, "allowUnauthenticated": allow_unauthenticated},+ "common": common,+ **L4_POOL["workers"],+ }+ docs = rendered_documents(tmp_path, {"workers": workers})+ mode = "none" if allow_unauthenticated else "token"+ assert worker_auth_requirements(docs) == {L4_WORKER: [f"--require-auth-mode={mode}"]}++[email protected]("allow_unauthenticated", [False, True])+def test_worker_auth_capability_covers_every_python_child_even_at_zero_replicas(+ tmp_path: Path, allow_unauthenticated: bool+) -> None:+ pools = {+ "l4": {+ "enabled": True,+ "gpu": {"count": 2},+ "bundles": {"default": {"minReplicas": 0, "maxReplicas": 1}},+ },+ "cpu": {+ "enabled": True,+ "bundles": {"candle": {"engine": "candle", "minReplicas": 0, "maxReplicas": 1}},+ },+ }+ auth = {"enabled": True, "allowUnauthenticated": allow_unauthenticated}+ docs = rendered_documents(tmp_path, {"workers": {"auth": auth, "pools": pools}})+ mode = "none" if allow_unauthenticated else "token"+ assert worker_auth_requirements(docs) == {+ "sie-sie-cluster-worker-l4-default/worker-0": [f"--require-auth-mode={mode}"],+ "sie-sie-cluster-worker-l4-default/worker-1": [f"--require-auth-mode={mode}"],+ "sie-sie-cluster-worker-cpu-default/worker": [f"--require-auth-mode={mode}"],+ }+ (lane,) = [doc for doc in docs if doc["kind"] == "StatefulSet" and doc["metadata"]["name"].endswith("l4-default")]+ assert lane["spec"]["replicas"] == 0++[email protected]("allow_unauthenticated", [False, True])+def test_worker_auth_capability_covers_the_remote_lane(tmp_path: Path, allow_unauthenticated: bool) -> None:+ values = remote_pool_values()+ values["workers"]["auth"] = {"enabled": True, "allowUnauthenticated": allow_unauthenticated}+ mode = "none" if allow_unauthenticated else "token"+ assert worker_auth_requirements(rendered_documents(tmp_path, values)) == {+ "sie-sie-cluster-worker-remote-remote/worker": [f"--require-auth-mode={mode}"],+ }+++def test_worker_auth_hook_failure_recommends_the_required_capability(tmp_path: Path) -> None:+ docs = rendered_documents(tmp_path, {"workers": {"auth": {"enabled": True}, **L4_POOL["workers"]}})+ (job,) = [doc for doc in docs if doc["kind"] == "Job" and doc["metadata"]["name"] == WORKER_AUTH_TEST_JOB]+ script = job["spec"]["template"]["spec"]["containers"][0]["args"][0]+ assert "Use worker images that support serve --require-auth-mode=token." in script+ assert "same release as the chart" not in script++[email protected]("tag", [None, "v0.10.1"], ids=["default-image", "explicit-v0.10.1"])[email protected]("auth", [{}, {"enabled": False}], ids=["default-auth", "explicit-auth-off"])+def test_worker_auth_off_preserves_existing_image_compatibility(tmp_path: Path, tag: str | None, auth: dict) -> None:+ common = {"image": {"tag": tag}} if tag is not None else {}+ docs = rendered_documents(tmp_path, {"workers": {"auth": auth, "common": common, **L4_POOL["workers"]}})+ env = container_env(docs, "sie-sie-cluster-worker-l4-default", "worker")+ assert env["SIE_AUTH_MODE"] == {"name": "SIE_AUTH_MODE", "value": "none"}+ assert "SIE_AUTH_TOKEN" not in env+ assert WORKER_AUTH_TEST_JOB not in hook_jobs(docs)+ assert worker_auth_requirements(docs) == {}