authzai 0.2.0__tar.gz → 0.2.1__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 (156) hide show
  1. {authzai-0.2.0/authzai.egg-info → authzai-0.2.1}/PKG-INFO +3 -1
  2. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/__init__.py +1 -1
  3. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/cli/audit.py +45 -0
  4. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/cli/manifest.py +85 -0
  5. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/embedded/__init__.py +34 -0
  6. authzai-0.2.1/agentic_auth/embedded/_schema.py +19 -0
  7. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/embedded/_transport.py +4 -3
  8. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/embedded/store.py +10 -3
  9. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/models/__init__.py +1 -0
  10. authzai-0.2.1/agentic_auth/models/imported_audit.py +57 -0
  11. authzai-0.2.1/agentic_auth/services/bundle_import.py +174 -0
  12. {authzai-0.2.0 → authzai-0.2.1/authzai.egg-info}/PKG-INFO +3 -1
  13. {authzai-0.2.0 → authzai-0.2.1}/authzai.egg-info/SOURCES.txt +2 -0
  14. {authzai-0.2.0 → authzai-0.2.1}/authzai.egg-info/requires.txt +2 -0
  15. {authzai-0.2.0 → authzai-0.2.1}/pyproject.toml +3 -0
  16. authzai-0.2.0/agentic_auth/embedded/_schema.py +0 -8
  17. {authzai-0.2.0 → authzai-0.2.1}/LICENSE +0 -0
  18. {authzai-0.2.0 → authzai-0.2.1}/NOTICE +0 -0
  19. {authzai-0.2.0 → authzai-0.2.1}/README.md +0 -0
  20. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/_extras.py +0 -0
  21. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/api/__init__.py +0 -0
  22. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/api/deps.py +0 -0
  23. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/api/errors.py +0 -0
  24. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/api/responses.py +0 -0
  25. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/api/service_deps.py +0 -0
  26. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/api/v1/__init__.py +0 -0
  27. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/api/v1/agents.py +0 -0
  28. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/api/v1/audit.py +0 -0
  29. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/api/v1/authorize.py +0 -0
  30. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/api/v1/consent.py +0 -0
  31. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/api/v1/decisions.py +0 -0
  32. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/api/v1/enrollment.py +0 -0
  33. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/api/v1/identity.py +0 -0
  34. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/api/v1/jwks.py +0 -0
  35. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/api/v1/manifests.py +0 -0
  36. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/api/v1/scopes.py +0 -0
  37. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/api/v1/token.py +0 -0
  38. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/api/v1/transaction.py +0 -0
  39. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/boundary/__init__.py +0 -0
  40. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/boundary/guarantee.py +0 -0
  41. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/cli/__init__.py +0 -0
  42. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/cli/drift.py +0 -0
  43. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/cli/drift_render.py +0 -0
  44. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/cli/identity.py +0 -0
  45. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/config.py +0 -0
  46. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/db.py +0 -0
  47. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/embedded/capabilities.py +0 -0
  48. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/embedded/export.py +0 -0
  49. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/embedded/idp.py +0 -0
  50. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/errors.py +0 -0
  51. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/main.py +0 -0
  52. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/models/agent.py +0 -0
  53. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/models/audit_decision.py +0 -0
  54. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/models/compiled_policy.py +0 -0
  55. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/models/manifest.py +0 -0
  56. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/models/reconciliation_report.py +0 -0
  57. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/models/sandbox_run.py +0 -0
  58. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/models/session.py +0 -0
  59. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/models/step_up_grant.py +0 -0
  60. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/models/transaction_token.py +0 -0
  61. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/models/trust_anchor.py +0 -0
  62. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/models/types.py +0 -0
  63. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/observability/__init__.py +0 -0
  64. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/observability/config.py +0 -0
  65. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/observability/context.py +0 -0
  66. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/observability/ids.py +0 -0
  67. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/observability/logs.py +0 -0
  68. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/observability/pep.py +0 -0
  69. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/observability/spans.py +0 -0
  70. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/observability/surface.py +0 -0
  71. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/observability/tracing.py +0 -0
  72. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/redis.py +0 -0
  73. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/repositories/__init__.py +0 -0
  74. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/repositories/agents.py +0 -0
  75. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/repositories/audit_decisions.py +0 -0
  76. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/repositories/compiled_policies.py +0 -0
  77. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/repositories/manifests.py +0 -0
  78. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/repositories/reconciliation_reports.py +0 -0
  79. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/repositories/sessions.py +0 -0
  80. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/repositories/transaction_tokens.py +0 -0
  81. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/repositories/trust_anchors.py +0 -0
  82. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/runtime.py +0 -0
  83. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/schemas/__init__.py +0 -0
  84. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/schemas/agent.py +0 -0
  85. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/schemas/audit.py +0 -0
  86. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/schemas/authorize.py +0 -0
  87. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/schemas/common.py +0 -0
  88. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/schemas/consent.py +0 -0
  89. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/schemas/dag.py +0 -0
  90. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/schemas/edge_trace.py +0 -0
  91. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/schemas/identity.py +0 -0
  92. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/schemas/manifest.py +0 -0
  93. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/schemas/manifest_api.py +0 -0
  94. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/schemas/reconciliation.py +0 -0
  95. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/schemas/token.py +0 -0
  96. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/schemas/transaction.py +0 -0
  97. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/sdk/__init__.py +0 -0
  98. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/sdk/client.py +0 -0
  99. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/sdk/context.py +0 -0
  100. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/sdk/drift.py +0 -0
  101. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/sdk/errors.py +0 -0
  102. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/sdk/identity.py +0 -0
  103. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/sdk/planes.py +0 -0
  104. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/sdk/provenance.py +0 -0
  105. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/services/__init__.py +0 -0
  106. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/services/anchors.py +0 -0
  107. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/services/audit.py +0 -0
  108. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/services/audit_chain.py +0 -0
  109. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/services/audit_cursor.py +0 -0
  110. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/services/catalog_service.py +0 -0
  111. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/services/chain_query.py +0 -0
  112. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/services/dag_compiler.py +0 -0
  113. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/services/decision_cache.py +0 -0
  114. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/services/decision_history.py +0 -0
  115. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/services/discovery.py +0 -0
  116. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/services/drift.py +0 -0
  117. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/services/edge_rules.py +0 -0
  118. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/services/edge_trace.py +0 -0
  119. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/services/enrollment.py +0 -0
  120. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/services/enrollment_rules.py +0 -0
  121. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/services/manifest_service.py +0 -0
  122. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/services/metrics.py +0 -0
  123. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/services/pdp.py +0 -0
  124. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/services/policy_loader.py +0 -0
  125. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/services/principal.py +0 -0
  126. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/services/reconciler.py +0 -0
  127. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/services/revocation.py +0 -0
  128. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/services/sessions.py +0 -0
  129. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/services/taint.py +0 -0
  130. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/services/tokens/__init__.py +0 -0
  131. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/services/tokens/act_chain.py +0 -0
  132. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/services/tokens/exchange.py +0 -0
  133. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/services/tokens/jwt_profile.py +0 -0
  134. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/services/tokens/keys.py +0 -0
  135. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/services/tokens/profile.py +0 -0
  136. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/services/tokens/replay.py +0 -0
  137. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/services/transactions.py +0 -0
  138. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/sidecar/__init__.py +0 -0
  139. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/sidecar/__main__.py +0 -0
  140. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/sidecar/app.py +0 -0
  141. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/sidecar/config.py +0 -0
  142. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/sidecar/deny.py +0 -0
  143. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/sidecar/enforce.py +0 -0
  144. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/sidecar/identity.py +0 -0
  145. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/verify/__init__.py +0 -0
  146. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/verify/admit.py +0 -0
  147. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/verify/anchors.py +0 -0
  148. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/verify/canonical.py +0 -0
  149. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/verify/grants.py +0 -0
  150. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/verify/identity.py +0 -0
  151. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/verify/replay.py +0 -0
  152. {authzai-0.2.0 → authzai-0.2.1}/agentic_auth/verify/transaction.py +0 -0
  153. {authzai-0.2.0 → authzai-0.2.1}/authzai.egg-info/dependency_links.txt +0 -0
  154. {authzai-0.2.0 → authzai-0.2.1}/authzai.egg-info/entry_points.txt +0 -0
  155. {authzai-0.2.0 → authzai-0.2.1}/authzai.egg-info/top_level.txt +0 -0
  156. {authzai-0.2.0 → authzai-0.2.1}/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.2.1
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.2.1"
@@ -128,3 +128,48 @@ def export(
128
128
  raise typer.Exit(EXIT_ERROR) from exc
129
129
 
130
130
  rprint(f"exported {count} audit rows older than {cutoff.isoformat()} to {out}")
131
+
132
+
133
+ @audit_app.command("import")
134
+ def import_(
135
+ bundle: Path = typer.Argument(..., help="Export bundle from EmbeddedControlPlane.export"),
136
+ database_url: str | None = typer.Option(
137
+ None, "--database-url", help="Defaults to AGENTIC_AUTH_DATABASE_URL"
138
+ ),
139
+ ) -> None:
140
+ """Append an embedded instance's decisions to imported_audit, apart from this
141
+ deployment's own log. Re-running the same import adds nothing."""
142
+ from agentic_auth.services.bundle_import import BundleError, read_bundle
143
+
144
+ try:
145
+ parsed = read_bundle(bundle)
146
+ except (OSError, BundleError) as exc:
147
+ rprint(f"[red]{exc}[/red]")
148
+ raise typer.Exit(EXIT_ERROR) from exc
149
+
150
+ require_extra("agentic-auth audit import", "server", "sqlalchemy", "asyncpg")
151
+ from agentic_auth.config import get_settings
152
+
153
+ try:
154
+ result = asyncio.run(import_bundle(database_url or get_settings().database_url, parsed))
155
+ except Exception as exc:
156
+ rprint(f"[red]import failed: {type(exc).__name__}[/red]")
157
+ raise typer.Exit(EXIT_ERROR) from exc
158
+ rprint(
159
+ f"imported {result.imported} decision(s) from a {parsed.header['source_deployment']} "
160
+ f"deployment; {result.already_present} already present"
161
+ )
162
+
163
+
164
+ async def import_bundle(database_url: str, bundle: Any) -> Any:
165
+ from sqlalchemy.ext.asyncio import async_sessionmaker, create_async_engine
166
+ from sqlalchemy.pool import NullPool
167
+
168
+ from agentic_auth.services.bundle_import import import_audit
169
+
170
+ engine = create_async_engine(database_url, poolclass=NullPool)
171
+ try:
172
+ async with async_sessionmaker(engine, expire_on_commit=False)() as db, db.begin():
173
+ return await import_audit(db, bundle)
174
+ finally:
175
+ await engine.dispose()
@@ -273,3 +273,88 @@ def diff(
273
273
  rprint(f" [red]{d['code']}[/red] {d['tool_ref']} — {d['remedy']}")
274
274
  if result["status"] != "reconciled":
275
275
  raise typer.Exit(EXIT_FINDINGS) from None
276
+
277
+
278
+ async def replay_bundle(
279
+ client: httpx.AsyncClient,
280
+ control_plane: str,
281
+ admin_token: str,
282
+ plan: list[tuple[str, list[dict[str, Any]]]],
283
+ override_reason: str,
284
+ ) -> list[tuple[str, int, int, dict[str, Any]]]:
285
+ """Register each agent's first manifest, then submit every later version in order.
286
+ Returns ``(agent, version_index, status, body)`` per request; stops an agent at its
287
+ first refusal, since a later version cannot be submitted for an agent that never
288
+ registered."""
289
+ base = control_plane.rstrip("/")
290
+ headers = {"Authorization": f"Bearer {admin_token}"}
291
+ override = {"reason": override_reason}
292
+ results: list[tuple[str, int, int, dict[str, Any]]] = []
293
+ for name, docs in plan:
294
+ for index, doc in enumerate(docs):
295
+ # The first version registers the agent; every later one is a new version of it.
296
+ if index == 0:
297
+ url, body = f"{base}/v1/agents", {"name": name, "manifest": doc}
298
+ else:
299
+ url, body = f"{base}/v1/manifests", {"agent": name, "manifest": doc}
300
+ response = await client.post(url, headers=headers, json={**body, "override": override})
301
+ try:
302
+ payload = response.json()
303
+ except ValueError:
304
+ payload = {}
305
+ results.append((name, index + 1, response.status_code, payload))
306
+ if response.status_code != 201:
307
+ break
308
+ return results
309
+
310
+
311
+ @manifest_app.command("register-bundle")
312
+ def register_bundle(
313
+ bundle: Path = typer.Argument(..., help="Export bundle from EmbeddedControlPlane.export"),
314
+ control_plane: str = typer.Option(..., "--control-plane", help="Control plane base URL"),
315
+ override_reason: str = typer.Option(
316
+ ..., "--override-reason", help="Recorded on every version that needs an override"
317
+ ),
318
+ timeout: float = typer.Option(10.0, "--timeout"),
319
+ ) -> None:
320
+ """Re-register an embedded instance's manifests, every version in order, downstream first.
321
+
322
+ Each version reconciles against this control plane's own capability discovery, exactly as
323
+ a fresh registration does. Enrollments are not carried over: an agent re-enrolls with its
324
+ own key. The admin token is read from AGENTIC_AUTH_ADMIN_TOKEN, never the command line.
325
+ """
326
+ from agentic_auth.services.bundle_import import BundleError, read_bundle, registration_plan
327
+
328
+ admin_token = os.environ.get("AGENTIC_AUTH_ADMIN_TOKEN", "")
329
+ if not admin_token:
330
+ rprint("[red]AGENTIC_AUTH_ADMIN_TOKEN is not set[/red]")
331
+ raise typer.Exit(EXIT_USAGE)
332
+ if not override_reason.strip():
333
+ rprint("[red]--override-reason must not be empty[/red]")
334
+ raise typer.Exit(EXIT_USAGE)
335
+ try:
336
+ plan = registration_plan(read_bundle(bundle))
337
+ except (OSError, BundleError) as exc:
338
+ rprint(f"[red]{exc}[/red]")
339
+ raise typer.Exit(EXIT_USAGE) from exc
340
+
341
+ async def run() -> list[tuple[str, int, int, dict[str, Any]]]:
342
+ client = _make_http_client(timeout)
343
+ try:
344
+ return await replay_bundle(client, control_plane, admin_token, plan, override_reason)
345
+ finally:
346
+ await client.aclose()
347
+
348
+ failed = False
349
+ for name, version, status, body in asyncio.run(run()):
350
+ if status == 201:
351
+ rprint(f"registered {name} v{version}: {body.get('status')}")
352
+ continue
353
+ failed = True
354
+ error = body.get("error", {}) if isinstance(body, dict) else {}
355
+ rprint(
356
+ f"[red]failed {name} v{version}: HTTP {status} {error.get('code', '')}[/red] "
357
+ f"{error.get('message', '')}"
358
+ )
359
+ if failed:
360
+ raise typer.Exit(EXIT_FINDINGS)
@@ -370,6 +370,39 @@ class EmbeddedControlPlane:
370
370
  enroll_token=self._runtime.settings.enroll_token,
371
371
  )
372
372
 
373
+ @property
374
+ def admin_token(self) -> str:
375
+ """This instance's admin bearer. In-process only; generated per instance."""
376
+ return self._runtime.settings.admin_token
377
+
378
+ @property
379
+ def audit_token(self) -> str:
380
+ """This instance's read-only audit and identity bearer."""
381
+ return self._runtime.settings.audit_read_token
382
+
383
+ @property
384
+ def enroll_token(self) -> str:
385
+ """This instance's enrollment bearer."""
386
+ return self._runtime.settings.enroll_token
387
+
388
+ @property
389
+ def idp(self) -> _idp.TestIdp:
390
+ """The built-in test identity provider: ``cp.idp.mint(agent=..., sub=...)``."""
391
+ return self._idp
392
+
393
+ def configure(self, **settings: Any) -> dict[str, Any]:
394
+ """Change control-plane settings for the rest of the run, as a redeploy would.
395
+ Returns what changed, ``{name: {"from": old, "to": new}}``."""
396
+ self._check_open()
397
+ current = self._runtime.settings
398
+ changed: dict[str, Any] = {}
399
+ for name, value in settings.items():
400
+ if name not in type(current).model_fields:
401
+ raise AttributeError(f"unknown setting {name!r}")
402
+ changed[name] = {"from": getattr(current, name), "to": value}
403
+ setattr(current, name, value)
404
+ return changed
405
+
373
406
  def mount(self, host: str, app: Any) -> None:
374
407
  """Serve an ASGI app (a tool server, say) at ``https://{host}`` on :attr:`http`."""
375
408
  self._check_open()
@@ -419,6 +452,7 @@ class _Opening:
419
452
 
420
453
  __all__ = [
421
454
  "BASE_URL",
455
+ "HOST",
422
456
  "EmbeddedControlPlane",
423
457
  "ManifestRejected",
424
458
  "PolicyDenied",
@@ -0,0 +1,19 @@
1
+ """The schema an embedded store is created with: the Alembic head this package was built at.
2
+
3
+ The migrations are not shipped in the wheel, so the revision is recorded here.
4
+ ``tests/unit/test_embedded_schema_revision.py`` fails when a new migration lands without this
5
+ moving with it. A store created at a different revision is refused rather than half-read.
6
+ """
7
+
8
+ SCHEMA_REVISION = "0007_imported_audit"
9
+
10
+ # Revisions an older store may be at that differ from SCHEMA_REVISION only by new tables, so
11
+ # opening one creates the missing tables and moves it forward. Anything not listed here is
12
+ # refused rather than guessed at. Add a revision only when the step after it is purely
13
+ # additive for the embedded store.
14
+ ADDITIVE_FROM = frozenset(
15
+ {
16
+ # 0007 adds imported_audit, which the embedded store never writes.
17
+ "0006_audit_deployment",
18
+ }
19
+ )
@@ -29,9 +29,10 @@ class HostRouter(httpx.AsyncBaseTransport):
29
29
  host = request.url.host
30
30
  if host in self.cut:
31
31
  raise httpx.ConnectError(f"{host} is unreachable", request=request)
32
- # A tool host's RFC 9728 document is served by the capability source, the way a real
33
- # MCP server answers on its own well-known path.
34
- if request.url.path == WELL_KNOWN and host not in self.routes:
32
+ # Every tool host's RFC 9728 document is served by the capability source — including
33
+ # a host with a tool server mounted, which answers only for its tools. That is what
34
+ # a real MCP server looks like from outside: one host, both paths.
35
+ if request.url.path == WELL_KNOWN:
35
36
  host = CAPABILITIES
36
37
  transport = self.routes.get(host)
37
38
  if transport is None:
@@ -35,7 +35,7 @@ from sqlalchemy.ext.asyncio import (
35
35
  )
36
36
 
37
37
  import agentic_auth
38
- from agentic_auth.embedded._schema import SCHEMA_REVISION
38
+ from agentic_auth.embedded._schema import ADDITIVE_FROM, SCHEMA_REVISION
39
39
  from agentic_auth.models import Base
40
40
 
41
41
  MEMORY = ":memory:"
@@ -161,10 +161,17 @@ async def open_store(target: str | os.PathLike[str] = MEMORY) -> StoreHandle:
161
161
  key = None
162
162
  else:
163
163
  row = (await conn.execute(select(embedded_meta))).one()
164
- if row.schema_revision != SCHEMA_REVISION:
164
+ if row.schema_revision in ADDITIVE_FROM:
165
+ # Only new tables since: create them, leave every existing row alone.
166
+ await conn.run_sync(Base.metadata.create_all)
167
+ elif row.schema_revision != SCHEMA_REVISION:
165
168
  raise StoreVersionMismatch(row.schema_revision, SCHEMA_REVISION)
166
169
  await conn.execute(
167
- embedded_meta.update().values(opened_at=now.replace(tzinfo=None))
170
+ embedded_meta.update().values(
171
+ opened_at=now.replace(tzinfo=None),
172
+ schema_revision=SCHEMA_REVISION,
173
+ package_version=agentic_auth.__version__,
174
+ )
168
175
  )
169
176
  key = row.issuer_private_key
170
177
  except BaseException:
@@ -45,6 +45,7 @@ def _sqlite_timestamps(_mapper: Any, connection: Any, target: Any) -> None:
45
45
  from agentic_auth.models.agent import Agent # noqa: E402,F401
46
46
  from agentic_auth.models.audit_decision import AuditDecision # noqa: E402,F401
47
47
  from agentic_auth.models.compiled_policy import CompiledPolicy # noqa: E402,F401
48
+ from agentic_auth.models.imported_audit import ImportedAudit # noqa: E402,F401
48
49
  from agentic_auth.models.manifest import Manifest # noqa: E402,F401
49
50
  from agentic_auth.models.reconciliation_report import ReconciliationReport # noqa: E402,F401
50
51
  from agentic_auth.models.sandbox_run import SandboxRun # noqa: E402,F401
@@ -0,0 +1,57 @@
1
+ """Audit history carried over from another deployment — kept apart from this one's own log.
2
+
3
+ An embedded control plane (``agentic_auth.embedded``) can export its decisions
4
+ (``EmbeddedControlPlane.export``). ``agentic-auth audit import`` lands them here, never in
5
+ ``audit_decisions``: those decisions were made by a different deployment, under a different
6
+ signing key, and a development-only one at that. Mixing them into this control plane's own log
7
+ would let a chain query here present someone else's record as this deployment's.
8
+
9
+ Each row is the exported decision verbatim (``row``), with where it came from. Append-only, the
10
+ same way the decision log is. The runtime role is granted nothing on it: imports are an
11
+ owner-run maintenance step, like ``agentic-auth audit export``.
12
+ """
13
+
14
+ from __future__ import annotations
15
+
16
+ import uuid
17
+ from datetime import datetime
18
+ from typing import Any
19
+
20
+ from sqlalchemy import String, func
21
+ from sqlalchemy.orm import Mapped, mapped_column
22
+ from sqlalchemy.types import Uuid
23
+
24
+ from agentic_auth.models import Base, UUIDPrimaryKey
25
+ from agentic_auth.models.types import PortableJSON, TZDateTime, install_append_only
26
+
27
+ # The SQL below is duplicated, frozen, in migrations/versions/0007_imported_audit.py.
28
+ # tests/unit/test_audit_ddl.py fails if the two drift apart.
29
+ IMPORTED_AUDIT_APPEND_ONLY_SQL = (
30
+ """CREATE OR REPLACE FUNCTION imported_audit_append_only() RETURNS trigger
31
+ LANGUAGE plpgsql AS $$
32
+ BEGIN
33
+ RAISE EXCEPTION 'imported_audit is append-only' USING ERRCODE = '55000';
34
+ END;
35
+ $$""",
36
+ """CREATE TRIGGER imported_audit_no_update_delete
37
+ BEFORE UPDATE OR DELETE ON imported_audit
38
+ FOR EACH ROW EXECUTE FUNCTION imported_audit_append_only()""",
39
+ )
40
+
41
+
42
+ class ImportedAudit(UUIDPrimaryKey, Base):
43
+ __tablename__ = "imported_audit"
44
+
45
+ # The decision's own action id in the deployment that made it. Unique, so importing the
46
+ # same bundle twice adds nothing the second time.
47
+ action_id: Mapped[uuid.UUID] = mapped_column(Uuid(as_uuid=True), nullable=False, unique=True)
48
+ source_deployment: Mapped[str] = mapped_column(String(16), nullable=False)
49
+ source_package_version: Mapped[str] = mapped_column(String(32), nullable=False)
50
+ exported_at: Mapped[datetime] = mapped_column(TZDateTime, nullable=False)
51
+ imported_at: Mapped[datetime] = mapped_column(
52
+ TZDateTime, server_default=func.now(), nullable=False
53
+ )
54
+ row: Mapped[dict[str, Any]] = mapped_column(PortableJSON, nullable=False)
55
+
56
+
57
+ install_append_only(ImportedAudit.__table__, IMPORTED_AUDIT_APPEND_ONLY_SQL)
@@ -0,0 +1,174 @@
1
+ """Read an embedded export bundle and carry it into a deployed control plane.
2
+
3
+ The bundle is ``EmbeddedControlPlane.export``'s NDJSON (agentic_auth/embedded/export.py). Two
4
+ things come across, each through the door that already exists for it:
5
+
6
+ - **Manifests** are re-registered through the admin API (``agentic-auth manifest
7
+ register-bundle``), so they reconcile against this deployment's real capability discovery
8
+ exactly as a fresh registration does. Every version is replayed in order.
9
+ - **Audit history** lands in ``imported_audit`` (``agentic-auth audit import``), apart from
10
+ this deployment's own log. See agentic_auth/models/imported_audit.py for why.
11
+
12
+ Two things deliberately do not: **trust anchors**, because enrollment is proof of possession
13
+ of a private key the bundle does not (and must not) contain — an agent re-enrolls with its own
14
+ key; and **sessions and keys**, which the export never writes.
15
+
16
+ The reader names the bundle line of every problem, so a hand-edited or truncated bundle points
17
+ at the exact record.
18
+ """
19
+
20
+ from __future__ import annotations
21
+
22
+ import json
23
+ import uuid
24
+ from collections.abc import Iterable, Mapping
25
+ from dataclasses import dataclass, field
26
+ from datetime import datetime
27
+ from pathlib import Path
28
+ from typing import TYPE_CHECKING, Any
29
+
30
+ if TYPE_CHECKING:
31
+ from sqlalchemy.ext.asyncio import AsyncSession
32
+
33
+ KINDS = ("agent", "manifest", "trust_anchor", "audit")
34
+
35
+
36
+ class BundleError(ValueError):
37
+ def __init__(self, line: int, message: str) -> None:
38
+ super().__init__(f"bundle line {line}: {message}")
39
+ self.line = line
40
+
41
+
42
+ @dataclass
43
+ class Bundle:
44
+ header: dict[str, Any]
45
+ agents: list[dict[str, Any]] = field(default_factory=list)
46
+ manifests: list[dict[str, Any]] = field(default_factory=list)
47
+ trust_anchors: list[dict[str, Any]] = field(default_factory=list)
48
+ audit: list[dict[str, Any]] = field(default_factory=list)
49
+
50
+ @property
51
+ def exported_at(self) -> datetime:
52
+ return datetime.fromisoformat(self.header["exported_at"])
53
+
54
+ def manifest_history(self) -> dict[str, list[dict[str, Any]]]:
55
+ """Agent name -> every manifest document it had, oldest version first."""
56
+ names = {agent["id"]: agent["name"] for agent in self.agents}
57
+ history: dict[str, list[tuple[int, dict[str, Any]]]] = {}
58
+ for manifest in self.manifests:
59
+ name = names.get(manifest["agent_id"])
60
+ if name is not None:
61
+ history.setdefault(name, []).append((manifest["version"], manifest["doc"]))
62
+ return {name: [doc for _, doc in sorted(rows)] for name, rows in history.items()}
63
+
64
+
65
+ def read_bundle(path: Path) -> Bundle:
66
+ bundle: Bundle | None = None
67
+ for number, raw in enumerate(path.read_text(encoding="utf-8").splitlines(), start=1):
68
+ if not raw.strip():
69
+ continue
70
+ try:
71
+ record = json.loads(raw)
72
+ except json.JSONDecodeError as exc:
73
+ raise BundleError(number, f"not JSON ({exc.msg})") from exc
74
+ if not isinstance(record, dict) or not isinstance(record.get("kind"), str):
75
+ raise BundleError(number, "a record must be an object with a `kind`")
76
+ kind = record.pop("kind")
77
+ if bundle is None:
78
+ if kind != "header":
79
+ raise BundleError(number, "the first record must be the header")
80
+ for key in ("source_deployment", "package_version", "exported_at", "counts"):
81
+ if key not in record:
82
+ raise BundleError(number, f"header is missing `{key}`")
83
+ bundle = Bundle(header=record)
84
+ continue
85
+ if kind not in KINDS:
86
+ raise BundleError(number, f"unknown record kind {kind!r}")
87
+ required = {
88
+ "agent": ("id", "name"),
89
+ "manifest": ("agent_id", "version", "doc"),
90
+ "trust_anchor": ("agent_id",),
91
+ "audit": ("id",),
92
+ }[kind]
93
+ missing = [key for key in required if key not in record]
94
+ if missing:
95
+ raise BundleError(number, f"{kind} record is missing {', '.join(missing)}")
96
+ target = {
97
+ "agent": bundle.agents,
98
+ "manifest": bundle.manifests,
99
+ "trust_anchor": bundle.trust_anchors,
100
+ "audit": bundle.audit,
101
+ }[kind]
102
+ target.append(record)
103
+ if bundle is None:
104
+ raise BundleError(1, "empty bundle")
105
+ counts = bundle.header["counts"]
106
+ for kind, rows in (
107
+ ("agent", bundle.agents),
108
+ ("manifest", bundle.manifests),
109
+ ("trust_anchor", bundle.trust_anchors),
110
+ ("audit", bundle.audit),
111
+ ):
112
+ if counts.get(kind) != len(rows):
113
+ raise BundleError(
114
+ 1, f"header counts {counts.get(kind)} {kind} record(s), the bundle has {len(rows)}"
115
+ )
116
+ return bundle
117
+
118
+
119
+ @dataclass(frozen=True)
120
+ class AuditImport:
121
+ imported: int
122
+ already_present: int
123
+
124
+
125
+ async def import_audit(db: AsyncSession, bundle: Bundle) -> AuditImport:
126
+ """Append the bundle's decisions to ``imported_audit``. Idempotent: a decision whose
127
+ action id is already there is skipped, so re-running an import adds nothing."""
128
+ from sqlalchemy import select
129
+
130
+ from agentic_auth.models import ImportedAudit
131
+
132
+ ids = [uuid.UUID(row["id"]) for row in bundle.audit]
133
+ present = (
134
+ set(
135
+ (
136
+ await db.execute(
137
+ select(ImportedAudit.action_id).where(ImportedAudit.action_id.in_(ids))
138
+ )
139
+ )
140
+ .scalars()
141
+ .all()
142
+ )
143
+ if ids
144
+ else set()
145
+ )
146
+ new = [row for row in bundle.audit if uuid.UUID(row["id"]) not in present]
147
+ db.add_all(
148
+ ImportedAudit(
149
+ action_id=uuid.UUID(row["id"]),
150
+ source_deployment=str(bundle.header["source_deployment"]),
151
+ source_package_version=str(bundle.header["package_version"]),
152
+ exported_at=bundle.exported_at,
153
+ row=row,
154
+ )
155
+ for row in new
156
+ )
157
+ await db.flush()
158
+ return AuditImport(imported=len(new), already_present=len(present))
159
+
160
+
161
+ def registration_plan(bundle: Bundle) -> list[tuple[str, list[dict[str, Any]]]]:
162
+ """Agents in registration order (downstream first), each with its manifest history."""
163
+ from agentic_auth.schemas.manifest import AgentManifest
164
+ from agentic_auth.services.drift import registration_order
165
+
166
+ history = bundle.manifest_history()
167
+ latest: Mapping[str, AgentManifest] = {
168
+ name: AgentManifest.model_validate(docs[-1]) for name, docs in history.items()
169
+ }
170
+ return [(name, history[name]) for name in registration_order(latest)]
171
+
172
+
173
+ def summarize(names: Iterable[str]) -> str:
174
+ return ", ".join(sorted(names)) or "none"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: authzai
3
- Version: 0.2.0
3
+ Version: 0.2.1
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"
@@ -47,6 +47,7 @@ agentic_auth/models/__init__.py
47
47
  agentic_auth/models/agent.py
48
48
  agentic_auth/models/audit_decision.py
49
49
  agentic_auth/models/compiled_policy.py
50
+ agentic_auth/models/imported_audit.py
50
51
  agentic_auth/models/manifest.py
51
52
  agentic_auth/models/reconciliation_report.py
52
53
  agentic_auth/models/sandbox_run.py
@@ -100,6 +101,7 @@ agentic_auth/services/anchors.py
100
101
  agentic_auth/services/audit.py
101
102
  agentic_auth/services/audit_chain.py
102
103
  agentic_auth/services/audit_cursor.py
104
+ agentic_auth/services/bundle_import.py
103
105
  agentic_auth/services/catalog_service.py
104
106
  agentic_auth/services/chain_query.py
105
107
  agentic_auth/services/dag_compiler.py
@@ -20,6 +20,8 @@ locust
20
20
  jsonschema
21
21
  build
22
22
  twine
23
+ nbclient>=0.10
24
+ ipykernel>=6
23
25
 
24
26
  [drift]
25
27
  authzai[client]
@@ -103,6 +103,9 @@ dev = [
103
103
  "jsonschema",
104
104
  "build",
105
105
  "twine",
106
+ # tests/embedded/test_walkthrough_notebook.py executes the notebook headless.
107
+ "nbclient>=0.10",
108
+ "ipykernel>=6",
106
109
  ]
107
110
 
108
111
  # Traces and logs. Deliberately NOT a base dependency:
@@ -1,8 +0,0 @@
1
- """The schema an embedded store is created with: the Alembic head this package was built at.
2
-
3
- The migrations are not shipped in the wheel, so the revision is recorded here.
4
- ``tests/unit/test_embedded_schema_revision.py`` fails when a new migration lands without this
5
- moving with it. A store created at a different revision is refused rather than half-read.
6
- """
7
-
8
- SCHEMA_REVISION = "0006_audit_deployment"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes