Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- **Breaking:** an Agent Manifest binding now requires issuer key
authorization (Agent Manifest spec §5.3.3). The trust anchor at
`agent_manifest.trust_anchor_path` carries an `issuers` list of SPIFFE URIs
per key, and the gateway passes it to the SDK as `trusted_key_issuers`.
Before, cMCP passed no issuer policy and agent-manifest 0.15.0 skipped the
check, so any trusted key could sign a manifest naming any issuer. Startup
now stops with `AGENT_MANIFEST_BINDING_FAILED` when no key in the trust
anchor lists `issuers`, and when the signing key is not authorized for the
manifest's `issuer`. `cmcp verify` and `verify_trace_claim` read the same
policy (new `trusted_agent_manifest_key_issuers` argument) and report the
binding unverified without it. The trust anchor is parsed once for keys and
policy, and loading it fails on a malformed SPIFFE ID in `issuers` or a
repeated `key_id`. Found by @litzki-systems on
agentrust-io/agent-manifest#493.
- Test fixtures and docs use vendor-neutral example model names.
- LICENSE and NOTICE name the copyright holder as AgenTrust Contributors. The
previous LICENSE line credited Agentic AI Foundation contributors, but the
Expand Down
4 changes: 2 additions & 2 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ policy_reload_interval_seconds: 0

An Agent Manifest is a signed document that declares which agent this is and which policy and tool catalog it was approved with. Setting this block makes the gateway check that manifest before it accepts any session.

All fields are optional as a group. If `path` is set, `trust_anchor_path` must also be set. When the block is configured, cMCP fails closed on manifest signature failure, subject mismatch, policy hash drift, or catalog hash drift.
All fields are optional as a group. If `path` is set, `trust_anchor_path` must also be set. When the block is configured, cMCP fails closed on manifest signature failure, a signing key not authorized for the manifest's issuer, subject mismatch, policy hash drift, or catalog hash drift.

| Field | Type | Default | Description |
|-------|------|---------|-------------|
| `path` | string | none | Path to the signed Agent Manifest JSON document. Path traversal (`..` components) is rejected. |
| `trust_anchor_path` | string | none | Path to a JSON trust anchor containing the issuer Ed25519 public key, either as `{ "key_id": "...", "public_key_base64url": "..." }` or `{ "keys": [...] }`. |
| `trust_anchor_path` | string | none | Path to a JSON trust anchor containing the issuer Ed25519 public key and the issuers it may sign for, either as `{ "key_id": "...", "public_key_base64url": "...", "issuers": ["spiffe://..."] }` or `{ "keys": [...] }` with the same fields per key. `issuers` is required (Agent Manifest spec §5.3.3): a trust anchor in which no key lists `issuers` stops startup with `AGENT_MANIFEST_BINDING_FAILED`, and a key that does not list the manifest's `issuer` is not authorized to sign it. Each issuer must be a well-formed SPIFFE ID (no userinfo, port, query or fragment), and a repeated `key_id` is refused. |
| `authenticated_subject` | string | none | SPIFFE URI for the authenticated agent subject. This must equal `manifest.agent_id`. In production this should come from the agent SVID/mTLS identity; the config field is the current runtime input for that subject. |
| `revocation_list_path` | string | none | Path to a JSON Lines revocation list, one record per line with `manifest_id`, `revoked_at`, `reason` and `revoked_by` (the format `manifest revoke` writes and `manifest verify --crl-path` reads). A manifest listed there fails startup. A missing, unreadable or malformed file also fails startup rather than being read as empty. Requires `path`. Without it, revocation is not checked and startup logs a warning. The list is read at startup only, so a revocation added later takes effect on the next restart. |

Expand Down
123 changes: 106 additions & 17 deletions src/cmcp_runtime/agent_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,31 +178,99 @@ def load_agent_manifest(path: str) -> dict[str, Any]:
return load_agent_manifest_document(path).manifest


def load_agent_manifest_trust_anchor(path: str) -> dict[str, bytes]:
"""Load issuer public keys from a JSON trust anchor file."""
# SPIFFE ID grammar (SPIFFE ID specification, section 2): a non-empty trust
# domain of lowercase letters, digits, ".", "-" and "_", with no userinfo, port,
# query or fragment, then optional path segments of letters, digits, ".", "-"
# and "_", none empty, "." or "..".
_SPIFFE_SCHEME = "spiffe://"
_SPIFFE_TRUST_DOMAIN = re.compile(r"[a-z0-9._-]{1,255}")
_SPIFFE_PATH_SEGMENT = re.compile(r"[A-Za-z0-9._-]+")
_MAX_SPIFFE_ID_BYTES = 2048


def _is_spiffe_id(value: object) -> bool:
"""Whether *value* is a well-formed SPIFFE ID."""
if not isinstance(value, str) or not value.startswith(_SPIFFE_SCHEME):
return False
try:
encoded = value.encode("utf-8")
except UnicodeEncodeError:
# A lone surrogate survives json.loads but is not a SPIFFE ID.
return False
if len(encoded) > _MAX_SPIFFE_ID_BYTES:
return False
trust_domain, has_path, path = value[len(_SPIFFE_SCHEME) :].partition("/")
if not _SPIFFE_TRUST_DOMAIN.fullmatch(trust_domain):
return False
if not has_path:
return True
return all(
_SPIFFE_PATH_SEGMENT.fullmatch(segment) and segment not in {".", ".."}
for segment in path.split("/")
)


def load_agent_manifest_trust_policy(
path: str,
) -> tuple[dict[str, bytes], dict[str, list[str]] | None]:
"""Load a trust anchor's keys and its issuer policy (spec 5.3.3) in one parse.

Each key is ``public_key_base64url`` with an optional ``key_id`` and an
optional ``issuers`` list of SPIFFE IDs that key may sign for, in the
single-key form or on each entry of ``keys[]``. A key with no ``issuers``
is authorized for no issuer.

The policy is None when no key in the file declares ``issuers``, which is
a trust anchor written before issuer authorization existed. The binding
refuses that rather than reading it as "any issuer". A repeated key_id or
a malformed issuer is a ConfigError, so neither can enter the policy.
"""
try:
with Path(path).open() as f:
raw = json.load(f)
except (OSError, json.JSONDecodeError) as exc:
raise ConfigError(f"Cannot read Agent Manifest trust anchor: {exc}") from exc

anchors: dict[str, bytes] = {}
if isinstance(raw, dict) and "public_key_base64url" in raw:
public_key = _b64url_decode(str(raw["public_key_base64url"]))
key_id = str(raw.get("key_id") or _key_id(public_key))
entries = [raw]
elif isinstance(raw, dict) and isinstance(raw.get("keys"), list):
entries = raw["keys"]
else:
raise ConfigError(
"Agent Manifest trust anchor must contain public_key_base64url or keys[]"
)

anchors: dict[str, bytes] = {}
policy: dict[str, list[str]] = {}
declared = False
for item in entries:
if not isinstance(item, dict):
raise ConfigError("Agent Manifest trust anchor keys must be objects")
public_key = _b64url_decode(str(item.get("public_key_base64url", "")))
key_id = str(item.get("key_id") or _key_id(public_key))
if key_id in anchors:
raise ConfigError(f"Agent Manifest trust anchor repeats key_id {key_id!r}")
anchors[key_id] = public_key
return anchors
if isinstance(raw, dict) and "keys" in raw and isinstance(raw["keys"], list):
for item in raw["keys"]:
if not isinstance(item, dict):
raise ConfigError("Agent Manifest trust anchor keys must be objects")
public_key = _b64url_decode(str(item.get("public_key_base64url", "")))
key_id = str(item.get("key_id") or _key_id(public_key))
anchors[key_id] = public_key
return anchors
raise ConfigError(
"Agent Manifest trust anchor must contain public_key_base64url or keys[]"
)
if "issuers" not in item:
continue
declared = True
issuers = item["issuers"]
if not isinstance(issuers, list) or not all(_is_spiffe_id(i) for i in issuers):
raise ConfigError(
"Agent Manifest trust anchor issuers must be a list of SPIFFE IDs"
)
policy[key_id] = list(issuers)
return anchors, (policy if declared else None)


def load_agent_manifest_trust_anchor(path: str) -> dict[str, bytes]:
"""Load issuer public keys from a JSON trust anchor file."""
return load_agent_manifest_trust_policy(path)[0]


def load_agent_manifest_issuer_policy(path: str) -> dict[str, list[str]] | None:
"""Load which issuers each trust-anchor key may sign for (spec 5.3.3)."""
return load_agent_manifest_trust_policy(path)[1]


# A revocation list is operator-supplied, so it is bounded the same way the
Expand Down Expand Up @@ -318,6 +386,11 @@ def _raise_for_sdk_result(result: Any, *, require_runtime_artifacts: bool) -> No
# as "tool_manifest.catalog_hash"; to an operator it is the same failure.
if mismatch_fields & {"tool_manifest", "tool_manifest.catalog_hash"}:
raise ConfigError("Agent Manifest tool catalog hash does not match runtime catalog")
if "signature.issuer" in mismatch_fields:
raise ConfigError(
"Agent Manifest signing key is not authorized for the manifest issuer "
"(spec 5.3.3)"
)
if "signature" in mismatch_fields:
raise ConfigError("Agent Manifest signature verification failed")
if result.result == agent_manifest_sdk.OverallResult.REVOKED:
Expand Down Expand Up @@ -354,6 +427,7 @@ def _verify_with_sdk(
envelope: bytes | None = None,
revocations: Any = None,
runtime_catalog: ToolCatalog | None = None,
trusted_key_issuers: dict[str, list[str]] | None = None,
) -> str | None:
"""Appraise the manifest; return the COSE signer's key id when there is exactly one."""
sealed_catalog_hash = tool_catalog_hash
Expand Down Expand Up @@ -400,6 +474,7 @@ def _verify_with_sdk(
else None
),
trusted_keys=_trusted_keys_for_sdk(trusted_keys),
trusted_key_issuers=trusted_key_issuers,
# The gateway performs a deliberately scoped appraisal. It holds the
# running policy bundle and tool catalog and verifies those two
# bindings; it does not hold the agent's system prompt or model
Expand Down Expand Up @@ -591,6 +666,7 @@ def verify_agent_manifest_binding(
envelope: bytes | None = None,
revocations: Any = None,
runtime_catalog: ToolCatalog | None = None,
trusted_key_issuers: dict[str, list[str]] | None = None,
) -> AgentManifestBinding:
"""Verify manifest signature and bind it to runtime session inputs.

Expand All @@ -611,7 +687,19 @@ def verify_agent_manifest_binding(
manifest does not bind.
The experimental evidence-requirements profile always binds this way and
must also sign the sealed digest.

*trusted_key_issuers* maps each trusted key_id to the issuers it may sign
for (load_agent_manifest_trust_policy). It is required: spec 5.3.3 forbids
a VALID manifest whose signing key has not been authorized for its declared
issuer, so a binding without the policy is refused rather than accepted on
the signature alone.
"""
if trusted_key_issuers is None:
raise ConfigError(
"Agent Manifest trust anchor authorizes no issuer: add an issuers list "
"to each key so the signing key can be authorized for the manifest "
"issuer (spec 5.3.3)"
)
manifest_id, agent_id, issuer, key_id, manifest_policy, manifest_catalog = (
_manifest_binding_fields(manifest)
)
Expand All @@ -633,6 +721,7 @@ def verify_agent_manifest_binding(
envelope=envelope,
revocations=revocations,
runtime_catalog=runtime_catalog,
trusted_key_issuers=trusted_key_issuers,
)
# A v0.2 manifest has no detached signature block; its signer is the key
# that verified the COSE envelope.
Expand Down
9 changes: 5 additions & 4 deletions src/cmcp_runtime/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def verify(

from cmcp_runtime.agent_manifest import (
load_agent_manifest,
load_agent_manifest_trust_anchor,
load_agent_manifest_trust_policy,
)
from cmcp_verify import ApprovedHashes, verify_audit_bundle, verify_trace_claim

Expand All @@ -273,10 +273,10 @@ def verify(
)

manifest_json = load_agent_manifest(agent_manifest) if agent_manifest is not None else None
manifest_keys = (
load_agent_manifest_trust_anchor(agent_manifest_trust_anchor)
manifest_keys, manifest_key_issuers = (
load_agent_manifest_trust_policy(agent_manifest_trust_anchor)
if agent_manifest_trust_anchor is not None
else None
else (None, None)
)
if agent_manifest is not None and agent_manifest_trust_anchor is None:
click.echo(
Expand All @@ -293,6 +293,7 @@ def verify(
trusted_public_key_hex=trusted_key,
agent_manifest=manifest_json,
trusted_agent_manifest_keys=manifest_keys,
trusted_agent_manifest_key_issuers=manifest_key_issuers,
trusted_tpm_ca_pem=tpm_ca_bundle,
expected_launch_measurements=launch_measurements or None,
)
Expand Down
5 changes: 3 additions & 2 deletions src/cmcp_runtime/startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
AgentManifestBinding,
load_agent_manifest_document,
load_agent_manifest_revocations,
load_agent_manifest_trust_anchor,
load_agent_manifest_trust_policy,
verify_agent_manifest_binding,
)
from cmcp_runtime.audit.keys import SigningKey
Expand Down Expand Up @@ -733,7 +733,7 @@ def run_startup(config_path: str) -> RuntimeContext:
if config.agent_manifest.path is not None and config.agent_manifest.trust_anchor_path is not None:
try:
loaded = load_agent_manifest_document(config.agent_manifest.path)
trusted_keys = load_agent_manifest_trust_anchor(
trusted_keys, trusted_key_issuers = load_agent_manifest_trust_policy(
config.agent_manifest.trust_anchor_path
)
revocations = (
Expand All @@ -757,6 +757,7 @@ def run_startup(config_path: str) -> RuntimeContext:
enforcement_mode=config.attestation.enforcement_mode,
allow_dev_subject_from_manifest=config.dev_mode,
revocations=revocations,
trusted_key_issuers=trusted_key_issuers,
)
except ConfigError as exc:
_fatal("AGENT_MANIFEST_BINDING_FAILED", str(exc), action="startup_aborted")
Expand Down
2 changes: 2 additions & 0 deletions src/cmcp_verify/verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,7 @@ def verify_trace_claim(
trusted_public_key_hex: str | None = None,
agent_manifest: dict[str, Any] | None = None,
trusted_agent_manifest_keys: dict[str, bytes] | None = None,
trusted_agent_manifest_key_issuers: dict[str, list[str]] | None = None,
trusted_ark_pem: bytes | None = None,
trusted_intel_root_pem: bytes | None = None,
trusted_tpm_ca_pem: bytes | None = None,
Expand Down Expand Up @@ -1068,6 +1069,7 @@ def verify_trace_claim(
allow_dev_subject_from_manifest=(
agent_identity.get("subject_source") == "manifest-dev"
),
trusted_key_issuers=trusted_agent_manifest_key_issuers,
)
expected_identity = {
"manifest_id": binding.manifest_id,
Expand Down
Loading
Loading