mirror of
https://github.com/NVIDIA/OpenShell.git
synced 2026-10-02 07:34:45 +08:00
feat(policy): preserve exact MCP revision allowlists (#3027)
* feat(mcp): add version-aware wire profile metadata Signed-off-by: Shiju <shiju@nvidia.com> * feat(policy): canonicalize MCP version allowlists Signed-off-by: Shiju <shiju@nvidia.com> * fix(policy): align MCP policy tests with current main Signed-off-by: Shiju <shiju@nvidia.com> * fix(policy): canonicalize supervisor protobuf ingress Materialize defaultable MCP revisions before ambiguity checks, OPA construction, and sidecar delivery. Reject invalid sidecar policies with bounded errors. Signed-off-by: Shiju <shiju@nvidia.com> --------- Signed-off-by: Shiju <shiju@nvidia.com>
This commit is contained in:
@@ -10,6 +10,7 @@ overly broad filesystem paths).
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import contextlib
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import grpc
|
||||
@@ -122,6 +123,60 @@ def test_create_sandbox_rejects_overly_broad_paths(
|
||||
assert "broad" in exc_info.value.details().lower()
|
||||
|
||||
|
||||
def test_create_sandbox_materializes_default_mcp_version(
|
||||
sandbox_client: SandboxClient,
|
||||
) -> None:
|
||||
"""An omitted MCP options stanza is stored with the pinned default version."""
|
||||
policy = _safe_policy()
|
||||
policy.network_policies["mcp_default"].CopyFrom(
|
||||
sandbox_pb2.NetworkPolicyRule(
|
||||
name="mcp_default",
|
||||
endpoints=[
|
||||
sandbox_pb2.NetworkEndpoint(
|
||||
host="mcp.example.com",
|
||||
port=443,
|
||||
protocol="mcp",
|
||||
rules=[
|
||||
sandbox_pb2.L7Rule(
|
||||
allow=sandbox_pb2.L7Allow(method="initialize")
|
||||
)
|
||||
],
|
||||
)
|
||||
],
|
||||
)
|
||||
)
|
||||
assert not policy.network_policies["mcp_default"].endpoints[0].HasField("mcp")
|
||||
spec = datamodel_pb2.SandboxSpec(policy=policy)
|
||||
|
||||
created = sandbox_client.create(workspace="default", spec=spec)
|
||||
try:
|
||||
stored = sandbox_client._stub.GetSandbox(
|
||||
openshell_pb2.GetSandboxRequest(
|
||||
name=created.name,
|
||||
workspace="default",
|
||||
)
|
||||
)
|
||||
stored_endpoint = stored.sandbox.spec.policy.network_policies[
|
||||
"mcp_default"
|
||||
].endpoints[0]
|
||||
|
||||
assert stored_endpoint.HasField("mcp")
|
||||
assert list(stored_endpoint.mcp.versions) == ["2025-11-25"]
|
||||
|
||||
config = sandbox_client._stub.GetSandboxConfig(
|
||||
sandbox_pb2.GetSandboxConfigRequest(sandbox_id=created.id)
|
||||
)
|
||||
endpoint = config.policy.network_policies["mcp_default"].endpoints[0]
|
||||
|
||||
assert endpoint.HasField("mcp")
|
||||
assert list(endpoint.mcp.versions) == ["2025-11-25"]
|
||||
finally:
|
||||
# Creation can complete before the compute driver reaches Ready, so
|
||||
# cleanup targets the gateway resource directly by its canonical name.
|
||||
with contextlib.suppress(grpc.RpcError):
|
||||
sandbox_client.delete(created.name, workspace="default")
|
||||
|
||||
|
||||
def test_update_policy_rejects_immutable_fields(
|
||||
sandbox: Callable[..., Sandbox],
|
||||
sandbox_client: SandboxClient,
|
||||
|
||||
Reference in New Issue
Block a user