From b1d062d994b5bd2095464d2abc27f0351080e25d Mon Sep 17 00:00:00 2001 From: Christopher Kevin Date: Thu, 19 Nov 2026 23:35:05 -0800 Subject: [PATCH 01/11] fix: update LiteLLM and handle Bedrock HTTPS endpoints Signed-off-by: Christopher Kevin --- CHANGELOG.md | 5 ++ docs/tier3-runtime.mdx | 5 +- pyproject.toml | 2 +- .../tier3/harbor/runtime_preflight.py | 1 + tests/conftest.py | 38 ++++++++++++ tests/test_harbor_runtime_preflight.py | 13 +++- tests/test_oss_packaging.py | 11 ++-- tests/test_retry_provider_transport.py | 41 +------------ uv.lock | 59 +++++++++---------- 9 files changed, 93 insertions(+), 82 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cac462d62..a4b1e1ff8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to SkillEvaluator are documented in this file. ## Unreleased +### Security + +- Update LiteLLM in the optional LLM and Tier 3 installs. Bedrock reports + invalid bearer-token endpoints as configuration errors. + ### Changed - Claude Code log recovery pairs batched and delayed tool results without repeatedly diff --git a/docs/tier3-runtime.mdx b/docs/tier3-runtime.mdx index 7f9437d3c..0f78541b9 100644 --- a/docs/tier3-runtime.mdx +++ b/docs/tier3-runtime.mdx @@ -167,9 +167,8 @@ The exact Harbor pin is deliberate: its CLI, Python models, result artifacts, and environment/agent subclass interfaces form one compatibility surface. This release targets stable Harbor 0.25.0 rather than unreleased `main`. Harbor stays behind the operator-selected `tier3` extra, so static Tier 1 installs do not pull -it in. The shared LLM client window (`litellm>=1.92.0,<1.94.0.dev0`) admits -patched 1.92 and 1.93 releases validated with this integration while excluding -prerelease and as-yet unvalidated 1.94 behavior. +it in. The shared LLM client uses `litellm>=1.110.2,<1.111.0.dev0`. Bedrock +bearer-token authentication requires HTTPS, including for custom endpoints. The integration preserves SkillEvaluator's runtime and artifact contracts while using Harbor 0.25: diff --git a/pyproject.toml b/pyproject.toml index a4f9a6cf9..7063b7298 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -60,7 +60,7 @@ dependencies = [ llm = [ "anthropic>=0.83.0", "boto3>=1.34.0", - "litellm>=1.92.0,<1.94.0.dev0", + "litellm>=1.110.2,<1.111.0.dev0", "openai>=2.21.0", ] # Tier 2 intra-skill deduplication and local-catalog inter-skill similarity. diff --git a/src/skillevaluator/tier3/harbor/runtime_preflight.py b/src/skillevaluator/tier3/harbor/runtime_preflight.py index 7c6b03e6b..8951385c9 100644 --- a/src/skillevaluator/tier3/harbor/runtime_preflight.py +++ b/src/skillevaluator/tier3/harbor/runtime_preflight.py @@ -161,6 +161,7 @@ class CredentialProbeDisposition(StrEnum): for _error_name, _target in ( ("LoginError", "authentication"), ("InvalidChecksumConfigError", "configuration"), + ("InvalidEndpointConfigurationError", "configuration"), ("UnknownTokenProviderError", "configuration"), ("UnsupportedServiceProtocolsError", "configuration"), ): diff --git a/tests/conftest.py b/tests/conftest.py index 8cd282122..46461f7ba 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -9,9 +9,12 @@ from __future__ import annotations import importlib.util +import ipaddress import json +import ssl import sys from collections.abc import Callable +from datetime import UTC, datetime, timedelta from pathlib import Path from types import ModuleType from typing import Any @@ -19,6 +22,41 @@ import pytest +@pytest.fixture +def loopback_tls(tmp_path: Path) -> tuple[ssl.SSLContext, Path]: + """Create a loopback TLS context and the certificate clients can trust.""" + x509 = pytest.importorskip("cryptography.x509") + from cryptography.hazmat.primitives import hashes, serialization + from cryptography.hazmat.primitives.asymmetric import rsa + from cryptography.x509.oid import NameOID + + key = rsa.generate_private_key(public_exponent=65537, key_size=2048) + name = x509.Name([x509.NameAttribute(NameOID.COMMON_NAME, "localhost")]) + certificate = ( + x509.CertificateBuilder() + .subject_name(name) + .issuer_name(name) + .public_key(key.public_key()) + .serial_number(x509.random_serial_number()) + .not_valid_before(datetime.now(UTC) - timedelta(days=1)) + .not_valid_after(datetime.now(UTC) + timedelta(days=1)) + .add_extension(x509.SubjectAlternativeName([x509.IPAddress(ipaddress.ip_address("127.0.0.1"))]), False) + .sign(key, hashes.SHA256()) + ) + cert_path, key_path = tmp_path / "certificate.pem", tmp_path / "key.pem" + cert_path.write_bytes(certificate.public_bytes(serialization.Encoding.PEM)) + key_path.write_bytes( + key.private_bytes( + serialization.Encoding.PEM, + serialization.PrivateFormat.PKCS8, + serialization.NoEncryption(), + ) + ) + context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER) + context.load_cert_chain(cert_path, key_path) + return context, cert_path + + @pytest.fixture(autouse=True) def _isolate_output_provenance_key(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None: """Keep every test away from the developer's persistent provenance key.""" diff --git a/tests/test_harbor_runtime_preflight.py b/tests/test_harbor_runtime_preflight.py index a904d2baa..150146469 100644 --- a/tests/test_harbor_runtime_preflight.py +++ b/tests/test_harbor_runtime_preflight.py @@ -10,6 +10,7 @@ import hashlib import json import os +import ssl import subprocess import sys from concurrent.futures import ThreadPoolExecutor @@ -33,6 +34,7 @@ EndpointProviderError, InvalidConfigError, InvalidDefaultsMode, + InvalidEndpointConfigurationError, InvalidIMDSEndpointError, InvalidIMDSEndpointModeError, InvalidProxiesConfigError, @@ -1601,6 +1603,7 @@ def client(self, service_name: str, **_kwargs): def test_bedrock_bearer_token_only_uses_real_catalog_transport( monkeypatch: pytest.MonkeyPatch, tmp_path: Path, + loopback_tls: tuple[ssl.SSLContext, Path], status_code: int, expected_ok: bool, expected_kind: str | None, @@ -1636,21 +1639,24 @@ def log_message(self, _format, *_args) -> None: config="[profile test]\nregion = us-west-2\n", ) monkeypatch.setenv("AWS_BEARER_TOKEN_BEDROCK", "test-bearer-token") + tls_context, ca_bundle = loopback_tls + monkeypatch.setenv("AWS_CA_BUNDLE", str(ca_bundle)) provider = ProviderConfig("bedrock", "test-model", None, None, "bedrock/test-model", region="us-west-2") with ThreadingHTTPServer(("127.0.0.1", 0), CatalogResponse) as server: - endpoint = f"http://127.0.0.1:{server.server_port}" + server.socket = tls_context.wrap_socket(server.socket, server_side=True) + endpoint = f"https://127.0.0.1:{server.server_port}" monkeypatch.setenv("AWS_ENDPOINT_URL_BEDROCK", endpoint) monkeypatch.setenv("AWS_ENDPOINT_URL_BEDROCK_RUNTIME", endpoint) worker = Thread(target=server.serve_forever, daemon=True) worker.start() try: - result = runtime_preflight.probe_model(provider, timeout_seconds=5) + result = runtime_preflight.probe_model(provider, timeout_seconds=15) finally: server.shutdown() worker.join(timeout=5) - assert seen_authorization == [True] + assert seen_authorization == [True], result.detail assert result.ok is expected_ok assert result.failure_kind == expected_kind assert runtime_preflight.credential_probe_disposition(provider, result) == expected_disposition @@ -2160,6 +2166,7 @@ def log_message(self, _format, *_args) -> None: (EndpointProviderError(msg="private endpoint detail"), "invalid_configuration"), (InvalidConfigError(error_msg="invalid profile"), "invalid_configuration"), (InvalidDefaultsMode(mode="private mode", valid_modes=["standard"]), "invalid_configuration"), + (InvalidEndpointConfigurationError(msg="private endpoint details"), "invalid_configuration"), (InvalidIMDSEndpointError(endpoint="private endpoint"), "invalid_configuration"), ( InvalidIMDSEndpointModeError(mode="private mode", valid_modes=["ipv4", "ipv6"]), diff --git a/tests/test_oss_packaging.py b/tests/test_oss_packaging.py index acf8d571d..ea5763ec3 100644 --- a/tests/test_oss_packaging.py +++ b/tests/test_oss_packaging.py @@ -18,6 +18,7 @@ from click.testing import CliRunner from packaging.requirements import Requirement +from packaging.specifiers import SpecifierSet from packaging.utils import canonicalize_name from packaging.version import Version @@ -159,9 +160,9 @@ def test_harbor_dependency_contract_keeps_base_install_isolated() -> None: assert str(harbor_requirements[0].specifier) == f"=={HARBOR_VERSION}" assert len(litellm_requirements) == 1 litellm_specifier = litellm_requirements[0].specifier - assert litellm_specifier.contains(Version("1.92.0"), prereleases=True) - assert litellm_specifier.contains(Version("1.93.0"), prereleases=True) - assert not litellm_specifier.contains(Version("1.94.0.dev0"), prereleases=True) + assert not litellm_specifier.contains(Version("1.93.2"), prereleases=True) + assert litellm_specifier.contains(Version("1.110.2"), prereleases=True) + assert not litellm_specifier.contains(Version("1.111.0.dev0"), prereleases=True) declared_names = base_names | { canonicalize_name(Requirement(raw).name) for requirements in extras.values() for raw in requirements } @@ -181,7 +182,7 @@ def test_harbor_dependency_contract_keeps_base_install_isolated() -> None: locked_harbor = [requirement for requirement in locked_requirements if requirement["name"] == "harbor"] locked_litellm = [requirement for requirement in locked_requirements if requirement["name"] == "litellm"] assert [requirement["specifier"] for requirement in locked_harbor] == [f"=={HARBOR_VERSION}"] - assert [requirement["specifier"] for requirement in locked_litellm] == [">=1.92.0,<1.94.0.dev0"] + assert [SpecifierSet(requirement["specifier"]) for requirement in locked_litellm] == [litellm_specifier] def test_harbor_environment_extra_mapping_matches_installed_metadata() -> None: @@ -923,7 +924,7 @@ def test_tier3_docs_name_the_supported_harbor_backend_version() -> None: assert f"The `tier3` extra installs Harbor {HARBOR_VERSION}" in normalized assert "The exact Harbor pin is deliberate" in normalized assert f"stable Harbor {HARBOR_VERSION} rather than unreleased `main`" in normalized - assert "litellm>=1.92.0,<1.94.0.dev0" in normalized + assert "litellm>=1.110.2,<1.111.0.dev0" in normalized assert "static Tier 1 installs do not pull it in" in normalized assert "0.13.2" not in normalized assert "0.22.0" not in normalized diff --git a/tests/test_retry_provider_transport.py b/tests/test_retry_provider_transport.py index b9a964c8c..c2db5e842 100644 --- a/tests/test_retry_provider_transport.py +++ b/tests/test_retry_provider_transport.py @@ -9,14 +9,11 @@ import json import os import socket -import ssl import threading import urllib.error import urllib.request from contextlib import contextmanager -from datetime import UTC, datetime, timedelta from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer -from pathlib import Path import pytest @@ -249,48 +246,16 @@ def test_provider_http_status_survives_sdk_wrapping( assert extract_http_status(raised.value) == status -def _untrusted_tls_context(tmp_path: Path): - x509 = pytest.importorskip("cryptography.x509") - from cryptography.hazmat.primitives import hashes, serialization - from cryptography.hazmat.primitives.asymmetric import rsa - from cryptography.x509.oid import NameOID - - key = rsa.generate_private_key(public_exponent=65537, key_size=2048) - name = x509.Name([x509.NameAttribute(NameOID.COMMON_NAME, "localhost")]) - certificate = ( - x509.CertificateBuilder() - .subject_name(name) - .issuer_name(name) - .public_key(key.public_key()) - .serial_number(x509.random_serial_number()) - .not_valid_before(datetime.now(UTC) - timedelta(days=1)) - .not_valid_after(datetime.now(UTC) + timedelta(days=1)) - .add_extension(x509.SubjectAlternativeName([x509.IPAddress(ipaddress.ip_address("127.0.0.1"))]), False) - .sign(key, hashes.SHA256()) - ) - cert_path, key_path = tmp_path / "certificate.pem", tmp_path / "key.pem" - cert_path.write_bytes(certificate.public_bytes(serialization.Encoding.PEM)) - key_path.write_bytes( - key.private_bytes( - serialization.Encoding.PEM, - serialization.PrivateFormat.PKCS8, - serialization.NoEncryption(), - ) - ) - context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER) - context.load_cert_chain(cert_path, key_path) - return context - - @pytest.mark.parametrize("provider", ["bedrock", "openai"]) def test_provider_certificate_failure_is_not_retried( isolated_provider_environment, monkeypatch, - tmp_path, + loopback_tls, provider, record_property, ): - with _server([503], _untrusted_tls_context(tmp_path)) as server: + tls_context, _ = loopback_tls + with _server([503], tls_context) as server: client = _client(monkeypatch, f"https://127.0.0.1:{server.server_port}", provider) with pytest.raises(Exception) as raised: client.completions("system", "user") diff --git a/uv.lock b/uv.lock index 802ea9b9c..d78e2504d 100644 --- a/uv.lock +++ b/uv.lock @@ -231,30 +231,30 @@ wheels = [ [[package]] name = "boto3" -version = "1.43.40" +version = "1.44.7" source = { registry = "https://pypi.org/simple" } dependencies = [ { name = "botocore" }, { name = "jmespath" }, { name = "s3transfer" }, ] -sdist = { url = "https://files.pythonhosted.org/packages/3b/43/38cdaf9c7bb50f0922ef87e6b6696c6aa589d978e4311a8287537e84ecf7/boto3-1.43.40.tar.gz", hash = "sha256:a7108b9ce25b8f92d1ce96b9e35090794d5c58b219ff2f6a7a65c8986a4ed6f4", size = 112655, upload-time = "2026-07-03T00:28:26.776Z" } +sdist = { url = "https://files.pythonhosted.org/packages/e9/43/710e43de1b424bd0b45efbfcde5bc27d96a9f8c4986428f02bd8b6eb1b3e/boto3-1.44.7.tar.gz", hash = "sha256:cc19922a2db90ac98f259b5290e08fcf7143a314eb6b2e430afec26a5d1f4e10", size = 112766, upload-time = "2026-11-19T20:34:14.541Z" } wheels = [ - { url = "https://files.pythonhosted.org/packages/d7/3b/2abcc7f47e955a8cb45a6378ec69cd8ed2dcb3d14ceb67717dea020a794a/boto3-1.43.40-py3-none-any.whl", hash = "sha256:5fa80de4b4b7bab383dd8c563e235d51fcc7df4502662af56f0a2472c3c15651", size = 140029, upload-time = "2026-07-03T00:28:25.028Z" }, + { url = "https://files.pythonhosted.org/packages/55/39/1b35b73d9f62c9a722ece0eed6673de7a56803bfb1f89926a36445cceab9/boto3-1.44.7-py3-none-any.whl", hash = "sha256:15fac273416d37cd5e3f0c02b33fd8d7f27d3e64c5f64b911f8b953772302609", size = 140157, upload-time = "2026-11-19T20:34:12.236Z" }, ] [[package]] name = "botocore" -version = "1.43.40" +version = "1.44.7" source = { registry = "https://pypi.org/simple" } dependencies = [ { name = "jmespath" }, { name = "python-dateutil" }, { name = "urllib3" }, ] -sdist = { url = "https://files.pythonhosted.org/packages/d0/50/269986277f852cc83029bccbdcdc0b343a685cfd570599e58029792808d8/botocore-1.43.40.tar.gz", hash = "sha256:2085a4314cfd2c8bc1d08ab8039f76c92e99278db0d2a0e2437010526d5d5d70", size = 15639899, upload-time = "2026-07-03T00:28:16.125Z" } +sdist = { url = "https://files.pythonhosted.org/packages/fe/b8/2140072cf06a608114614d8efde2ecd76cc24edf81d83263269412d0aa93/botocore-1.44.7.tar.gz", hash = "sha256:3cbf1d9f50b5f1f95b715e570bc03b8c7c94b86777f96dd647321134f57290b2", size = 17046633, upload-time = "2026-11-19T20:34:08.792Z" } wheels = [ - { url = "https://files.pythonhosted.org/packages/dc/8c/5f7e73fd66b28f0705bc55d7060d41ef72328b656b86ca53e75765b3ba2c/botocore-1.43.40-py3-none-any.whl", hash = "sha256:0bc9d352267c9e48415c5d7bb61ff05c3f193eac2fc7e69cfd229a05fbab67d6", size = 15323870, upload-time = "2026-07-03T00:28:12.56Z" }, + { url = "https://files.pythonhosted.org/packages/0b/47/a6d5d012e4d6e70f80d4d0dffac7622f8f64edce635200ea23a3c531f397/botocore-1.44.7-py3-none-any.whl", hash = "sha256:56ec7cf3a7c0012c7e105c8f498c67077afa722df916dbdbe667b584fe7e5f99", size = 16741609, upload-time = "2026-11-19T20:34:04.837Z" }, ] [[package]] @@ -1228,45 +1228,40 @@ wheels = [ [[package]] name = "litellm" -version = "1.93.2" +version = "1.110.2" source = { registry = "https://pypi.org/simple" } dependencies = [ { name = "aiohttp" }, + { name = "anyio" }, + { name = "boto3" }, + { name = "certifi" }, { name = "click" }, { name = "fastuuid" }, - { name = "httpx" }, + { name = "filelock" }, + { name = "httpx", extra = ["http2"] }, + { name = "huggingface-hub" }, { name = "importlib-metadata" }, { name = "jinja2" }, { name = "jsonschema" }, { name = "openai" }, + { name = "packaging" }, { name = "pydantic" }, + { name = "pydantic-settings" }, { name = "python-dotenv" }, + { name = "pyyaml" }, { name = "tiktoken" }, { name = "tokenizers" }, + { name = "typing-extensions" }, ] -sdist = { url = "https://files.pythonhosted.org/packages/97/dd/28024c0e4cf2dc6ab1bad59b8357af7f460e952c69526eae28f12ac4ee5e/litellm-1.93.2.tar.gz", hash = "sha256:c5d5223ef07f36e0886397fb45cc9db4150f86a0c6f6835cee1d5524cab69dfd", size = 15955441, upload-time = "2026-08-09T02:17:49.646Z" } -wheels = [ - { url = "https://files.pythonhosted.org/packages/d0/05/72fd8051f0f2f3c84b90986e6f4551db7c8b190ba3300f111461b7701689/litellm-1.93.2-cp312-cp312-macosx_10_12_x86_64.whl", hash = "sha256:3bf532c164ad7cb1b76f2c62afefdcc656b9b296374d075a4150e2ce10bb74c3", size = 19937403, upload-time = "2026-08-09T02:16:55.545Z" }, - { url = "https://files.pythonhosted.org/packages/9e/4d/5081b39bdb73cab04f8a86294a4534a029cf0434ac6932c7ae8049d55723/litellm-1.93.2-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:526b7afc037f79dfdd5c607f5085ac597c7fd301a6dedabea40baae899b27f19", size = 19853652, upload-time = "2026-08-09T02:16:57.977Z" }, - { url = "https://files.pythonhosted.org/packages/70/3f/fb70691266a7fd08c202406abea0153e82fa17f134cd9d58e4029cc741db/litellm-1.93.2-cp312-cp312-manylinux_2_28_aarch64.whl", hash = "sha256:294ad19f356f821ce97a5428d09439be5f38d22b218c73008d8a49e3e42eb145", size = 20165680, upload-time = "2026-08-09T02:17:00.65Z" }, - { url = "https://files.pythonhosted.org/packages/81/91/84424ce2a25595463e5d24e9cf8949877cd4ce93c0fcbf6486ecd685094f/litellm-1.93.2-cp312-cp312-manylinux_2_28_x86_64.whl", hash = "sha256:6f6a5e3907f0a1c9d8ff8d71a6cbac8a592e47a40da3f97167074947b5ba7d11", size = 20157772, upload-time = "2026-08-09T02:17:03.027Z" }, - { url = "https://files.pythonhosted.org/packages/8f/8d/b0eac7ee6d174564f820565c8c9a726ae83dbb8c4d3522daf175b95da002/litellm-1.93.2-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:8541f1b7fd5c437ad249ad68d0a11f68e5e2866b0649da5fa7d63b595e9b8b22", size = 20229256, upload-time = "2026-08-09T02:17:05.271Z" }, - { url = "https://files.pythonhosted.org/packages/ee/6d/03e931c1cb2d1e1b7a968de21aa9e4db853928200da856c35c940ee6faa9/litellm-1.93.2-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:712c9387419d7b06a10df59973f5e530592d61b2314102b0fa3142f3743f9a9e", size = 20287257, upload-time = "2026-08-09T02:17:08.175Z" }, - { url = "https://files.pythonhosted.org/packages/16/05/6c0fe2fcf31c260474c55fabe4ecb0e9e1343c9b9132e28589391b2ad33e/litellm-1.93.2-cp312-cp312-win_amd64.whl", hash = "sha256:cc0d58ccabd22ef7ef44a9e6f7247deb54ae42f5e126e6f00360c2b28b41bc2b", size = 19772580, upload-time = "2026-08-09T02:17:11.254Z" }, - { url = "https://files.pythonhosted.org/packages/70/74/e9046cffa69b32b710452480598e418b26a29896ece680c80ec23997fd16/litellm-1.93.2-cp313-cp313-macosx_10_12_x86_64.whl", hash = "sha256:f4071bef03e4c2942cd2ddc752727345b85447d6a7fee1ff5a4f8b92187966b0", size = 19938095, upload-time = "2026-08-09T02:17:13.929Z" }, - { url = "https://files.pythonhosted.org/packages/fa/db/6ef38a7a2f73d5cc507423954fa535a8546ead375c4c71265c093bdb4e9e/litellm-1.93.2-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:8a99ac7c0c1b78acd6bfd1959e9f203dca71fdbceb5f0c8691c2ad8eee450d7d", size = 19854187, upload-time = "2026-08-09T02:17:16.588Z" }, - { url = "https://files.pythonhosted.org/packages/cb/b3/80ee0143b88e2921f8c8f24c7331478258a8bf25a3d4d4450bd96043403e/litellm-1.93.2-cp313-cp313-manylinux_2_28_aarch64.whl", hash = "sha256:a81ceff44c58ef504ab8bd787d03b82618765b9cfd530942386ae6d23c58be94", size = 20166307, upload-time = "2026-08-09T02:17:19.078Z" }, - { url = "https://files.pythonhosted.org/packages/98/60/cb326e1094f7042f28f9e21543d9f367a8aa25af6915bf4253b77da5c2a2/litellm-1.93.2-cp313-cp313-manylinux_2_28_x86_64.whl", hash = "sha256:dee1b02b7f52a5a408bf7c8d499f0834e49194651743758a511dcdd926c0b692", size = 20158336, upload-time = "2026-08-09T02:17:21.507Z" }, - { url = "https://files.pythonhosted.org/packages/b1/87/bad75146863531172c9dbae189486c7f4425b56a6641b55ab20745316048/litellm-1.93.2-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:d2edfa14b99bce706b35981703692e3ee631f9b87bf6dc28fb53b574f6480b20", size = 20229711, upload-time = "2026-08-09T02:17:24.073Z" }, - { url = "https://files.pythonhosted.org/packages/df/28/040b1853021ed8fd57be19eb2affb024d168951fe7e7abdbad91da3f6f3f/litellm-1.93.2-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:ae75a61c9abc827aa3131b7e640c952367a450830bb7c531b426b4ec2bb45f85", size = 20287584, upload-time = "2026-08-09T02:17:26.542Z" }, - { url = "https://files.pythonhosted.org/packages/d9/0b/4208815b0d666636cbf7afbd571eec3004d3a15d3150a23a9009fc2ce930/litellm-1.93.2-cp313-cp313-win_amd64.whl", hash = "sha256:c54a09ab20f94120a9d60a30d9970439dcefa00d2565d190505ff006a80c7a69", size = 19772641, upload-time = "2026-08-09T02:17:29.308Z" }, - { url = "https://files.pythonhosted.org/packages/09/4a/ff7a9c000519d2bab362318bf744a24c2500228e5fceaa6ac23acab96fa0/litellm-1.93.2-cp314-cp314-macosx_10_12_x86_64.whl", hash = "sha256:204cb0763fff9285bc87eb2dc0fc59b591999e5d94863d0964f806424d3c0cd6", size = 19943639, upload-time = "2026-08-09T02:17:31.811Z" }, - { url = "https://files.pythonhosted.org/packages/c4/26/29e9276ce4aa8ed133d9fd5ecc07375017d2228215547c6bbb17ccbc59b4/litellm-1.93.2-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:3126c84361606b9fb07fde7d57eccd8a1747304d64c4143e2e5e40ae6e7693fb", size = 19855435, upload-time = "2026-08-09T02:17:34.376Z" }, - { url = "https://files.pythonhosted.org/packages/f8/20/2c9c818248ae019b2d496ca41900a9a5651ab05e2400794cd8dc8b89b6d2/litellm-1.93.2-cp314-cp314-manylinux_2_28_aarch64.whl", hash = "sha256:1c84f7c4acb4e926a79b93145ab23231b300fc687bde7172ef884fc52d6011e0", size = 20166947, upload-time = "2026-08-09T02:17:36.828Z" }, - { url = "https://files.pythonhosted.org/packages/50/af/4016682be48350407837941ad1a1ae8185cca65b102e04e89eee2a2abccb/litellm-1.93.2-cp314-cp314-manylinux_2_28_x86_64.whl", hash = "sha256:cacf35cf703b12c54516fc6464a3e08c6dbb1dcfb97239e1f629294fe36a1cba", size = 20160055, upload-time = "2026-08-09T02:17:39.674Z" }, - { url = "https://files.pythonhosted.org/packages/5b/b5/c25d7fbe08490d8211bd6b69af23f3a922b68ad8c87c776480b0de64a505/litellm-1.93.2-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:0a7f3e5138e307e429bd8fa29cc0c48bb1e2b827792e8f7799ca4c8cff736103", size = 20230910, upload-time = "2026-08-09T02:17:42.159Z" }, - { url = "https://files.pythonhosted.org/packages/21/27/341b18a40d4d98a2ac09025c248a3a7edddaf15ce4096ac4a783ff2f70db/litellm-1.93.2-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:d8684629be3f7b5f8e2b6e5fe5ea27ff957c63a8d525d81c1460d8436e2e1857", size = 20288903, upload-time = "2026-08-09T02:17:44.433Z" }, - { url = "https://files.pythonhosted.org/packages/8d/45/dd9ef72075a83854f852b1bf9a97ec7029a2be9fb4e338fc6623eb09fc90/litellm-1.93.2-cp314-cp314-win_amd64.whl", hash = "sha256:a783b8b18ed68cb6a3b79d2b00273ec21aef92442e9b2712a50036cb84bfe583", size = 19772974, upload-time = "2026-08-09T02:17:46.972Z" }, +sdist = { url = "https://files.pythonhosted.org/packages/31/f4/613cbb97aa1482653ccfad1f79ff18c0c3bec7180008193854023d179213/litellm-1.110.2.tar.gz", hash = "sha256:a483c8d3078c1bd27a9fe9c831ac2ce09d41b728a7ea6e9a3ce48db276edeef5", size = 25954106, upload-time = "2026-11-20T04:05:49.184Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/07/38/01927037d254660c4b8962a69f2defd13b3dfa6806477a5c56965300dc16/litellm-1.110.2-cp310-abi3-macosx_10_12_x86_64.whl", hash = "sha256:b219de9b88c483fe40ebe0ec580a1cd3ada8417e5b18118fb0af59f0fd4071b0", size = 43308025, upload-time = "2026-11-20T04:05:22.369Z" }, + { url = "https://files.pythonhosted.org/packages/90/44/a7e7fb165af1ab8713dd47c5f56dc0db2c25a29f0e838ccd8dc12f985dc1/litellm-1.110.2-cp310-abi3-macosx_11_0_arm64.whl", hash = "sha256:a002de994ff50f9b72443e8a78b0731783f8bb14898dc6b473acba89128eb769", size = 42465352, upload-time = "2026-11-20T04:05:26.416Z" }, + { url = "https://files.pythonhosted.org/packages/a6/29/0cf887d925dae801ee42cd06319d454dadd409bb1744f3b1c5fa2ddd05d0/litellm-1.110.2-cp310-abi3-manylinux_2_28_aarch64.whl", hash = "sha256:4e877371f0bb90623f112731c55a2d71acc3fbccbc57bfc7ef9346bd1af0f214", size = 43059564, upload-time = "2026-11-20T04:05:30.458Z" }, + { url = "https://files.pythonhosted.org/packages/d3/51/825f430f07bf864ade5f58462816437bbfaa22c229f5bb474073352bffc4/litellm-1.110.2-cp310-abi3-manylinux_2_28_x86_64.whl", hash = "sha256:9d94d1c7d524b6fd10c14f9c8c6c4f0ac31705f9964ac59dcfd8337c046d8917", size = 43842416, upload-time = "2026-11-20T04:05:34.365Z" }, + { url = "https://files.pythonhosted.org/packages/73/b1/fd1d5e306de1ac528a9344a38d528dab9e13f7c96c3f197acbcfb5375567/litellm-1.110.2-cp310-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:4a60695eb840bcb040f09ff2c67581f7b4bd0386cf568c282b532924225719cf", size = 43172399, upload-time = "2026-11-20T04:05:38.138Z" }, + { url = "https://files.pythonhosted.org/packages/8f/77/c815b917e038eaa723f164360cccb3c4cc597bc9867b123057ac3a6ae9bb/litellm-1.110.2-cp310-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:507fe440514f4234434b3e4cc60952b5253058c8f0c20afaa462f583260a9a24", size = 44121927, upload-time = "2026-11-20T04:05:42.018Z" }, + { url = "https://files.pythonhosted.org/packages/69/2b/f3e05ed9014c3f6fb54b3a9d338401eac8407b8e156e6395a0c6b5c2f725/litellm-1.110.2-cp310-abi3-win_amd64.whl", hash = "sha256:7db952ab951f6fd59d7b88706f0a5794d2d3b4fde7a47f0bdc7e1effd4d61502", size = 45273032, upload-time = "2026-11-20T04:05:45.873Z" }, ] [[package]] @@ -2706,7 +2701,7 @@ requires-dist = [ { name = "httpx", marker = "extra == 'dev'", specifier = ">=0.27" }, { name = "idna", specifier = ">=3.10,<4" }, { name = "jinja2", specifier = ">=3.1" }, - { name = "litellm", marker = "extra == 'llm'", specifier = ">=1.92.0,<1.94.0.dev0" }, + { name = "litellm", marker = "extra == 'llm'", specifier = ">=1.110.2,<1.111.0.dev0" }, { name = "markdown-it-py", specifier = ">=4.2,<5" }, { name = "mcp", marker = "extra == 'tier3'", specifier = ">=1.28.1,<2" }, { name = "oauthlib", marker = "extra == 'tier3'", specifier = ">=4.0.0" }, From d048488ac003acb5cb26cd1419feca3820d36314 Mon Sep 17 00:00:00 2001 From: Christopher Kevin Date: Fri, 20 Nov 2026 00:14:20 -0800 Subject: [PATCH 02/11] fix: enforce HTTPS for Bedrock bearer authentication Signed-off-by: Christopher Kevin --- CHANGELOG.md | 5 ++-- docs/tier3-runtime.mdx | 6 +++-- pyproject.toml | 3 ++- src/skillevaluator/inference/client.py | 14 ++++++++++ .../tier3/harbor/runtime_preflight.py | 18 ++++++------- tests/test_harbor_runtime_preflight.py | 18 +++++++++++++ tests/test_oss_packaging.py | 9 +++++-- tests/test_retry_provider_transport.py | 27 +++++++++++++++++++ uv.lock | 2 +- 9 files changed, 84 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a4b1e1ff8..c08ff68bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,8 +6,9 @@ All notable changes to SkillEvaluator are documented in this file. ### Security -- Update LiteLLM in the optional LLM and Tier 3 installs. Bedrock reports - invalid bearer-token endpoints as configuration errors. +- Update LiteLLM and the minimum AWS SDK version in the optional LLM and + Tier 3 installs. Bedrock preflight and host inference reject HTTP endpoint + overrides when bearer authentication is configured. ### Changed diff --git a/docs/tier3-runtime.mdx b/docs/tier3-runtime.mdx index 0f78541b9..41917fb13 100644 --- a/docs/tier3-runtime.mdx +++ b/docs/tier3-runtime.mdx @@ -167,8 +167,10 @@ The exact Harbor pin is deliberate: its CLI, Python models, result artifacts, and environment/agent subclass interfaces form one compatibility surface. This release targets stable Harbor 0.25.0 rather than unreleased `main`. Harbor stays behind the operator-selected `tier3` extra, so static Tier 1 installs do not pull -it in. The shared LLM client uses `litellm>=1.110.2,<1.111.0.dev0`. Bedrock -bearer-token authentication requires HTTPS, including for custom endpoints. +it in. The shared LLM client uses `litellm>=1.110.2,<1.111.0.dev0` with +`boto3>=1.44.0`. When you set `AWS_BEARER_TOKEN_BEDROCK`, use HTTPS for the +Bedrock catalog and runtime endpoints checked by preflight and for the +`AWS_BEDROCK_RUNTIME_ENDPOINT` override used by the LiteLLM client. The integration preserves SkillEvaluator's runtime and artifact contracts while using Harbor 0.25: diff --git a/pyproject.toml b/pyproject.toml index 7063b7298..6088acda2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -59,7 +59,8 @@ dependencies = [ # Shared public LLM / embedding clients used by LLM-backed checks, Tier 2, and Tier 3. llm = [ "anthropic>=0.83.0", - "boto3>=1.34.0", + # Botocore 1.44 introduced HTTPS enforcement for bearer authentication. + "boto3>=1.44.0", "litellm>=1.110.2,<1.111.0.dev0", "openai>=2.21.0", ] diff --git a/src/skillevaluator/inference/client.py b/src/skillevaluator/inference/client.py index f446fa010..7631dd128 100644 --- a/src/skillevaluator/inference/client.py +++ b/src/skillevaluator/inference/client.py @@ -786,6 +786,19 @@ def _anthropic_kwargs(include_schema: bool) -> dict[str, Any]: ) return _checked_content(content.strip(), getattr(response, "stop_reason", None)) if config.provider == "bedrock": + endpoint = ( + os.environ.get("AWS_BEDROCK_RUNTIME_ENDPOINT") + if os.environ.get("AWS_BEARER_TOKEN_BEDROCK") + else None + ) + if endpoint: + try: + target = urlsplit(endpoint) + uses_https = target.scheme == "https" and target.hostname is not None + except ValueError: + uses_https = False + if not uses_https: + raise LLMClientError("AWS_BEDROCK_RUNTIME_ENDPOINT must use HTTPS with a Bedrock bearer token.") try: from litellm import completion except ImportError as exc: @@ -796,6 +809,7 @@ def _anthropic_kwargs(include_schema: bool) -> dict[str, Any]: model=config.litellm_model, messages=_chat_messages(system_prompt, turns), aws_region_name=config.region, + **({"aws_bedrock_runtime_endpoint": endpoint} if endpoint else {}), **_temperature_kwargs(config.model, self._temperature), **({"max_tokens": max_tokens} if max_tokens is not None else {}), **({"timeout": self._timeout} if self._timeout is not None else {}), diff --git a/src/skillevaluator/tier3/harbor/runtime_preflight.py b/src/skillevaluator/tier3/harbor/runtime_preflight.py index 8951385c9..ab7b58751 100644 --- a/src/skillevaluator/tier3/harbor/runtime_preflight.py +++ b/src/skillevaluator/tier3/harbor/runtime_preflight.py @@ -1291,14 +1291,10 @@ def _probe_bedrock_model(provider: ProviderConfig, *, timeout_seconds: float) -> ) session = boto3.session.Session() _validate_bedrock_local_sdk_configuration(session) - bearer_token = os.environ.get("AWS_BEARER_TOKEN_BEDROCK") - if ( - isinstance(bearer_token, str) - and bearer_token.strip() - and any(not 0x21 <= ord(character) <= 0x7E for character in bearer_token) - ): + bearer_token = os.environ.get("AWS_BEARER_TOKEN_BEDROCK", "") + if bearer_token and any(not 0x21 <= ord(character) <= 0x7E for character in bearer_token): raise InvalidConfigError(error_msg="Bedrock bearer token contains invalid characters") - if not isinstance(bearer_token, str) or not bearer_token.strip(): + if not bearer_token: metadata_unavailable = _monitor_bedrock_metadata_unavailability(session) get_credentials = getattr(session, "get_credentials", None) if callable(get_credentials): @@ -1324,9 +1320,11 @@ def _probe_bedrock_model(provider: ProviderConfig, *, timeout_seconds: float) -> region_name=provider.region or "us-west-2", config=request_config, ) - if (_bedrock_client_uses_tls(bedrock) or _bedrock_client_uses_tls(bedrock_runtime)) and ( - _is_invalid_bedrock_ca_bundle(session) - ): + catalog_uses_tls = _bedrock_client_uses_tls(bedrock) + runtime_uses_tls = _bedrock_client_uses_tls(bedrock_runtime) + if bearer_token and not (catalog_uses_tls and runtime_uses_tls): + raise InvalidConfigError(error_msg="Bedrock bearer authentication requires HTTPS endpoints") + if (catalog_uses_tls or runtime_uses_tls) and _is_invalid_bedrock_ca_bundle(session): raise InvalidConfigError(error_msg="configured AWS CA bundle cannot be loaded") region_name = provider.region or "us-west-2" catalog_authoritative = _is_native_bedrock_endpoint( diff --git a/tests/test_harbor_runtime_preflight.py b/tests/test_harbor_runtime_preflight.py index 150146469..06f0644bf 100644 --- a/tests/test_harbor_runtime_preflight.py +++ b/tests/test_harbor_runtime_preflight.py @@ -1664,6 +1664,24 @@ def log_message(self, _format, *_args) -> None: assert "private rejected bearer" not in result.detail +@pytest.mark.parametrize("endpoint_variable", ["AWS_ENDPOINT_URL_BEDROCK", "AWS_ENDPOINT_URL_BEDROCK_RUNTIME"]) +def test_bedrock_preflight_requires_https_for_bearer_endpoints( + monkeypatch: pytest.MonkeyPatch, tmp_path: Path, endpoint_variable: str +) -> None: + _configure_isolated_aws_profile(monkeypatch, tmp_path, config="[profile test]\nregion = us-west-2\n") + monkeypatch.setenv("AWS_BEARER_TOKEN_BEDROCK", "test-bearer-token") + monkeypatch.setenv("AWS_ENDPOINT_URL_BEDROCK", "https://127.0.0.1:1") + monkeypatch.setenv("AWS_ENDPOINT_URL_BEDROCK_RUNTIME", "https://127.0.0.1:1") + monkeypatch.setenv(endpoint_variable, "http://127.0.0.1:1") + provider = ProviderConfig("bedrock", "test-model", None, None, "bedrock/test-model", region="us-west-2") + + result = runtime_preflight.probe_model(provider, timeout_seconds=15) + + assert result.failure_kind == "invalid_configuration", result.detail + assert runtime_preflight.credential_probe_disposition(provider, result) == "fatal" + assert "test-bearer-token" not in result.detail + + @pytest.mark.parametrize( "bearer_token", ["bad\nvalue", "bad\rvalue", "bad\x7fvalue", "bad value", "bad\N{LATIN SMALL LETTER E WITH ACUTE}value"], diff --git a/tests/test_oss_packaging.py b/tests/test_oss_packaging.py index ea5763ec3..c99795e3a 100644 --- a/tests/test_oss_packaging.py +++ b/tests/test_oss_packaging.py @@ -153,7 +153,9 @@ def test_harbor_dependency_contract_keeps_base_install_isolated() -> None: requirement for requirement in llm_requirements if canonicalize_name(requirement.name) == "litellm" ] - assert base_names.isdisjoint({"harbor", "litellm"}) + assert base_names.isdisjoint({"boto3", "harbor", "litellm"}) + aws_sdk = next(requirement for requirement in llm_requirements if requirement.name == "boto3") + assert aws_sdk.specifier == SpecifierSet(">=1.44.0") assert len(harbor_requirements) == 1 assert harbor_requirements[0].extras == {"gke"} assert HARBOR_VERSION == "0.25.0" @@ -171,9 +173,12 @@ def test_harbor_dependency_contract_keeps_base_install_isolated() -> None: lock = _lock() locked_versions = { name: [Version(package["version"]) for package in lock["package"] if package["name"] == name] - for name in ("harbor", "litellm") + for name in ("boto3", "botocore", "harbor", "litellm") } assert locked_versions["harbor"] == [Version(HARBOR_VERSION)] + for name in ("boto3", "botocore"): + assert len(locked_versions[name]) == 1 + assert locked_versions[name][0] >= Version("1.44.0") assert len(locked_versions["litellm"]) == 1 assert litellm_specifier.contains(locked_versions["litellm"][0], prereleases=True) diff --git a/tests/test_retry_provider_transport.py b/tests/test_retry_provider_transport.py index c2db5e842..e7addb402 100644 --- a/tests/test_retry_provider_transport.py +++ b/tests/test_retry_provider_transport.py @@ -19,6 +19,7 @@ from skillevaluator.inference.client import LLMClient from skillevaluator.inference.retry import extract_http_status, is_retriable_exception, retry_call_with_backoff +from skillevaluator.inference.types import LLMClientError from skillevaluator.provider_config import ProviderConfig @@ -74,6 +75,7 @@ def __init__(self, statuses, tls_context=None, *, retry_after=None): self.statuses = statuses self.retry_after = retry_after self.requests: list[int] = [] + self.bearer_requests = 0 self.connections = 0 self.tls_context = tls_context super().__init__(("127.0.0.1", 0), _Handler) @@ -95,6 +97,7 @@ def do_POST(self): self.rfile.read(int(self.headers.get("Content-Length", "0"))) status = self.server.statuses[min(len(self.server.requests), len(self.server.statuses) - 1)] self.server.requests.append(status) + self.server.bearer_requests += self.headers.get("Authorization", "").startswith("Bearer ") payload = {"message": "loopback response"} if status == 200: if self.path.endswith("/converse"): @@ -246,6 +249,30 @@ def test_provider_http_status_survives_sdk_wrapping( assert extract_http_status(raised.value) == status +def test_bedrock_inference_rejects_http_bearer_override(isolated_provider_environment, monkeypatch): + monkeypatch.setenv("AWS_BEARER_TOKEN_BEDROCK", "loopback-bearer-token") + with _server([200]) as server: + client = _client(monkeypatch, f"http://127.0.0.1:{server.server_port}") + with pytest.raises(LLMClientError, match="AWS_BEDROCK_RUNTIME_ENDPOINT must use HTTPS"): + client.completions("system", "user") + assert server.connections == 0 + + +def test_bedrock_inference_accepts_https_bearer_override(isolated_provider_environment, monkeypatch, loopback_tls): + litellm = pytest.importorskip("litellm") + from litellm.caching.llm_caching_handler import LLMClientCache + + tls_context, ca_bundle = loopback_tls + monkeypatch.setenv("AWS_BEARER_TOKEN_BEDROCK", "loopback-bearer-token") + monkeypatch.setenv("SSL_VERIFY", str(ca_bundle)) + monkeypatch.setattr(litellm, "in_memory_llm_clients_cache", LLMClientCache(), raising=False) + with _server([200], tls_context) as server: + client = _client(monkeypatch, f"https://127.0.0.1:{server.server_port}") + assert client.completions("system", "user") == "recovered" + assert server.requests == [200] + assert server.bearer_requests == 1 + + @pytest.mark.parametrize("provider", ["bedrock", "openai"]) def test_provider_certificate_failure_is_not_retried( isolated_provider_environment, diff --git a/uv.lock b/uv.lock index d78e2504d..c9c010416 100644 --- a/uv.lock +++ b/uv.lock @@ -2694,7 +2694,7 @@ tier3 = [ requires-dist = [ { name = "anthropic", marker = "extra == 'llm'", specifier = ">=0.83.0" }, { name = "bandit", specifier = ">=1.9.4" }, - { name = "boto3", marker = "extra == 'llm'", specifier = ">=1.34.0" }, + { name = "boto3", marker = "extra == 'llm'", specifier = ">=1.44.0" }, { name = "build", marker = "extra == 'dev'", specifier = ">=1.2" }, { name = "click", specifier = ">=8.3.3,<9" }, { name = "harbor", extras = ["gke"], marker = "extra == 'tier3'", specifier = "==0.25.0" }, From ae5e030e69e80c1ef78e9bccc7c51caba5e57136 Mon Sep 17 00:00:00 2001 From: Christopher Kevin Date: Fri, 20 Nov 2026 00:18:21 -0800 Subject: [PATCH 03/11] fix: validate Bedrock settings after loading LiteLLM Signed-off-by: Christopher Kevin --- src/skillevaluator/inference/client.py | 13 +++++++------ tests/test_retry_provider_transport.py | 21 +++++++++++++++++++++ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/skillevaluator/inference/client.py b/src/skillevaluator/inference/client.py index 7631dd128..611ca5a2f 100644 --- a/src/skillevaluator/inference/client.py +++ b/src/skillevaluator/inference/client.py @@ -786,6 +786,13 @@ def _anthropic_kwargs(include_schema: bool) -> dict[str, Any]: ) return _checked_content(content.strip(), getattr(response, "stop_reason", None)) if config.provider == "bedrock": + try: + from litellm import completion + except ImportError as exc: + raise LLMClientError( + "The 'litellm' package is required for Bedrock LLM operations. Install with: pip install 'skillevaluator[llm]'" + ) from exc + # LiteLLM can load environment variables on its first import. endpoint = ( os.environ.get("AWS_BEDROCK_RUNTIME_ENDPOINT") if os.environ.get("AWS_BEARER_TOKEN_BEDROCK") @@ -799,12 +806,6 @@ def _anthropic_kwargs(include_schema: bool) -> dict[str, Any]: uses_https = False if not uses_https: raise LLMClientError("AWS_BEDROCK_RUNTIME_ENDPOINT must use HTTPS with a Bedrock bearer token.") - try: - from litellm import completion - except ImportError as exc: - raise LLMClientError( - "The 'litellm' package is required for Bedrock LLM operations. Install with: pip install 'skillevaluator[llm]'" - ) from exc response = completion( model=config.litellm_model, messages=_chat_messages(system_prompt, turns), diff --git a/tests/test_retry_provider_transport.py b/tests/test_retry_provider_transport.py index e7addb402..cf70a6754 100644 --- a/tests/test_retry_provider_transport.py +++ b/tests/test_retry_provider_transport.py @@ -9,11 +9,13 @@ import json import os import socket +import sys import threading import urllib.error import urllib.request from contextlib import contextmanager from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer +from types import ModuleType import pytest @@ -258,6 +260,25 @@ def test_bedrock_inference_rejects_http_bearer_override(isolated_provider_enviro assert server.connections == 0 +def test_bedrock_inference_validates_credentials_loaded_at_sdk_import(isolated_provider_environment, monkeypatch): + def unexpected_completion(**_kwargs): + pytest.fail("Bedrock completion must not be called for an HTTP bearer endpoint") + + class LazyLiteLLM(ModuleType): + def __getattr__(self, name): + if name != "completion": + raise AttributeError(name) + monkeypatch.setenv("AWS_BEARER_TOKEN_BEDROCK", "loopback-bearer-token") + return unexpected_completion + + with _server([200]) as server: + client = _client(monkeypatch, f"http://127.0.0.1:{server.server_port}") + monkeypatch.setitem(sys.modules, "litellm", LazyLiteLLM("litellm")) + with pytest.raises(LLMClientError, match="AWS_BEDROCK_RUNTIME_ENDPOINT must use HTTPS"): + client.completions("system", "user") + assert server.connections == 0 + + def test_bedrock_inference_accepts_https_bearer_override(isolated_provider_environment, monkeypatch, loopback_tls): litellm = pytest.importorskip("litellm") from litellm.caching.llm_caching_handler import LLMClientCache From 1bdc36f20d09034cb731954ed19d1b3ae9e04803 Mon Sep 17 00:00:00 2001 From: Christopher Kevin Date: Fri, 20 Nov 2026 00:24:35 -0800 Subject: [PATCH 04/11] fix: keep blank Bedrock bearer tokens on the IAM path Signed-off-by: Christopher Kevin --- src/skillevaluator/tier3/harbor/runtime_preflight.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/skillevaluator/tier3/harbor/runtime_preflight.py b/src/skillevaluator/tier3/harbor/runtime_preflight.py index ab7b58751..233dd10f1 100644 --- a/src/skillevaluator/tier3/harbor/runtime_preflight.py +++ b/src/skillevaluator/tier3/harbor/runtime_preflight.py @@ -1292,9 +1292,10 @@ def _probe_bedrock_model(provider: ProviderConfig, *, timeout_seconds: float) -> session = boto3.session.Session() _validate_bedrock_local_sdk_configuration(session) bearer_token = os.environ.get("AWS_BEARER_TOKEN_BEDROCK", "") - if bearer_token and any(not 0x21 <= ord(character) <= 0x7E for character in bearer_token): + has_bearer_token = bool(bearer_token.strip()) + if has_bearer_token and any(not 0x21 <= ord(character) <= 0x7E for character in bearer_token): raise InvalidConfigError(error_msg="Bedrock bearer token contains invalid characters") - if not bearer_token: + if not has_bearer_token: metadata_unavailable = _monitor_bedrock_metadata_unavailability(session) get_credentials = getattr(session, "get_credentials", None) if callable(get_credentials): @@ -1322,7 +1323,7 @@ def _probe_bedrock_model(provider: ProviderConfig, *, timeout_seconds: float) -> ) catalog_uses_tls = _bedrock_client_uses_tls(bedrock) runtime_uses_tls = _bedrock_client_uses_tls(bedrock_runtime) - if bearer_token and not (catalog_uses_tls and runtime_uses_tls): + if has_bearer_token and not (catalog_uses_tls and runtime_uses_tls): raise InvalidConfigError(error_msg="Bedrock bearer authentication requires HTTPS endpoints") if (catalog_uses_tls or runtime_uses_tls) and _is_invalid_bedrock_ca_bundle(session): raise InvalidConfigError(error_msg="configured AWS CA bundle cannot be loaded") From c3f7089129667b6407547a7a6862affc8a300f68 Mon Sep 17 00:00:00 2001 From: Christopher Kevin Date: Fri, 20 Nov 2026 00:49:38 -0800 Subject: [PATCH 05/11] fix: sign Bedrock preflight requests with SigV4 when the bearer token is blank A blank or whitespace-only AWS_BEARER_TOKEN_BEDROCK is treated as absent and the IAM credentials are validated, but Botocore still selects bearer authentication for any set value and sends "Authorization: Bearer ". Pin SigV4 on both Bedrock clients in that case, without touching os.environ, and cover it with a real-client test against a loopback TLS endpoint. Signed-off-by: Christopher Kevin --- .../tier3/harbor/runtime_preflight.py | 3 + tests/test_harbor_runtime_preflight.py | 81 +++++++++++++++++++ 2 files changed, 84 insertions(+) diff --git a/src/skillevaluator/tier3/harbor/runtime_preflight.py b/src/skillevaluator/tier3/harbor/runtime_preflight.py index 233dd10f1..bddf445e3 100644 --- a/src/skillevaluator/tier3/harbor/runtime_preflight.py +++ b/src/skillevaluator/tier3/harbor/runtime_preflight.py @@ -1311,6 +1311,9 @@ def _probe_bedrock_model(provider: ProviderConfig, *, timeout_seconds: float) -> ) raise NoCredentialsError credentials.get_frozen_credentials() + # Botocore treats any set bearer variable, even a blank one, as a token. + # Pin SigV4 so the clients use the credentials checked above. + request_config = request_config.merge(BotoConfig(signature_version="v4")) bedrock = session.client( "bedrock", region_name=provider.region or "us-west-2", diff --git a/tests/test_harbor_runtime_preflight.py b/tests/test_harbor_runtime_preflight.py index 06f0644bf..510ddd2ec 100644 --- a/tests/test_harbor_runtime_preflight.py +++ b/tests/test_harbor_runtime_preflight.py @@ -1682,6 +1682,87 @@ def test_bedrock_preflight_requires_https_for_bearer_endpoints( assert "test-bearer-token" not in result.detail +@pytest.mark.parametrize("bearer_token", ["", " \t "]) +def test_bedrock_blank_bearer_token_signs_both_clients_with_sigv4( + monkeypatch: pytest.MonkeyPatch, + tmp_path: Path, + loopback_tls: tuple[ssl.SSLContext, Path], + bearer_token: str, +) -> None: + auth_schemes = BotocoreSession().get_service_model("bedrock").metadata.get("auth", []) + if "smithy.api#httpBearerAuth" not in auth_schemes: + pytest.skip("installed Botocore does not support Bedrock bearer authentication") + + seen_authorization: list[tuple[str, str]] = [] + + class BedrockResponse(BaseHTTPRequestHandler): + def _respond(self) -> None: + self.rfile.read(int(self.headers.get("Content-Length", 0))) + seen_authorization.append((self.command, self.headers.get("Authorization", ""))) + encoded = json.dumps({"modelSummaries": [{"modelId": "test-model"}]}).encode() + self.send_response(200) + self.send_header("Content-Type", "application/json") + self.send_header("Content-Length", str(len(encoded))) + self.end_headers() + self.wfile.write(encoded) + + def do_GET(self) -> None: + self._respond() + + def do_POST(self) -> None: + self._respond() + + def log_message(self, _format, *_args) -> None: + return + + _configure_isolated_aws_profile( + monkeypatch, + tmp_path, + config="[profile test]\nregion = us-west-2\n", + credentials="""\ +[test] +aws_access_key_id = test-access-key +aws_secret_access_key = test-secret-key +""", + ) + monkeypatch.setenv("AWS_BEARER_TOKEN_BEDROCK", bearer_token) + tls_context, ca_bundle = loopback_tls + monkeypatch.setenv("AWS_CA_BUNDLE", str(ca_bundle)) + clients: dict[str, object] = {} + real_session_type = runtime_preflight.boto3.session.Session + + class RecordingSession(real_session_type): + def client(self, service_name: str, **kwargs): + clients[service_name] = super().client(service_name, **kwargs) + return clients[service_name] + + monkeypatch.setattr(runtime_preflight.boto3.session, "Session", RecordingSession) + provider = ProviderConfig("bedrock", "test-model", None, None, "bedrock/test-model", region="us-west-2") + + with ThreadingHTTPServer(("127.0.0.1", 0), BedrockResponse) as server: + server.socket = tls_context.wrap_socket(server.socket, server_side=True) + endpoint = f"https://127.0.0.1:{server.server_port}" + monkeypatch.setenv("AWS_ENDPOINT_URL_BEDROCK", endpoint) + monkeypatch.setenv("AWS_ENDPOINT_URL_BEDROCK_RUNTIME", endpoint) + worker = Thread(target=server.serve_forever, daemon=True) + worker.start() + try: + result = runtime_preflight.probe_model(provider, timeout_seconds=15) + clients["bedrock-runtime"].converse( + modelId="test-model", + messages=[{"role": "user", "content": [{"text": "hello"}]}], + ) + finally: + server.shutdown() + worker.join(timeout=5) + + assert result.ok is True, result.detail + assert [method for method, _authorization in seen_authorization] == ["GET", "POST"] + for _method, authorization in seen_authorization: + assert authorization.startswith("AWS4-HMAC-SHA256 ") + assert "Bearer" not in authorization + + @pytest.mark.parametrize( "bearer_token", ["bad\nvalue", "bad\rvalue", "bad\x7fvalue", "bad value", "bad\N{LATIN SMALL LETTER E WITH ACUTE}value"], From 8fd18ed9780b7c25bce7bc4c2a5da4cb0c05a29e Mon Sep 17 00:00:00 2001 From: Christopher Kevin Date: Fri, 20 Nov 2026 10:38:02 -0800 Subject: [PATCH 06/11] fix: treat a blank Bedrock bearer token as unset in host inference A whitespace-only AWS_BEARER_TOKEN_BEDROCK now counts as no token in host inference, the same as in the Tier 3 preflight. The HTTPS-only endpoint check no longer fires for it, and LiteLLM signs with the IAM credentials instead of sending a blank Bearer header. The blank-token check lives in one shared helper used by both paths. Signed-off-by: Christopher Kevin --- src/skillevaluator/inference/client.py | 12 +++++++----- src/skillevaluator/provider_config.py | 8 ++++++++ .../tier3/harbor/runtime_preflight.py | 3 ++- tests/test_retry_provider_transport.py | 16 ++++++++++++++++ 4 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/skillevaluator/inference/client.py b/src/skillevaluator/inference/client.py index 611ca5a2f..19f4f5ca0 100644 --- a/src/skillevaluator/inference/client.py +++ b/src/skillevaluator/inference/client.py @@ -56,6 +56,7 @@ class supports two usage patterns: anthropic_refusal_fallback_model, completion_token_limit, effective_reasoning_effort, + has_bedrock_bearer_token, is_claude_5_5_or_later, is_openai_reasoning_model, resolve_extra_headers, @@ -793,11 +794,8 @@ def _anthropic_kwargs(include_schema: bool) -> dict[str, Any]: "The 'litellm' package is required for Bedrock LLM operations. Install with: pip install 'skillevaluator[llm]'" ) from exc # LiteLLM can load environment variables on its first import. - endpoint = ( - os.environ.get("AWS_BEDROCK_RUNTIME_ENDPOINT") - if os.environ.get("AWS_BEARER_TOKEN_BEDROCK") - else None - ) + has_bearer_token = has_bedrock_bearer_token() + endpoint = os.environ.get("AWS_BEDROCK_RUNTIME_ENDPOINT") if has_bearer_token else None if endpoint: try: target = urlsplit(endpoint) @@ -806,11 +804,15 @@ def _anthropic_kwargs(include_schema: bool) -> dict[str, Any]: uses_https = False if not uses_https: raise LLMClientError("AWS_BEDROCK_RUNTIME_ENDPOINT must use HTTPS with a Bedrock bearer token.") + # LiteLLM sends a whitespace-only AWS_BEARER_TOKEN_BEDROCK as a blank Bearer header. + # An empty key makes it sign with the IAM credentials, as it does for an unset variable. + ignore_blank_token = "AWS_BEARER_TOKEN_BEDROCK" in os.environ and not has_bearer_token response = completion( model=config.litellm_model, messages=_chat_messages(system_prompt, turns), aws_region_name=config.region, **({"aws_bedrock_runtime_endpoint": endpoint} if endpoint else {}), + **({"api_key": ""} if ignore_blank_token else {}), **_temperature_kwargs(config.model, self._temperature), **({"max_tokens": max_tokens} if max_tokens is not None else {}), **({"timeout": self._timeout} if self._timeout is not None else {}), diff --git a/src/skillevaluator/provider_config.py b/src/skillevaluator/provider_config.py index debe87c5b..2efc38508 100644 --- a/src/skillevaluator/provider_config.py +++ b/src/skillevaluator/provider_config.py @@ -692,6 +692,14 @@ def _environment(environ: Mapping[str, str] | None) -> Mapping[str, str]: return os.environ if environ is None else environ +def has_bedrock_bearer_token(environ: Mapping[str, str] | None = None) -> bool: + """Return whether AWS_BEARER_TOKEN_BEDROCK holds a real token. + + An unset, empty, or whitespace-only value means no token, so Bedrock calls use IAM credentials. + """ + return bool(_environment(environ).get("AWS_BEARER_TOKEN_BEDROCK", "").strip()) + + def _required(environ: Mapping[str, str], variable: str) -> str: value = environ.get(variable, "").strip() if not value: diff --git a/src/skillevaluator/tier3/harbor/runtime_preflight.py b/src/skillevaluator/tier3/harbor/runtime_preflight.py index bddf445e3..044f3a938 100644 --- a/src/skillevaluator/tier3/harbor/runtime_preflight.py +++ b/src/skillevaluator/tier3/harbor/runtime_preflight.py @@ -753,6 +753,7 @@ def _catalog_listing_is_authoritative(provider: ProviderConfig) -> bool: _get_google_access_token, _is_vertex_openapi_endpoint, _parse_vertex_openapi_metadata, + has_bedrock_bearer_token, ) @@ -1292,7 +1293,7 @@ def _probe_bedrock_model(provider: ProviderConfig, *, timeout_seconds: float) -> session = boto3.session.Session() _validate_bedrock_local_sdk_configuration(session) bearer_token = os.environ.get("AWS_BEARER_TOKEN_BEDROCK", "") - has_bearer_token = bool(bearer_token.strip()) + has_bearer_token = has_bedrock_bearer_token() if has_bearer_token and any(not 0x21 <= ord(character) <= 0x7E for character in bearer_token): raise InvalidConfigError(error_msg="Bedrock bearer token contains invalid characters") if not has_bearer_token: diff --git a/tests/test_retry_provider_transport.py b/tests/test_retry_provider_transport.py index cf70a6754..4f4d21003 100644 --- a/tests/test_retry_provider_transport.py +++ b/tests/test_retry_provider_transport.py @@ -78,6 +78,7 @@ def __init__(self, statuses, tls_context=None, *, retry_after=None): self.retry_after = retry_after self.requests: list[int] = [] self.bearer_requests = 0 + self.authorizations: list[str] = [] self.connections = 0 self.tls_context = tls_context super().__init__(("127.0.0.1", 0), _Handler) @@ -99,6 +100,7 @@ def do_POST(self): self.rfile.read(int(self.headers.get("Content-Length", "0"))) status = self.server.statuses[min(len(self.server.requests), len(self.server.statuses) - 1)] self.server.requests.append(status) + self.server.authorizations.append(self.headers.get("Authorization", "")) self.server.bearer_requests += self.headers.get("Authorization", "").startswith("Bearer ") payload = {"message": "loopback response"} if status == 200: @@ -260,6 +262,20 @@ def test_bedrock_inference_rejects_http_bearer_override(isolated_provider_enviro assert server.connections == 0 +@pytest.mark.parametrize("bearer_token", ["", " ", " \t "]) +def test_bedrock_inference_signs_with_sigv4_when_bearer_token_is_blank( + isolated_provider_environment, monkeypatch, bearer_token +): + monkeypatch.setenv("AWS_BEARER_TOKEN_BEDROCK", bearer_token) + with _server([200]) as server: + client = _client(monkeypatch, f"http://127.0.0.1:{server.server_port}") + assert client.completions("system", "user") == "recovered" + assert server.requests == [200] + assert len(server.authorizations) == 1 + assert server.authorizations[0].startswith("AWS4-HMAC-SHA256 ") + assert "Bearer" not in server.authorizations[0] + + def test_bedrock_inference_validates_credentials_loaded_at_sdk_import(isolated_provider_environment, monkeypatch): def unexpected_completion(**_kwargs): pytest.fail("Bedrock completion must not be called for an HTTP bearer endpoint") From add793b3ca54c1cc380b3721f03c96ea13878d50 Mon Sep 17 00:00:00 2001 From: Christopher Kevin Date: Fri, 20 Nov 2026 11:01:37 -0800 Subject: [PATCH 07/11] fix: sign Bedrock Responses calls with IAM when the bearer token is blank LiteLLM's Bedrock Responses route takes its token from the api_key argument or, when that is empty, from AWS_BEARER_TOKEN_BEDROCK. A whitespace-only value therefore still became a Bearer header and the request failed before it was sent. Host inference now blanks the variable for the duration of the call when it holds only whitespace, and puts the exact value back afterwards. Overlapping calls share one blanked window. Real tokens and other Bedrock routes are unchanged. Signed-off-by: Christopher Kevin --- src/skillevaluator/inference/client.py | 66 ++++++++++++++---- tests/test_retry_provider_transport.py | 94 +++++++++++++++++++++++--- 2 files changed, 137 insertions(+), 23 deletions(-) diff --git a/src/skillevaluator/inference/client.py b/src/skillevaluator/inference/client.py index 19f4f5ca0..3e921a55d 100644 --- a/src/skillevaluator/inference/client.py +++ b/src/skillevaluator/inference/client.py @@ -24,7 +24,8 @@ class supports two usage patterns: import re import threading import urllib.error -from collections.abc import Callable, Mapping, Sequence +from collections.abc import Callable, Iterator, Mapping, Sequence +from contextlib import contextmanager, nullcontext from dataclasses import replace from typing import Any, NamedTuple from urllib.parse import urlsplit @@ -68,6 +69,45 @@ class supports two usage patterns: _NATIVE_OPENAI_AUTHORITIES = frozenset({"api.openai.com", "api.openai.com:443"}) _NATIVE_OPENAI_PATHS = frozenset({"/v1", "/v1/"}) +_BEDROCK_BEARER_TOKEN_ENV = "AWS_BEARER_TOKEN_BEDROCK" + + +class _BedrockTokenWindow: + """Blank AWS_BEARER_TOKEN_BEDROCK while Bedrock calls are in flight, then restore it exactly. + + LiteLLM's Bedrock Responses route picks its token as `api_key or `, so an empty + `api_key` still falls back to a whitespace-only value and sends it as a Bearer header. LiteLLM + has no per-call setting that skips that fallback. Concurrent calls share one blanked window: + the first saves the value and the last puts it back. + """ + + def __init__(self) -> None: + self._lock = threading.Lock() + self._holders = 0 + self._saved: str | None = None + + @contextmanager + def blank(self) -> Iterator[None]: + with self._lock: + if self._holders == 0: + self._saved = os.environ.get(_BEDROCK_BEARER_TOKEN_ENV) + os.environ[_BEDROCK_BEARER_TOKEN_ENV] = "" + self._holders += 1 + try: + yield + finally: + with self._lock: + self._holders -= 1 + if self._holders == 0: + if self._saved is None: + os.environ.pop(_BEDROCK_BEARER_TOKEN_ENV, None) + else: + os.environ[_BEDROCK_BEARER_TOKEN_ENV] = self._saved + self._saved = None + + +_bedrock_token_window = _BedrockTokenWindow() + def _effective_openai_base_url(explicit_base_url: str | None) -> str: if explicit_base_url is not None: @@ -806,17 +846,19 @@ def _anthropic_kwargs(include_schema: bool) -> dict[str, Any]: raise LLMClientError("AWS_BEDROCK_RUNTIME_ENDPOINT must use HTTPS with a Bedrock bearer token.") # LiteLLM sends a whitespace-only AWS_BEARER_TOKEN_BEDROCK as a blank Bearer header. # An empty key makes it sign with the IAM credentials, as it does for an unset variable. - ignore_blank_token = "AWS_BEARER_TOKEN_BEDROCK" in os.environ and not has_bearer_token - response = completion( - model=config.litellm_model, - messages=_chat_messages(system_prompt, turns), - aws_region_name=config.region, - **({"aws_bedrock_runtime_endpoint": endpoint} if endpoint else {}), - **({"api_key": ""} if ignore_blank_token else {}), - **_temperature_kwargs(config.model, self._temperature), - **({"max_tokens": max_tokens} if max_tokens is not None else {}), - **({"timeout": self._timeout} if self._timeout is not None else {}), - ) + # The Responses route also reads the variable itself, so hide it for the call. + ignore_blank_token = _BEDROCK_BEARER_TOKEN_ENV in os.environ and not has_bearer_token + with _bedrock_token_window.blank() if ignore_blank_token else nullcontext(): + response = completion( + model=config.litellm_model, + messages=_chat_messages(system_prompt, turns), + aws_region_name=config.region, + **({"aws_bedrock_runtime_endpoint": endpoint} if endpoint else {}), + **({"api_key": ""} if ignore_blank_token else {}), + **_temperature_kwargs(config.model, self._temperature), + **({"max_tokens": max_tokens} if max_tokens is not None else {}), + **({"timeout": self._timeout} if self._timeout is not None else {}), + ) return _extract_choice_content(response) def _openai_kwargs(include_schema: bool) -> dict[str, Any]: diff --git a/tests/test_retry_provider_transport.py b/tests/test_retry_provider_transport.py index 4f4d21003..794948f79 100644 --- a/tests/test_retry_provider_transport.py +++ b/tests/test_retry_provider_transport.py @@ -77,6 +77,7 @@ def __init__(self, statuses, tls_context=None, *, retry_after=None): self.statuses = statuses self.retry_after = retry_after self.requests: list[int] = [] + self.paths: list[str] = [] self.bearer_requests = 0 self.authorizations: list[str] = [] self.connections = 0 @@ -100,6 +101,7 @@ def do_POST(self): self.rfile.read(int(self.headers.get("Content-Length", "0"))) status = self.server.statuses[min(len(self.server.requests), len(self.server.statuses) - 1)] self.server.requests.append(status) + self.server.paths.append(self.path) self.server.authorizations.append(self.headers.get("Authorization", "")) self.server.bearer_requests += self.headers.get("Authorization", "").startswith("Bearer ") payload = {"message": "loopback response"} @@ -111,6 +113,24 @@ def do_POST(self): "usage": {"inputTokens": 2, "outputTokens": 1, "totalTokens": 3}, "metrics": {"latencyMs": 1}, } + elif self.path.endswith("/responses"): + payload = { + "id": "loopback", + "object": "response", + "created_at": 0, + "model": "loopback", + "status": "completed", + "output": [ + { + "id": "loopback", + "type": "message", + "role": "assistant", + "status": "completed", + "content": [{"type": "output_text", "text": "recovered", "annotations": []}], + } + ], + "usage": {"input_tokens": 2, "output_tokens": 1, "total_tokens": 3}, + } elif self.path.endswith("/invoke"): payload = { "id": "loopback", @@ -206,19 +226,12 @@ def operation(): assert server.requests == [429] -def _client(monkeypatch, endpoint, provider="bedrock"): +def _client(monkeypatch, endpoint, provider="bedrock", model="anthropic.claude-3-haiku-20240307-v1:0"): if provider == "bedrock": pytest.importorskip("litellm") monkeypatch.setenv("AWS_BEDROCK_RUNTIME_ENDPOINT", endpoint) client = LLMClient(max_retries=2, retry_base_delay=0, retry_max_delay=0) - client._provider_config = ProviderConfig( - "bedrock", - "anthropic.claude-3-haiku-20240307-v1:0", - None, - None, - "bedrock/anthropic.claude-3-haiku-20240307-v1:0", - region="us-west-2", - ) + client._provider_config = ProviderConfig("bedrock", model, None, None, f"bedrock/{model}", region="us-west-2") return client pytest.importorskip("openai") return LLMClient( @@ -276,6 +289,59 @@ def test_bedrock_inference_signs_with_sigv4_when_bearer_token_is_blank( assert "Bearer" not in server.authorizations[0] +@pytest.mark.parametrize("bearer_token", ["", " ", " \t "]) +def test_bedrock_responses_route_signs_with_sigv4_when_bearer_token_is_blank( + isolated_provider_environment, monkeypatch, bearer_token +): + litellm = pytest.importorskip("litellm") + monkeypatch.setenv("AWS_BEARER_TOKEN_BEDROCK", bearer_token) + monkeypatch.setattr(litellm, "drop_params", True) + with _server([200]) as server: + client = _client(monkeypatch, f"http://127.0.0.1:{server.server_port}", model="responses/us.openai.gpt-5.6-sol") + assert client.completions("system", "user") == "recovered" + assert server.paths == ["/openai/v1/responses"] + assert len(server.authorizations) == 1 + assert server.authorizations[0].startswith("AWS4-HMAC-SHA256 ") + assert "Bearer" not in server.authorizations[0] + assert os.environ["AWS_BEARER_TOKEN_BEDROCK"] == bearer_token + + +def test_bedrock_responses_route_restores_blank_bearer_token_after_a_failed_call( + isolated_provider_environment, monkeypatch +): + litellm = pytest.importorskip("litellm") + monkeypatch.setenv("AWS_BEARER_TOKEN_BEDROCK", " \t ") + monkeypatch.setattr(litellm, "drop_params", True) + with _server([400]) as server: + client = _client(monkeypatch, f"http://127.0.0.1:{server.server_port}", model="responses/us.openai.gpt-5.6-sol") + with pytest.raises(Exception) as raised: + client.completions("system", "user") + assert extract_http_status(raised.value) == 400 + assert server.paths == ["/openai/v1/responses"] + assert os.environ["AWS_BEARER_TOKEN_BEDROCK"] == " \t " + + +def test_blank_bedrock_bearer_token_is_restored_exactly(monkeypatch): + from skillevaluator.inference.client import _bedrock_token_window + + name = "AWS_BEARER_TOKEN_BEDROCK" + monkeypatch.setenv(name, " \t ") + with _bedrock_token_window.blank(): + assert os.environ[name] == "" + with _bedrock_token_window.blank(): + assert os.environ[name] == "" + # An overlapping call finishing must not put the value back for the one still running. + assert os.environ[name] == "" + assert os.environ[name] == " \t " + with pytest.raises(RuntimeError), _bedrock_token_window.blank(): + raise RuntimeError("call failed") + assert os.environ[name] == " \t " + monkeypatch.delenv(name) + with _bedrock_token_window.blank(): + assert os.environ[name] == "" + assert name not in os.environ + + def test_bedrock_inference_validates_credentials_loaded_at_sdk_import(isolated_provider_environment, monkeypatch): def unexpected_completion(**_kwargs): pytest.fail("Bedrock completion must not be called for an HTTP bearer endpoint") @@ -295,7 +361,10 @@ def __getattr__(self, name): assert server.connections == 0 -def test_bedrock_inference_accepts_https_bearer_override(isolated_provider_environment, monkeypatch, loopback_tls): +@pytest.mark.parametrize("model", ["anthropic.claude-3-haiku-20240307-v1:0", "responses/us.openai.gpt-5.6-sol"]) +def test_bedrock_inference_accepts_https_bearer_override( + isolated_provider_environment, monkeypatch, loopback_tls, model +): litellm = pytest.importorskip("litellm") from litellm.caching.llm_caching_handler import LLMClientCache @@ -303,11 +372,14 @@ def test_bedrock_inference_accepts_https_bearer_override(isolated_provider_envir monkeypatch.setenv("AWS_BEARER_TOKEN_BEDROCK", "loopback-bearer-token") monkeypatch.setenv("SSL_VERIFY", str(ca_bundle)) monkeypatch.setattr(litellm, "in_memory_llm_clients_cache", LLMClientCache(), raising=False) + monkeypatch.setattr(litellm, "drop_params", True) with _server([200], tls_context) as server: - client = _client(monkeypatch, f"https://127.0.0.1:{server.server_port}") + client = _client(monkeypatch, f"https://127.0.0.1:{server.server_port}", model=model) assert client.completions("system", "user") == "recovered" assert server.requests == [200] + assert server.paths[0].endswith("/openai/v1/responses" if model.startswith("responses/") else "/converse") assert server.bearer_requests == 1 + assert os.environ["AWS_BEARER_TOKEN_BEDROCK"] == "loopback-bearer-token" @pytest.mark.parametrize("provider", ["bedrock", "openai"]) From 536727d754fe84a9ca89e2e182e12035936dbc10 Mon Sep 17 00:00:00 2001 From: Christopher Kevin Date: Fri, 20 Nov 2026 12:34:42 -0800 Subject: [PATCH 08/11] fix: name the HTTPS requirement in the Bedrock bearer preflight failure The preflight raised InvalidConfigError, but only the exception class name reached the result detail, so the cause was hidden. Return the failure directly with a constant detail that names the HTTPS requirement and keeps the token and endpoint out of the output. Signed-off-by: Christopher Kevin --- src/skillevaluator/tier3/harbor/runtime_preflight.py | 10 +++++++++- tests/test_harbor_runtime_preflight.py | 3 +++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/skillevaluator/tier3/harbor/runtime_preflight.py b/src/skillevaluator/tier3/harbor/runtime_preflight.py index 044f3a938..a5d9563b3 100644 --- a/src/skillevaluator/tier3/harbor/runtime_preflight.py +++ b/src/skillevaluator/tier3/harbor/runtime_preflight.py @@ -1328,7 +1328,15 @@ def _probe_bedrock_model(provider: ProviderConfig, *, timeout_seconds: float) -> catalog_uses_tls = _bedrock_client_uses_tls(bedrock) runtime_uses_tls = _bedrock_client_uses_tls(bedrock_runtime) if has_bearer_token and not (catalog_uses_tls and runtime_uses_tls): - raise InvalidConfigError(error_msg="Bedrock bearer authentication requires HTTPS endpoints") + # A constant detail names the cause and keeps the token and endpoint out of the output. + return ModelProbeResult( + False, + provider.provider, + provider.model, + "Bedrock bearer authentication (AWS_BEARER_TOKEN_BEDROCK) requires https:// Bedrock endpoints; " + "use an HTTPS endpoint override or unset the token", + failure_kind=ModelCatalogFailureKind.INVALID_CONFIGURATION, + ) if (catalog_uses_tls or runtime_uses_tls) and _is_invalid_bedrock_ca_bundle(session): raise InvalidConfigError(error_msg="configured AWS CA bundle cannot be loaded") region_name = provider.region or "us-west-2" diff --git a/tests/test_harbor_runtime_preflight.py b/tests/test_harbor_runtime_preflight.py index 510ddd2ec..e6bd9f2d0 100644 --- a/tests/test_harbor_runtime_preflight.py +++ b/tests/test_harbor_runtime_preflight.py @@ -1679,7 +1679,10 @@ def test_bedrock_preflight_requires_https_for_bearer_endpoints( assert result.failure_kind == "invalid_configuration", result.detail assert runtime_preflight.credential_probe_disposition(provider, result) == "fatal" + assert "https" in result.detail.lower() + assert "AWS_BEARER_TOKEN_BEDROCK" in result.detail assert "test-bearer-token" not in result.detail + assert "127.0.0.1" not in result.detail @pytest.mark.parametrize("bearer_token", ["", " \t "]) From 897691566cb9432665b7e7949d0bf9135de8bf6f Mon Sep 17 00:00:00 2001 From: Christopher Kevin Date: Fri, 20 Nov 2026 12:40:45 -0800 Subject: [PATCH 09/11] docs: record the blank Bedrock bearer token fix in the changelog Add a Fixed entry for the preflight and host inference now using IAM credentials when AWS_BEARER_TOKEN_BEDROCK is empty or whitespace-only. Signed-off-by: Christopher Kevin --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2386b350f..38437c262 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -58,6 +58,12 @@ All notable changes to SkillEvaluator are documented in this file. ### Fixed +- Bedrock preflight and host inference now sign requests with IAM credentials + when `AWS_BEARER_TOKEN_BEDROCK` is empty or whitespace-only, for example when + a CI job exports an unset secret. Previously the Tier 3 preflight sent a blank + `Authorization: Bearer` header, and host inference failed with an illegal + header value. This includes models called through the Bedrock Responses + route. - Tier 1 code risk no longer lets a skill configure its own Bandit scan. A `.bandit` file shipped in the skill (at the root or nested, for example `scripts/.bandit`) with `skips` or `tests`, or `# nosec` comments on risky From 96a78b887bff3f5111b18730c2107bfadd6a7303 Mon Sep 17 00:00:00 2001 From: Christopher Kevin Date: Fri, 20 Nov 2026 12:42:17 -0800 Subject: [PATCH 10/11] fix: require HTTPS for every Bedrock endpoint override that carries the bearer token Host inference only checked AWS_BEDROCK_RUNTIME_ENDPOINT, so the mantle route (BEDROCK_MANTLE_API_BASE) and the hosted-platform route could still send the bearer token over HTTP. Check all of those overrides with one helper, and only when a real bearer token is set. Signed-off-by: Christopher Kevin --- docs/tier3-runtime.mdx | 4 +- src/skillevaluator/inference/client.py | 34 +++++++++--- tests/test_retry_provider_transport.py | 76 ++++++++++++++++++++++++-- 3 files changed, 101 insertions(+), 13 deletions(-) diff --git a/docs/tier3-runtime.mdx b/docs/tier3-runtime.mdx index 41917fb13..5f14dddd1 100644 --- a/docs/tier3-runtime.mdx +++ b/docs/tier3-runtime.mdx @@ -170,7 +170,9 @@ behind the operator-selected `tier3` extra, so static Tier 1 installs do not pul it in. The shared LLM client uses `litellm>=1.110.2,<1.111.0.dev0` with `boto3>=1.44.0`. When you set `AWS_BEARER_TOKEN_BEDROCK`, use HTTPS for the Bedrock catalog and runtime endpoints checked by preflight and for the -`AWS_BEDROCK_RUNTIME_ENDPOINT` override used by the LiteLLM client. +endpoint overrides used by the LiteLLM client: `AWS_BEDROCK_RUNTIME_ENDPOINT`, +`BEDROCK_MANTLE_API_BASE`, `ANTHROPIC_AWS_BASE_URL`, and +`ANTHROPIC_AWS_API_BASE`. The integration preserves SkillEvaluator's runtime and artifact contracts while using Harbor 0.25: diff --git a/src/skillevaluator/inference/client.py b/src/skillevaluator/inference/client.py index 3e921a55d..842dfbc4f 100644 --- a/src/skillevaluator/inference/client.py +++ b/src/skillevaluator/inference/client.py @@ -108,6 +108,30 @@ def blank(self) -> Iterator[None]: _bedrock_token_window = _BedrockTokenWindow() +# Endpoint overrides that LiteLLM's Bedrock routes send the bearer token to. +_BEDROCK_BEARER_ENDPOINT_VARIABLES = ( + "AWS_BEDROCK_RUNTIME_ENDPOINT", # bedrock-runtime routes, such as Converse and Responses + "BEDROCK_MANTLE_API_BASE", # the mantle/ route + # The hosted-platform route sends the token only when its own API key is not set. + "ANTHROPIC_AWS_BASE_URL", + "ANTHROPIC_AWS_API_BASE", +) + + +def _require_https_for_bedrock_bearer_endpoints() -> None: + """Refuse to send a Bedrock bearer token to a plain HTTP endpoint override.""" + for variable in _BEDROCK_BEARER_ENDPOINT_VARIABLES: + endpoint = os.environ.get(variable) + if not endpoint: + continue + try: + target = urlsplit(endpoint) + uses_https = target.scheme == "https" and target.hostname is not None + except ValueError: + uses_https = False + if not uses_https: + raise LLMClientError(f"{variable} must use HTTPS with a Bedrock bearer token.") + def _effective_openai_base_url(explicit_base_url: str | None) -> str: if explicit_base_url is not None: @@ -835,15 +859,9 @@ def _anthropic_kwargs(include_schema: bool) -> dict[str, Any]: ) from exc # LiteLLM can load environment variables on its first import. has_bearer_token = has_bedrock_bearer_token() + if has_bearer_token: + _require_https_for_bedrock_bearer_endpoints() endpoint = os.environ.get("AWS_BEDROCK_RUNTIME_ENDPOINT") if has_bearer_token else None - if endpoint: - try: - target = urlsplit(endpoint) - uses_https = target.scheme == "https" and target.hostname is not None - except ValueError: - uses_https = False - if not uses_https: - raise LLMClientError("AWS_BEDROCK_RUNTIME_ENDPOINT must use HTTPS with a Bedrock bearer token.") # LiteLLM sends a whitespace-only AWS_BEARER_TOKEN_BEDROCK as a blank Bearer header. # An empty key makes it sign with the IAM credentials, as it does for an unset variable. # The Responses route also reads the variable itself, so hide it for the call. diff --git a/tests/test_retry_provider_transport.py b/tests/test_retry_provider_transport.py index 794948f79..754a7d2c6 100644 --- a/tests/test_retry_provider_transport.py +++ b/tests/test_retry_provider_transport.py @@ -29,7 +29,7 @@ def isolated_provider_environment(monkeypatch, tmp_path): """Use synthetic credentials and refuse any network address outside loopback.""" for name in tuple(os.environ): - if name.startswith("AWS_"): + if name.startswith(("AWS_", "BEDROCK_MANTLE_", "ANTHROPIC_AWS_")): monkeypatch.delenv(name) monkeypatch.setenv("HOME", str(tmp_path)) monkeypatch.setenv("AWS_SHARED_CREDENTIALS_FILE", str(tmp_path / "credentials")) @@ -131,9 +131,10 @@ def do_POST(self): ], "usage": {"input_tokens": 2, "output_tokens": 1, "total_tokens": 3}, } - elif self.path.endswith("/invoke"): + elif self.path.endswith(("/invoke", "/messages")): payload = { "id": "loopback", + "model": "loopback", "type": "message", "role": "assistant", "content": [{"type": "text", "text": "recovered"}], @@ -226,10 +227,16 @@ def operation(): assert server.requests == [429] -def _client(monkeypatch, endpoint, provider="bedrock", model="anthropic.claude-3-haiku-20240307-v1:0"): +def _client( + monkeypatch, + endpoint, + provider="bedrock", + model="anthropic.claude-3-haiku-20240307-v1:0", + endpoint_variable="AWS_BEDROCK_RUNTIME_ENDPOINT", +): if provider == "bedrock": pytest.importorskip("litellm") - monkeypatch.setenv("AWS_BEDROCK_RUNTIME_ENDPOINT", endpoint) + monkeypatch.setenv(endpoint_variable, endpoint) client = LLMClient(max_retries=2, retry_base_delay=0, retry_max_delay=0) client._provider_config = ProviderConfig("bedrock", model, None, None, f"bedrock/{model}", region="us-west-2") return client @@ -275,6 +282,67 @@ def test_bedrock_inference_rejects_http_bearer_override(isolated_provider_enviro assert server.connections == 0 +_MANTLE_MODEL = "mantle/anthropic.claude-3-haiku-20240307-v1:0" +_PLATFORM_MODEL = "claude_platform/anthropic.claude-3-haiku-20240307-v1:0" +_OTHER_ROUTE_ENDPOINTS = [ + (_MANTLE_MODEL, "BEDROCK_MANTLE_API_BASE", "/anthropic/v1/messages"), + (_PLATFORM_MODEL, "ANTHROPIC_AWS_BASE_URL", "/v1/messages"), + (_PLATFORM_MODEL, "ANTHROPIC_AWS_API_BASE", "/v1/messages"), +] + + +@pytest.mark.parametrize(("model", "variable", "_path"), _OTHER_ROUTE_ENDPOINTS) +def test_bedrock_inference_rejects_http_bearer_override_on_other_routes( + isolated_provider_environment, monkeypatch, model, variable, _path +): + monkeypatch.setenv("AWS_BEARER_TOKEN_BEDROCK", "loopback-bearer-token") + monkeypatch.setenv("ANTHROPIC_AWS_WORKSPACE_ID", "loopback-workspace") + with _server([200]) as server: + client = _client(monkeypatch, f"http://127.0.0.1:{server.server_port}", model=model, endpoint_variable=variable) + with pytest.raises(LLMClientError, match=f"{variable} must use HTTPS"): + client.completions("system", "user") + assert server.connections == 0 + + +@pytest.mark.parametrize(("model", "variable", "path"), _OTHER_ROUTE_ENDPOINTS) +def test_bedrock_inference_accepts_https_bearer_override_on_other_routes( + isolated_provider_environment, monkeypatch, loopback_tls, model, variable, path +): + litellm = pytest.importorskip("litellm") + from litellm.caching.llm_caching_handler import LLMClientCache + + tls_context, ca_bundle = loopback_tls + monkeypatch.setenv("AWS_BEARER_TOKEN_BEDROCK", "loopback-bearer-token") + monkeypatch.setenv("ANTHROPIC_AWS_WORKSPACE_ID", "loopback-workspace") + monkeypatch.setenv("SSL_VERIFY", str(ca_bundle)) + monkeypatch.setattr(litellm, "in_memory_llm_clients_cache", LLMClientCache(), raising=False) + monkeypatch.setattr(litellm, "drop_params", True) + with _server([200], tls_context) as server: + client = _client( + monkeypatch, f"https://127.0.0.1:{server.server_port}", model=model, endpoint_variable=variable + ) + assert client.completions("system", "user") == "recovered" + assert server.paths == [path] + assert server.bearer_requests == 1 + + +@pytest.mark.parametrize("bearer_token", ["", " \t "]) +@pytest.mark.parametrize(("model", "variable", "path"), _OTHER_ROUTE_ENDPOINTS) +def test_bedrock_inference_ignores_http_override_on_other_routes_when_bearer_token_is_blank( + isolated_provider_environment, monkeypatch, model, variable, path, bearer_token +): + litellm = pytest.importorskip("litellm") + monkeypatch.setenv("AWS_BEARER_TOKEN_BEDROCK", bearer_token) + monkeypatch.setenv("ANTHROPIC_AWS_WORKSPACE_ID", "loopback-workspace") + monkeypatch.setattr(litellm, "drop_params", True) + with _server([200]) as server: + client = _client(monkeypatch, f"http://127.0.0.1:{server.server_port}", model=model, endpoint_variable=variable) + assert client.completions("system", "user") == "recovered" + assert server.paths == [path] + assert server.authorizations[0].startswith("AWS4-HMAC-SHA256 ") + assert server.bearer_requests == 0 + + @pytest.mark.parametrize("bearer_token", ["", " ", " \t "]) def test_bedrock_inference_signs_with_sigv4_when_bearer_token_is_blank( isolated_provider_environment, monkeypatch, bearer_token From 6f13bc607b01ff1c9e081a6b40d0823969c1e10a Mon Sep 17 00:00:00 2001 From: Christopher Kevin Date: Fri, 20 Nov 2026 13:12:11 -0800 Subject: [PATCH 11/11] fix: preserve Bedrock route endpoints and GPT capabilities Signed-off-by: Christopher Kevin --- src/skillevaluator/inference/client.py | 7 +++++- src/skillevaluator/provider_config.py | 4 ++-- tests/test_retry_provider_transport.py | 31 +++++++++++++++++++++++--- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/src/skillevaluator/inference/client.py b/src/skillevaluator/inference/client.py index 842dfbc4f..dc2eaf148 100644 --- a/src/skillevaluator/inference/client.py +++ b/src/skillevaluator/inference/client.py @@ -861,7 +861,12 @@ def _anthropic_kwargs(include_schema: bool) -> dict[str, Any]: has_bearer_token = has_bedrock_bearer_token() if has_bearer_token: _require_https_for_bedrock_bearer_endpoints() - endpoint = os.environ.get("AWS_BEDROCK_RUNTIME_ENDPOINT") if has_bearer_token else None + # Mantle resolves its own endpoint. An explicit runtime override takes precedence in LiteLLM. + endpoint = ( + os.environ.get("AWS_BEDROCK_RUNTIME_ENDPOINT") + if has_bearer_token and "/mantle/" not in f"/{config.model}" + else None + ) # LiteLLM sends a whitespace-only AWS_BEARER_TOKEN_BEDROCK as a blank Bearer header. # An empty key makes it sign with the IAM credentials, as it does for an unset variable. # The Responses route also reads the variable itself, so hide it for the call. diff --git a/src/skillevaluator/provider_config.py b/src/skillevaluator/provider_config.py index 2efc38508..8dc32a83d 100644 --- a/src/skillevaluator/provider_config.py +++ b/src/skillevaluator/provider_config.py @@ -103,7 +103,7 @@ _HEX_DIGIT_BYTES = frozenset(b"0123456789abcdefABCDEF") _UNRESERVED_BYTES = frozenset(b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~") _NO_CUSTOM_TEMPERATURE_MODEL_IDS = frozenset({"claude-mythos-preview"}) -_ANTHROPIC_BEDROCK_PREFIX_RE = re.compile(r"^(?:(?:[a-z]{2}|global)\.)?anthropic\.") +_BEDROCK_VENDOR_PREFIX_RE = re.compile(r"^(?:(?:[a-z]{2}|global)\.)?(?:anthropic|openai)\.") # Gateway catalogs can put vendor words before the model name, as in # ``aws/anthropic/bedrock-claude-opus-5-5``. _GATEWAY_LEAF_PREFIX_RE = re.compile(r"^(?:[a-z]+-)+?(?=(?:claude|gpt)-)") @@ -150,7 +150,7 @@ def _model_leaf(model: str) -> str: """Return a normalized model ID for capability checks only.""" leaf = str(model or "").strip().casefold().rsplit("/", 1)[-1] leaf = _GATEWAY_LEAF_PREFIX_RE.sub("", leaf, count=1) - return _ANTHROPIC_BEDROCK_PREFIX_RE.sub("", leaf, count=1) + return _BEDROCK_VENDOR_PREFIX_RE.sub("", leaf, count=1) def _claude_version(model: str) -> tuple[int, int] | None: diff --git a/tests/test_retry_provider_transport.py b/tests/test_retry_provider_transport.py index 754a7d2c6..8d5eab51f 100644 --- a/tests/test_retry_provider_transport.py +++ b/tests/test_retry_provider_transport.py @@ -326,6 +326,31 @@ def test_bedrock_inference_accepts_https_bearer_override_on_other_routes( assert server.bearer_requests == 1 +@pytest.mark.parametrize("model_prefix", ["", "bedrock/"]) +def test_bedrock_mantle_uses_its_own_endpoint_when_runtime_is_also_set( + isolated_provider_environment, monkeypatch, loopback_tls, model_prefix +): + litellm = pytest.importorskip("litellm") + from litellm.caching.llm_caching_handler import LLMClientCache + + tls_context, ca_bundle = loopback_tls + monkeypatch.setenv("AWS_BEARER_TOKEN_BEDROCK", "loopback-bearer-token") + monkeypatch.setenv("SSL_VERIFY", str(ca_bundle)) + monkeypatch.setattr(litellm, "in_memory_llm_clients_cache", LLMClientCache(), raising=False) + monkeypatch.setattr(litellm, "drop_params", False) + with _server([200], tls_context) as runtime, _server([200], tls_context) as mantle: + monkeypatch.setenv("AWS_BEDROCK_RUNTIME_ENDPOINT", f"https://127.0.0.1:{runtime.server_port}") + client = _client( + monkeypatch, + f"https://127.0.0.1:{mantle.server_port}", + model=f"{model_prefix}{_MANTLE_MODEL}", + endpoint_variable="BEDROCK_MANTLE_API_BASE", + ) + assert client.completions("system", "user") == "recovered" + assert mantle.paths == ["/anthropic/v1/messages"] + assert runtime.connections == 0 + + @pytest.mark.parametrize("bearer_token", ["", " \t "]) @pytest.mark.parametrize(("model", "variable", "path"), _OTHER_ROUTE_ENDPOINTS) def test_bedrock_inference_ignores_http_override_on_other_routes_when_bearer_token_is_blank( @@ -363,7 +388,7 @@ def test_bedrock_responses_route_signs_with_sigv4_when_bearer_token_is_blank( ): litellm = pytest.importorskip("litellm") monkeypatch.setenv("AWS_BEARER_TOKEN_BEDROCK", bearer_token) - monkeypatch.setattr(litellm, "drop_params", True) + monkeypatch.setattr(litellm, "drop_params", False) with _server([200]) as server: client = _client(monkeypatch, f"http://127.0.0.1:{server.server_port}", model="responses/us.openai.gpt-5.6-sol") assert client.completions("system", "user") == "recovered" @@ -379,7 +404,7 @@ def test_bedrock_responses_route_restores_blank_bearer_token_after_a_failed_call ): litellm = pytest.importorskip("litellm") monkeypatch.setenv("AWS_BEARER_TOKEN_BEDROCK", " \t ") - monkeypatch.setattr(litellm, "drop_params", True) + monkeypatch.setattr(litellm, "drop_params", False) with _server([400]) as server: client = _client(monkeypatch, f"http://127.0.0.1:{server.server_port}", model="responses/us.openai.gpt-5.6-sol") with pytest.raises(Exception) as raised: @@ -440,7 +465,7 @@ def test_bedrock_inference_accepts_https_bearer_override( monkeypatch.setenv("AWS_BEARER_TOKEN_BEDROCK", "loopback-bearer-token") monkeypatch.setenv("SSL_VERIFY", str(ca_bundle)) monkeypatch.setattr(litellm, "in_memory_llm_clients_cache", LLMClientCache(), raising=False) - monkeypatch.setattr(litellm, "drop_params", True) + monkeypatch.setattr(litellm, "drop_params", False) with _server([200], tls_context) as server: client = _client(monkeypatch, f"https://127.0.0.1:{server.server_port}", model=model) assert client.completions("system", "user") == "recovered"