authzai 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- agentic_auth/__init__.py +8 -0
- agentic_auth/_extras.py +24 -0
- agentic_auth/api/__init__.py +0 -0
- agentic_auth/api/deps.py +112 -0
- agentic_auth/api/errors.py +51 -0
- agentic_auth/api/responses.py +38 -0
- agentic_auth/api/service_deps.py +113 -0
- agentic_auth/api/v1/__init__.py +0 -0
- agentic_auth/api/v1/agents.py +88 -0
- agentic_auth/api/v1/audit.py +67 -0
- agentic_auth/api/v1/authorize.py +439 -0
- agentic_auth/api/v1/consent.py +21 -0
- agentic_auth/api/v1/decisions.py +43 -0
- agentic_auth/api/v1/enrollment.py +48 -0
- agentic_auth/api/v1/identity.py +97 -0
- agentic_auth/api/v1/jwks.py +21 -0
- agentic_auth/api/v1/manifests.py +68 -0
- agentic_auth/api/v1/scopes.py +22 -0
- agentic_auth/api/v1/token.py +203 -0
- agentic_auth/api/v1/transaction.py +94 -0
- agentic_auth/boundary/__init__.py +26 -0
- agentic_auth/boundary/guarantee.py +96 -0
- agentic_auth/cli/__init__.py +27 -0
- agentic_auth/cli/audit.py +130 -0
- agentic_auth/cli/drift.py +164 -0
- agentic_auth/cli/drift_render.py +148 -0
- agentic_auth/cli/identity.py +63 -0
- agentic_auth/cli/manifest.py +275 -0
- agentic_auth/config.py +182 -0
- agentic_auth/db.py +49 -0
- agentic_auth/embedded/__init__.py +427 -0
- agentic_auth/embedded/_schema.py +8 -0
- agentic_auth/embedded/_transport.py +39 -0
- agentic_auth/embedded/capabilities.py +34 -0
- agentic_auth/embedded/export.py +86 -0
- agentic_auth/embedded/idp.py +78 -0
- agentic_auth/embedded/store.py +240 -0
- agentic_auth/errors.py +145 -0
- agentic_auth/main.py +141 -0
- agentic_auth/models/__init__.py +70 -0
- agentic_auth/models/agent.py +58 -0
- agentic_auth/models/audit_decision.py +199 -0
- agentic_auth/models/compiled_policy.py +28 -0
- agentic_auth/models/manifest.py +96 -0
- agentic_auth/models/reconciliation_report.py +27 -0
- agentic_auth/models/sandbox_run.py +93 -0
- agentic_auth/models/session.py +63 -0
- agentic_auth/models/step_up_grant.py +106 -0
- agentic_auth/models/transaction_token.py +73 -0
- agentic_auth/models/trust_anchor.py +59 -0
- agentic_auth/models/types.py +95 -0
- agentic_auth/observability/__init__.py +370 -0
- agentic_auth/observability/config.py +137 -0
- agentic_auth/observability/context.py +128 -0
- agentic_auth/observability/ids.py +122 -0
- agentic_auth/observability/logs.py +191 -0
- agentic_auth/observability/pep.py +169 -0
- agentic_auth/observability/spans.py +225 -0
- agentic_auth/observability/surface.py +286 -0
- agentic_auth/observability/tracing.py +167 -0
- agentic_auth/redis.py +27 -0
- agentic_auth/repositories/__init__.py +0 -0
- agentic_auth/repositories/agents.py +96 -0
- agentic_auth/repositories/audit_decisions.py +152 -0
- agentic_auth/repositories/compiled_policies.py +72 -0
- agentic_auth/repositories/manifests.py +149 -0
- agentic_auth/repositories/reconciliation_reports.py +40 -0
- agentic_auth/repositories/sessions.py +41 -0
- agentic_auth/repositories/transaction_tokens.py +60 -0
- agentic_auth/repositories/trust_anchors.py +150 -0
- agentic_auth/runtime.py +81 -0
- agentic_auth/schemas/__init__.py +0 -0
- agentic_auth/schemas/agent.py +58 -0
- agentic_auth/schemas/audit.py +207 -0
- agentic_auth/schemas/authorize.py +205 -0
- agentic_auth/schemas/common.py +40 -0
- agentic_auth/schemas/consent.py +74 -0
- agentic_auth/schemas/dag.py +39 -0
- agentic_auth/schemas/edge_trace.py +166 -0
- agentic_auth/schemas/identity.py +152 -0
- agentic_auth/schemas/manifest.py +117 -0
- agentic_auth/schemas/manifest_api.py +38 -0
- agentic_auth/schemas/reconciliation.py +49 -0
- agentic_auth/schemas/token.py +122 -0
- agentic_auth/schemas/transaction.py +28 -0
- agentic_auth/sdk/__init__.py +114 -0
- agentic_auth/sdk/client.py +677 -0
- agentic_auth/sdk/context.py +95 -0
- agentic_auth/sdk/drift.py +118 -0
- agentic_auth/sdk/errors.py +147 -0
- agentic_auth/sdk/identity.py +162 -0
- agentic_auth/sdk/planes.py +362 -0
- agentic_auth/sdk/provenance.py +63 -0
- agentic_auth/services/__init__.py +0 -0
- agentic_auth/services/anchors.py +81 -0
- agentic_auth/services/audit.py +222 -0
- agentic_auth/services/audit_chain.py +144 -0
- agentic_auth/services/audit_cursor.py +55 -0
- agentic_auth/services/catalog_service.py +58 -0
- agentic_auth/services/chain_query.py +152 -0
- agentic_auth/services/dag_compiler.py +199 -0
- agentic_auth/services/decision_cache.py +123 -0
- agentic_auth/services/decision_history.py +71 -0
- agentic_auth/services/discovery.py +95 -0
- agentic_auth/services/drift.py +330 -0
- agentic_auth/services/edge_rules.py +62 -0
- agentic_auth/services/edge_trace.py +198 -0
- agentic_auth/services/enrollment.py +310 -0
- agentic_auth/services/enrollment_rules.py +80 -0
- agentic_auth/services/manifest_service.py +166 -0
- agentic_auth/services/metrics.py +419 -0
- agentic_auth/services/pdp.py +312 -0
- agentic_auth/services/policy_loader.py +255 -0
- agentic_auth/services/principal.py +143 -0
- agentic_auth/services/reconciler.py +119 -0
- agentic_auth/services/revocation.py +149 -0
- agentic_auth/services/sessions.py +231 -0
- agentic_auth/services/taint.py +204 -0
- agentic_auth/services/tokens/__init__.py +11 -0
- agentic_auth/services/tokens/act_chain.py +76 -0
- agentic_auth/services/tokens/exchange.py +319 -0
- agentic_auth/services/tokens/jwt_profile.py +362 -0
- agentic_auth/services/tokens/keys.py +117 -0
- agentic_auth/services/tokens/profile.py +167 -0
- agentic_auth/services/tokens/replay.py +53 -0
- agentic_auth/services/transactions.py +172 -0
- agentic_auth/sidecar/__init__.py +7 -0
- agentic_auth/sidecar/__main__.py +66 -0
- agentic_auth/sidecar/app.py +349 -0
- agentic_auth/sidecar/config.py +253 -0
- agentic_auth/sidecar/deny.py +108 -0
- agentic_auth/sidecar/enforce.py +640 -0
- agentic_auth/sidecar/identity.py +37 -0
- agentic_auth/verify/__init__.py +208 -0
- agentic_auth/verify/admit.py +131 -0
- agentic_auth/verify/anchors.py +250 -0
- agentic_auth/verify/canonical.py +228 -0
- agentic_auth/verify/grants.py +158 -0
- agentic_auth/verify/identity.py +111 -0
- agentic_auth/verify/replay.py +67 -0
- agentic_auth/verify/transaction.py +164 -0
- authzai-0.2.0.dist-info/METADATA +276 -0
- authzai-0.2.0.dist-info/RECORD +148 -0
- authzai-0.2.0.dist-info/WHEEL +5 -0
- authzai-0.2.0.dist-info/entry_points.txt +5 -0
- authzai-0.2.0.dist-info/licenses/LICENSE +202 -0
- authzai-0.2.0.dist-info/licenses/NOTICE +8 -0
- authzai-0.2.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
"""Per-hop authorization: the deny vocabulary, the request, and the decision.
|
|
2
|
+
|
|
3
|
+
Note what is absent: there is no ``hop_count`` field anywhere in this module. Delegation
|
|
4
|
+
depth is derived from the verified ``act`` chain of the presented token. A caller-supplied
|
|
5
|
+
integer is attacker-controlled, and accepting one alongside the signed value would only
|
|
6
|
+
create a question about which wins.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import uuid
|
|
12
|
+
from datetime import datetime
|
|
13
|
+
from enum import StrEnum
|
|
14
|
+
|
|
15
|
+
from pydantic import BaseModel, ConfigDict, Field
|
|
16
|
+
|
|
17
|
+
from agentic_auth.boundary.guarantee import Guarantee
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class Taint(StrEnum):
|
|
21
|
+
TRUSTED_INTERNAL = "trusted_internal"
|
|
22
|
+
UNTRUSTED_EXTERNAL = "untrusted_external"
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class DenyReason(StrEnum):
|
|
26
|
+
OUT_OF_SCOPE = "OUT_OF_SCOPE"
|
|
27
|
+
HOP_BUDGET_EXCEEDED = "HOP_BUDGET_EXCEEDED"
|
|
28
|
+
EDGE_NOT_IN_DAG = "EDGE_NOT_IN_DAG"
|
|
29
|
+
SCOPE_NOT_CONSENTED = "SCOPE_NOT_CONSENTED"
|
|
30
|
+
PDP_UNAVAILABLE = "PDP_UNAVAILABLE"
|
|
31
|
+
TOKEN_SERVICE_UNAVAILABLE = "TOKEN_SERVICE_UNAVAILABLE"
|
|
32
|
+
# Returned, never stored: it exists precisely because the record could not be written.
|
|
33
|
+
AUDIT_UNAVAILABLE = "AUDIT_UNAVAILABLE"
|
|
34
|
+
# Phase 4. Effective taint is untrusted_external and the target is protected. A consent
|
|
35
|
+
# prompt cannot launder injected content, so it is never recoverable.
|
|
36
|
+
TAINTED_INTO_PRIVILEGED = "TAINTED_INTO_PRIVILEGED"
|
|
37
|
+
# Phase 4. The holder, or an agent on the chain, has a revoked trust anchor.
|
|
38
|
+
AGENT_REVOKED = "AGENT_REVOKED"
|
|
39
|
+
# Phase 4. identity_required is on and the holder has no live trust anchor.
|
|
40
|
+
AGENT_NOT_ENROLLED = "AGENT_NOT_ENROLLED"
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
# Recoverability is a property of the reason, not a per-call judgement, so the PDP, the
|
|
44
|
+
# sidecar and the SDK can never disagree about it. Only SCOPE_NOT_CONSENTED is a step-up
|
|
45
|
+
# candidate; a consent prompt cannot widen a hop budget or invent an undeclared edge.
|
|
46
|
+
RECOVERABLE: dict[DenyReason, bool] = {
|
|
47
|
+
DenyReason.OUT_OF_SCOPE: False,
|
|
48
|
+
DenyReason.HOP_BUDGET_EXCEEDED: False,
|
|
49
|
+
DenyReason.EDGE_NOT_IN_DAG: False,
|
|
50
|
+
DenyReason.SCOPE_NOT_CONSENTED: True,
|
|
51
|
+
DenyReason.PDP_UNAVAILABLE: False,
|
|
52
|
+
DenyReason.TOKEN_SERVICE_UNAVAILABLE: False,
|
|
53
|
+
DenyReason.AUDIT_UNAVAILABLE: False,
|
|
54
|
+
DenyReason.TAINTED_INTO_PRIVILEGED: False,
|
|
55
|
+
DenyReason.AGENT_REVOKED: False,
|
|
56
|
+
DenyReason.AGENT_NOT_ENROLLED: False,
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
# What policy decided, versus what could not be decided or recorded. Observe mode may let a
|
|
60
|
+
# POLICY reason through — that is its whole purpose. It must never let an INFRASTRUCTURE
|
|
61
|
+
# reason through: that would forward an outage as if it were a prediction.
|
|
62
|
+
POLICY_REASONS: frozenset[DenyReason] = frozenset(
|
|
63
|
+
{
|
|
64
|
+
DenyReason.OUT_OF_SCOPE,
|
|
65
|
+
DenyReason.HOP_BUDGET_EXCEEDED,
|
|
66
|
+
DenyReason.EDGE_NOT_IN_DAG,
|
|
67
|
+
DenyReason.SCOPE_NOT_CONSENTED,
|
|
68
|
+
# Predictable from configuration and state, not outages — so observe mode may
|
|
69
|
+
# forward them, recorded `enforced=false`, exactly like OUT_OF_SCOPE.
|
|
70
|
+
DenyReason.TAINTED_INTO_PRIVILEGED,
|
|
71
|
+
DenyReason.AGENT_REVOKED,
|
|
72
|
+
DenyReason.AGENT_NOT_ENROLLED,
|
|
73
|
+
}
|
|
74
|
+
)
|
|
75
|
+
INFRASTRUCTURE_REASONS: frozenset[DenyReason] = frozenset(
|
|
76
|
+
{
|
|
77
|
+
DenyReason.PDP_UNAVAILABLE,
|
|
78
|
+
DenyReason.TOKEN_SERVICE_UNAVAILABLE,
|
|
79
|
+
DenyReason.AUDIT_UNAVAILABLE,
|
|
80
|
+
}
|
|
81
|
+
)
|
|
82
|
+
assert set(DenyReason) == POLICY_REASONS | INFRASTRUCTURE_REASONS, "unclassified deny reason"
|
|
83
|
+
assert not POLICY_REASONS & INFRASTRUCTURE_REASONS, "a reason cannot be both"
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def is_recoverable(reason: DenyReason) -> bool:
|
|
87
|
+
return RECOVERABLE[reason]
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
class StepUpChallenge(BaseModel):
|
|
91
|
+
"""The challenge handed back on a recoverable deny.
|
|
92
|
+
|
|
93
|
+
Defined here rather than in ``agentic_auth.schemas.stepup`` to keep ``AuthorizeDecision``'s
|
|
94
|
+
imports acyclic: the step-up schemas import the deny vocabulary from this module.
|
|
95
|
+
"""
|
|
96
|
+
|
|
97
|
+
model_config = ConfigDict(extra="forbid")
|
|
98
|
+
|
|
99
|
+
challenge_id: str = Field(description="Single use. Only its SHA-256 is ever stored.")
|
|
100
|
+
session_id: str
|
|
101
|
+
blocked_hop: int = Field(ge=1)
|
|
102
|
+
blocked_action_id: uuid.UUID
|
|
103
|
+
data_class: str
|
|
104
|
+
target: str
|
|
105
|
+
reason: DenyReason
|
|
106
|
+
expires_at: datetime
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
class AuthorizeRequest(BaseModel):
|
|
110
|
+
model_config = ConfigDict(extra="forbid")
|
|
111
|
+
|
|
112
|
+
session_id: str
|
|
113
|
+
caller: str = Field(max_length=255, description="agent://<name>, or user:<sub> at hop 1")
|
|
114
|
+
target: str = Field(max_length=512, description="mcp://host/tool, or agent://<name>")
|
|
115
|
+
data_class: str = Field(max_length=128, description="exactly one data class")
|
|
116
|
+
taint: Taint | None = Field(
|
|
117
|
+
default=None,
|
|
118
|
+
description=(
|
|
119
|
+
"Agent-reported label. ADDITIVE ONLY: it can raise the effective taint the "
|
|
120
|
+
"decision uses, never lower it. The control plane derives the rest."
|
|
121
|
+
),
|
|
122
|
+
)
|
|
123
|
+
guarantee: Guarantee = Field(
|
|
124
|
+
description=(
|
|
125
|
+
"How strong the enforcement at this point actually is. Reported by the "
|
|
126
|
+
"enforcement point, exactly like `enforced`, and NEVER an input to the "
|
|
127
|
+
"decision. **Deliberately no default**: a PEP that omits it gets a 422, "
|
|
128
|
+
"which is how the rule ('refuse to emit a decision whose guarantee level "
|
|
129
|
+
"cannot be determined') is enforced by the schema rather than by a runtime "
|
|
130
|
+
"branch some path could miss."
|
|
131
|
+
),
|
|
132
|
+
)
|
|
133
|
+
enforced: bool = Field(
|
|
134
|
+
default=True,
|
|
135
|
+
description=(
|
|
136
|
+
"Reported by the enforcement point: will it act on a deny, or is it in "
|
|
137
|
+
"observe mode? An allow is always recorded as enforced, since it is "
|
|
138
|
+
"forwarded either way — so `enforced=false` means exactly 'would have been "
|
|
139
|
+
"blocked'. NEVER an input to the decision itself: the PDP is mode-blind, "
|
|
140
|
+
"which is what makes the observe-mode report a trustworthy prediction of "
|
|
141
|
+
"enforcement."
|
|
142
|
+
),
|
|
143
|
+
)
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
class AuthorizeDecision(BaseModel):
|
|
147
|
+
model_config = ConfigDict(extra="forbid")
|
|
148
|
+
|
|
149
|
+
outcome: str # "allow" | "deny"
|
|
150
|
+
hop: int = Field(ge=1, description="Derived from the verified act chain")
|
|
151
|
+
policy_version: int
|
|
152
|
+
session_id: str
|
|
153
|
+
reason: DenyReason | None = None
|
|
154
|
+
recoverable: bool | None = None
|
|
155
|
+
target: str | None = None
|
|
156
|
+
taint: Taint | None = Field(
|
|
157
|
+
default=None,
|
|
158
|
+
description="The EFFECTIVE taint the decision was made under, not an echo of the request.",
|
|
159
|
+
)
|
|
160
|
+
taint_source: str | None = Field(
|
|
161
|
+
default=None, description="The target that introduced the taint into this context."
|
|
162
|
+
)
|
|
163
|
+
privileged: bool = Field(
|
|
164
|
+
default=False, description="The target is privileged in the session's pinned policy."
|
|
165
|
+
)
|
|
166
|
+
transaction_required: bool = Field(
|
|
167
|
+
default=False,
|
|
168
|
+
description="privileged AND transaction tokens enabled: mint POST /v1/token/transaction "
|
|
169
|
+
"before calling the resource.",
|
|
170
|
+
)
|
|
171
|
+
message: str | None = Field(
|
|
172
|
+
default=None, description="Human-readable detail; never the machine contract"
|
|
173
|
+
)
|
|
174
|
+
action_id: uuid.UUID | None = Field(
|
|
175
|
+
default=None,
|
|
176
|
+
description="The audit row for this decision. Required by the token exchange. "
|
|
177
|
+
"Null only when the decision could not be recorded.",
|
|
178
|
+
)
|
|
179
|
+
acting_agent: str | None = Field(
|
|
180
|
+
default=None,
|
|
181
|
+
description="The verified token holder. Null for a token minted for a tool call.",
|
|
182
|
+
)
|
|
183
|
+
recorded: bool = Field(
|
|
184
|
+
default=True,
|
|
185
|
+
description="The audit row was committed before this response was sent.",
|
|
186
|
+
)
|
|
187
|
+
guarantee: Guarantee | None = Field(
|
|
188
|
+
default=None,
|
|
189
|
+
description=(
|
|
190
|
+
"Echoed from the request and written to the audit row. Null only on a "
|
|
191
|
+
"response rendered before the request was parsed."
|
|
192
|
+
),
|
|
193
|
+
)
|
|
194
|
+
step_up: StepUpChallenge | None = Field(
|
|
195
|
+
default=None,
|
|
196
|
+
description=(
|
|
197
|
+
"Present only on a RECOVERABLE deny with step-up enabled: the challenge to "
|
|
198
|
+
"put to the consenting human. A non-recoverable deny never carries one, so a "
|
|
199
|
+
"client cannot offer a prompt for something that can never be granted."
|
|
200
|
+
),
|
|
201
|
+
)
|
|
202
|
+
|
|
203
|
+
@property
|
|
204
|
+
def allowed(self) -> bool:
|
|
205
|
+
return self.outcome == "allow"
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"""Shared response envelope, pagination, and error models (rest-response-standard)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
from pydantic import BaseModel, Field
|
|
8
|
+
|
|
9
|
+
DEFAULT_PAGE_LIMIT = 20
|
|
10
|
+
MAX_PAGE_LIMIT = 100
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class PageInfo(BaseModel):
|
|
14
|
+
next_cursor: str | None = None
|
|
15
|
+
limit: int
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class Page[T](BaseModel):
|
|
19
|
+
data: list[T]
|
|
20
|
+
page: PageInfo
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class FieldError(BaseModel):
|
|
24
|
+
loc: list[str]
|
|
25
|
+
msg: str
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class ErrorBody(BaseModel):
|
|
29
|
+
code: str
|
|
30
|
+
message: str
|
|
31
|
+
details: dict[str, Any] | None = None
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class ErrorEnvelope(BaseModel):
|
|
35
|
+
error: ErrorBody
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class PaginationParams(BaseModel):
|
|
39
|
+
limit: int = Field(default=DEFAULT_PAGE_LIMIT, ge=1, le=MAX_PAGE_LIMIT)
|
|
40
|
+
cursor: str | None = None
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"""Consent: the human act that roots all downstream authority."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from datetime import datetime
|
|
6
|
+
|
|
7
|
+
from pydantic import BaseModel, ConfigDict, Field
|
|
8
|
+
|
|
9
|
+
MIN_SESSION_TTL = 60
|
|
10
|
+
MAX_SESSION_TTL = 86_400
|
|
11
|
+
# A bound on the consented subset. Generous — a real scope declares a handful — but a
|
|
12
|
+
# request is attacker-shaped input and an unbounded list is an unbounded array column.
|
|
13
|
+
MAX_CONSENTED_DATA_CLASSES = 256
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class ConsentCreate(BaseModel):
|
|
17
|
+
model_config = ConfigDict(extra="forbid")
|
|
18
|
+
|
|
19
|
+
scope: str = Field(max_length=255, min_length=1)
|
|
20
|
+
# Asserted by the integrator in this phase. Binding it to a verified IdP identity is
|
|
21
|
+
# Phase 4's identity work.
|
|
22
|
+
user_sub: str = Field(max_length=255, min_length=1)
|
|
23
|
+
ttl_seconds: int | None = Field(default=None, ge=MIN_SESSION_TTL, le=MAX_SESSION_TTL)
|
|
24
|
+
# Phase 5. The subset of the pinned policy's data classes this consent covers.
|
|
25
|
+
#
|
|
26
|
+
# Omitted (the default) means "everything the policy declares", which is exactly
|
|
27
|
+
# Phase 2-4 semantics — so every existing caller is unaffected. Supplying a subset is
|
|
28
|
+
# what makes SCOPE_NOT_CONSENTED mean "the human did not approve this" rather than
|
|
29
|
+
# "the manifest never declared it", and therefore what makes step-up able to grant
|
|
30
|
+
# anything at all.
|
|
31
|
+
#
|
|
32
|
+
# Validated against the pinned policy at consent time, not at first use: a typo
|
|
33
|
+
# should surface to the integrator immediately, not as a refusal three hops into a
|
|
34
|
+
# chain. Rejected entirely unless `consent_granularity_enabled`.
|
|
35
|
+
data_classes: list[str] | None = Field(
|
|
36
|
+
default=None,
|
|
37
|
+
min_length=1,
|
|
38
|
+
max_length=MAX_CONSENTED_DATA_CLASSES,
|
|
39
|
+
description=(
|
|
40
|
+
"Subset of the pinned policy's data classes to consent to. Omit for all of "
|
|
41
|
+
"them. Every entry must be declared by some agent in the compiled scope."
|
|
42
|
+
),
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class ConsentRead(BaseModel):
|
|
47
|
+
"""What the integrator gets back. ``root_grant`` is the hop-1 token."""
|
|
48
|
+
|
|
49
|
+
model_config = ConfigDict(extra="forbid")
|
|
50
|
+
|
|
51
|
+
session_id: str
|
|
52
|
+
root_grant: str
|
|
53
|
+
policy_version: int
|
|
54
|
+
scope: str
|
|
55
|
+
user_sub: str
|
|
56
|
+
hop_budget: int
|
|
57
|
+
expires_at: datetime
|
|
58
|
+
# Phase 5. What was actually pinned: null means every class the policy declares.
|
|
59
|
+
data_classes: list[str] | None = None
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class SessionRead(BaseModel):
|
|
63
|
+
"""The session without any token material — for reads and diagnostics."""
|
|
64
|
+
|
|
65
|
+
model_config = ConfigDict(extra="forbid")
|
|
66
|
+
|
|
67
|
+
session_id: str
|
|
68
|
+
scope: str
|
|
69
|
+
user_sub: str
|
|
70
|
+
policy_version: int
|
|
71
|
+
hop_budget: int
|
|
72
|
+
created_at: datetime
|
|
73
|
+
expires_at: datetime
|
|
74
|
+
data_classes: list[str] | None = None
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"""Read models for the compiled scope→capability DAG and scope catalog."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from pydantic import BaseModel
|
|
6
|
+
|
|
7
|
+
from agentic_auth.schemas.manifest import DataClassDecl
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class CatalogTool(BaseModel):
|
|
11
|
+
ref: str
|
|
12
|
+
data_classes: list[str]
|
|
13
|
+
privileged: bool
|
|
14
|
+
# Phase 4: RFC 6901 pointers a transaction token binds; None = whole body. Read-only.
|
|
15
|
+
binding_params: list[str] | None = None
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class DagPath(BaseModel):
|
|
19
|
+
path: list[str]
|
|
20
|
+
effective_hop_budget: int
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class ScopeCatalog(BaseModel):
|
|
24
|
+
scope: str
|
|
25
|
+
version: int
|
|
26
|
+
tools: list[CatalogTool]
|
|
27
|
+
data_classes: DataClassDecl
|
|
28
|
+
downstream_agents: list[str]
|
|
29
|
+
hop_budget: int
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class CompiledPolicyRead(BaseModel):
|
|
33
|
+
scope: str
|
|
34
|
+
version: int
|
|
35
|
+
tools: list[CatalogTool]
|
|
36
|
+
data_classes: DataClassDecl
|
|
37
|
+
downstream_agents: list[str]
|
|
38
|
+
hop_budget: int
|
|
39
|
+
paths: list[DagPath]
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"""Edge recording and drift reporting — see contracts/edge-trace.schema.json.
|
|
2
|
+
|
|
3
|
+
Every model is closed (``extra="forbid"``). There is no field anywhere in this module that
|
|
4
|
+
could carry a token, a header, a credential, a query string, or a payload — the absence is
|
|
5
|
+
the guarantee, and a line or file with an unknown field is rejected rather than
|
|
6
|
+
partially trusted.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
from datetime import datetime
|
|
12
|
+
from typing import Annotated, Literal, Self
|
|
13
|
+
|
|
14
|
+
from pydantic import BaseModel, ConfigDict, Field, StringConstraints, model_validator
|
|
15
|
+
|
|
16
|
+
AgentName = Annotated[str, StringConstraints(pattern=r"^[a-z0-9][a-z0-9-]{0,62}$")]
|
|
17
|
+
Target = Annotated[
|
|
18
|
+
str,
|
|
19
|
+
StringConstraints(
|
|
20
|
+
pattern=r"^(mcp://[^/\s]+/\S+|agent://[a-z0-9][a-z0-9-]{0,62})$", max_length=512
|
|
21
|
+
),
|
|
22
|
+
]
|
|
23
|
+
Reason = Annotated[str, StringConstraints(pattern=r"^[A-Z_]{1,32}$")]
|
|
24
|
+
Kind = Literal["tool", "delegation"]
|
|
25
|
+
Outcome = Literal["allow", "deny", "observed", "blocked_infra", "blocked_local"]
|
|
26
|
+
Source = Literal["sidecar", "sdk"]
|
|
27
|
+
Verdict = Literal["UNDECLARED_TOOL", "UNDECLARED_DELEGATION", "UNKNOWN_AGENT"]
|
|
28
|
+
|
|
29
|
+
# Outcomes where the policy actually evaluated this caller -> target edge.
|
|
30
|
+
EVALUATED_OUTCOMES: frozenset[str] = frozenset({"allow", "deny", "observed"})
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def kind_of(target: str | None) -> Kind | None:
|
|
34
|
+
if target is None:
|
|
35
|
+
return None
|
|
36
|
+
return "delegation" if target.startswith("agent://") else "tool"
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class _Closed(BaseModel):
|
|
40
|
+
model_config = ConfigDict(extra="forbid", populate_by_name=True)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
# -- the JSONL events file -----------------------------------------------------
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class EdgeEvent(_Closed):
|
|
47
|
+
v: Literal[1] = 1
|
|
48
|
+
ts: datetime
|
|
49
|
+
source: Source
|
|
50
|
+
acting_agent: AgentName | None
|
|
51
|
+
target: Target | None
|
|
52
|
+
kind: Kind | None
|
|
53
|
+
outcome: Outcome
|
|
54
|
+
reason: Reason | None
|
|
55
|
+
|
|
56
|
+
@model_validator(mode="after")
|
|
57
|
+
def _kind_matches_target(self) -> Self:
|
|
58
|
+
if self.kind != kind_of(self.target):
|
|
59
|
+
raise ValueError(f"kind {self.kind!r} does not match target {self.target!r}")
|
|
60
|
+
return self
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
class RecorderErrorLine(_Closed):
|
|
64
|
+
v: Literal[1] = 1
|
|
65
|
+
ts: datetime
|
|
66
|
+
source: Source
|
|
67
|
+
recorder_error: int = Field(ge=1, description="Events lost since the last successful write")
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
# -- the aggregated trace --------------------------------------------------------
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
class EdgeOutcomes(_Closed):
|
|
74
|
+
allow: int = Field(default=0, ge=0)
|
|
75
|
+
deny: int = Field(default=0, ge=0)
|
|
76
|
+
observed: int = Field(default=0, ge=0)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
class ObservedEdge(_Closed):
|
|
80
|
+
from_: AgentName = Field(alias="from")
|
|
81
|
+
to: Target
|
|
82
|
+
kind: Kind
|
|
83
|
+
count: int = Field(ge=1)
|
|
84
|
+
outcomes: EdgeOutcomes
|
|
85
|
+
|
|
86
|
+
@model_validator(mode="after")
|
|
87
|
+
def _consistent(self) -> Self:
|
|
88
|
+
total = self.outcomes.allow + self.outcomes.deny + self.outcomes.observed
|
|
89
|
+
if self.count != total:
|
|
90
|
+
raise ValueError(f"count {self.count} does not equal the sum of outcomes ({total})")
|
|
91
|
+
if self.kind != kind_of(self.to):
|
|
92
|
+
raise ValueError(f"kind {self.kind!r} does not match target {self.to!r}")
|
|
93
|
+
return self
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
class Unattributed(_Closed):
|
|
97
|
+
count: int = Field(default=0, ge=0)
|
|
98
|
+
by_reason: dict[str, Annotated[int, Field(ge=1)]] = Field(default_factory=dict)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
class TraceRun(_Closed):
|
|
102
|
+
started_at: datetime
|
|
103
|
+
finished_at: datetime
|
|
104
|
+
command: list[str] | None
|
|
105
|
+
event_files: list[str]
|
|
106
|
+
exit_code: int | None
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
class EdgeTrace(_Closed):
|
|
110
|
+
schema_version: Literal[1] = 1
|
|
111
|
+
run: TraceRun
|
|
112
|
+
edges: list[ObservedEdge]
|
|
113
|
+
unattributed: Unattributed
|
|
114
|
+
recorder_errors: int = Field(ge=0)
|
|
115
|
+
events_total: int = Field(ge=0)
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
# -- the drift report --------------------------------------------------------------
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
class UndeclaredEdge(_Closed):
|
|
122
|
+
from_: str = Field(alias="from")
|
|
123
|
+
to: str
|
|
124
|
+
kind: Kind
|
|
125
|
+
count: int = Field(ge=1)
|
|
126
|
+
verdict: Verdict
|
|
127
|
+
runtime_reason: str
|
|
128
|
+
manifest_path: str | None
|
|
129
|
+
hint: str
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
class DriftError(_Closed):
|
|
133
|
+
code: str
|
|
134
|
+
message: str
|
|
135
|
+
path: str | None = None
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
class DriftWarning(_Closed):
|
|
139
|
+
code: str
|
|
140
|
+
message: str
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
class DriftSummary(_Closed):
|
|
144
|
+
edges_observed: int = Field(ge=0)
|
|
145
|
+
edges_declared: int = Field(ge=0)
|
|
146
|
+
edges_undeclared: int = Field(ge=0)
|
|
147
|
+
calls_observed: int = Field(ge=0)
|
|
148
|
+
unattributed_calls: int = Field(ge=0)
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
class DriftInputs(_Closed):
|
|
152
|
+
manifest_dirs: list[str]
|
|
153
|
+
trace: str
|
|
154
|
+
manifests_loaded: int = Field(ge=0)
|
|
155
|
+
skipped_files: list[str]
|
|
156
|
+
generated_at: datetime | None = None
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
class DriftReport(_Closed):
|
|
160
|
+
schema_version: Literal[1] = 1
|
|
161
|
+
result: Literal["pass", "drift", "error"]
|
|
162
|
+
summary: DriftSummary
|
|
163
|
+
undeclared: list[UndeclaredEdge]
|
|
164
|
+
errors: list[DriftError]
|
|
165
|
+
warnings: list[DriftWarning]
|
|
166
|
+
inputs: DriftInputs
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"""Identity plane request/response models.
|
|
2
|
+
|
|
3
|
+
Inbound models are ``extra="forbid"``. ``Jwk`` accepts OKP/Ed25519 public keys only and
|
|
4
|
+
rejects a private member outright: an identity document that leaks ``d`` is a bug on the
|
|
5
|
+
agent's side that the control plane refuses to store.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import base64
|
|
11
|
+
import uuid
|
|
12
|
+
from datetime import datetime
|
|
13
|
+
from typing import Any, Literal
|
|
14
|
+
|
|
15
|
+
from pydantic import BaseModel, ConfigDict, Field, field_validator
|
|
16
|
+
|
|
17
|
+
from agentic_auth.schemas.agent import AgentStatus
|
|
18
|
+
from agentic_auth.schemas.manifest import AgentUri
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class Jwk(BaseModel):
|
|
22
|
+
model_config = ConfigDict(extra="forbid")
|
|
23
|
+
|
|
24
|
+
kty: Literal["OKP"]
|
|
25
|
+
crv: Literal["Ed25519"]
|
|
26
|
+
x: str = Field(description="base64url, 32 bytes")
|
|
27
|
+
kid: str = Field(min_length=1, max_length=64)
|
|
28
|
+
alg: Literal["EdDSA"] = "EdDSA"
|
|
29
|
+
use: Literal["sig"] = "sig"
|
|
30
|
+
|
|
31
|
+
@field_validator("x")
|
|
32
|
+
@classmethod
|
|
33
|
+
def _thirty_two_bytes(cls, value: str) -> str:
|
|
34
|
+
try:
|
|
35
|
+
raw = base64.urlsafe_b64decode(value + "=" * (-len(value) % 4))
|
|
36
|
+
except (ValueError, TypeError) as exc:
|
|
37
|
+
raise ValueError("x must be base64url") from exc
|
|
38
|
+
if len(raw) != 32:
|
|
39
|
+
raise ValueError("x must decode to 32 bytes")
|
|
40
|
+
return value
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class Jwks(BaseModel):
|
|
44
|
+
model_config = ConfigDict(extra="forbid")
|
|
45
|
+
|
|
46
|
+
keys: list[Jwk] = Field(min_length=1, max_length=8)
|
|
47
|
+
|
|
48
|
+
@field_validator("keys")
|
|
49
|
+
@classmethod
|
|
50
|
+
def _unique_kids(cls, keys: list[Jwk]) -> list[Jwk]:
|
|
51
|
+
kids = [k.kid for k in keys]
|
|
52
|
+
if len(set(kids)) != len(kids):
|
|
53
|
+
raise ValueError("kid values must be unique")
|
|
54
|
+
return keys
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
class IdentityDocument(BaseModel):
|
|
58
|
+
model_config = ConfigDict(extra="forbid")
|
|
59
|
+
|
|
60
|
+
sub: AgentUri
|
|
61
|
+
jwks: Jwks
|
|
62
|
+
claims: dict[str, Any] = Field(default_factory=dict)
|
|
63
|
+
principal_assertion: str | None = Field(default=None, max_length=8192)
|
|
64
|
+
|
|
65
|
+
def public_document(self) -> dict[str, Any]:
|
|
66
|
+
"""What may be stored: never the assertion (a bearer credential for the IdP)."""
|
|
67
|
+
return {"sub": self.sub, "jwks": self.jwks.model_dump(), "claims": self.claims}
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
class EnrollBegin(BaseModel):
|
|
71
|
+
model_config = ConfigDict(extra="forbid")
|
|
72
|
+
|
|
73
|
+
identity_doc: IdentityDocument
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
class EnrollChallenge(BaseModel):
|
|
77
|
+
model_config = ConfigDict(extra="forbid")
|
|
78
|
+
|
|
79
|
+
challenge_id: uuid.UUID
|
|
80
|
+
nonce: str
|
|
81
|
+
expires_at: datetime
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
class EnrollComplete(BaseModel):
|
|
85
|
+
model_config = ConfigDict(extra="forbid")
|
|
86
|
+
|
|
87
|
+
challenge_id: uuid.UUID
|
|
88
|
+
signed_response: str = Field(max_length=8192)
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
QuarantineReason = Literal["PRINCIPAL_UNBINDABLE", "PRINCIPAL_IDP_NOT_CONFIGURED"]
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
class EnrollOutcome(BaseModel):
|
|
95
|
+
model_config = ConfigDict(extra="forbid")
|
|
96
|
+
|
|
97
|
+
status: Literal["enrolled", "quarantined"]
|
|
98
|
+
trust_anchor_version: int | None = None
|
|
99
|
+
principal_ref: str | None = None
|
|
100
|
+
reason: QuarantineReason | None = None
|
|
101
|
+
detail: str | None = None
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
class RevokeRequest(BaseModel):
|
|
105
|
+
model_config = ConfigDict(extra="forbid")
|
|
106
|
+
|
|
107
|
+
reason: str | None = Field(default=None, max_length=1024)
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
class RevokeOutcome(BaseModel):
|
|
111
|
+
model_config = ConfigDict(extra="forbid")
|
|
112
|
+
|
|
113
|
+
status: Literal["revoked"]
|
|
114
|
+
trust_anchor_version: int
|
|
115
|
+
revoked_at: datetime
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
class AgentIdentityRead(BaseModel):
|
|
119
|
+
model_config = ConfigDict(extra="forbid")
|
|
120
|
+
|
|
121
|
+
agent: str
|
|
122
|
+
status: AgentStatus
|
|
123
|
+
trust_anchor_version: int | None
|
|
124
|
+
jwks: dict[str, Any] | None
|
|
125
|
+
principal_ref: str | None
|
|
126
|
+
manifest_version: int | None
|
|
127
|
+
revoked: bool
|
|
128
|
+
revoked_at: datetime | None
|
|
129
|
+
as_of: datetime
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
class RevocationItem(BaseModel):
|
|
133
|
+
model_config = ConfigDict(extra="forbid")
|
|
134
|
+
|
|
135
|
+
agent: str
|
|
136
|
+
trust_anchor_version: int
|
|
137
|
+
revoked_at: datetime
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
class RevocationPage(BaseModel):
|
|
141
|
+
model_config = ConfigDict(extra="forbid")
|
|
142
|
+
|
|
143
|
+
next_cursor: str | None
|
|
144
|
+
limit: int
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
class RevocationListRead(BaseModel):
|
|
148
|
+
model_config = ConfigDict(extra="forbid")
|
|
149
|
+
|
|
150
|
+
as_of: datetime
|
|
151
|
+
items: list[RevocationItem]
|
|
152
|
+
page: RevocationPage
|