secrets-engine/src/secrets_engine/authorization.py

417 lines
17 KiB
Python
Raw Normal View History

"""Fail-closed consumer validation for flex-auth action authorizations.
The canonical contract is flex-auth revision c473f19. State Hub does not yet
provide the durable authoritative endpoint, so this module validates supplied
objects but does not resolve or enable production actions by itself.
"""
from __future__ import annotations
import hashlib
import json
feat: bind the destroy gate to approval_binding_digest and pdp_path The vocabulary mapping this path was waiting on is not coming: gate-house rejected it in GH-DEC-2026-008, because a translation can be confidently wrong and fails open by accepting a claim approved for a different action. The stronger option arrived instead, and both halves are enforced here. flex-auth published binding.approval_binding_digest (FLEX-DEC-2026-007) to fix the circularity this repo reported: a pdp_digest recorded at issue time can never equal the request_digest of the request that carries the claim in its hashed context, so with GH-DEC-2026-008 requiring that equality, destroy would have failed closed forever on a check no correct record could pass. - authorization.approval_binding_digest implements the published exclusion rule, including Go's context,omitempty behaviour when stripping empties the context; digest_material drops an empty context for the same reason. - validate_decision_envelope recomputes the field rather than trusting it, refuses a claim-bearing request whose decision records none, and compares the claim's digest from step 1 against it -- never against request_digest, which still covers the claim so it stays a sound replay identity. - validate_approval_claim requires binding.pdp_path true before using pdp_digest at all. Path intent is never inferred from a digest that happens to be present; pre-schema-v3 approvals carry pdp_path false regardless of any digest they hold. Replay fixtures re-vendored from dd3ce4c. The destroy pins moved a second and final time; approval_binding_digest did not, which is the point. The fixture now demonstrates the property instead of asserting it: we rederive fa07becf... from its own request through our canonical implementation, proving we hash the same material flex-auth does rather than pinning a constant we cannot reproduce. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01E4tNMAYcSQmZWUE4wqP4ij Assistant: claude-code Assistant-Model: opus Assistant-Process: 715726@bnt-lap001 Assistant-Session: 80a42b32-cba6-4b23-8be0-68819b1a6092
2026-09-06 20:39:59 +02:00
import re
import uuid
from dataclasses import dataclass
from datetime import datetime, timezone
from typing import Any
from secrets_engine.catalog import CatalogEntry
from secrets_engine.errors import DecisionError
feat: bind the destroy gate to approval_binding_digest and pdp_path The vocabulary mapping this path was waiting on is not coming: gate-house rejected it in GH-DEC-2026-008, because a translation can be confidently wrong and fails open by accepting a claim approved for a different action. The stronger option arrived instead, and both halves are enforced here. flex-auth published binding.approval_binding_digest (FLEX-DEC-2026-007) to fix the circularity this repo reported: a pdp_digest recorded at issue time can never equal the request_digest of the request that carries the claim in its hashed context, so with GH-DEC-2026-008 requiring that equality, destroy would have failed closed forever on a check no correct record could pass. - authorization.approval_binding_digest implements the published exclusion rule, including Go's context,omitempty behaviour when stripping empties the context; digest_material drops an empty context for the same reason. - validate_decision_envelope recomputes the field rather than trusting it, refuses a claim-bearing request whose decision records none, and compares the claim's digest from step 1 against it -- never against request_digest, which still covers the claim so it stays a sound replay identity. - validate_approval_claim requires binding.pdp_path true before using pdp_digest at all. Path intent is never inferred from a digest that happens to be present; pre-schema-v3 approvals carry pdp_path false regardless of any digest they hold. Replay fixtures re-vendored from dd3ce4c. The destroy pins moved a second and final time; approval_binding_digest did not, which is the point. The fixture now demonstrates the property instead of asserting it: we rederive fa07becf... from its own request through our canonical implementation, proving we hash the same material flex-auth does rather than pinning a constant we cannot reproduce. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01E4tNMAYcSQmZWUE4wqP4ij Assistant: claude-code Assistant-Model: opus Assistant-Process: 715726@bnt-lap001 Assistant-Session: 80a42b32-cba6-4b23-8be0-68819b1a6092
2026-09-06 20:39:59 +02:00
DIGEST_RE = re.compile(r"^sha256:[0-9a-f]{64}$")
fix: send the tenant the policy package scopes us to, and adopt v2 build_action_request emitted no tenant field at all. The deployed secrets-engine.catalog-lane.lifecycle v2 package reads known_tenant := "tenant:platform" request_tenant := object.get(input, "tenant", "") so an absent tenant is not an ignored field, it matches the wrong_tenant first-denial branch. Every gated action this engine sent would have been denied -- and the omission also produced a request_digest that could match no correctly issued decision, since tenant is hashed material. That is the same class of defect as hashing excluded fields, arriving from the other direction, and again only a real artifact exposed it. Found by answering the GLAS-WP-0015 tenant-alignment question instead of assuming the values lined up. - REQUEST_TENANT is pinned against the vendored allow envelopes, so a package retenanting fails a test rather than denying production. - An empty tenant is refused at build time. - Accepted policy version moves v1 -> v2. v1 had no tenant rule and failed open: a rotate under tenant:coulomb returned allow against the deployed package. flex-auth superseded rather than amended it, because a fail-open correction has to be visible as a version change. A test pins that a v1 decision is refused. - Vendored decision_wrong_tenant_deny.json as the denial evidence glas asked for, with tests that we refuse it on effect before anything else and that a deny legally carries no lifetime. docs/tenant-alignment.md states the three tenant values as this repo holds them. It does not resolve the JWT/store mapping: service_auth.TENANT is tenant:coulomb, which is exactly the value the package denies. That is either two layers sharing a namespace format or one wrong constant, and picking between them without an owner ruling is the fail-open shape GH-DEC-2026-008 rejected for action vocabularies. Both constants stay as they are, deliberately not unified. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01E4tNMAYcSQmZWUE4wqP4ij Assistant: claude-code Assistant-Model: opus Assistant-Process: 715726@bnt-lap001 Assistant-Session: 80a42b32-cba6-4b23-8be0-68819b1a6092
2026-09-06 22:32:54 +02:00
#: The single tenant the published policy package scopes this engine to.
#:
#: `secrets-engine.catalog-lane.lifecycle` v2 reads
#: ``request_tenant := object.get(input, "tenant", "")`` and allows only
#: ``known_tenant := "tenant:platform"``; anything else, **an absent tenant
#: included**, matches its ``wrong_tenant`` first-denial branch. Sending no
#: tenant is therefore not a neutral omission, it is a denial.
#:
#: v1 had no tenant rule at all and failed open -- a `rotate` sent under
#: ``tenant:coulomb`` returned allow against the deployed package. That is why
#: v1 is superseded rather than amended, and why this value is pinned against
#: the vendored replay fixtures in ``tests/test_decision_replay.py`` instead of
#: being left to a deployment to supply correctly.
#:
#: This is not the KeyCape JWT tenant. ``service_auth.TENANT`` is
#: ``tenant:coulomb``, which is the exact value this package denies. Whether
#: those name one tenant or two layers is an open owner question -- see
#: ``docs/tenant-alignment.md`` -- and is deliberately not resolved by reusing
#: one constant for both.
REQUEST_TENANT = "tenant:platform"
SCHEMA_VERSION = "0.1"
feat: split the validator by owning layer per GH-DEC-2026-005 gate-house resolved APPROVAL-IN-0002. Two changes fell to this repo. 1. Split validate_action_authorization. The claim from approval-engine now carries the approval fact (issuer, valid_now, consumption, binding digest, freshness, reason_code) via approval_claim.validate_approval_claim; the flex-auth DecisionEnvelope carries the decision (effect, binding match, request digest, lifetime, policy pin) via validate_decision_envelope. ActionAuthorization is deferred and never ratified (FLEX-DEC-2026-006) and cannot be served from a step-1 call; nothing validates it now. 2. Dropped AUTHORITY = "state-hub" and the provenance.authority requirement. State Hub is a read model with no runtime approval authority, so the check failed closed against every correctly issued record. flex-auth traced the constant to their own fixture and fixed it at source. Two consequences recorded rather than buried: there are now two distinct digests over the same action (approval-engine native over {action,actor,principal,purpose,target}, and the flex-auth CheckRequest digest) which are never compared to each other; and the distinct-approver threshold is no longer checked here, since the claim exposes no approver entries and approval-engine folds it into valid_now. The canonical request digest is unchanged and its contract test is preserved verbatim. Production still fails closed. 251 tests pass. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01M65ovP3eiiPHubibvWs9mD Assistant: claude-code Assistant-Model: opus Assistant-Process: 393550@bnt-lap001 Assistant-Session: 4bb359f9-1f12-4410-9e76-079cf23c82e4
2026-09-06 08:02:01 +02:00
CONTRACT_VERSION = "flex-auth.decision-record.v1"
@dataclass(frozen=True)
feat: split the validator by owning layer per GH-DEC-2026-005 gate-house resolved APPROVAL-IN-0002. Two changes fell to this repo. 1. Split validate_action_authorization. The claim from approval-engine now carries the approval fact (issuer, valid_now, consumption, binding digest, freshness, reason_code) via approval_claim.validate_approval_claim; the flex-auth DecisionEnvelope carries the decision (effect, binding match, request digest, lifetime, policy pin) via validate_decision_envelope. ActionAuthorization is deferred and never ratified (FLEX-DEC-2026-006) and cannot be served from a step-1 call; nothing validates it now. 2. Dropped AUTHORITY = "state-hub" and the provenance.authority requirement. State Hub is a read model with no runtime approval authority, so the check failed closed against every correctly issued record. flex-auth traced the constant to their own fixture and fixed it at source. Two consequences recorded rather than buried: there are now two distinct digests over the same action (approval-engine native over {action,actor,principal,purpose,target}, and the flex-auth CheckRequest digest) which are never compared to each other; and the distinct-approver threshold is no longer checked here, since the claim exposes no approver entries and approval-engine folds it into valid_now. The canonical request digest is unchanged and its contract test is preserved verbatim. Production still fails closed. 251 tests pass. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01M65ovP3eiiPHubibvWs9mD Assistant: claude-code Assistant-Model: opus Assistant-Process: 393550@bnt-lap001 Assistant-Session: 4bb359f9-1f12-4410-9e76-079cf23c82e4
2026-09-06 08:02:01 +02:00
class ValidatedDecision:
decision_id: str
action: str
subject_id: str
expires_at: str
def build_action_request(
entry: CatalogEntry,
action: str,
*,
subject_id: str,
subject_type: str,
purpose: str,
fields: list[str] | tuple[str, ...] = (),
policy_targets: list[str] | tuple[str, ...] = (),
auth_targets: list[str] | tuple[str, ...] = (),
request_id: str = "",
fix: send the tenant the policy package scopes us to, and adopt v2 build_action_request emitted no tenant field at all. The deployed secrets-engine.catalog-lane.lifecycle v2 package reads known_tenant := "tenant:platform" request_tenant := object.get(input, "tenant", "") so an absent tenant is not an ignored field, it matches the wrong_tenant first-denial branch. Every gated action this engine sent would have been denied -- and the omission also produced a request_digest that could match no correctly issued decision, since tenant is hashed material. That is the same class of defect as hashing excluded fields, arriving from the other direction, and again only a real artifact exposed it. Found by answering the GLAS-WP-0015 tenant-alignment question instead of assuming the values lined up. - REQUEST_TENANT is pinned against the vendored allow envelopes, so a package retenanting fails a test rather than denying production. - An empty tenant is refused at build time. - Accepted policy version moves v1 -> v2. v1 had no tenant rule and failed open: a rotate under tenant:coulomb returned allow against the deployed package. flex-auth superseded rather than amended it, because a fail-open correction has to be visible as a version change. A test pins that a v1 decision is refused. - Vendored decision_wrong_tenant_deny.json as the denial evidence glas asked for, with tests that we refuse it on effect before anything else and that a deny legally carries no lifetime. docs/tenant-alignment.md states the three tenant values as this repo holds them. It does not resolve the JWT/store mapping: service_auth.TENANT is tenant:coulomb, which is exactly the value the package denies. That is either two layers sharing a namespace format or one wrong constant, and picking between them without an owner ruling is the fail-open shape GH-DEC-2026-008 rejected for action vocabularies. Both constants stay as they are, deliberately not unified. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01E4tNMAYcSQmZWUE4wqP4ij Assistant: claude-code Assistant-Model: opus Assistant-Process: 715726@bnt-lap001 Assistant-Session: 80a42b32-cba6-4b23-8be0-68819b1a6092
2026-09-06 22:32:54 +02:00
tenant: str = REQUEST_TENANT,
) -> dict[str, Any]:
fix: send the tenant the policy package scopes us to, and adopt v2 build_action_request emitted no tenant field at all. The deployed secrets-engine.catalog-lane.lifecycle v2 package reads known_tenant := "tenant:platform" request_tenant := object.get(input, "tenant", "") so an absent tenant is not an ignored field, it matches the wrong_tenant first-denial branch. Every gated action this engine sent would have been denied -- and the omission also produced a request_digest that could match no correctly issued decision, since tenant is hashed material. That is the same class of defect as hashing excluded fields, arriving from the other direction, and again only a real artifact exposed it. Found by answering the GLAS-WP-0015 tenant-alignment question instead of assuming the values lined up. - REQUEST_TENANT is pinned against the vendored allow envelopes, so a package retenanting fails a test rather than denying production. - An empty tenant is refused at build time. - Accepted policy version moves v1 -> v2. v1 had no tenant rule and failed open: a rotate under tenant:coulomb returned allow against the deployed package. flex-auth superseded rather than amended it, because a fail-open correction has to be visible as a version change. A test pins that a v1 decision is refused. - Vendored decision_wrong_tenant_deny.json as the denial evidence glas asked for, with tests that we refuse it on effect before anything else and that a deny legally carries no lifetime. docs/tenant-alignment.md states the three tenant values as this repo holds them. It does not resolve the JWT/store mapping: service_auth.TENANT is tenant:coulomb, which is exactly the value the package denies. That is either two layers sharing a namespace format or one wrong constant, and picking between them without an owner ruling is the fail-open shape GH-DEC-2026-008 rejected for action vocabularies. Both constants stay as they are, deliberately not unified. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01E4tNMAYcSQmZWUE4wqP4ij Assistant: claude-code Assistant-Model: opus Assistant-Process: 715726@bnt-lap001 Assistant-Session: 80a42b32-cba6-4b23-8be0-68819b1a6092
2026-09-06 22:32:54 +02:00
"""Build the exact normalized secrets-engine profile for flex-auth.
``tenant`` is required and defaults to the package's published
``known_tenant``. It is hashed into the request digest and compared by the
package's ``wrong_tenant`` branch, so an omitted tenant is a denial rather
than a field the evaluator ignores.
"""
if not action or not subject_id or not subject_type or not purpose:
raise DecisionError(
"action request requires action, subject id/type, and purpose"
)
fix: send the tenant the policy package scopes us to, and adopt v2 build_action_request emitted no tenant field at all. The deployed secrets-engine.catalog-lane.lifecycle v2 package reads known_tenant := "tenant:platform" request_tenant := object.get(input, "tenant", "") so an absent tenant is not an ignored field, it matches the wrong_tenant first-denial branch. Every gated action this engine sent would have been denied -- and the omission also produced a request_digest that could match no correctly issued decision, since tenant is hashed material. That is the same class of defect as hashing excluded fields, arriving from the other direction, and again only a real artifact exposed it. Found by answering the GLAS-WP-0015 tenant-alignment question instead of assuming the values lined up. - REQUEST_TENANT is pinned against the vendored allow envelopes, so a package retenanting fails a test rather than denying production. - An empty tenant is refused at build time. - Accepted policy version moves v1 -> v2. v1 had no tenant rule and failed open: a rotate under tenant:coulomb returned allow against the deployed package. flex-auth superseded rather than amended it, because a fail-open correction has to be visible as a version change. A test pins that a v1 decision is refused. - Vendored decision_wrong_tenant_deny.json as the denial evidence glas asked for, with tests that we refuse it on effect before anything else and that a deny legally carries no lifetime. docs/tenant-alignment.md states the three tenant values as this repo holds them. It does not resolve the JWT/store mapping: service_auth.TENANT is tenant:coulomb, which is exactly the value the package denies. That is either two layers sharing a namespace format or one wrong constant, and picking between them without an owner ruling is the fail-open shape GH-DEC-2026-008 rejected for action vocabularies. Both constants stay as they are, deliberately not unified. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01E4tNMAYcSQmZWUE4wqP4ij Assistant: claude-code Assistant-Model: opus Assistant-Process: 715726@bnt-lap001 Assistant-Session: 80a42b32-cba6-4b23-8be0-68819b1a6092
2026-09-06 22:32:54 +02:00
if not tenant:
raise DecisionError(
"action request requires a tenant; the policy package denies an "
"absent tenant as wrong_tenant rather than ignoring it"
)
request: dict[str, Any] = {}
if request_id:
request["id"] = request_id
request.update(
{
fix: send the tenant the policy package scopes us to, and adopt v2 build_action_request emitted no tenant field at all. The deployed secrets-engine.catalog-lane.lifecycle v2 package reads known_tenant := "tenant:platform" request_tenant := object.get(input, "tenant", "") so an absent tenant is not an ignored field, it matches the wrong_tenant first-denial branch. Every gated action this engine sent would have been denied -- and the omission also produced a request_digest that could match no correctly issued decision, since tenant is hashed material. That is the same class of defect as hashing excluded fields, arriving from the other direction, and again only a real artifact exposed it. Found by answering the GLAS-WP-0015 tenant-alignment question instead of assuming the values lined up. - REQUEST_TENANT is pinned against the vendored allow envelopes, so a package retenanting fails a test rather than denying production. - An empty tenant is refused at build time. - Accepted policy version moves v1 -> v2. v1 had no tenant rule and failed open: a rotate under tenant:coulomb returned allow against the deployed package. flex-auth superseded rather than amended it, because a fail-open correction has to be visible as a version change. A test pins that a v1 decision is refused. - Vendored decision_wrong_tenant_deny.json as the denial evidence glas asked for, with tests that we refuse it on effect before anything else and that a deny legally carries no lifetime. docs/tenant-alignment.md states the three tenant values as this repo holds them. It does not resolve the JWT/store mapping: service_auth.TENANT is tenant:coulomb, which is exactly the value the package denies. That is either two layers sharing a namespace format or one wrong constant, and picking between them without an owner ruling is the fail-open shape GH-DEC-2026-008 rejected for action vocabularies. Both constants stay as they are, deliberately not unified. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01E4tNMAYcSQmZWUE4wqP4ij Assistant: claude-code Assistant-Model: opus Assistant-Process: 715726@bnt-lap001 Assistant-Session: 80a42b32-cba6-4b23-8be0-68819b1a6092
2026-09-06 22:32:54 +02:00
"tenant": tenant,
"subject": {"id": subject_id, "type": subject_type},
"action": action,
"resource": {
"id": f"catalog:{entry.id}",
"type": "secret-catalog-lane",
"system": "secrets-engine",
"attributes": {
"stage": entry.stage,
"fields": sorted(set(fields)),
"policy_targets": sorted(set(policy_targets)),
"auth_targets": sorted(set(auth_targets)),
},
},
"context": {"purpose": purpose},
}
)
return request
def _required_dict(container: dict[str, Any], name: str) -> dict[str, Any]:
value = container.get(name)
if not isinstance(value, dict):
raise DecisionError(f"action authorization requires object '{name}'")
return value
def _required_text(container: dict[str, Any], name: str) -> str:
value = container.get(name)
if not isinstance(value, str) or not value:
raise DecisionError(f"action authorization requires non-empty '{name}'")
return value
def _parse_time(value: object, name: str) -> datetime:
if not isinstance(value, str):
raise DecisionError(f"action authorization requires timestamp '{name}'")
try:
parsed = datetime.fromisoformat(value.replace("Z", "+00:00"))
except ValueError as e:
raise DecisionError(f"action authorization has invalid timestamp '{name}'") from e
if parsed.tzinfo is None:
raise DecisionError(f"action authorization timestamp '{name}' needs timezone")
return parsed.astimezone(timezone.utc)
def _sorted_map(value: object) -> dict[str, Any]:
if not isinstance(value, dict):
return {}
return {key: _canonical_map_value(value[key]) for key in sorted(value)}
def _canonical_map_value(value: Any) -> Any:
if isinstance(value, dict):
return _sorted_map(value)
if isinstance(value, list):
return [_canonical_map_value(item) for item in value]
return value
def _subject_ref(value: object) -> dict[str, Any]:
if not isinstance(value, dict):
raise DecisionError("action authorization subject must be an object")
subject: dict[str, Any] = {"id": _required_text(value, "id")}
for name in ("type", "tenant"):
if value.get(name):
subject[name] = _required_text(value, name)
if value.get("attributes") is not None:
subject["attributes"] = _sorted_map(value.get("attributes"))
return subject
def _resource_ref(value: object) -> dict[str, Any]:
if not isinstance(value, dict):
raise DecisionError("action authorization resource must be an object")
resource: dict[str, Any] = {"id": _required_text(value, "id")}
for name in ("type", "system", "tenant"):
if value.get(name):
resource[name] = _required_text(value, name)
if value.get("attributes") is not None:
resource["attributes"] = _sorted_map(value.get("attributes"))
return resource
def canonical_check_request(request: object) -> dict[str, Any]:
"""Match Go encoding/json field order used by flex-auth request digests."""
if not isinstance(request, dict):
raise DecisionError("action authorization request must be an object")
canonical: dict[str, Any] = {}
if request.get("id"):
canonical["id"] = _required_text(request, "id")
if request.get("tenant"):
canonical["tenant"] = _required_text(request, "tenant")
canonical["subject"] = _subject_ref(request.get("subject"))
canonical["action"] = _required_text(request, "action")
canonical["resource"] = _resource_ref(request.get("resource"))
if request.get("context") is not None:
canonical["context"] = _sorted_map(request.get("context"))
if request.get("caring_context") is not None:
canonical["caring_context"] = _canonical_map_value(
request.get("caring_context")
)
if request.get("policy_version"):
canonical["policy_version"] = _required_text(request, "policy_version")
return canonical
fix: exclude correlation fields from the flex-auth request digest Verified the digest join against flex-auth's T03 replay fixtures and found request_digest was hashing fields docs/canonical-request-digest.md excludes. The material is tenant, subject, action, resource, context only: id is correlation, policy_version lives in provenance, caring_context is hashed separately. This engine included all three when present. Because the join adopts the served request id, every real production request would have carried one, so the computed digest would have matched no issued decision and failed closed against every correct allow. Same unsatisfiable shape as the removed AUTHORITY constant. The old pinned constant was computed with the id inside the material, so it was wrong and its passing proved nothing. Replaced with fixture-driven tests over two real envelopes (vendored with provenance) plus a structural test that correlation fields do not move the digest. Both fixtures are needed: input_claim_digests.context appears only with a non-empty context. Also stops computing the native claim digest. The claim's binding.action and binding.target speak approval-engine's vocabulary while ours speaks the catalog's, and no mapping is published; flex-auth makes no cross-check and states the correspondence is ours via pdp_digest. A claim recording no pdp_digest now fails closed naming the missing mapping rather than comparing two different languages. That mapping is a prerequisite for destroy. 274 tests pass. Production still fails closed. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01M65ovP3eiiPHubibvWs9mD Assistant: claude-code Assistant-Model: opus Assistant-Process: 393550@bnt-lap001 Assistant-Session: 4bb359f9-1f12-4410-9e76-079cf23c82e4
2026-09-06 14:17:38 +02:00
#: Correlation-only or separately-hashed fields, excluded from the digest
#: material by docs/canonical-request-digest.md "What is hashed".
_UNHASHED_FIELDS = ("id", "policy_version", "caring_context")
def digest_material(request: object) -> dict[str, Any]:
"""The exact tuple flex-auth hashes: tenant, subject, action, resource, context.
``id`` is correlation only, ``policy_version`` is recorded in provenance, and
``caring_context`` is hashed separately as
``provenance.input_claim_digests.caring_context``. Including any of them
produces a digest that matches no real DecisionEnvelope, which fails closed
against every correctly issued decision.
"""
canonical = canonical_check_request(request)
feat: bind the destroy gate to approval_binding_digest and pdp_path The vocabulary mapping this path was waiting on is not coming: gate-house rejected it in GH-DEC-2026-008, because a translation can be confidently wrong and fails open by accepting a claim approved for a different action. The stronger option arrived instead, and both halves are enforced here. flex-auth published binding.approval_binding_digest (FLEX-DEC-2026-007) to fix the circularity this repo reported: a pdp_digest recorded at issue time can never equal the request_digest of the request that carries the claim in its hashed context, so with GH-DEC-2026-008 requiring that equality, destroy would have failed closed forever on a check no correct record could pass. - authorization.approval_binding_digest implements the published exclusion rule, including Go's context,omitempty behaviour when stripping empties the context; digest_material drops an empty context for the same reason. - validate_decision_envelope recomputes the field rather than trusting it, refuses a claim-bearing request whose decision records none, and compares the claim's digest from step 1 against it -- never against request_digest, which still covers the claim so it stays a sound replay identity. - validate_approval_claim requires binding.pdp_path true before using pdp_digest at all. Path intent is never inferred from a digest that happens to be present; pre-schema-v3 approvals carry pdp_path false regardless of any digest they hold. Replay fixtures re-vendored from dd3ce4c. The destroy pins moved a second and final time; approval_binding_digest did not, which is the point. The fixture now demonstrates the property instead of asserting it: we rederive fa07becf... from its own request through our canonical implementation, proving we hash the same material flex-auth does rather than pinning a constant we cannot reproduce. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01E4tNMAYcSQmZWUE4wqP4ij Assistant: claude-code Assistant-Model: opus Assistant-Process: 715726@bnt-lap001 Assistant-Session: 80a42b32-cba6-4b23-8be0-68819b1a6092
2026-09-06 20:39:59 +02:00
material = {k: v for k, v in canonical.items() if k not in _UNHASHED_FIELDS}
# flex-auth tags Context `json:"context,omitempty"`, which drops the key for
# an empty map as well as a nil one. Keeping an empty object here would hash
# different material than the evaluator did.
if material.get("context") == {}:
del material["context"]
return material
fix: exclude correlation fields from the flex-auth request digest Verified the digest join against flex-auth's T03 replay fixtures and found request_digest was hashing fields docs/canonical-request-digest.md excludes. The material is tenant, subject, action, resource, context only: id is correlation, policy_version lives in provenance, caring_context is hashed separately. This engine included all three when present. Because the join adopts the served request id, every real production request would have carried one, so the computed digest would have matched no issued decision and failed closed against every correct allow. Same unsatisfiable shape as the removed AUTHORITY constant. The old pinned constant was computed with the id inside the material, so it was wrong and its passing proved nothing. Replaced with fixture-driven tests over two real envelopes (vendored with provenance) plus a structural test that correlation fields do not move the digest. Both fixtures are needed: input_claim_digests.context appears only with a non-empty context. Also stops computing the native claim digest. The claim's binding.action and binding.target speak approval-engine's vocabulary while ours speaks the catalog's, and no mapping is published; flex-auth makes no cross-check and states the correspondence is ours via pdp_digest. A claim recording no pdp_digest now fails closed naming the missing mapping rather than comparing two different languages. That mapping is a prerequisite for destroy. 274 tests pass. Production still fails closed. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01M65ovP3eiiPHubibvWs9mD Assistant: claude-code Assistant-Model: opus Assistant-Process: 393550@bnt-lap001 Assistant-Session: 4bb359f9-1f12-4410-9e76-079cf23c82e4
2026-09-06 14:17:38 +02:00
def request_digest(request: object) -> str:
canonical = digest_material(request)
encoded = json.dumps(
canonical, ensure_ascii=False, separators=(",", ":")
).encode("utf-8")
return "sha256:" + hashlib.sha256(encoded).hexdigest()
feat: bind the destroy gate to approval_binding_digest and pdp_path The vocabulary mapping this path was waiting on is not coming: gate-house rejected it in GH-DEC-2026-008, because a translation can be confidently wrong and fails open by accepting a claim approved for a different action. The stronger option arrived instead, and both halves are enforced here. flex-auth published binding.approval_binding_digest (FLEX-DEC-2026-007) to fix the circularity this repo reported: a pdp_digest recorded at issue time can never equal the request_digest of the request that carries the claim in its hashed context, so with GH-DEC-2026-008 requiring that equality, destroy would have failed closed forever on a check no correct record could pass. - authorization.approval_binding_digest implements the published exclusion rule, including Go's context,omitempty behaviour when stripping empties the context; digest_material drops an empty context for the same reason. - validate_decision_envelope recomputes the field rather than trusting it, refuses a claim-bearing request whose decision records none, and compares the claim's digest from step 1 against it -- never against request_digest, which still covers the claim so it stays a sound replay identity. - validate_approval_claim requires binding.pdp_path true before using pdp_digest at all. Path intent is never inferred from a digest that happens to be present; pre-schema-v3 approvals carry pdp_path false regardless of any digest they hold. Replay fixtures re-vendored from dd3ce4c. The destroy pins moved a second and final time; approval_binding_digest did not, which is the point. The fixture now demonstrates the property instead of asserting it: we rederive fa07becf... from its own request through our canonical implementation, proving we hash the same material flex-auth does rather than pinning a constant we cannot reproduce. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01E4tNMAYcSQmZWUE4wqP4ij Assistant: claude-code Assistant-Model: opus Assistant-Process: 715726@bnt-lap001 Assistant-Session: 80a42b32-cba6-4b23-8be0-68819b1a6092
2026-09-06 20:39:59 +02:00
#: The context key an approval claim travels on, per flex-auth's
#: ``ApprovalContextKey``.
APPROVAL_CONTEXT_KEY = "approval"
def approval_binding_digest(request: object) -> str:
"""flex-auth's ``binding.approval_binding_digest`` for this request.
The same canonical digest with ``context.approval`` removed, so it is stable
across attaching the claim. A request that carries no claim has no separate
binding digest, and flex-auth returns the plain request digest there.
This exists because a ``pdp_digest`` recorded at approval-issue time can
never equal the ``request_digest`` of the request that later carries the
claim: the claim is part of the hashed context. See
``flex-auth/docs/canonical-request-digest.md`` "The approval-binding digest"
and FLEX-DEC-2026-007. It is deliberately NOT a replay identity.
"""
canonical = canonical_check_request(request)
context = canonical.get("context")
if not isinstance(context, dict) or APPROVAL_CONTEXT_KEY not in context:
return request_digest(request)
stripped = dict(canonical)
stripped["context"] = {
k: v for k, v in context.items() if k != APPROVAL_CONTEXT_KEY
}
return request_digest(stripped)
def _require_exact_target_sets(request: dict[str, Any]) -> None:
resource = _required_dict(request, "resource")
attributes = resource.get("attributes", {})
if not isinstance(attributes, dict):
raise DecisionError("action authorization resource attributes must be an object")
for name in ("fields", "policy_targets", "auth_targets"):
values = attributes.get(name, [])
if not isinstance(values, list) or not all(
isinstance(item, str) and item for item in values
):
raise DecisionError(f"action authorization target set '{name}' is invalid")
if values != sorted(set(values)):
raise DecisionError(
f"action authorization target set '{name}' must be sorted and unique"
)
feat: bind the destroy gate to approval_binding_digest and pdp_path The vocabulary mapping this path was waiting on is not coming: gate-house rejected it in GH-DEC-2026-008, because a translation can be confidently wrong and fails open by accepting a claim approved for a different action. The stronger option arrived instead, and both halves are enforced here. flex-auth published binding.approval_binding_digest (FLEX-DEC-2026-007) to fix the circularity this repo reported: a pdp_digest recorded at issue time can never equal the request_digest of the request that carries the claim in its hashed context, so with GH-DEC-2026-008 requiring that equality, destroy would have failed closed forever on a check no correct record could pass. - authorization.approval_binding_digest implements the published exclusion rule, including Go's context,omitempty behaviour when stripping empties the context; digest_material drops an empty context for the same reason. - validate_decision_envelope recomputes the field rather than trusting it, refuses a claim-bearing request whose decision records none, and compares the claim's digest from step 1 against it -- never against request_digest, which still covers the claim so it stays a sound replay identity. - validate_approval_claim requires binding.pdp_path true before using pdp_digest at all. Path intent is never inferred from a digest that happens to be present; pre-schema-v3 approvals carry pdp_path false regardless of any digest they hold. Replay fixtures re-vendored from dd3ce4c. The destroy pins moved a second and final time; approval_binding_digest did not, which is the point. The fixture now demonstrates the property instead of asserting it: we rederive fa07becf... from its own request through our canonical implementation, proving we hash the same material flex-auth does rather than pinning a constant we cannot reproduce. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01E4tNMAYcSQmZWUE4wqP4ij Assistant: claude-code Assistant-Model: opus Assistant-Process: 715726@bnt-lap001 Assistant-Session: 80a42b32-cba6-4b23-8be0-68819b1a6092
2026-09-06 20:39:59 +02:00
def _check_approval_binding_digest(
binding: dict[str, Any],
expected: dict[str, Any],
expected_digest: str,
) -> None:
"""Tie an approval claim to this exact request (FLEX-DEC-2026-007).
``binding.approval_binding_digest`` is the canonical request digest computed
with ``context.approval`` removed, and it appears only when the request
carried a claim there. It is the ONLY sound comparand for a claim's
``pdp_digest``: a digest recorded at issue time can never equal the
``request_digest`` of the request that carries the claim, because the claim
is part of the hashed material. Comparing against ``request_digest`` fails
closed forever; comparing against nothing fails open.
It is deliberately NOT a replay identity -- two requests differing only in
which approval was presented share it while their decisions differ -- so it
is checked here in addition to ``request_digest``, never instead of it.
When our own request is claim-free the field is absent by contract, and the
identity already holds transitively: step 1 compared the claim's pdp_digest
to this same canonical digest of the claim-free request.
"""
present = binding.get("approval_binding_digest")
if present is not None:
if not isinstance(present, str) or not DIGEST_RE.fullmatch(present):
raise DecisionError("flex-auth approval binding digest is malformed")
if present != approval_binding_digest(expected):
raise DecisionError(
"flex-auth approval binding digest does not match this request "
"with the approval claim removed"
)
if expected_digest:
if present is None:
context = expected.get("context")
if not isinstance(context, dict) or APPROVAL_CONTEXT_KEY not in context:
# Claim-free request: no approval_binding_digest is emitted and
# step 1 already bound the claim to this canonical digest.
return
raise DecisionError(
"request carried an approval claim but the decision records no "
"approval_binding_digest; the claim cannot be tied to it"
)
if present != expected_digest:
raise DecisionError(
"approval claim pdp digest does not match the decision's "
"approval binding digest"
)
feat: split the validator by owning layer per GH-DEC-2026-005 gate-house resolved APPROVAL-IN-0002. Two changes fell to this repo. 1. Split validate_action_authorization. The claim from approval-engine now carries the approval fact (issuer, valid_now, consumption, binding digest, freshness, reason_code) via approval_claim.validate_approval_claim; the flex-auth DecisionEnvelope carries the decision (effect, binding match, request digest, lifetime, policy pin) via validate_decision_envelope. ActionAuthorization is deferred and never ratified (FLEX-DEC-2026-006) and cannot be served from a step-1 call; nothing validates it now. 2. Dropped AUTHORITY = "state-hub" and the provenance.authority requirement. State Hub is a read model with no runtime approval authority, so the check failed closed against every correctly issued record. flex-auth traced the constant to their own fixture and fixed it at source. Two consequences recorded rather than buried: there are now two distinct digests over the same action (approval-engine native over {action,actor,principal,purpose,target}, and the flex-auth CheckRequest digest) which are never compared to each other; and the distinct-approver threshold is no longer checked here, since the claim exposes no approver entries and approval-engine folds it into valid_now. The canonical request digest is unchanged and its contract test is preserved verbatim. Production still fails closed. 251 tests pass. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01M65ovP3eiiPHubibvWs9mD Assistant: claude-code Assistant-Model: opus Assistant-Process: 393550@bnt-lap001 Assistant-Session: 4bb359f9-1f12-4410-9e76-079cf23c82e4
2026-09-06 08:02:01 +02:00
def validate_decision_envelope(
envelope: object,
expected_request: object,
*,
accepted_policy_packages: set[str],
accepted_policy_versions: set[str],
feat: bind the destroy gate to approval_binding_digest and pdp_path The vocabulary mapping this path was waiting on is not coming: gate-house rejected it in GH-DEC-2026-008, because a translation can be confidently wrong and fails open by accepting a claim approved for a different action. The stronger option arrived instead, and both halves are enforced here. flex-auth published binding.approval_binding_digest (FLEX-DEC-2026-007) to fix the circularity this repo reported: a pdp_digest recorded at issue time can never equal the request_digest of the request that carries the claim in its hashed context, so with GH-DEC-2026-008 requiring that equality, destroy would have failed closed forever on a check no correct record could pass. - authorization.approval_binding_digest implements the published exclusion rule, including Go's context,omitempty behaviour when stripping empties the context; digest_material drops an empty context for the same reason. - validate_decision_envelope recomputes the field rather than trusting it, refuses a claim-bearing request whose decision records none, and compares the claim's digest from step 1 against it -- never against request_digest, which still covers the claim so it stays a sound replay identity. - validate_approval_claim requires binding.pdp_path true before using pdp_digest at all. Path intent is never inferred from a digest that happens to be present; pre-schema-v3 approvals carry pdp_path false regardless of any digest they hold. Replay fixtures re-vendored from dd3ce4c. The destroy pins moved a second and final time; approval_binding_digest did not, which is the point. The fixture now demonstrates the property instead of asserting it: we rederive fa07becf... from its own request through our canonical implementation, proving we hash the same material flex-auth does rather than pinning a constant we cannot reproduce. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01E4tNMAYcSQmZWUE4wqP4ij Assistant: claude-code Assistant-Model: opus Assistant-Process: 715726@bnt-lap001 Assistant-Session: 80a42b32-cba6-4b23-8be0-68819b1a6092
2026-09-06 20:39:59 +02:00
expected_approval_binding_digest: str = "",
now: datetime | None = None,
feat: split the validator by owning layer per GH-DEC-2026-005 gate-house resolved APPROVAL-IN-0002. Two changes fell to this repo. 1. Split validate_action_authorization. The claim from approval-engine now carries the approval fact (issuer, valid_now, consumption, binding digest, freshness, reason_code) via approval_claim.validate_approval_claim; the flex-auth DecisionEnvelope carries the decision (effect, binding match, request digest, lifetime, policy pin) via validate_decision_envelope. ActionAuthorization is deferred and never ratified (FLEX-DEC-2026-006) and cannot be served from a step-1 call; nothing validates it now. 2. Dropped AUTHORITY = "state-hub" and the provenance.authority requirement. State Hub is a read model with no runtime approval authority, so the check failed closed against every correctly issued record. flex-auth traced the constant to their own fixture and fixed it at source. Two consequences recorded rather than buried: there are now two distinct digests over the same action (approval-engine native over {action,actor,principal,purpose,target}, and the flex-auth CheckRequest digest) which are never compared to each other; and the distinct-approver threshold is no longer checked here, since the claim exposes no approver entries and approval-engine folds it into valid_now. The canonical request digest is unchanged and its contract test is preserved verbatim. Production still fails closed. 251 tests pass. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01M65ovP3eiiPHubibvWs9mD Assistant: claude-code Assistant-Model: opus Assistant-Process: 393550@bnt-lap001 Assistant-Session: 4bb359f9-1f12-4410-9e76-079cf23c82e4
2026-09-06 08:02:01 +02:00
) -> ValidatedDecision:
"""Validate a flex-auth DecisionEnvelope against the proposed action.
This is step 2 of GH-DEC-2026-003. It owns exactly the decision-layer
checks: effect, exact CheckRequest binding, canonical request digest,
lifetime, and the policy package/version pin. The approval fact -- validity,
supersession, consumption, distinct approvers -- belongs to the
approval-engine claim and is NOT re-checked here (GH-DEC-2026-005: a PIP
must not republish the PDP's decision, and neither layer republishes the
other's data).
There is deliberately no authority constant. State Hub is a read model and
holds no runtime approval authority; requiring it fails closed against every
correctly issued record.
"""
if not accepted_policy_packages or not accepted_policy_versions:
raise DecisionError("accepted flex-auth policy package/version is required")
if not isinstance(envelope, dict):
feat: split the validator by owning layer per GH-DEC-2026-005 gate-house resolved APPROVAL-IN-0002. Two changes fell to this repo. 1. Split validate_action_authorization. The claim from approval-engine now carries the approval fact (issuer, valid_now, consumption, binding digest, freshness, reason_code) via approval_claim.validate_approval_claim; the flex-auth DecisionEnvelope carries the decision (effect, binding match, request digest, lifetime, policy pin) via validate_decision_envelope. ActionAuthorization is deferred and never ratified (FLEX-DEC-2026-006) and cannot be served from a step-1 call; nothing validates it now. 2. Dropped AUTHORITY = "state-hub" and the provenance.authority requirement. State Hub is a read model with no runtime approval authority, so the check failed closed against every correctly issued record. flex-auth traced the constant to their own fixture and fixed it at source. Two consequences recorded rather than buried: there are now two distinct digests over the same action (approval-engine native over {action,actor,principal,purpose,target}, and the flex-auth CheckRequest digest) which are never compared to each other; and the distinct-approver threshold is no longer checked here, since the claim exposes no approver entries and approval-engine folds it into valid_now. The canonical request digest is unchanged and its contract test is preserved verbatim. Production still fails closed. 251 tests pass. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01M65ovP3eiiPHubibvWs9mD Assistant: claude-code Assistant-Model: opus Assistant-Process: 393550@bnt-lap001 Assistant-Session: 4bb359f9-1f12-4410-9e76-079cf23c82e4
2026-09-06 08:02:01 +02:00
raise DecisionError("decision envelope must be an object")
contract = envelope.get("contract_version")
if contract is not None and contract != CONTRACT_VERSION:
raise DecisionError("unsupported decision envelope contract version")
if envelope.get("effect") != "allow":
raise DecisionError("flex-auth decision effect is not allow")
decision_id = _required_text(envelope, "id")
expected = canonical_check_request(expected_request)
_require_exact_target_sets(expected)
feat: split the validator by owning layer per GH-DEC-2026-005 gate-house resolved APPROVAL-IN-0002. Two changes fell to this repo. 1. Split validate_action_authorization. The claim from approval-engine now carries the approval fact (issuer, valid_now, consumption, binding digest, freshness, reason_code) via approval_claim.validate_approval_claim; the flex-auth DecisionEnvelope carries the decision (effect, binding match, request digest, lifetime, policy pin) via validate_decision_envelope. ActionAuthorization is deferred and never ratified (FLEX-DEC-2026-006) and cannot be served from a step-1 call; nothing validates it now. 2. Dropped AUTHORITY = "state-hub" and the provenance.authority requirement. State Hub is a read model with no runtime approval authority, so the check failed closed against every correctly issued record. flex-auth traced the constant to their own fixture and fixed it at source. Two consequences recorded rather than buried: there are now two distinct digests over the same action (approval-engine native over {action,actor,principal,purpose,target}, and the flex-auth CheckRequest digest) which are never compared to each other; and the distinct-approver threshold is no longer checked here, since the claim exposes no approver entries and approval-engine folds it into valid_now. The canonical request digest is unchanged and its contract test is preserved verbatim. Production still fails closed. 251 tests pass. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01M65ovP3eiiPHubibvWs9mD Assistant: claude-code Assistant-Model: opus Assistant-Process: 393550@bnt-lap001 Assistant-Session: 4bb359f9-1f12-4410-9e76-079cf23c82e4
2026-09-06 08:02:01 +02:00
if expected.get("id") and envelope.get("request_id") not in (None, expected["id"]):
raise DecisionError("flex-auth decision request id does not match request")
feat: split the validator by owning layer per GH-DEC-2026-005 gate-house resolved APPROVAL-IN-0002. Two changes fell to this repo. 1. Split validate_action_authorization. The claim from approval-engine now carries the approval fact (issuer, valid_now, consumption, binding digest, freshness, reason_code) via approval_claim.validate_approval_claim; the flex-auth DecisionEnvelope carries the decision (effect, binding match, request digest, lifetime, policy pin) via validate_decision_envelope. ActionAuthorization is deferred and never ratified (FLEX-DEC-2026-006) and cannot be served from a step-1 call; nothing validates it now. 2. Dropped AUTHORITY = "state-hub" and the provenance.authority requirement. State Hub is a read model with no runtime approval authority, so the check failed closed against every correctly issued record. flex-auth traced the constant to their own fixture and fixed it at source. Two consequences recorded rather than buried: there are now two distinct digests over the same action (approval-engine native over {action,actor,principal,purpose,target}, and the flex-auth CheckRequest digest) which are never compared to each other; and the distinct-approver threshold is no longer checked here, since the claim exposes no approver entries and approval-engine folds it into valid_now. The canonical request digest is unchanged and its contract test is preserved verbatim. Production still fails closed. 251 tests pass. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01M65ovP3eiiPHubibvWs9mD Assistant: claude-code Assistant-Model: opus Assistant-Process: 393550@bnt-lap001 Assistant-Session: 4bb359f9-1f12-4410-9e76-079cf23c82e4
2026-09-06 08:02:01 +02:00
binding = _required_dict(envelope, "binding")
bound_request: dict[str, Any] = {}
if binding.get("tenant"):
bound_request["tenant"] = binding["tenant"]
bound_request.update(
{
"subject": binding.get("subject"),
"action": binding.get("action"),
"resource": binding.get("resource"),
"context": binding.get("context", {}),
}
)
expected_bound: dict[str, Any] = {}
feat: split the validator by owning layer per GH-DEC-2026-005 gate-house resolved APPROVAL-IN-0002. Two changes fell to this repo. 1. Split validate_action_authorization. The claim from approval-engine now carries the approval fact (issuer, valid_now, consumption, binding digest, freshness, reason_code) via approval_claim.validate_approval_claim; the flex-auth DecisionEnvelope carries the decision (effect, binding match, request digest, lifetime, policy pin) via validate_decision_envelope. ActionAuthorization is deferred and never ratified (FLEX-DEC-2026-006) and cannot be served from a step-1 call; nothing validates it now. 2. Dropped AUTHORITY = "state-hub" and the provenance.authority requirement. State Hub is a read model with no runtime approval authority, so the check failed closed against every correctly issued record. flex-auth traced the constant to their own fixture and fixed it at source. Two consequences recorded rather than buried: there are now two distinct digests over the same action (approval-engine native over {action,actor,principal,purpose,target}, and the flex-auth CheckRequest digest) which are never compared to each other; and the distinct-approver threshold is no longer checked here, since the claim exposes no approver entries and approval-engine folds it into valid_now. The canonical request digest is unchanged and its contract test is preserved verbatim. Production still fails closed. 251 tests pass. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01M65ovP3eiiPHubibvWs9mD Assistant: claude-code Assistant-Model: opus Assistant-Process: 393550@bnt-lap001 Assistant-Session: 4bb359f9-1f12-4410-9e76-079cf23c82e4
2026-09-06 08:02:01 +02:00
if expected.get("tenant"):
expected_bound["tenant"] = expected["tenant"]
expected_bound.update(
{
feat: split the validator by owning layer per GH-DEC-2026-005 gate-house resolved APPROVAL-IN-0002. Two changes fell to this repo. 1. Split validate_action_authorization. The claim from approval-engine now carries the approval fact (issuer, valid_now, consumption, binding digest, freshness, reason_code) via approval_claim.validate_approval_claim; the flex-auth DecisionEnvelope carries the decision (effect, binding match, request digest, lifetime, policy pin) via validate_decision_envelope. ActionAuthorization is deferred and never ratified (FLEX-DEC-2026-006) and cannot be served from a step-1 call; nothing validates it now. 2. Dropped AUTHORITY = "state-hub" and the provenance.authority requirement. State Hub is a read model with no runtime approval authority, so the check failed closed against every correctly issued record. flex-auth traced the constant to their own fixture and fixed it at source. Two consequences recorded rather than buried: there are now two distinct digests over the same action (approval-engine native over {action,actor,principal,purpose,target}, and the flex-auth CheckRequest digest) which are never compared to each other; and the distinct-approver threshold is no longer checked here, since the claim exposes no approver entries and approval-engine folds it into valid_now. The canonical request digest is unchanged and its contract test is preserved verbatim. Production still fails closed. 251 tests pass. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01M65ovP3eiiPHubibvWs9mD Assistant: claude-code Assistant-Model: opus Assistant-Process: 393550@bnt-lap001 Assistant-Session: 4bb359f9-1f12-4410-9e76-079cf23c82e4
2026-09-06 08:02:01 +02:00
"subject": expected["subject"],
"action": expected["action"],
"resource": expected["resource"],
"context": expected.get("context", {}),
}
)
feat: split the validator by owning layer per GH-DEC-2026-005 gate-house resolved APPROVAL-IN-0002. Two changes fell to this repo. 1. Split validate_action_authorization. The claim from approval-engine now carries the approval fact (issuer, valid_now, consumption, binding digest, freshness, reason_code) via approval_claim.validate_approval_claim; the flex-auth DecisionEnvelope carries the decision (effect, binding match, request digest, lifetime, policy pin) via validate_decision_envelope. ActionAuthorization is deferred and never ratified (FLEX-DEC-2026-006) and cannot be served from a step-1 call; nothing validates it now. 2. Dropped AUTHORITY = "state-hub" and the provenance.authority requirement. State Hub is a read model with no runtime approval authority, so the check failed closed against every correctly issued record. flex-auth traced the constant to their own fixture and fixed it at source. Two consequences recorded rather than buried: there are now two distinct digests over the same action (approval-engine native over {action,actor,principal,purpose,target}, and the flex-auth CheckRequest digest) which are never compared to each other; and the distinct-approver threshold is no longer checked here, since the claim exposes no approver entries and approval-engine folds it into valid_now. The canonical request digest is unchanged and its contract test is preserved verbatim. Production still fails closed. 251 tests pass. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01M65ovP3eiiPHubibvWs9mD Assistant: claude-code Assistant-Model: opus Assistant-Process: 393550@bnt-lap001 Assistant-Session: 4bb359f9-1f12-4410-9e76-079cf23c82e4
2026-09-06 08:02:01 +02:00
if canonical_check_request(bound_request) != canonical_check_request(expected_bound):
raise DecisionError("flex-auth decision binding does not match request")
feat: split the validator by owning layer per GH-DEC-2026-005 gate-house resolved APPROVAL-IN-0002. Two changes fell to this repo. 1. Split validate_action_authorization. The claim from approval-engine now carries the approval fact (issuer, valid_now, consumption, binding digest, freshness, reason_code) via approval_claim.validate_approval_claim; the flex-auth DecisionEnvelope carries the decision (effect, binding match, request digest, lifetime, policy pin) via validate_decision_envelope. ActionAuthorization is deferred and never ratified (FLEX-DEC-2026-006) and cannot be served from a step-1 call; nothing validates it now. 2. Dropped AUTHORITY = "state-hub" and the provenance.authority requirement. State Hub is a read model with no runtime approval authority, so the check failed closed against every correctly issued record. flex-auth traced the constant to their own fixture and fixed it at source. Two consequences recorded rather than buried: there are now two distinct digests over the same action (approval-engine native over {action,actor,principal,purpose,target}, and the flex-auth CheckRequest digest) which are never compared to each other; and the distinct-approver threshold is no longer checked here, since the claim exposes no approver entries and approval-engine folds it into valid_now. The canonical request digest is unchanged and its contract test is preserved verbatim. Production still fails closed. 251 tests pass. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01M65ovP3eiiPHubibvWs9mD Assistant: claude-code Assistant-Model: opus Assistant-Process: 393550@bnt-lap001 Assistant-Session: 4bb359f9-1f12-4410-9e76-079cf23c82e4
2026-09-06 08:02:01 +02:00
if binding.get("request_digest") != request_digest(expected):
raise DecisionError("flex-auth request digest does not match request")
feat: bind the destroy gate to approval_binding_digest and pdp_path The vocabulary mapping this path was waiting on is not coming: gate-house rejected it in GH-DEC-2026-008, because a translation can be confidently wrong and fails open by accepting a claim approved for a different action. The stronger option arrived instead, and both halves are enforced here. flex-auth published binding.approval_binding_digest (FLEX-DEC-2026-007) to fix the circularity this repo reported: a pdp_digest recorded at issue time can never equal the request_digest of the request that carries the claim in its hashed context, so with GH-DEC-2026-008 requiring that equality, destroy would have failed closed forever on a check no correct record could pass. - authorization.approval_binding_digest implements the published exclusion rule, including Go's context,omitempty behaviour when stripping empties the context; digest_material drops an empty context for the same reason. - validate_decision_envelope recomputes the field rather than trusting it, refuses a claim-bearing request whose decision records none, and compares the claim's digest from step 1 against it -- never against request_digest, which still covers the claim so it stays a sound replay identity. - validate_approval_claim requires binding.pdp_path true before using pdp_digest at all. Path intent is never inferred from a digest that happens to be present; pre-schema-v3 approvals carry pdp_path false regardless of any digest they hold. Replay fixtures re-vendored from dd3ce4c. The destroy pins moved a second and final time; approval_binding_digest did not, which is the point. The fixture now demonstrates the property instead of asserting it: we rederive fa07becf... from its own request through our canonical implementation, proving we hash the same material flex-auth does rather than pinning a constant we cannot reproduce. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01E4tNMAYcSQmZWUE4wqP4ij Assistant: claude-code Assistant-Model: opus Assistant-Process: 715726@bnt-lap001 Assistant-Session: 80a42b32-cba6-4b23-8be0-68819b1a6092
2026-09-06 20:39:59 +02:00
_check_approval_binding_digest(binding, expected, expected_approval_binding_digest)
feat: split the validator by owning layer per GH-DEC-2026-005 gate-house resolved APPROVAL-IN-0002. Two changes fell to this repo. 1. Split validate_action_authorization. The claim from approval-engine now carries the approval fact (issuer, valid_now, consumption, binding digest, freshness, reason_code) via approval_claim.validate_approval_claim; the flex-auth DecisionEnvelope carries the decision (effect, binding match, request digest, lifetime, policy pin) via validate_decision_envelope. ActionAuthorization is deferred and never ratified (FLEX-DEC-2026-006) and cannot be served from a step-1 call; nothing validates it now. 2. Dropped AUTHORITY = "state-hub" and the provenance.authority requirement. State Hub is a read model with no runtime approval authority, so the check failed closed against every correctly issued record. flex-auth traced the constant to their own fixture and fixed it at source. Two consequences recorded rather than buried: there are now two distinct digests over the same action (approval-engine native over {action,actor,principal,purpose,target}, and the flex-auth CheckRequest digest) which are never compared to each other; and the distinct-approver threshold is no longer checked here, since the claim exposes no approver entries and approval-engine folds it into valid_now. The canonical request digest is unchanged and its contract test is preserved verbatim. Production still fails closed. 251 tests pass. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01M65ovP3eiiPHubibvWs9mD Assistant: claude-code Assistant-Model: opus Assistant-Process: 393550@bnt-lap001 Assistant-Session: 4bb359f9-1f12-4410-9e76-079cf23c82e4
2026-09-06 08:02:01 +02:00
if _subject_ref(envelope.get("subject")) != expected["subject"]:
raise DecisionError("flex-auth decision subject does not match request")
feat: split the validator by owning layer per GH-DEC-2026-005 gate-house resolved APPROVAL-IN-0002. Two changes fell to this repo. 1. Split validate_action_authorization. The claim from approval-engine now carries the approval fact (issuer, valid_now, consumption, binding digest, freshness, reason_code) via approval_claim.validate_approval_claim; the flex-auth DecisionEnvelope carries the decision (effect, binding match, request digest, lifetime, policy pin) via validate_decision_envelope. ActionAuthorization is deferred and never ratified (FLEX-DEC-2026-006) and cannot be served from a step-1 call; nothing validates it now. 2. Dropped AUTHORITY = "state-hub" and the provenance.authority requirement. State Hub is a read model with no runtime approval authority, so the check failed closed against every correctly issued record. flex-auth traced the constant to their own fixture and fixed it at source. Two consequences recorded rather than buried: there are now two distinct digests over the same action (approval-engine native over {action,actor,principal,purpose,target}, and the flex-auth CheckRequest digest) which are never compared to each other; and the distinct-approver threshold is no longer checked here, since the claim exposes no approver entries and approval-engine folds it into valid_now. The canonical request digest is unchanged and its contract test is preserved verbatim. Production still fails closed. 251 tests pass. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01M65ovP3eiiPHubibvWs9mD Assistant: claude-code Assistant-Model: opus Assistant-Process: 393550@bnt-lap001 Assistant-Session: 4bb359f9-1f12-4410-9e76-079cf23c82e4
2026-09-06 08:02:01 +02:00
if _resource_ref(envelope.get("resource")) != expected["resource"]:
raise DecisionError("flex-auth decision resource does not match request")
feat: split the validator by owning layer per GH-DEC-2026-005 gate-house resolved APPROVAL-IN-0002. Two changes fell to this repo. 1. Split validate_action_authorization. The claim from approval-engine now carries the approval fact (issuer, valid_now, consumption, binding digest, freshness, reason_code) via approval_claim.validate_approval_claim; the flex-auth DecisionEnvelope carries the decision (effect, binding match, request digest, lifetime, policy pin) via validate_decision_envelope. ActionAuthorization is deferred and never ratified (FLEX-DEC-2026-006) and cannot be served from a step-1 call; nothing validates it now. 2. Dropped AUTHORITY = "state-hub" and the provenance.authority requirement. State Hub is a read model with no runtime approval authority, so the check failed closed against every correctly issued record. flex-auth traced the constant to their own fixture and fixed it at source. Two consequences recorded rather than buried: there are now two distinct digests over the same action (approval-engine native over {action,actor,principal,purpose,target}, and the flex-auth CheckRequest digest) which are never compared to each other; and the distinct-approver threshold is no longer checked here, since the claim exposes no approver entries and approval-engine folds it into valid_now. The canonical request digest is unchanged and its contract test is preserved verbatim. Production still fails closed. 251 tests pass. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01M65ovP3eiiPHubibvWs9mD Assistant: claude-code Assistant-Model: opus Assistant-Process: 393550@bnt-lap001 Assistant-Session: 4bb359f9-1f12-4410-9e76-079cf23c82e4
2026-09-06 08:02:01 +02:00
current = (now or datetime.now(timezone.utc)).astimezone(timezone.utc)
lifetime = _required_dict(envelope, "lifetime")
expires = _parse_time(lifetime.get("expires_at"), "expires_at")
if current >= expires:
raise DecisionError("flex-auth decision lifetime has expired")
if lifetime.get("not_before") is not None:
if current < _parse_time(lifetime.get("not_before"), "not_before"):
raise DecisionError("flex-auth decision lifetime has not started")
provenance = _required_dict(envelope, "provenance")
if provenance.get("policy_package") not in accepted_policy_packages:
raise DecisionError("flex-auth policy package is not accepted")
feat: split the validator by owning layer per GH-DEC-2026-005 gate-house resolved APPROVAL-IN-0002. Two changes fell to this repo. 1. Split validate_action_authorization. The claim from approval-engine now carries the approval fact (issuer, valid_now, consumption, binding digest, freshness, reason_code) via approval_claim.validate_approval_claim; the flex-auth DecisionEnvelope carries the decision (effect, binding match, request digest, lifetime, policy pin) via validate_decision_envelope. ActionAuthorization is deferred and never ratified (FLEX-DEC-2026-006) and cannot be served from a step-1 call; nothing validates it now. 2. Dropped AUTHORITY = "state-hub" and the provenance.authority requirement. State Hub is a read model with no runtime approval authority, so the check failed closed against every correctly issued record. flex-auth traced the constant to their own fixture and fixed it at source. Two consequences recorded rather than buried: there are now two distinct digests over the same action (approval-engine native over {action,actor,principal,purpose,target}, and the flex-auth CheckRequest digest) which are never compared to each other; and the distinct-approver threshold is no longer checked here, since the claim exposes no approver entries and approval-engine folds it into valid_now. The canonical request digest is unchanged and its contract test is preserved verbatim. Production still fails closed. 251 tests pass. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01M65ovP3eiiPHubibvWs9mD Assistant: claude-code Assistant-Model: opus Assistant-Process: 393550@bnt-lap001 Assistant-Session: 4bb359f9-1f12-4410-9e76-079cf23c82e4
2026-09-06 08:02:01 +02:00
if provenance.get("policy_version") not in accepted_policy_versions:
raise DecisionError("flex-auth policy version is not accepted")
feat: split the validator by owning layer per GH-DEC-2026-005 gate-house resolved APPROVAL-IN-0002. Two changes fell to this repo. 1. Split validate_action_authorization. The claim from approval-engine now carries the approval fact (issuer, valid_now, consumption, binding digest, freshness, reason_code) via approval_claim.validate_approval_claim; the flex-auth DecisionEnvelope carries the decision (effect, binding match, request digest, lifetime, policy pin) via validate_decision_envelope. ActionAuthorization is deferred and never ratified (FLEX-DEC-2026-006) and cannot be served from a step-1 call; nothing validates it now. 2. Dropped AUTHORITY = "state-hub" and the provenance.authority requirement. State Hub is a read model with no runtime approval authority, so the check failed closed against every correctly issued record. flex-auth traced the constant to their own fixture and fixed it at source. Two consequences recorded rather than buried: there are now two distinct digests over the same action (approval-engine native over {action,actor,principal,purpose,target}, and the flex-auth CheckRequest digest) which are never compared to each other; and the distinct-approver threshold is no longer checked here, since the claim exposes no approver entries and approval-engine folds it into valid_now. The canonical request digest is unchanged and its contract test is preserved verbatim. Production still fails closed. 251 tests pass. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01M65ovP3eiiPHubibvWs9mD Assistant: claude-code Assistant-Model: opus Assistant-Process: 393550@bnt-lap001 Assistant-Session: 4bb359f9-1f12-4410-9e76-079cf23c82e4
2026-09-06 08:02:01 +02:00
return ValidatedDecision(
decision_id=decision_id,
feat: split the validator by owning layer per GH-DEC-2026-005 gate-house resolved APPROVAL-IN-0002. Two changes fell to this repo. 1. Split validate_action_authorization. The claim from approval-engine now carries the approval fact (issuer, valid_now, consumption, binding digest, freshness, reason_code) via approval_claim.validate_approval_claim; the flex-auth DecisionEnvelope carries the decision (effect, binding match, request digest, lifetime, policy pin) via validate_decision_envelope. ActionAuthorization is deferred and never ratified (FLEX-DEC-2026-006) and cannot be served from a step-1 call; nothing validates it now. 2. Dropped AUTHORITY = "state-hub" and the provenance.authority requirement. State Hub is a read model with no runtime approval authority, so the check failed closed against every correctly issued record. flex-auth traced the constant to their own fixture and fixed it at source. Two consequences recorded rather than buried: there are now two distinct digests over the same action (approval-engine native over {action,actor,principal,purpose,target}, and the flex-auth CheckRequest digest) which are never compared to each other; and the distinct-approver threshold is no longer checked here, since the claim exposes no approver entries and approval-engine folds it into valid_now. The canonical request digest is unchanged and its contract test is preserved verbatim. Production still fails closed. 251 tests pass. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01M65ovP3eiiPHubibvWs9mD Assistant: claude-code Assistant-Model: opus Assistant-Process: 393550@bnt-lap001 Assistant-Session: 4bb359f9-1f12-4410-9e76-079cf23c82e4
2026-09-06 08:02:01 +02:00
action=expected["action"],
subject_id=expected["subject"]["id"],
expires_at=expires.isoformat(),
)