Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to SkillEvaluator are documented in this file.

## Unreleased

### Security

- Update LiteLLM and the minimum AWS SDK version in the optional LLM and
Comment thread
chrisknvidia marked this conversation as resolved.
Resolved
Tier 3 installs. Bedrock preflight and host inference reject HTTP endpoint
overrides when bearer authentication is configured.

### Changed

- Claude Code log recovery pairs batched and delayed tool results without repeatedly
Expand Down
7 changes: 4 additions & 3 deletions docs/tier3-runtime.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +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 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` 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:
Expand Down
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ 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",
"litellm>=1.92.0,<1.94.0.dev0",
# Botocore 1.44 introduced HTTPS enforcement for bearer authentication.
"boto3>=1.44.0",
"litellm>=1.110.2,<1.111.0.dev0",
Comment thread
chrisknvidia marked this conversation as resolved.
Resolved
"openai>=2.21.0",
]
# Tier 2 intra-skill deduplication and local-catalog inter-skill similarity.
Expand Down
15 changes: 15 additions & 0 deletions src/skillevaluator/inference/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -792,10 +792,25 @@ def _anthropic_kwargs(include_schema: bool) -> dict[str, Any]:
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")
Comment thread
chrisknvidia marked this conversation as resolved.
Resolved
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.")
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 {}),
**_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 {}),
Expand Down
20 changes: 10 additions & 10 deletions src/skillevaluator/tier3/harbor/runtime_preflight.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ class CredentialProbeDisposition(StrEnum):
for _error_name, _target in (
("LoginError", "authentication"),
("InvalidChecksumConfigError", "configuration"),
("InvalidEndpointConfigurationError", "configuration"),
("UnknownTokenProviderError", "configuration"),
("UnsupportedServiceProtocolsError", "configuration"),
):
Expand Down Expand Up @@ -1290,14 +1291,11 @@ 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", "")
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 isinstance(bearer_token, str) or not bearer_token.strip():
if not has_bearer_token:
Comment thread
chrisknvidia marked this conversation as resolved.
Resolved
metadata_unavailable = _monitor_bedrock_metadata_unavailability(session)
get_credentials = getattr(session, "get_credentials", None)
if callable(get_credentials):
Expand All @@ -1323,9 +1321,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 has_bearer_token and not (catalog_uses_tls and runtime_uses_tls):
raise InvalidConfigError(error_msg="Bedrock bearer authentication requires HTTPS endpoints")
Comment thread
chrisknvidia marked this conversation as resolved.
Resolved
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(
Expand Down
38 changes: 38 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,54 @@
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

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."""
Expand Down
31 changes: 28 additions & 3 deletions tests/test_harbor_runtime_preflight.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import hashlib
import json
import os
import ssl
import subprocess
import sys
from concurrent.futures import ThreadPoolExecutor
Expand All @@ -33,6 +34,7 @@
EndpointProviderError,
InvalidConfigError,
InvalidDefaultsMode,
InvalidEndpointConfigurationError,
InvalidIMDSEndpointError,
InvalidIMDSEndpointModeError,
InvalidProxiesConfigError,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -1636,28 +1639,49 @@ 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
assert "test-bearer-token" not in result.detail
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"],
Expand Down Expand Up @@ -2160,6 +2184,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"]),
Expand Down
20 changes: 13 additions & 7 deletions tests/test_oss_packaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -152,16 +153,18 @@ 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"
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
}
Expand All @@ -170,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)

Expand All @@ -181,7 +187,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:
Expand Down Expand Up @@ -923,7 +929,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
Expand Down
Loading
Loading