authzai 0.2.0__tar.gz → 0.3.0__tar.gz

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.
Files changed (179) hide show
  1. {authzai-0.2.0/authzai.egg-info → authzai-0.3.0}/PKG-INFO +3 -1
  2. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/__init__.py +1 -1
  3. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/api/deps.py +42 -0
  4. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/api/service_deps.py +12 -0
  5. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/api/v1/authorize.py +63 -0
  6. authzai-0.3.0/agentic_auth/api/v1/sandbox.py +181 -0
  7. authzai-0.3.0/agentic_auth/api/v1/stepup.py +86 -0
  8. authzai-0.3.0/agentic_auth/boundary/__main__.py +92 -0
  9. authzai-0.3.0/agentic_auth/boundary/egress.py +229 -0
  10. authzai-0.3.0/agentic_auth/boundary/mcp.py +309 -0
  11. authzai-0.3.0/agentic_auth/boundary/resource.py +204 -0
  12. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/cli/__init__.py +2 -0
  13. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/cli/audit.py +45 -0
  14. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/cli/manifest.py +85 -0
  15. authzai-0.3.0/agentic_auth/cli/sandbox.py +128 -0
  16. authzai-0.3.0/agentic_auth/coldstart/__init__.py +20 -0
  17. authzai-0.3.0/agentic_auth/coldstart/propose.py +212 -0
  18. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/embedded/__init__.py +34 -0
  19. authzai-0.3.0/agentic_auth/embedded/_schema.py +19 -0
  20. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/embedded/_transport.py +4 -3
  21. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/embedded/idp.py +6 -4
  22. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/embedded/store.py +10 -3
  23. authzai-0.3.0/agentic_auth/gateway/__init__.py +16 -0
  24. authzai-0.3.0/agentic_auth/gateway/__main__.py +35 -0
  25. authzai-0.3.0/agentic_auth/gateway/app.py +299 -0
  26. authzai-0.3.0/agentic_auth/gateway/config.py +224 -0
  27. authzai-0.3.0/agentic_auth/gateway/metrics.py +86 -0
  28. authzai-0.3.0/agentic_auth/gateway/resolve.py +98 -0
  29. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/main.py +6 -1
  30. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/models/__init__.py +1 -0
  31. authzai-0.3.0/agentic_auth/models/imported_audit.py +57 -0
  32. authzai-0.3.0/agentic_auth/repositories/sandbox_runs.py +103 -0
  33. authzai-0.3.0/agentic_auth/repositories/step_up_grants.py +78 -0
  34. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/schemas/agent.py +5 -1
  35. authzai-0.3.0/agentic_auth/schemas/sandbox.py +133 -0
  36. authzai-0.3.0/agentic_auth/schemas/stepup.py +92 -0
  37. authzai-0.3.0/agentic_auth/services/bundle_import.py +174 -0
  38. authzai-0.3.0/agentic_auth/services/guarantee.py +162 -0
  39. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/services/manifest_service.py +20 -3
  40. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/services/principal.py +38 -0
  41. authzai-0.3.0/agentic_auth/services/sandbox.py +281 -0
  42. authzai-0.3.0/agentic_auth/services/stepup.py +380 -0
  43. authzai-0.3.0/agentic_auth/services/stepup_rules.py +72 -0
  44. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/sidecar/enforce.py +13 -4
  45. {authzai-0.2.0 → authzai-0.3.0/authzai.egg-info}/PKG-INFO +3 -1
  46. {authzai-0.2.0 → authzai-0.3.0}/authzai.egg-info/SOURCES.txt +25 -0
  47. {authzai-0.2.0 → authzai-0.3.0}/authzai.egg-info/requires.txt +2 -0
  48. {authzai-0.2.0 → authzai-0.3.0}/pyproject.toml +3 -0
  49. authzai-0.2.0/agentic_auth/embedded/_schema.py +0 -8
  50. {authzai-0.2.0 → authzai-0.3.0}/LICENSE +0 -0
  51. {authzai-0.2.0 → authzai-0.3.0}/NOTICE +0 -0
  52. {authzai-0.2.0 → authzai-0.3.0}/README.md +0 -0
  53. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/_extras.py +0 -0
  54. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/api/__init__.py +0 -0
  55. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/api/errors.py +0 -0
  56. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/api/responses.py +0 -0
  57. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/api/v1/__init__.py +0 -0
  58. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/api/v1/agents.py +0 -0
  59. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/api/v1/audit.py +0 -0
  60. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/api/v1/consent.py +0 -0
  61. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/api/v1/decisions.py +0 -0
  62. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/api/v1/enrollment.py +0 -0
  63. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/api/v1/identity.py +0 -0
  64. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/api/v1/jwks.py +0 -0
  65. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/api/v1/manifests.py +0 -0
  66. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/api/v1/scopes.py +0 -0
  67. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/api/v1/token.py +0 -0
  68. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/api/v1/transaction.py +0 -0
  69. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/boundary/__init__.py +0 -0
  70. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/boundary/guarantee.py +0 -0
  71. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/cli/drift.py +0 -0
  72. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/cli/drift_render.py +0 -0
  73. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/cli/identity.py +0 -0
  74. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/config.py +0 -0
  75. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/db.py +0 -0
  76. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/embedded/capabilities.py +0 -0
  77. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/embedded/export.py +0 -0
  78. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/errors.py +0 -0
  79. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/models/agent.py +0 -0
  80. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/models/audit_decision.py +0 -0
  81. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/models/compiled_policy.py +0 -0
  82. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/models/manifest.py +0 -0
  83. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/models/reconciliation_report.py +0 -0
  84. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/models/sandbox_run.py +0 -0
  85. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/models/session.py +0 -0
  86. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/models/step_up_grant.py +0 -0
  87. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/models/transaction_token.py +0 -0
  88. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/models/trust_anchor.py +0 -0
  89. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/models/types.py +0 -0
  90. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/observability/__init__.py +0 -0
  91. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/observability/config.py +0 -0
  92. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/observability/context.py +0 -0
  93. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/observability/ids.py +0 -0
  94. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/observability/logs.py +0 -0
  95. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/observability/pep.py +0 -0
  96. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/observability/spans.py +0 -0
  97. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/observability/surface.py +0 -0
  98. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/observability/tracing.py +0 -0
  99. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/redis.py +0 -0
  100. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/repositories/__init__.py +0 -0
  101. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/repositories/agents.py +0 -0
  102. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/repositories/audit_decisions.py +0 -0
  103. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/repositories/compiled_policies.py +0 -0
  104. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/repositories/manifests.py +0 -0
  105. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/repositories/reconciliation_reports.py +0 -0
  106. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/repositories/sessions.py +0 -0
  107. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/repositories/transaction_tokens.py +0 -0
  108. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/repositories/trust_anchors.py +0 -0
  109. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/runtime.py +0 -0
  110. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/schemas/__init__.py +0 -0
  111. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/schemas/audit.py +0 -0
  112. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/schemas/authorize.py +0 -0
  113. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/schemas/common.py +0 -0
  114. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/schemas/consent.py +0 -0
  115. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/schemas/dag.py +0 -0
  116. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/schemas/edge_trace.py +0 -0
  117. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/schemas/identity.py +0 -0
  118. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/schemas/manifest.py +0 -0
  119. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/schemas/manifest_api.py +0 -0
  120. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/schemas/reconciliation.py +0 -0
  121. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/schemas/token.py +0 -0
  122. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/schemas/transaction.py +0 -0
  123. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/sdk/__init__.py +0 -0
  124. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/sdk/client.py +0 -0
  125. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/sdk/context.py +0 -0
  126. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/sdk/drift.py +0 -0
  127. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/sdk/errors.py +0 -0
  128. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/sdk/identity.py +0 -0
  129. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/sdk/planes.py +0 -0
  130. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/sdk/provenance.py +0 -0
  131. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/services/__init__.py +0 -0
  132. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/services/anchors.py +0 -0
  133. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/services/audit.py +0 -0
  134. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/services/audit_chain.py +0 -0
  135. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/services/audit_cursor.py +0 -0
  136. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/services/catalog_service.py +0 -0
  137. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/services/chain_query.py +0 -0
  138. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/services/dag_compiler.py +0 -0
  139. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/services/decision_cache.py +0 -0
  140. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/services/decision_history.py +0 -0
  141. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/services/discovery.py +0 -0
  142. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/services/drift.py +0 -0
  143. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/services/edge_rules.py +0 -0
  144. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/services/edge_trace.py +0 -0
  145. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/services/enrollment.py +0 -0
  146. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/services/enrollment_rules.py +0 -0
  147. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/services/metrics.py +0 -0
  148. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/services/pdp.py +0 -0
  149. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/services/policy_loader.py +0 -0
  150. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/services/reconciler.py +0 -0
  151. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/services/revocation.py +0 -0
  152. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/services/sessions.py +0 -0
  153. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/services/taint.py +0 -0
  154. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/services/tokens/__init__.py +0 -0
  155. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/services/tokens/act_chain.py +0 -0
  156. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/services/tokens/exchange.py +0 -0
  157. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/services/tokens/jwt_profile.py +0 -0
  158. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/services/tokens/keys.py +0 -0
  159. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/services/tokens/profile.py +0 -0
  160. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/services/tokens/replay.py +0 -0
  161. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/services/transactions.py +0 -0
  162. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/sidecar/__init__.py +0 -0
  163. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/sidecar/__main__.py +0 -0
  164. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/sidecar/app.py +0 -0
  165. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/sidecar/config.py +0 -0
  166. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/sidecar/deny.py +0 -0
  167. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/sidecar/identity.py +0 -0
  168. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/verify/__init__.py +0 -0
  169. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/verify/admit.py +0 -0
  170. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/verify/anchors.py +0 -0
  171. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/verify/canonical.py +0 -0
  172. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/verify/grants.py +0 -0
  173. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/verify/identity.py +0 -0
  174. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/verify/replay.py +0 -0
  175. {authzai-0.2.0 → authzai-0.3.0}/agentic_auth/verify/transaction.py +0 -0
  176. {authzai-0.2.0 → authzai-0.3.0}/authzai.egg-info/dependency_links.txt +0 -0
  177. {authzai-0.2.0 → authzai-0.3.0}/authzai.egg-info/entry_points.txt +0 -0
  178. {authzai-0.2.0 → authzai-0.3.0}/authzai.egg-info/top_level.txt +0 -0
  179. {authzai-0.2.0 → authzai-0.3.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: authzai
3
- Version: 0.2.0
3
+ Version: 0.3.0
4
4
  Summary: Authorization for AI agents: per-hop narrowing authority, verifiable delegation chains, and an append-only audit log
5
5
  Author: Wong Xin Wei
6
6
  License-Expression: Apache-2.0
@@ -61,6 +61,8 @@ Requires-Dist: locust; extra == "dev"
61
61
  Requires-Dist: jsonschema; extra == "dev"
62
62
  Requires-Dist: build; extra == "dev"
63
63
  Requires-Dist: twine; extra == "dev"
64
+ Requires-Dist: nbclient>=0.10; extra == "dev"
65
+ Requires-Dist: ipykernel>=6; extra == "dev"
64
66
  Provides-Extra: otel
65
67
  Requires-Dist: opentelemetry-api>=1.30; extra == "otel"
66
68
  Requires-Dist: opentelemetry-sdk>=1.30; extra == "otel"
@@ -5,4 +5,4 @@ Imports nothing: ``import agentic_auth`` must work from the base install, which
5
5
  ``pyjwt[crypto]``.
6
6
  """
7
7
 
8
- __version__ = "0.2.0"
8
+ __version__ = "0.3.0"
@@ -105,8 +105,50 @@ async def presented_token(
105
105
 
106
106
  SessionDep = Annotated[AsyncSession, Depends(get_session)]
107
107
  PresentedTokenDep = Annotated[VerifiedToken, Depends(presented_token)]
108
+
109
+
110
+ async def require_consenting_human(
111
+ authorization: Annotated[str | None, Header()] = None,
112
+ ) -> str:
113
+ """Who may APPROVE a step-up widening: the human, not the agent (research.md R6).
114
+
115
+ The whole threat model assumes the agent may be under an attacker's influence. An
116
+ agent that could approve its own widening would turn ``SCOPE_NOT_CONSENTED`` from a
117
+ control into a formality — the injected instruction would simply answer the prompt it
118
+ triggered. So the session's own root grant is deliberately NOT sufficient here, even
119
+ though it is sufficient to *raise* the challenge.
120
+
121
+ Where the deployment has configured a human identity provider, this is an ID token
122
+ from it and the subject is its ``sub``. Where it has not, the admin bearer stands in
123
+ and the subject is recorded as ``admin`` — a deployment with no independent human
124
+ channel, which its documentation must say plainly rather than imply otherwise.
125
+
126
+ Returns the subject to record as the approver.
127
+ """
128
+ settings = get_settings()
129
+ if not authorization or not authorization.startswith("Bearer "):
130
+ raise UnauthorizedError("missing or malformed credential")
131
+ token = authorization.removeprefix("Bearer ").strip()
132
+
133
+ if settings.principal_idp_issuer:
134
+ from agentic_auth.services.principal import PrincipalBinder
135
+
136
+ try:
137
+ return await PrincipalBinder().verify_human(token)
138
+ except Exception as exc: # noqa: BLE001 - any failure here is a refusal
139
+ raise UnauthorizedError(f"human credential did not verify: {exc}") from exc
140
+
141
+ if hmac.compare_digest(token.encode(), settings.admin_token.encode()):
142
+ return "admin"
143
+ raise UnauthorizedError(
144
+ "step-up approval requires the consenting human's credential; the session's own "
145
+ "grant is not sufficient"
146
+ )
147
+
148
+
108
149
  AdminDep = Depends(require_admin)
109
150
  AuditReaderDep = Depends(require_audit_reader)
110
151
  EnrollerDep = Depends(require_enroller)
111
152
  IdentityReaderDep = Depends(require_identity_reader)
153
+ ConsentingHumanDep = Annotated[str, Depends(require_consenting_human)]
112
154
  PaginationDep = Annotated[PaginationParams, Depends(pagination_params)]
@@ -20,7 +20,9 @@ from agentic_auth.services.enrollment import EnrollmentService
20
20
  from agentic_auth.services.manifest_service import ManifestService
21
21
  from agentic_auth.services.principal import PrincipalBinder
22
22
  from agentic_auth.services.revocation import RevocationService
23
+ from agentic_auth.services.sandbox import SandboxService
23
24
  from agentic_auth.services.sessions import SessionService
25
+ from agentic_auth.services.stepup import StepUpService
24
26
  from agentic_auth.services.tokens.exchange import TokenExchangeService
25
27
  from agentic_auth.services.tokens.jwt_profile import JwtTokenProfile
26
28
  from agentic_auth.services.tokens.profile import TokenProfile
@@ -100,6 +102,14 @@ def get_chain_query_service() -> ChainQueryService:
100
102
  return ChainQueryService()
101
103
 
102
104
 
105
+ def get_step_up_service() -> StepUpService:
106
+ return StepUpService()
107
+
108
+
109
+ def get_sandbox_service() -> SandboxService:
110
+ return SandboxService()
111
+
112
+
103
113
  ManifestServiceDep = Annotated[ManifestService, Depends(get_manifest_service)]
104
114
  RedisDep = Annotated[Redis, Depends(get_redis_dep)]
105
115
  TokenProfileDep = Annotated[TokenProfile, Depends(get_token_profile)]
@@ -111,3 +121,5 @@ AnchorCacheDep = Annotated[AnchorCache, Depends(get_anchor_cache)]
111
121
  EnrollmentServiceDep = Annotated[EnrollmentService, Depends(get_enrollment_service)]
112
122
  RevocationServiceDep = Annotated[RevocationService, Depends(get_revocation_service)]
113
123
  ChainQueryServiceDep = Annotated[ChainQueryService, Depends(get_chain_query_service)]
124
+ StepUpServiceDep = Annotated[StepUpService, Depends(get_step_up_service)]
125
+ SandboxServiceDep = Annotated[SandboxService, Depends(get_sandbox_service)]
@@ -34,8 +34,10 @@ from agentic_auth.observability import logs, surface
34
34
  from agentic_auth.schemas.authorize import AuthorizeDecision, AuthorizeRequest, DenyReason, Taint
35
35
  from agentic_auth.services import decision_cache, policy_loader
36
36
  from agentic_auth.services.audit import AuditService, RecordResult
37
+ from agentic_auth.services.guarantee import note_level
37
38
  from agentic_auth.services.metrics import get_metrics
38
39
  from agentic_auth.services.pdp import Decision, decide
40
+ from agentic_auth.services.stepup import StepUpService, granted_classes
39
41
  from agentic_auth.services.taint import (
40
42
  Marked,
41
43
  TaintStore,
@@ -156,6 +158,24 @@ async def authorize(
156
158
  chain_agents.add(body.target.removeprefix("agent://")) # delegating TO a revoked agent
157
159
  revoked_on_chain = frozenset(revoked & chain_agents)
158
160
 
161
+ # -- step-up (Phase 5) -------------------------------------------------------
162
+ # The third decision input of this shape, after taint and the revoked set: loaded
163
+ # here, handed to the pure `decide()` as a parameter. A session is never mutated to
164
+ # record a widening (research.md R6).
165
+ consented = (
166
+ frozenset(session.consented_data_classes)
167
+ if session.consented_data_classes is not None
168
+ else None
169
+ )
170
+ step_up: frozenset[str] = frozenset()
171
+ if consented is not None and settings.step_up_enabled:
172
+ step_up = await granted_classes(
173
+ db,
174
+ redis,
175
+ body.session_id,
176
+ ttl_seconds=int((session.expires_at - _now()).total_seconds()),
177
+ )
178
+
159
179
  cache_key = decision_cache.key(
160
180
  body,
161
181
  policy_version=session.policy_version,
@@ -165,6 +185,8 @@ async def authorize(
165
185
  act_chain=token.act_chain,
166
186
  taint=taint,
167
187
  revoked=revoked_on_chain,
188
+ consented_data_classes=consented,
189
+ step_up=step_up,
168
190
  )
169
191
  decision = await decision_cache.get(redis, cache_key)
170
192
  if decision is None:
@@ -177,6 +199,8 @@ async def authorize(
177
199
  taint=taint,
178
200
  taint_enforced=settings.taint_enforcement_enabled,
179
201
  revoked=revoked_on_chain,
202
+ consented_data_classes=consented,
203
+ step_up=step_up,
180
204
  )
181
205
  await decision_cache.put(redis, cache_key, decision)
182
206
 
@@ -196,9 +220,48 @@ async def authorize(
196
220
  headers=request.headers,
197
221
  )
198
222
 
223
+ # -- the guarantee level: count it, and never let a degrade pass quietly --------
199
224
  get_metrics().decisions_by_guarantee.labels(
200
225
  level=body.guarantee.value, outcome=rendered.outcome
201
226
  ).inc()
227
+ await note_level(
228
+ db,
229
+ redis,
230
+ session_id=body.session_id,
231
+ level=body.guarantee,
232
+ caller=body.caller,
233
+ target=body.target,
234
+ policy_version=session.policy_version,
235
+ act_chain=token.act_chain,
236
+ ttl_seconds=int((session.expires_at - _now()).total_seconds()),
237
+ )
238
+
239
+ # -- offer a challenge, but only where one could actually be granted -------------
240
+ # A non-recoverable refusal never carries a challenge, so a client cannot put a
241
+ # prompt in front of a human for something that can never be approved (FR-024).
242
+ if (
243
+ settings.step_up_enabled
244
+ and rendered.recoverable
245
+ and rendered.action_id is not None
246
+ and consented is not None
247
+ ):
248
+ try:
249
+ rendered = rendered.model_copy(
250
+ update={
251
+ "step_up": await StepUpService().challenge(
252
+ db,
253
+ redis,
254
+ session_id=uuid.UUID(body.session_id),
255
+ blocked_action_id=rendered.action_id,
256
+ policy=policy,
257
+ )
258
+ }
259
+ )
260
+ except DomainError:
261
+ # The refusal stands on its own. A challenge that cannot be raised — the
262
+ # class is outside the manifest ceiling, say — must not turn a clean deny
263
+ # into an error the caller cannot act on.
264
+ logger.info("no step-up challenge offered for %s", rendered.reason)
202
265
 
203
266
  # -- mark: this call reaches for a source the caller does not trust ---------------
204
267
  # On an allow (or an observe-mode forwarded policy deny) the result will be consumed
@@ -0,0 +1,181 @@
1
+ """``/v1/agents/{id}/sandbox`` and the proposal endpoints (FR-032..FR-042).
2
+
3
+ Admin-only throughout, and 404 unless ``sandbox_enabled``: a deployment that has not
4
+ adopted cold start should not advertise routes that run agents.
5
+
6
+ Nothing here can affect a decision. A proposal is a ``manifests`` row with status
7
+ ``proposed``, which the compiler never selects — so no policy is compiled for it, no
8
+ session can pin it, and no decision can resolve against it. That is asserted directly in
9
+ ``tests/unit/test_proposed_is_inert.py`` rather than left to emerge (research.md R12).
10
+ """
11
+
12
+ from __future__ import annotations
13
+
14
+ import uuid
15
+
16
+ from fastapi import APIRouter, Query, status
17
+ from sqlalchemy.ext.asyncio import AsyncSession
18
+
19
+ from agentic_auth.api.deps import AdminDep, SessionDep
20
+ from agentic_auth.api.service_deps import SandboxServiceDep
21
+ from agentic_auth.config import get_settings
22
+ from agentic_auth.errors import NotFoundError
23
+ from agentic_auth.models import Agent, SandboxRun
24
+ from agentic_auth.repositories import agents as agents_repo
25
+ from agentic_auth.repositories import sandbox_runs as runs_repo
26
+ from agentic_auth.schemas.sandbox import (
27
+ ObservedRead,
28
+ ProposedManifestRead,
29
+ RatifyRequest,
30
+ SandboxRunListItem,
31
+ SandboxRunPage,
32
+ SandboxRunRead,
33
+ SandboxStart,
34
+ )
35
+
36
+ router = APIRouter(prefix="/v1/agents", tags=["cold-start"], dependencies=[AdminDep])
37
+
38
+
39
+ def _require_enabled() -> None:
40
+ if not get_settings().sandbox_enabled:
41
+ raise NotFoundError("sandboxed observation is not enabled on this deployment")
42
+
43
+
44
+ async def _agent(db: AsyncSession, agent_id: uuid.UUID) -> Agent:
45
+ agent = await agents_repo.get_by_id(db, agent_id)
46
+ if agent is None:
47
+ raise NotFoundError(f"unknown agent {agent_id}")
48
+ return agent
49
+
50
+
51
+ def _read(run: SandboxRun) -> SandboxRunRead:
52
+ observed = None
53
+ proposal = (run.trace or {}).get("x-proposal") if isinstance(run.trace, dict) else None
54
+ if proposal:
55
+ observed = ObservedRead(**proposal.get("observed", {}))
56
+ return SandboxRunRead(
57
+ id=run.id,
58
+ agent_id=run.agent_id,
59
+ status=run.status,
60
+ scope=run.scope,
61
+ started_at=run.started_at,
62
+ deadline_at=run.deadline_at,
63
+ ended_at=run.ended_at,
64
+ recorder_errors=run.recorder_errors,
65
+ observed=observed,
66
+ )
67
+
68
+
69
+ @router.post(
70
+ "/{agent_id}/sandbox", response_model=SandboxRunRead, status_code=status.HTTP_201_CREATED
71
+ )
72
+ async def start_run(
73
+ agent_id: uuid.UUID,
74
+ body: SandboxStart,
75
+ db: SessionDep,
76
+ sandbox: SandboxServiceDep,
77
+ ) -> SandboxRunRead:
78
+ """Begin observing. Every call the agent attempts is allowed and recorded, and every
79
+ tool it can reach is a mock with nothing real behind it (FR-032)."""
80
+ _require_enabled()
81
+ await _agent(db, agent_id)
82
+ run = await sandbox.start(
83
+ db, agent_id=agent_id, scope=body.scope, deadline_seconds=body.deadline_seconds
84
+ )
85
+ return _read(run)
86
+
87
+
88
+ @router.get("/{agent_id}/sandbox", response_model=SandboxRunPage)
89
+ async def list_runs(
90
+ agent_id: uuid.UUID,
91
+ db: SessionDep,
92
+ limit: int = Query(default=50, ge=1, le=200),
93
+ ) -> SandboxRunPage:
94
+ _require_enabled()
95
+ await _agent(db, agent_id)
96
+ rows = await runs_repo.list_for_agent(db, agent_id, limit=limit)
97
+ return SandboxRunPage(
98
+ data=[SandboxRunListItem.model_validate(r) for r in rows],
99
+ next_cursor=rows[-1].started_at.isoformat() if len(rows) == limit else None,
100
+ )
101
+
102
+
103
+ @router.get("/{agent_id}/sandbox/{run_id}", response_model=SandboxRunRead)
104
+ async def read_run(
105
+ agent_id: uuid.UUID,
106
+ run_id: uuid.UUID,
107
+ db: SessionDep,
108
+ sandbox: SandboxServiceDep,
109
+ ) -> SandboxRunRead:
110
+ _require_enabled()
111
+ run = await runs_repo.get(db, run_id)
112
+ if run is None or run.agent_id != agent_id:
113
+ raise NotFoundError(f"unknown run {run_id}")
114
+ # The deadline is applied on read rather than by a sweeper: a run only matters when
115
+ # someone asks, and a second place to get the deadline wrong is a second bug.
116
+ return _read(await sandbox.expire_if_due(db, run))
117
+
118
+
119
+ @router.get("/{agent_id}/proposed-manifest", response_model=ProposedManifestRead)
120
+ async def read_proposal(
121
+ agent_id: uuid.UUID,
122
+ db: SessionDep,
123
+ sandbox: SandboxServiceDep,
124
+ run_id: uuid.UUID | None = None,
125
+ ) -> ProposedManifestRead:
126
+ """The manifest proposed from a run — inert until ratified."""
127
+ _require_enabled()
128
+ agent = await _agent(db, agent_id)
129
+
130
+ run = (
131
+ await runs_repo.get(db, run_id)
132
+ if run_id is not None
133
+ else await runs_repo.latest_completed(db, agent_id)
134
+ )
135
+ if run is None or run.agent_id != agent_id:
136
+ raise NotFoundError("no completed sandbox run for this agent")
137
+
138
+ row = await sandbox.propose(db, run, agent_name=agent.name)
139
+ return ProposedManifestRead(
140
+ manifest_id=row.id,
141
+ agent_id=agent_id,
142
+ run_id=run.id,
143
+ status="proposed",
144
+ doc=row.doc,
145
+ covers_no_behaviour=bool(
146
+ (row.doc.get("x-proposal") or {}).get("covers_no_behaviour", False)
147
+ ),
148
+ )
149
+
150
+
151
+ @router.post("/{agent_id}/proposed-manifest/ratify", status_code=status.HTTP_201_CREATED)
152
+ async def ratify_proposal(
153
+ agent_id: uuid.UUID,
154
+ body: RatifyRequest,
155
+ db: SessionDep,
156
+ sandbox: SandboxServiceDep,
157
+ ) -> dict:
158
+ """The human act that makes a proposal real (FR-037).
159
+
160
+ For an agent with no prior manifest this pins version 1, immutable from here
161
+ (FR-038). Reconciliation then runs against it exactly as it would for a hand-written
162
+ manifest, so a ratified manifest that fails reconciliation does not enrol the agent
163
+ (FR-042).
164
+ """
165
+ _require_enabled()
166
+ await _agent(db, agent_id)
167
+ row = await sandbox.ratify(
168
+ db,
169
+ run_id=body.run_id,
170
+ agent_id=agent_id,
171
+ approved_by="admin",
172
+ document=body.doc,
173
+ )
174
+ return {
175
+ "manifest_id": str(row.id),
176
+ "agent_id": str(agent_id),
177
+ "version": row.version,
178
+ "status": row.status,
179
+ "ratified_by": row.ratified_by,
180
+ "ratified_at": row.ratified_at.isoformat() if row.ratified_at else None,
181
+ }
@@ -0,0 +1,86 @@
1
+ """``/v1/consent/step-up`` — a recoverable refusal becomes a question (FR-022..FR-031).
2
+
3
+ Two routes, with deliberately different authentication:
4
+
5
+ - **Raising** a challenge takes the session's own grant or an admin bearer. Asking is
6
+ harmless; it grants nothing.
7
+ - **Answering** one takes the consenting human's credential. An agent that could approve
8
+ its own widening would turn ``SCOPE_NOT_CONSENTED`` into a formality, and the whole
9
+ threat model assumes the agent may be under an attacker's influence (research.md R6).
10
+
11
+ Both answer 404 unless ``step_up_enabled``, so a deployment that has not adopted step-up
12
+ does not advertise an endpoint it will refuse everything from.
13
+ """
14
+
15
+ from __future__ import annotations
16
+
17
+ from fastapi import APIRouter, status
18
+
19
+ from agentic_auth.api.deps import AdminDep, ConsentingHumanDep, SessionDep
20
+ from agentic_auth.api.service_deps import RedisDep, SessionServiceDep, StepUpServiceDep
21
+ from agentic_auth.config import get_settings
22
+ from agentic_auth.errors import NotFoundError
23
+ from agentic_auth.schemas.authorize import StepUpChallenge
24
+ from agentic_auth.schemas.stepup import StepUpComplete, StepUpGrantRead, StepUpRequest
25
+ from agentic_auth.services import policy_loader
26
+
27
+ router = APIRouter(prefix="/v1/consent", tags=["step-up"])
28
+
29
+
30
+ def _require_enabled() -> None:
31
+ if not get_settings().step_up_enabled:
32
+ raise NotFoundError("step-up consent is not enabled on this deployment")
33
+
34
+
35
+ @router.post(
36
+ "/step-up",
37
+ response_model=StepUpChallenge,
38
+ status_code=status.HTTP_201_CREATED,
39
+ dependencies=[AdminDep],
40
+ )
41
+ async def raise_challenge(
42
+ body: StepUpRequest,
43
+ db: SessionDep,
44
+ redis: RedisDep,
45
+ sessions: SessionServiceDep,
46
+ stepup: StepUpServiceDep,
47
+ ) -> StepUpChallenge:
48
+ """Ask the human whether to widen this session by the data class that was refused.
49
+
50
+ The session's pinned policy is loaded here so the ceiling can be checked before a
51
+ human is ever asked: a widening that could not be granted should fail now, not after
52
+ someone approves it.
53
+ """
54
+ _require_enabled()
55
+ session = await sessions.get(db, redis, str(body.session_id))
56
+ policy = await policy_loader.load(db, redis, session.scope, session.policy_version)
57
+ return await stepup.challenge(
58
+ db,
59
+ redis,
60
+ session_id=body.session_id,
61
+ blocked_action_id=body.blocked_action_id,
62
+ policy=policy,
63
+ )
64
+
65
+
66
+ @router.post("/step-up/complete", response_model=StepUpGrantRead)
67
+ async def complete_challenge(
68
+ body: StepUpComplete,
69
+ approver: ConsentingHumanDep,
70
+ db: SessionDep,
71
+ redis: RedisDep,
72
+ sessions: SessionServiceDep,
73
+ stepup: StepUpServiceDep,
74
+ ) -> StepUpGrantRead:
75
+ """Record the human's answer. On an approval the chain may resume from the blocked
76
+ hop; on a decline the original refusal stands."""
77
+ _require_enabled()
78
+ settings = get_settings()
79
+ return await stepup.complete(
80
+ db,
81
+ redis,
82
+ challenge_id=body.challenge_id,
83
+ approved=body.approved,
84
+ approved_by=approver,
85
+ session_ttl_seconds=settings.session_ttl_seconds,
86
+ )
@@ -0,0 +1,92 @@
1
+ """``agentic-auth-boundary`` — run a boundary adapter, or emit the egress CA.
2
+
3
+ Three subcommands, one per FR-14 rung that needs a process:
4
+
5
+ agentic-auth-boundary mcp-proxy [config.yaml] # connector mode
6
+ agentic-auth-boundary egress-proxy [config.yaml] # network mode (not available yet)
7
+ agentic-auth-boundary egress-ca [--out DIR] # the operator's trust material
8
+
9
+ The resource-side guard has no subcommand: it is middleware the integrator adds to their
10
+ own app, not a process we run.
11
+ """
12
+
13
+ from __future__ import annotations
14
+
15
+ import logging
16
+ import sys
17
+ from pathlib import Path
18
+
19
+
20
+ def _usage() -> int:
21
+ print(__doc__, file=sys.stderr)
22
+ return 2
23
+
24
+
25
+ def _egress_ca(args: list[str]) -> int:
26
+ from cryptography.hazmat.primitives import serialization
27
+
28
+ from agentic_auth.boundary.egress import CertificateAuthority, install_snippet
29
+
30
+ out = Path(args[1]) if len(args) > 1 else Path.cwd()
31
+ out.mkdir(parents=True, exist_ok=True)
32
+ ca = CertificateAuthority.generate()
33
+
34
+ cert_path = out / "egress-ca.pem"
35
+ key_path = out / "egress-ca-key.pem"
36
+ cert_path.write_bytes(ca.certificate_pem())
37
+ key_path.write_bytes(
38
+ ca.private_key.private_bytes(
39
+ encoding=serialization.Encoding.PEM,
40
+ format=serialization.PrivateFormat.PKCS8,
41
+ encryption_algorithm=serialization.NoEncryption(),
42
+ )
43
+ )
44
+ key_path.chmod(0o600)
45
+
46
+ print(f"wrote {cert_path}")
47
+ print(f"wrote {key_path} (keep this private)")
48
+ print()
49
+ print(install_snippet(ca))
50
+ return 0
51
+
52
+
53
+ def main(argv: list[str] | None = None) -> int:
54
+ logging.basicConfig(level=logging.INFO)
55
+ args = sys.argv[1:] if argv is None else argv
56
+ if not args:
57
+ return _usage()
58
+
59
+ command, *rest = args
60
+ if command == "egress-ca":
61
+ return _egress_ca(args)
62
+
63
+ if command in {"mcp-proxy", "egress-proxy"}:
64
+ from agentic_auth.gateway.config import GatewayConfigError, load
65
+
66
+ try:
67
+ config = load(rest[0] if rest else None)
68
+ except GatewayConfigError as exc:
69
+ print(f"agentic-auth-boundary {command}: {exc}", file=sys.stderr)
70
+ return 2
71
+
72
+ if command == "mcp-proxy":
73
+ from agentic_auth.boundary.mcp import build_app
74
+ else: # pragma: no cover - the transport needs a real socket
75
+ print(
76
+ "egress-proxy is not available yet: it needs a CONNECT-capable listener. "
77
+ "`egress-ca` generates the CA it will use. Until then, use mcp-proxy, or "
78
+ "the resource-side guard where you own the tool.",
79
+ file=sys.stderr,
80
+ )
81
+ return 2
82
+
83
+ import uvicorn
84
+
85
+ uvicorn.run(build_app(config), host=config.host, port=config.port, log_level="info")
86
+ return 0
87
+
88
+ return _usage()
89
+
90
+
91
+ if __name__ == "__main__": # pragma: no cover
92
+ raise SystemExit(main())