authzai 0.3.0__tar.gz → 0.4.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.
- {authzai-0.3.0/authzai.egg-info → authzai-0.4.0}/PKG-INFO +1 -1
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/__init__.py +1 -1
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/api/deps.py +20 -0
- authzai-0.4.0/agentic_auth/api/v1/agent_clients.py +65 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/api/v1/authorize.py +7 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/api/v1/consent.py +4 -2
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/api/v1/token.py +2 -0
- authzai-0.4.0/agentic_auth/api/v1/well_known.py +33 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/boundary/__main__.py +9 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/boundary/mcp.py +133 -22
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/config.py +69 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/embedded/__init__.py +18 -14
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/embedded/_schema.py +6 -7
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/embedded/idp.py +58 -1
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/errors.py +42 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/gateway/__main__.py +9 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/gateway/app.py +75 -9
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/gateway/config.py +117 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/main.py +4 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/models/__init__.py +1 -0
- authzai-0.4.0/agentic_auth/models/agent_client.py +58 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/models/audit_decision.py +5 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/models/session.py +14 -0
- authzai-0.4.0/agentic_auth/oauth/__init__.py +6 -0
- authzai-0.4.0/agentic_auth/oauth/metadata.py +124 -0
- authzai-0.4.0/agentic_auth/oauth/resource.py +466 -0
- authzai-0.4.0/agentic_auth/oauth/validate.py +334 -0
- authzai-0.4.0/agentic_auth/repositories/agent_clients.py +93 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/repositories/audit_decisions.py +4 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/repositories/compiled_policies.py +16 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/repositories/sessions.py +6 -0
- authzai-0.4.0/agentic_auth/schemas/agent_client.py +33 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/schemas/audit.py +5 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/schemas/common.py +14 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/schemas/consent.py +39 -5
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/schemas/reconciliation.py +11 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/sdk/client.py +12 -1
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/services/audit.py +6 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/services/catalog_service.py +16 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/services/chain_query.py +4 -0
- authzai-0.4.0/agentic_auth/services/client_mapping.py +92 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/services/discovery.py +50 -1
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/services/metrics.py +11 -0
- authzai-0.4.0/agentic_auth/services/principal.py +133 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/services/reconciler.py +72 -1
- authzai-0.4.0/agentic_auth/services/sessions.py +447 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/services/stepup.py +2 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/services/tokens/exchange.py +5 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/sidecar/config.py +18 -1
- {authzai-0.3.0 → authzai-0.4.0/authzai.egg-info}/PKG-INFO +1 -1
- {authzai-0.3.0 → authzai-0.4.0}/authzai.egg-info/SOURCES.txt +10 -0
- {authzai-0.3.0 → authzai-0.4.0}/pyproject.toml +4 -0
- authzai-0.3.0/agentic_auth/services/principal.py +0 -181
- authzai-0.3.0/agentic_auth/services/sessions.py +0 -231
- {authzai-0.3.0 → authzai-0.4.0}/LICENSE +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/NOTICE +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/README.md +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/_extras.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/api/__init__.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/api/errors.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/api/responses.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/api/service_deps.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/api/v1/__init__.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/api/v1/agents.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/api/v1/audit.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/api/v1/decisions.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/api/v1/enrollment.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/api/v1/identity.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/api/v1/jwks.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/api/v1/manifests.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/api/v1/sandbox.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/api/v1/scopes.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/api/v1/stepup.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/api/v1/transaction.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/boundary/__init__.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/boundary/egress.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/boundary/guarantee.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/boundary/resource.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/cli/__init__.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/cli/audit.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/cli/drift.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/cli/drift_render.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/cli/identity.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/cli/manifest.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/cli/sandbox.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/coldstart/__init__.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/coldstart/propose.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/db.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/embedded/_transport.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/embedded/capabilities.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/embedded/export.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/embedded/store.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/gateway/__init__.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/gateway/metrics.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/gateway/resolve.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/models/agent.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/models/compiled_policy.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/models/imported_audit.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/models/manifest.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/models/reconciliation_report.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/models/sandbox_run.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/models/step_up_grant.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/models/transaction_token.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/models/trust_anchor.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/models/types.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/observability/__init__.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/observability/config.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/observability/context.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/observability/ids.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/observability/logs.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/observability/pep.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/observability/spans.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/observability/surface.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/observability/tracing.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/redis.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/repositories/__init__.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/repositories/agents.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/repositories/manifests.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/repositories/reconciliation_reports.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/repositories/sandbox_runs.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/repositories/step_up_grants.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/repositories/transaction_tokens.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/repositories/trust_anchors.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/runtime.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/schemas/__init__.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/schemas/agent.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/schemas/authorize.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/schemas/dag.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/schemas/edge_trace.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/schemas/identity.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/schemas/manifest.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/schemas/manifest_api.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/schemas/sandbox.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/schemas/stepup.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/schemas/token.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/schemas/transaction.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/sdk/__init__.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/sdk/context.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/sdk/drift.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/sdk/errors.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/sdk/identity.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/sdk/planes.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/sdk/provenance.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/services/__init__.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/services/anchors.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/services/audit_chain.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/services/audit_cursor.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/services/bundle_import.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/services/dag_compiler.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/services/decision_cache.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/services/decision_history.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/services/drift.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/services/edge_rules.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/services/edge_trace.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/services/enrollment.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/services/enrollment_rules.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/services/guarantee.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/services/manifest_service.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/services/pdp.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/services/policy_loader.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/services/revocation.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/services/sandbox.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/services/stepup_rules.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/services/taint.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/services/tokens/__init__.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/services/tokens/act_chain.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/services/tokens/jwt_profile.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/services/tokens/keys.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/services/tokens/profile.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/services/tokens/replay.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/services/transactions.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/sidecar/__init__.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/sidecar/__main__.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/sidecar/app.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/sidecar/deny.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/sidecar/enforce.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/sidecar/identity.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/verify/__init__.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/verify/admit.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/verify/anchors.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/verify/canonical.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/verify/grants.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/verify/identity.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/verify/replay.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/agentic_auth/verify/transaction.py +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/authzai.egg-info/dependency_links.txt +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/authzai.egg-info/entry_points.txt +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/authzai.egg-info/requires.txt +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/authzai.egg-info/top_level.txt +0 -0
- {authzai-0.3.0 → authzai-0.4.0}/setup.cfg +0 -0
|
@@ -60,6 +60,25 @@ async def require_enroller(authorization: Annotated[str | None, Header()] = None
|
|
|
60
60
|
raise UnauthorizedError("invalid enroller bearer token")
|
|
61
61
|
|
|
62
62
|
|
|
63
|
+
async def require_consenter(authorization: Annotated[str | None, Header()] = None) -> None:
|
|
64
|
+
"""Consent is called with the dedicated consent token or the admin token (feature 011).
|
|
65
|
+
|
|
66
|
+
A connector proxy or gateway starts sessions for the users it validates, so it needs to
|
|
67
|
+
call consent; it must not hold the admin token, which could register manifests (research
|
|
68
|
+
F2). An empty setting disables the consent token, never accepts an empty bearer.
|
|
69
|
+
"""
|
|
70
|
+
if not authorization or not authorization.startswith("Bearer "):
|
|
71
|
+
raise UnauthorizedError("missing or malformed consenter bearer token")
|
|
72
|
+
presented = authorization.removeprefix("Bearer ").strip().encode()
|
|
73
|
+
settings = get_settings()
|
|
74
|
+
accepted = [t.encode() for t in (settings.consent_token, settings.admin_token) if t]
|
|
75
|
+
# Compare against every accepted token, not just until the first match, so timing does
|
|
76
|
+
# not reveal which one was presented.
|
|
77
|
+
matches = [hmac.compare_digest(presented, token) for token in accepted]
|
|
78
|
+
if not presented or not any(matches):
|
|
79
|
+
raise UnauthorizedError("invalid consenter bearer token")
|
|
80
|
+
|
|
81
|
+
|
|
63
82
|
async def require_identity_reader(authorization: Annotated[str | None, Header()] = None) -> None:
|
|
64
83
|
"""Identity material and the revocation list are readable by verifiers and operators:
|
|
65
84
|
the audit reader token or the admin token."""
|
|
@@ -149,6 +168,7 @@ async def require_consenting_human(
|
|
|
149
168
|
AdminDep = Depends(require_admin)
|
|
150
169
|
AuditReaderDep = Depends(require_audit_reader)
|
|
151
170
|
EnrollerDep = Depends(require_enroller)
|
|
171
|
+
ConsenterDep = Depends(require_consenter)
|
|
152
172
|
IdentityReaderDep = Depends(require_identity_reader)
|
|
153
173
|
ConsentingHumanDep = Annotated[str, Depends(require_consenting_human)]
|
|
154
174
|
PaginationDep = Annotated[PaginationParams, Depends(pagination_params)]
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"""``/v1/agents/{agent_id}/clients`` — which IdP clients act as this agent (feature 011, M4).
|
|
2
|
+
|
|
3
|
+
Admin-only, and 404 unless ``client_mapping_enabled``: a deployment that has not opted in
|
|
4
|
+
should not discover the endpoints.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import uuid
|
|
10
|
+
from typing import Annotated
|
|
11
|
+
|
|
12
|
+
from fastapi import APIRouter, Query, Response, status
|
|
13
|
+
|
|
14
|
+
from agentic_auth.api.deps import AdminDep, PaginationDep, SessionDep
|
|
15
|
+
from agentic_auth.config import get_settings
|
|
16
|
+
from agentic_auth.errors import NotFoundError
|
|
17
|
+
from agentic_auth.schemas.agent_client import AgentClientCreate, AgentClientRead
|
|
18
|
+
from agentic_auth.schemas.common import Page, PageInfo
|
|
19
|
+
from agentic_auth.services.client_mapping import ClientMappingService
|
|
20
|
+
|
|
21
|
+
router = APIRouter(prefix="/v1/agents", tags=["client-mapping"], dependencies=[AdminDep])
|
|
22
|
+
|
|
23
|
+
ADMIN_IDENTITY = "admin"
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _require_enabled() -> None:
|
|
27
|
+
if not get_settings().client_mapping_enabled:
|
|
28
|
+
raise NotFoundError("client mapping is not enabled on this deployment")
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@router.post(
|
|
32
|
+
"/{agent_id}/clients", response_model=AgentClientRead, status_code=status.HTTP_201_CREATED
|
|
33
|
+
)
|
|
34
|
+
async def map_client(
|
|
35
|
+
agent_id: uuid.UUID, body: AgentClientCreate, db: SessionDep
|
|
36
|
+
) -> AgentClientRead:
|
|
37
|
+
_require_enabled()
|
|
38
|
+
row = await ClientMappingService().create(
|
|
39
|
+
db, agent_id, body.client_id, created_by=ADMIN_IDENTITY
|
|
40
|
+
)
|
|
41
|
+
return AgentClientRead.model_validate(row)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@router.get("/{agent_id}/clients", response_model=Page[AgentClientRead])
|
|
45
|
+
async def list_clients(
|
|
46
|
+
agent_id: uuid.UUID,
|
|
47
|
+
db: SessionDep,
|
|
48
|
+
pagination: PaginationDep,
|
|
49
|
+
include_removed: Annotated[bool, Query()] = False,
|
|
50
|
+
) -> Page[AgentClientRead]:
|
|
51
|
+
_require_enabled()
|
|
52
|
+
rows, next_cursor = await ClientMappingService().list(
|
|
53
|
+
db, agent_id, pagination.limit, pagination.cursor, include_removed=include_removed
|
|
54
|
+
)
|
|
55
|
+
return Page(
|
|
56
|
+
data=[AgentClientRead.model_validate(r) for r in rows],
|
|
57
|
+
page=PageInfo(next_cursor=next_cursor, limit=pagination.limit),
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
@router.delete("/{agent_id}/clients/{client_id}", status_code=status.HTTP_204_NO_CONTENT)
|
|
62
|
+
async def unmap_client(agent_id: uuid.UUID, client_id: str, db: SessionDep) -> Response:
|
|
63
|
+
_require_enabled()
|
|
64
|
+
await ClientMappingService().remove(db, agent_id, client_id, removed_by=ADMIN_IDENTITY)
|
|
65
|
+
return Response(status_code=status.HTTP_204_NO_CONTENT)
|
|
@@ -37,6 +37,7 @@ from agentic_auth.services.audit import AuditService, RecordResult
|
|
|
37
37
|
from agentic_auth.services.guarantee import note_level
|
|
38
38
|
from agentic_auth.services.metrics import get_metrics
|
|
39
39
|
from agentic_auth.services.pdp import Decision, decide
|
|
40
|
+
from agentic_auth.services.sessions import PinnedSession
|
|
40
41
|
from agentic_auth.services.stepup import StepUpService, granted_classes
|
|
41
42
|
from agentic_auth.services.taint import (
|
|
42
43
|
Marked,
|
|
@@ -140,6 +141,7 @@ async def authorize(
|
|
|
140
141
|
message="taint state could not be read for a protected target",
|
|
141
142
|
),
|
|
142
143
|
policy_version=session.policy_version,
|
|
144
|
+
session=session,
|
|
143
145
|
token=token,
|
|
144
146
|
headers=request.headers,
|
|
145
147
|
)
|
|
@@ -215,6 +217,7 @@ async def authorize(
|
|
|
215
217
|
body,
|
|
216
218
|
decision,
|
|
217
219
|
policy_version=session.policy_version,
|
|
220
|
+
session=session,
|
|
218
221
|
token=token,
|
|
219
222
|
taint_source=taint_source,
|
|
220
223
|
headers=request.headers,
|
|
@@ -379,6 +382,7 @@ async def _record(
|
|
|
379
382
|
taint_source: str | None = None,
|
|
380
383
|
step_up_ref: uuid.UUID | None = None,
|
|
381
384
|
headers: Mapping[str, str] | None = None,
|
|
385
|
+
session: PinnedSession | None = None,
|
|
382
386
|
) -> tuple[AuthorizeDecision, RecordResult]:
|
|
383
387
|
"""Record, commit, then render from the result. Every decision is recorded — including
|
|
384
388
|
the ones caused by an unreachable dependency, which are the ones an operator most needs
|
|
@@ -408,6 +412,9 @@ async def _record(
|
|
|
408
412
|
# Phase 5. What the enforcement point said it is; recorded on every row.
|
|
409
413
|
guarantee_level=body.guarantee.value,
|
|
410
414
|
step_up_ref=step_up_ref,
|
|
415
|
+
# 0.4.0. None only when the session itself could not be read.
|
|
416
|
+
principal_source=session.principal_source if session is not None else None,
|
|
417
|
+
client_id=session.client_id if session is not None else None,
|
|
411
418
|
)
|
|
412
419
|
|
|
413
420
|
# A call leaves the host on an allow, and on an unenforced (observe-mode) deny. Either
|
|
@@ -4,11 +4,13 @@ from __future__ import annotations
|
|
|
4
4
|
|
|
5
5
|
from fastapi import APIRouter, status
|
|
6
6
|
|
|
7
|
-
from agentic_auth.api.deps import
|
|
7
|
+
from agentic_auth.api.deps import ConsenterDep, SessionDep
|
|
8
8
|
from agentic_auth.api.service_deps import RedisDep, SessionServiceDep
|
|
9
9
|
from agentic_auth.schemas.consent import ConsentCreate, ConsentRead
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
# The consent token or admin (feature 011): what a connector proxy holds is enough to start a
|
|
12
|
+
# session for a user it validated, and nothing else.
|
|
13
|
+
router = APIRouter(prefix="/v1", tags=["consent"], dependencies=[ConsenterDep])
|
|
12
14
|
|
|
13
15
|
|
|
14
16
|
@router.post("/consent", response_model=ConsentRead, status_code=status.HTTP_201_CREATED)
|
|
@@ -131,6 +131,8 @@ async def exchange_token(
|
|
|
131
131
|
privileged=denied.decision.privileged,
|
|
132
132
|
policy_version=denied.policy_version,
|
|
133
133
|
token=denied.token,
|
|
134
|
+
principal_source=denied.principal_source,
|
|
135
|
+
client_id=denied.client_id,
|
|
134
136
|
)
|
|
135
137
|
if denied.decision.reason is not None:
|
|
136
138
|
get_metrics().denials.labels(reason=denied.decision.reason.value).inc()
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"""``/.well-known/oauth-authorization-server`` — the control plane's RFC 8414 metadata
|
|
2
|
+
(feature 011, M3).
|
|
3
|
+
|
|
4
|
+
Unauthenticated and cacheable, like the JWKS. 404 unless ``as_metadata_enabled``.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from typing import Any
|
|
10
|
+
|
|
11
|
+
from fastapi import APIRouter
|
|
12
|
+
from fastapi.responses import JSONResponse
|
|
13
|
+
|
|
14
|
+
from agentic_auth.api.deps import SessionDep
|
|
15
|
+
from agentic_auth.config import get_settings
|
|
16
|
+
from agentic_auth.errors import NotFoundError
|
|
17
|
+
from agentic_auth.oauth.metadata import authorization_server_metadata
|
|
18
|
+
from agentic_auth.services.catalog_service import pinned_data_classes
|
|
19
|
+
|
|
20
|
+
router = APIRouter(tags=["ops"])
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@router.get("/.well-known/oauth-authorization-server")
|
|
24
|
+
async def get_authorization_server_metadata(db: SessionDep) -> Any:
|
|
25
|
+
settings = get_settings()
|
|
26
|
+
if not settings.as_metadata_enabled:
|
|
27
|
+
raise NotFoundError("authorization server metadata is not enabled on this deployment")
|
|
28
|
+
document = authorization_server_metadata(
|
|
29
|
+
settings.issuer,
|
|
30
|
+
scopes=await pinned_data_classes(db),
|
|
31
|
+
transaction_tokens=settings.transaction_tokens_enabled,
|
|
32
|
+
)
|
|
33
|
+
return JSONResponse(document, headers={"cache-control": "public, max-age=300"})
|
|
@@ -80,6 +80,15 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
80
80
|
)
|
|
81
81
|
return 2
|
|
82
82
|
|
|
83
|
+
import asyncio
|
|
84
|
+
|
|
85
|
+
from agentic_auth.oauth.resource import startup_check
|
|
86
|
+
|
|
87
|
+
problem = asyncio.run(startup_check(config))
|
|
88
|
+
if problem is not None:
|
|
89
|
+
print(f"agentic-auth-boundary {command}: {problem}", file=sys.stderr)
|
|
90
|
+
return 2
|
|
91
|
+
|
|
83
92
|
import uvicorn
|
|
84
93
|
|
|
85
94
|
uvicorn.run(build_app(config), host=config.host, port=config.port, log_level="info")
|
|
@@ -7,10 +7,11 @@ never knows.
|
|
|
7
7
|
|
|
8
8
|
Two deliberate limits on how much protocol this module implements (research.md R8):
|
|
9
9
|
|
|
10
|
-
- **The
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
- **The client's credentials are never relayed** (feature 011, research R4). Relayed
|
|
11
|
+
methods lose ``authorization``, ``cookie`` and ``proxy-authorization``; an upstream that
|
|
12
|
+
wants a credential on them gets the route's operator-owned ``relay_authorization``.
|
|
13
|
+
Everything else in the upstream's own protocol passes through: we add a policy layer,
|
|
14
|
+
we are not an MCP implementation.
|
|
14
15
|
- **No MCP SDK dependency.** The envelope this needs to understand is a handful of JSON
|
|
15
16
|
fields, and a dependency whose release cadence tracks a moving spec is a liability on
|
|
16
17
|
a fail-closed path.
|
|
@@ -26,6 +27,13 @@ everything else Relayed unchanged.
|
|
|
26
27
|
|
|
27
28
|
Refusals come back as JSON-RPC errors, carrying the same ``reason``/``recoverable`` pair
|
|
28
29
|
every other enforcement point returns, so an SDK-aware caller branches identically.
|
|
30
|
+
|
|
31
|
+
**As an OAuth 2.1 protected resource** (feature 011, M1, ``oauth_resource_enabled``): every
|
|
32
|
+
method needs a bearer token from the customer's IdP. The proxy publishes Protected Resource
|
|
33
|
+
Metadata, answers a missing or bad token with an HTTP ``401`` and a ``WWW-Authenticate``
|
|
34
|
+
challenge (MCP clients discover authorization from HTTP, not JSON-RPC), validates the token
|
|
35
|
+
itself, and starts a session with it through consent. ``enforce()`` then runs unchanged with
|
|
36
|
+
that session's root grant. The client's token never goes upstream.
|
|
29
37
|
"""
|
|
30
38
|
|
|
31
39
|
from __future__ import annotations
|
|
@@ -46,9 +54,10 @@ from starlette.routing import Route
|
|
|
46
54
|
from agentic_auth.boundary.guarantee import Guarantee
|
|
47
55
|
from agentic_auth.gateway.config import GatewayConfig
|
|
48
56
|
from agentic_auth.gateway.resolve import agent_name, agent_of
|
|
57
|
+
from agentic_auth.oauth.resource import Admitted, Refused, ResourceGate, gate_for, metadata_paths
|
|
49
58
|
from agentic_auth.services.edge_trace import EdgeRecorder
|
|
50
59
|
from agentic_auth.sidecar.config import Upstream
|
|
51
|
-
from agentic_auth.sidecar.enforce import Allow, Blocked, Observed, enforce
|
|
60
|
+
from agentic_auth.sidecar.enforce import SESSION_HEADER, Allow, Blocked, Observed, enforce
|
|
52
61
|
|
|
53
62
|
logger = logging.getLogger(__name__)
|
|
54
63
|
|
|
@@ -67,6 +76,19 @@ INVALID_REQUEST = -32600
|
|
|
67
76
|
TOOLS_CALL = "tools/call"
|
|
68
77
|
TOOLS_LIST = "tools/list"
|
|
69
78
|
|
|
79
|
+
# Never relayed: they are the client's credentials, and the upstream is not who the client
|
|
80
|
+
# authenticated to (research F1). ``host`` and ``content-length`` are recomputed by httpx.
|
|
81
|
+
_NOT_RELAYED = frozenset(
|
|
82
|
+
{"host", "content-length", "authorization", "cookie", "proxy-authorization"}
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def _relay_headers(request: Request, upstream: Upstream) -> dict[str, str]:
|
|
87
|
+
headers = {k: v for k, v in request.headers.items() if k.lower() not in _NOT_RELAYED}
|
|
88
|
+
if upstream.relay_authorization is not None:
|
|
89
|
+
headers["authorization"] = upstream.relay_authorization
|
|
90
|
+
return headers
|
|
91
|
+
|
|
70
92
|
|
|
71
93
|
def _error(request_id: object, code: int, message: str, **data: object) -> JSONResponse:
|
|
72
94
|
return JSONResponse(
|
|
@@ -105,6 +127,11 @@ def build_app(
|
|
|
105
127
|
owned = client is None
|
|
106
128
|
http = client or httpx.AsyncClient()
|
|
107
129
|
recorder = EdgeRecorder(config.trace_path, "sidecar") if config.trace_path else None
|
|
130
|
+
gate = gate_for(config, http) if config.oauth_resource_enabled else None
|
|
131
|
+
|
|
132
|
+
async def metadata(_request: Request) -> JSONResponse:
|
|
133
|
+
assert gate is not None # routed only when M1 is on
|
|
134
|
+
return JSONResponse(gate.metadata(), headers={"cache-control": "public, max-age=300"})
|
|
108
135
|
|
|
109
136
|
async def rpc(request: Request) -> Response:
|
|
110
137
|
raw = await request.body()
|
|
@@ -119,8 +146,11 @@ def build_app(
|
|
|
119
146
|
|
|
120
147
|
request_id = envelope.get("id")
|
|
121
148
|
method = envelope.get("method")
|
|
122
|
-
|
|
123
|
-
|
|
149
|
+
headers: dict[str, str] = dict(request.headers.items())
|
|
150
|
+
token = headers.get("authorization", "").removeprefix("Bearer ").strip()
|
|
151
|
+
# Under M1 the inbound token is the IdP's: its claims say nothing about which agent
|
|
152
|
+
# route to take, so only the any-agent routes apply.
|
|
153
|
+
agent = agent_name(agent_of(token)) if token and gate is None else None
|
|
124
154
|
|
|
125
155
|
match = config.resolve(agent, request.url.path)
|
|
126
156
|
if match is None:
|
|
@@ -129,9 +159,40 @@ def build_app(
|
|
|
129
159
|
)
|
|
130
160
|
prefix, upstream = match
|
|
131
161
|
|
|
162
|
+
if gate is not None:
|
|
163
|
+
target = None
|
|
164
|
+
if method == TOOLS_CALL:
|
|
165
|
+
name = (envelope.get("params") or {}).get("name")
|
|
166
|
+
target = _tool_target(upstream, name) if isinstance(name, str) and name else None
|
|
167
|
+
admitted = await gate.admit(
|
|
168
|
+
headers,
|
|
169
|
+
request.query_params,
|
|
170
|
+
data_class=upstream.data_class if method == TOOLS_CALL else None,
|
|
171
|
+
)
|
|
172
|
+
if isinstance(admitted, Refused):
|
|
173
|
+
if recorder is not None:
|
|
174
|
+
recorder.record(
|
|
175
|
+
acting_agent=None,
|
|
176
|
+
target=target,
|
|
177
|
+
outcome="blocked_infra" if admitted.kind == "infra" else "blocked_local",
|
|
178
|
+
reason=admitted.reason,
|
|
179
|
+
)
|
|
180
|
+
return _gate_refusal(request_id, admitted, gate)
|
|
181
|
+
token = admitted.root_grant
|
|
182
|
+
headers = _with_session(headers, admitted)
|
|
183
|
+
|
|
132
184
|
if method == TOOLS_CALL:
|
|
133
185
|
return await _tools_call(
|
|
134
|
-
request,
|
|
186
|
+
request,
|
|
187
|
+
headers,
|
|
188
|
+
envelope,
|
|
189
|
+
request_id,
|
|
190
|
+
prefix,
|
|
191
|
+
upstream,
|
|
192
|
+
token,
|
|
193
|
+
http,
|
|
194
|
+
recorder,
|
|
195
|
+
config,
|
|
135
196
|
)
|
|
136
197
|
|
|
137
198
|
relayed = await _relay(request, raw, upstream, http, config)
|
|
@@ -141,6 +202,7 @@ def build_app(
|
|
|
141
202
|
|
|
142
203
|
async def _tools_call(
|
|
143
204
|
request: Request,
|
|
205
|
+
headers: dict[str, str],
|
|
144
206
|
envelope: dict[str, Any],
|
|
145
207
|
request_id: Any,
|
|
146
208
|
prefix: str,
|
|
@@ -156,7 +218,7 @@ def build_app(
|
|
|
156
218
|
return _error(request_id, INVALID_REQUEST, "tools/call needs a tool name")
|
|
157
219
|
|
|
158
220
|
target = _tool_target(upstream, tool_name)
|
|
159
|
-
data_class = upstream.data_class or
|
|
221
|
+
data_class = upstream.data_class or headers.get("x-agentic-data-class")
|
|
160
222
|
if not data_class:
|
|
161
223
|
# Guessing a data class would be inventing consent. Same rule as everywhere.
|
|
162
224
|
return _error(
|
|
@@ -177,10 +239,10 @@ def build_app(
|
|
|
177
239
|
http,
|
|
178
240
|
config,
|
|
179
241
|
path=request.url.path,
|
|
180
|
-
headers=
|
|
242
|
+
headers=headers,
|
|
181
243
|
body_reader=body_reader,
|
|
182
244
|
identity=None,
|
|
183
|
-
actor_token=
|
|
245
|
+
actor_token=headers.get("actor-token"),
|
|
184
246
|
resolved=(prefix, upstream, target, data_class),
|
|
185
247
|
)
|
|
186
248
|
if recorder is not None:
|
|
@@ -189,24 +251,26 @@ def build_app(
|
|
|
189
251
|
if isinstance(outcome, Blocked):
|
|
190
252
|
return _jsonrpc_refusal(request_id, outcome)
|
|
191
253
|
|
|
254
|
+
# Observed forwards what was presented. Under M1 that is the session's root grant,
|
|
255
|
+
# never the client's token, and M1 refuses observe mode at start-up regardless.
|
|
192
256
|
forwarded = token if isinstance(outcome, Observed) else outcome.token
|
|
193
|
-
|
|
257
|
+
upstream_headers = {
|
|
194
258
|
"authorization": f"Bearer {forwarded}",
|
|
195
259
|
"content-type": "application/json",
|
|
196
|
-
"accept":
|
|
260
|
+
"accept": headers.get("accept", "application/json"),
|
|
197
261
|
}
|
|
198
262
|
if isinstance(outcome, Allow):
|
|
199
263
|
if outcome.transaction_token is not None:
|
|
200
|
-
|
|
264
|
+
upstream_headers["txn-token"] = outcome.transaction_token
|
|
201
265
|
if outcome.identity_assertion is not None:
|
|
202
|
-
|
|
266
|
+
upstream_headers["agent-identity"] = outcome.identity_assertion
|
|
203
267
|
|
|
204
268
|
# The narrowed token, the transaction token and the upstream's own credentials
|
|
205
269
|
# go OUT; none of them is ever returned to the agent (FR-011).
|
|
206
270
|
try:
|
|
207
271
|
upstream_response = await http.post(
|
|
208
272
|
f"{upstream.url}{request.url.path[len(prefix.rstrip('/')) :] or '/'}",
|
|
209
|
-
headers=
|
|
273
|
+
headers=upstream_headers,
|
|
210
274
|
content=await request.body(),
|
|
211
275
|
timeout=httpx.Timeout(config.request_timeout_seconds),
|
|
212
276
|
)
|
|
@@ -231,11 +295,7 @@ def build_app(
|
|
|
231
295
|
try:
|
|
232
296
|
response = await http.post(
|
|
233
297
|
f"{upstream.url}{request.url.path}",
|
|
234
|
-
headers=
|
|
235
|
-
k: v
|
|
236
|
-
for k, v in request.headers.items()
|
|
237
|
-
if k.lower() not in {"host", "content-length"}
|
|
238
|
-
},
|
|
298
|
+
headers=_relay_headers(request, upstream),
|
|
239
299
|
content=raw,
|
|
240
300
|
timeout=httpx.Timeout(config.request_timeout_seconds),
|
|
241
301
|
)
|
|
@@ -253,7 +313,58 @@ def build_app(
|
|
|
253
313
|
if owned:
|
|
254
314
|
await http.aclose()
|
|
255
315
|
|
|
256
|
-
|
|
316
|
+
routes = [
|
|
317
|
+
*(
|
|
318
|
+
Route(path, metadata, methods=["GET"])
|
|
319
|
+
for path in (metadata_paths(config.resource_url) if gate is not None else [])
|
|
320
|
+
),
|
|
321
|
+
Route("/{path:path}", rpc, methods=["POST"]),
|
|
322
|
+
]
|
|
323
|
+
return Starlette(routes=routes, lifespan=lifespan)
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
def _with_session(headers: dict[str, str], admitted: Admitted) -> dict[str, str]:
|
|
327
|
+
"""What ``enforce()`` sees: the session's root grant in place of the client's token, and
|
|
328
|
+
that session's id, so nothing the client sent can point the decision at another."""
|
|
329
|
+
return {
|
|
330
|
+
**{k: v for k, v in headers.items() if k != SESSION_HEADER},
|
|
331
|
+
"authorization": f"Bearer {admitted.root_grant}",
|
|
332
|
+
SESSION_HEADER: admitted.session_id,
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
def _gate_refusal(request_id: object, refused: Refused, gate: ResourceGate) -> Response:
|
|
337
|
+
"""A challenge in HTTP, where MCP clients look for one; anything else as the JSON-RPC
|
|
338
|
+
refusal every other path returns."""
|
|
339
|
+
if refused.kind == "challenge":
|
|
340
|
+
body: dict[str, Any] = {
|
|
341
|
+
"error": refused.reason.lower(),
|
|
342
|
+
"error_description": refused.message,
|
|
343
|
+
}
|
|
344
|
+
return JSONResponse(
|
|
345
|
+
body,
|
|
346
|
+
status_code=refused.status,
|
|
347
|
+
headers={"www-authenticate": refused.www_authenticate or ""},
|
|
348
|
+
)
|
|
349
|
+
data: dict[str, Any] = {
|
|
350
|
+
"reason": refused.reason,
|
|
351
|
+
"recoverable": refused.recoverable,
|
|
352
|
+
"guarantee_level": GUARANTEE.value,
|
|
353
|
+
**{k: v for k, v in refused.details.items() if k not in {"reason", "recoverable"}},
|
|
354
|
+
}
|
|
355
|
+
if gate.asserted_root:
|
|
356
|
+
# Spec edge case: M1 with verified consent off roots sessions in an asserted subject,
|
|
357
|
+
# and the refusal says so rather than implying a verified one.
|
|
358
|
+
data["root_of_authority"] = "asserted"
|
|
359
|
+
response = _error(
|
|
360
|
+
request_id,
|
|
361
|
+
INFRASTRUCTURE if refused.kind == "infra" else POLICY_REFUSED,
|
|
362
|
+
refused.message,
|
|
363
|
+
**data,
|
|
364
|
+
)
|
|
365
|
+
if refused.kind == "infra":
|
|
366
|
+
response.status_code = 503
|
|
367
|
+
return response
|
|
257
368
|
|
|
258
369
|
|
|
259
370
|
def _jsonrpc_refusal(request_id: object, outcome: Blocked) -> JSONResponse:
|
|
@@ -7,6 +7,7 @@ from functools import lru_cache
|
|
|
7
7
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
8
8
|
|
|
9
9
|
from agentic_auth import runtime
|
|
10
|
+
from agentic_auth.oauth.validate import DEFAULT_ALGORITHMS, check_algorithms
|
|
10
11
|
|
|
11
12
|
|
|
12
13
|
class Settings(BaseSettings):
|
|
@@ -74,6 +75,10 @@ class Settings(BaseSettings):
|
|
|
74
75
|
principal_idp_audience: str = ""
|
|
75
76
|
# The ID-token claim that must equal "agent://<name>".
|
|
76
77
|
principal_binding_claim: str = "agent"
|
|
78
|
+
# Signing algorithms accepted on any token from the human IdP: enrollment binding,
|
|
79
|
+
# step-up and verified consent. Comma-separated, asymmetric only. Before 0.4.0 the
|
|
80
|
+
# token's own header chose (feature 011, research F4); this applies with every flag off.
|
|
81
|
+
principal_idp_algorithms: str = ",".join(DEFAULT_ALGORITHMS)
|
|
77
82
|
# How long an offline verifier may go without refreshing revocation state before it
|
|
78
83
|
# refuses every identity as stale.
|
|
79
84
|
revocation_freshness_seconds: int = 30
|
|
@@ -134,6 +139,36 @@ class Settings(BaseSettings):
|
|
|
134
139
|
telemetry_identity_disclosure: bool = False
|
|
135
140
|
telemetry_allow_sample_ratio: float = 1.0
|
|
136
141
|
|
|
142
|
+
# -- 0.4.0: MCP OAuth 2.1 baseline (feature 011) ---------------------------------
|
|
143
|
+
# Each milestone is off by default, so a 0.3.0 deployment is unchanged until an
|
|
144
|
+
# operator opts in. M1 is configured on each proxy or gateway (AGENTIC_AUTH_GATEWAY_*).
|
|
145
|
+
#
|
|
146
|
+
# verified_consent_enabled (M2): consent requires the user's IdP token as
|
|
147
|
+
# ``subject_token``, verifies it against the principal IdP, and roots the session at
|
|
148
|
+
# ``iss#sub``. An asserted ``user_sub`` alone is refused.
|
|
149
|
+
# as_metadata_enabled (M3): /.well-known/oauth-authorization-server is routed and
|
|
150
|
+
# reconciliation follows each MCP server's authorization server. Needs an https
|
|
151
|
+
# ``issuer``, which changes ``iss`` in new tokens.
|
|
152
|
+
# client_mapping_enabled (M4): /v1/agents/{id}/clients is routed, and consent picks the
|
|
153
|
+
# scope from the agent the token's client maps to. Needs M2.
|
|
154
|
+
verified_consent_enabled: bool = False
|
|
155
|
+
as_metadata_enabled: bool = False
|
|
156
|
+
client_mapping_enabled: bool = False
|
|
157
|
+
# Bearer that may call POST /v1/consent and nothing else: what a connector proxy or
|
|
158
|
+
# gateway holds, so it never needs the admin token. Empty disables it.
|
|
159
|
+
consent_token: str = ""
|
|
160
|
+
# Audiences consent accepts on a subject_token, comma-separated: this control plane's
|
|
161
|
+
# own identifier plus the resource URL of every proxy that relays tokens to consent.
|
|
162
|
+
consent_idp_audiences: str = ""
|
|
163
|
+
|
|
164
|
+
@property
|
|
165
|
+
def principal_algorithms(self) -> tuple[str, ...]:
|
|
166
|
+
return check_algorithms(self.principal_idp_algorithms.split(","))
|
|
167
|
+
|
|
168
|
+
@property
|
|
169
|
+
def consent_audiences(self) -> tuple[str, ...]:
|
|
170
|
+
return tuple(a.strip() for a in self.consent_idp_audiences.split(",") if a.strip())
|
|
171
|
+
|
|
137
172
|
def model_post_init(self, _context: object) -> None:
|
|
138
173
|
"""Refuse a configuration that cannot do what it claims.
|
|
139
174
|
|
|
@@ -151,6 +186,40 @@ class Settings(BaseSettings):
|
|
|
151
186
|
"the pinned policy never declared, which step-up may never grant. Set "
|
|
152
187
|
"AGENTIC_AUTH_CONSENT_GRANULARITY_ENABLED=true, or turn step-up off."
|
|
153
188
|
)
|
|
189
|
+
try:
|
|
190
|
+
_ = self.principal_algorithms
|
|
191
|
+
except ValueError as exc:
|
|
192
|
+
raise ValueError(f"AGENTIC_AUTH_PRINCIPAL_IDP_ALGORITHMS: {exc}") from exc
|
|
193
|
+
self._check_mcp_oauth()
|
|
194
|
+
|
|
195
|
+
def _check_mcp_oauth(self) -> None:
|
|
196
|
+
"""Feature 011 start-up refusals (FR-020): each names the setting to fix."""
|
|
197
|
+
if self.client_mapping_enabled and not self.verified_consent_enabled:
|
|
198
|
+
raise ValueError(
|
|
199
|
+
"AGENTIC_AUTH_CLIENT_MAPPING_ENABLED requires "
|
|
200
|
+
"AGENTIC_AUTH_VERIFIED_CONSENT_ENABLED: a client is read from a verified IdP "
|
|
201
|
+
"token, and without verified consent there is none."
|
|
202
|
+
)
|
|
203
|
+
if self.verified_consent_enabled:
|
|
204
|
+
for name in ("principal_idp_issuer", "principal_idp_jwks_url"):
|
|
205
|
+
if not getattr(self, name):
|
|
206
|
+
raise ValueError(
|
|
207
|
+
f"AGENTIC_AUTH_VERIFIED_CONSENT_ENABLED requires "
|
|
208
|
+
f"AGENTIC_AUTH_{name.upper()}: consent verifies the user's token "
|
|
209
|
+
"against the principal IdP."
|
|
210
|
+
)
|
|
211
|
+
if not self.consent_audiences:
|
|
212
|
+
raise ValueError(
|
|
213
|
+
"AGENTIC_AUTH_VERIFIED_CONSENT_ENABLED requires "
|
|
214
|
+
"AGENTIC_AUTH_CONSENT_IDP_AUDIENCES: the audiences a subject_token may be "
|
|
215
|
+
"issued for (this control plane, and each proxy that relays to it)."
|
|
216
|
+
)
|
|
217
|
+
if self.as_metadata_enabled and not self.issuer.startswith("https://"):
|
|
218
|
+
raise ValueError(
|
|
219
|
+
"AGENTIC_AUTH_AS_METADATA_ENABLED requires AGENTIC_AUTH_ISSUER to be an https "
|
|
220
|
+
f"URL (RFC 8414), got {self.issuer!r}. Changing it changes `iss` in new "
|
|
221
|
+
"tokens: update any offline verifier pinned to the old value."
|
|
222
|
+
)
|
|
154
223
|
|
|
155
224
|
# NOTE: there is deliberately no server-side observe-mode setting. The PDP is
|
|
156
225
|
# mode-blind — it always decides honestly and always records — so it cannot be a
|
|
@@ -214,22 +214,26 @@ class EmbeddedControlPlane:
|
|
|
214
214
|
issuer_key = IssuerKey(private_key=private, kid=_thumbprint(private.public_key()))
|
|
215
215
|
await remember_issuer_key(handle, issuer_key.private_pem().decode())
|
|
216
216
|
|
|
217
|
-
|
|
217
|
+
defaults: dict[str, Any] = {
|
|
218
218
|
# Informational only: the engine below is what the instance uses.
|
|
219
|
-
database_url
|
|
220
|
-
redis_url
|
|
219
|
+
"database_url": f"sqlite+aiosqlite:///{handle.path}",
|
|
220
|
+
"redis_url": "redis://embedded.invalid/0",
|
|
221
221
|
# Per-instance bearers. Nothing outside this object ever needs them.
|
|
222
|
-
admin_token
|
|
223
|
-
audit_read_token
|
|
224
|
-
enroll_token
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
222
|
+
"admin_token": secrets.token_urlsafe(32),
|
|
223
|
+
"audit_read_token": secrets.token_urlsafe(32),
|
|
224
|
+
"enroll_token": secrets.token_urlsafe(32),
|
|
225
|
+
"consent_token": secrets.token_urlsafe(32),
|
|
226
|
+
"principal_idp_issuer": _idp.ISSUER,
|
|
227
|
+
"principal_idp_jwks_url": f"{_idp.ISSUER}/.well-known/jwks.json",
|
|
228
|
+
"principal_idp_audience": _idp.AUDIENCE,
|
|
229
|
+
"principal_binding_claim": _idp.BINDING_CLAIM,
|
|
230
|
+
# 0.4.0: what the built-in IdP mints for, so turning on verified consent needs
|
|
231
|
+
# nothing else. A test that puts a proxy in front adds the proxy's URL.
|
|
232
|
+
"consent_idp_audiences": _idp.AUDIENCE,
|
|
233
|
+
"identity_required": identity_required,
|
|
234
|
+
"telemetry_enabled": False,
|
|
235
|
+
}
|
|
236
|
+
config = _EmbeddedSettings(**{**defaults, **settings})
|
|
233
237
|
|
|
234
238
|
router = HostRouter()
|
|
235
239
|
http = httpx.AsyncClient(transport=router, timeout=httpx.Timeout(10.0))
|
|
@@ -5,15 +5,14 @@ The migrations are not shipped in the wheel, so the revision is recorded here.
|
|
|
5
5
|
moving with it. A store created at a different revision is refused rather than half-read.
|
|
6
6
|
"""
|
|
7
7
|
|
|
8
|
-
SCHEMA_REVISION = "
|
|
8
|
+
SCHEMA_REVISION = "0008_mcp_oauth_baseline"
|
|
9
9
|
|
|
10
10
|
# Revisions an older store may be at that differ from SCHEMA_REVISION only by new tables, so
|
|
11
11
|
# opening one creates the missing tables and moves it forward. Anything not listed here is
|
|
12
12
|
# refused rather than guessed at. Add a revision only when the step after it is purely
|
|
13
13
|
# additive for the embedded store.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
)
|
|
14
|
+
#
|
|
15
|
+
# Empty since 0008: it adds columns to sessions and audit_decisions, which creating missing
|
|
16
|
+
# tables cannot do, so a 0.2.0 or 0.3.0 store is refused and must be re-created. This is the
|
|
17
|
+
# embedded-only exception listed in feature 011's spec (FR-019); server deployments migrate.
|
|
18
|
+
ADDITIVE_FROM: frozenset[str] = frozenset()
|