introspection-aauth 1.0.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.
Potentially problematic release.
This version of introspection-aauth might be problematic. Click here for more details.
- introspection_aauth-1.0.0/.gitignore +19 -0
- introspection_aauth-1.0.0/LICENSE +191 -0
- introspection_aauth-1.0.0/PKG-INFO +180 -0
- introspection_aauth-1.0.0/README.md +158 -0
- introspection_aauth-1.0.0/introspection_aauth/__init__.py +7 -0
- introspection_aauth-1.0.0/introspection_aauth/access_server/__init__.py +23 -0
- introspection_aauth-1.0.0/introspection_aauth/access_server/hooks.py +25 -0
- introspection_aauth-1.0.0/introspection_aauth/access_server/models.py +131 -0
- introspection_aauth-1.0.0/introspection_aauth/access_server/server.py +377 -0
- introspection_aauth-1.0.0/introspection_aauth/access_server/store.py +39 -0
- introspection_aauth-1.0.0/introspection_aauth/fastapi/__init__.py +38 -0
- introspection_aauth-1.0.0/introspection_aauth/fastapi/access_server.py +87 -0
- introspection_aauth-1.0.0/introspection_aauth/fastapi/person_server.py +169 -0
- introspection_aauth-1.0.0/introspection_aauth/fastapi/routes.py +272 -0
- introspection_aauth-1.0.0/introspection_aauth/person_server/__init__.py +44 -0
- introspection_aauth-1.0.0/introspection_aauth/person_server/access_server_client.py +277 -0
- introspection_aauth-1.0.0/introspection_aauth/person_server/directory.py +19 -0
- introspection_aauth-1.0.0/introspection_aauth/person_server/hooks.py +31 -0
- introspection_aauth-1.0.0/introspection_aauth/person_server/models.py +253 -0
- introspection_aauth-1.0.0/introspection_aauth/person_server/server.py +1091 -0
- introspection_aauth-1.0.0/introspection_aauth/person_server/store.py +214 -0
- introspection_aauth-1.0.0/introspection_aauth/protocol/__init__.py +106 -0
- introspection_aauth-1.0.0/introspection_aauth/protocol/answer.py +19 -0
- introspection_aauth-1.0.0/introspection_aauth/protocol/claims.py +194 -0
- introspection_aauth-1.0.0/introspection_aauth/protocol/discovery.py +146 -0
- introspection_aauth-1.0.0/introspection_aauth/protocol/errors.py +154 -0
- introspection_aauth-1.0.0/introspection_aauth/protocol/expectations.py +128 -0
- introspection_aauth-1.0.0/introspection_aauth/protocol/httpsig/__init__.py +47 -0
- introspection_aauth-1.0.0/introspection_aauth/protocol/httpsig/signing.py +132 -0
- introspection_aauth-1.0.0/introspection_aauth/protocol/httpsig/verification.py +234 -0
- introspection_aauth-1.0.0/introspection_aauth/protocol/identity.py +120 -0
- introspection_aauth-1.0.0/introspection_aauth/protocol/json.py +8 -0
- introspection_aauth-1.0.0/introspection_aauth/protocol/jwt.py +162 -0
- introspection_aauth-1.0.0/introspection_aauth/protocol/keys.py +169 -0
- introspection_aauth-1.0.0/introspection_aauth/protocol/memory.py +32 -0
- introspection_aauth-1.0.0/introspection_aauth/protocol/models.py +46 -0
- introspection_aauth-1.0.0/introspection_aauth/protocol/pending.py +63 -0
- introspection_aauth-1.0.0/introspection_aauth/protocol/server.py +117 -0
- introspection_aauth-1.0.0/introspection_aauth/protocol/urls.py +46 -0
- introspection_aauth-1.0.0/introspection_aauth/protocol/verification.py +150 -0
- introspection_aauth-1.0.0/introspection_aauth/protocol/wire.py +108 -0
- introspection_aauth-1.0.0/introspection_aauth/py.typed +0 -0
- introspection_aauth-1.0.0/pyproject.toml +62 -0
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding any notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
Copyright 2026 Introspection AI Inc.
|
|
180
|
+
|
|
181
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
182
|
+
you may not use this file except in compliance with the License.
|
|
183
|
+
You may obtain a copy of the License at
|
|
184
|
+
|
|
185
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
186
|
+
|
|
187
|
+
Unless required by applicable law or agreed to in writing, software
|
|
188
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
189
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
190
|
+
See the License for the specific language governing permissions and
|
|
191
|
+
limitations under the License.
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: introspection-aauth
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: An AAuth Person Server and Access Server (draft-hardt-oauth-aauth-protocol -11): missions, person and auth tokens, budgets, approvals and four-party federation, over a store you provide
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Requires-Python: >=3.11
|
|
8
|
+
Requires-Dist: cryptography>=44.0.0
|
|
9
|
+
Requires-Dist: http-sfv>=0.9.9
|
|
10
|
+
Requires-Dist: httpx2>=2.12.0
|
|
11
|
+
Requires-Dist: opentelemetry-api>=1.39.0
|
|
12
|
+
Requires-Dist: pydantic>=2.10.0
|
|
13
|
+
Provides-Extra: fastapi
|
|
14
|
+
Requires-Dist: fastapi>=0.115.0; extra == 'fastapi'
|
|
15
|
+
Provides-Extra: test
|
|
16
|
+
Requires-Dist: aauth-signing==0.2.0; extra == 'test'
|
|
17
|
+
Requires-Dist: opentelemetry-sdk>=1.39.0; extra == 'test'
|
|
18
|
+
Requires-Dist: pytest-asyncio>=1.3.0; extra == 'test'
|
|
19
|
+
Requires-Dist: pytest-cov>=7.1.0; extra == 'test'
|
|
20
|
+
Requires-Dist: pytest>=9.0.0; extra == 'test'
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
|
|
23
|
+
# introspection-aauth
|
|
24
|
+
|
|
25
|
+
An AAuth Person Server and Access Server for Python, implementing
|
|
26
|
+
[draft-hardt-oauth-aauth-protocol -11](https://github.com/dickhardt/AAuth):
|
|
27
|
+
missions, person and auth tokens, budgets, approvals, and four-party
|
|
28
|
+
federation (`#access-server-federation`). You provide the store; nothing
|
|
29
|
+
here names a database, a queue or a web framework.
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pip install introspection-aauth # the servers
|
|
33
|
+
pip install 'introspection-aauth[fastapi]' # and FastAPI routers for them
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Layout
|
|
37
|
+
|
|
38
|
+
| Module | Holds |
|
|
39
|
+
| --- | --- |
|
|
40
|
+
| `introspection_aauth.protocol` | What both servers share, written once: `AAuthError`, a subclass per AAuth error code (`InvalidRequest`, `InvalidToken`, `InvalidCode`, …), and their problem+json; Ed25519 signing keys (current and previous) and Ed25519/ES256 verification; RFC 9421 signing and verification with `Signature-Key`; AAuth's tokens; discovery of metadata and keys, cached for a bounded time; budgets; and the server plumbing both use: the `Server` base, verifying an agent's or a server's signed request, the `202` pending answer, reading an R3 proposal. |
|
|
41
|
+
| `introspection_aauth.person_server` | `PersonServer`, its `Store` and `Directory` protocols, a `MemoryStore`, and `AccessServerClient`, its client for a resource's own Access Server. |
|
|
42
|
+
| `introspection_aauth.access_server` | `AccessServer`, its policy `Verdict`s, its `Store` protocol and a `MemoryStore`. |
|
|
43
|
+
| `introspection_aauth.fastapi` | `person_server_router` and `access_server_router`, and `*_well_known_router` for the documents alone (the `fastapi` extra). Each takes an `APIRouter` of yours for its tags, dependencies, responses or `include_in_schema`. |
|
|
44
|
+
|
|
45
|
+
Neither server imports the other, and `protocol` imports neither.
|
|
46
|
+
|
|
47
|
+
Every body either server sends or reads is a pydantic model in
|
|
48
|
+
`protocol.wire`, and every token's claims a model in `protocol.claims`
|
|
49
|
+
that checks what the token must be on its own: `exp` after `iat`, a
|
|
50
|
+
lifetime of at most an hour where the protocol caps it, a `cnf` that is a
|
|
51
|
+
public key, a budget of non-negative integers. Whether a token that
|
|
52
|
+
verified is the one a caller expected is an expectation's `failures`,
|
|
53
|
+
which names every check it fails (`["sub", "tenant"]`). Discovery reads
|
|
54
|
+
only AAuth server identifiers (`https://` and a lowercase host, nothing
|
|
55
|
+
more), requires an https `jwks_uri`, and follows no redirect. An agent's
|
|
56
|
+
request is signed `sig=jwt` and a server's `sig=jwks_uri`; any other scheme,
|
|
57
|
+
server or `dwk` is refused before anything is fetched. An R3 proposal is
|
|
58
|
+
read only from its resource's own https origin. An approved auth token is
|
|
59
|
+
collected once; a second poll is `410 invalid_code`.
|
|
60
|
+
|
|
61
|
+
## Dependencies
|
|
62
|
+
|
|
63
|
+
```
|
|
64
|
+
introspection-aauth
|
|
65
|
+
├── cryptography Ed25519 and ES256, JWK thumbprints, PEM keys
|
|
66
|
+
├── http-sfv RFC 9651 structured fields: Signature-Input, Signature, Signature-Key, AAuth-Requirement
|
|
67
|
+
├── httpx2 discovery, federation and R3 fetches
|
|
68
|
+
├── pydantic models and request bodies
|
|
69
|
+
└── fastapi (extra: fastapi) the routers
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
JWS is done here, on `cryptography`: AAuth's tokens use fully-specified
|
|
73
|
+
algorithms (`alg: Ed25519`, RFC 9864), and every claim check is the
|
|
74
|
+
protocol's own, so a JWT library would add nothing but a dependency.
|
|
75
|
+
|
|
76
|
+
## A Person Server
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
import httpx2 as httpx
|
|
80
|
+
from introspection_aauth.fastapi import person_server_router
|
|
81
|
+
from introspection_aauth.person_server import MemoryStore, PersonServer
|
|
82
|
+
from introspection_aauth.protocol import SigningKey
|
|
83
|
+
|
|
84
|
+
person_server = PersonServer(
|
|
85
|
+
"https://ps.example",
|
|
86
|
+
SigningKey.from_pem(open("ps.pem").read()),
|
|
87
|
+
MemoryStore(),
|
|
88
|
+
subject_secret=b"...", # keys each person's directed `sub`
|
|
89
|
+
agent_providers=["https://agents.example"],
|
|
90
|
+
http=httpx.AsyncClient(),
|
|
91
|
+
endpoint_base="https://ps.example/aauth",
|
|
92
|
+
default_tenant="acme",
|
|
93
|
+
)
|
|
94
|
+
app.include_router(person_server_router(person_server))
|
|
95
|
+
# Or with your own router: its prefix is the start of the endpoint base's
|
|
96
|
+
# path, and the well-known documents are mounted at the root on their own.
|
|
97
|
+
# app.include_router(person_server_router(person_server, APIRouter(prefix="/aauth", tags=["AAuth"])))
|
|
98
|
+
# app.include_router(person_server_well_known_router(person_server))
|
|
99
|
+
|
|
100
|
+
# Your approval app answers what it asks:
|
|
101
|
+
await person_server.decide(tenant, approval_id, ApprovalStatus.APPROVED,
|
|
102
|
+
decided_by="dana", budget=Budget(amount=200_000, unit="USD", decimals=2))
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
`subject_secret` is separate from the signing key, so rotating the key
|
|
106
|
+
changes no one's identifier. Pass `previous_keys` to keep a rotated key
|
|
107
|
+
published until what it signed has expired.
|
|
108
|
+
|
|
109
|
+
## An Access Server
|
|
110
|
+
|
|
111
|
+
```python
|
|
112
|
+
def policy(request: AccessRequest) -> Verdict:
|
|
113
|
+
if request.tenant == "acme":
|
|
114
|
+
return Verdict.allow() # or allow(scope=..., budget=...) for less
|
|
115
|
+
return Verdict.approval() # wait; settle it with decide()
|
|
116
|
+
|
|
117
|
+
access_server = AccessServer("https://as.example", key, policy,
|
|
118
|
+
resources=["https://booking.example"],
|
|
119
|
+
person_servers=["https://ps.example"],
|
|
120
|
+
agent_providers=["https://agents.example"],
|
|
121
|
+
http=httpx.AsyncClient())
|
|
122
|
+
app.include_router(access_server_router(access_server))
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Bring your own store
|
|
126
|
+
|
|
127
|
+
`person_server.Store` is the Person Server's state in logical operations,
|
|
128
|
+
named by their CRUD verb: `select_binding` and `insert_binding` (bind a key
|
|
129
|
+
to the first person it names), `select_mission`, `insert_mission`,
|
|
130
|
+
`update_spend` (spend only if it fits, atomically), `update_mission_log`,
|
|
131
|
+
`update_mission_end`, `select_approval`, `insert_approval`, and
|
|
132
|
+
`transition_approval`, which replaces an approval only if its status and
|
|
133
|
+
version have not changed. `transaction()` groups the writes that commit together: a decision
|
|
134
|
+
with the mission it creates or spends, and a federated auth token with the
|
|
135
|
+
spend it pays for. `transaction()` yields a store scoped to it; pass it as
|
|
136
|
+
`decide(..., store=tx)` to make a decision part of a unit of work of your
|
|
137
|
+
own, and call `decided` once that commits. Whether a store encrypts what it keeps is its own
|
|
138
|
+
choice. `access_server.Store` is `select_pending`, `insert_pending` and `transition_pending`.
|
|
139
|
+
|
|
140
|
+
## Durable federation
|
|
141
|
+
|
|
142
|
+
`PersonServer(on_federate=...)` is told of each approved request a
|
|
143
|
+
resource's Access Server must decide. Unset, `PersonServer.federate` drives
|
|
144
|
+
it in this process. A host with a durable executor journals the steps
|
|
145
|
+
itself: `federation_due`, `AccessServerClient.discover`, `.request`,
|
|
146
|
+
`record_federation`, wait `Outcome.poll_delay()`, `.poll`,
|
|
147
|
+
`record_federation`, and so on until `record_federation` returns False.
|
|
148
|
+
|
|
149
|
+
The server makes every call through the `httpx.AsyncClient` it is given, so
|
|
150
|
+
retrying a dropped connection is that client's: pass one with
|
|
151
|
+
`transport=httpx.AsyncHTTPTransport(retries=3)` to retry, or a mock transport
|
|
152
|
+
in tests.
|
|
153
|
+
|
|
154
|
+
## Logging and tracing
|
|
155
|
+
|
|
156
|
+
The package configures no logging and no tracer provider; it writes through
|
|
157
|
+
`logging.getLogger(__name__)` and the OpenTelemetry API, so your formatter
|
|
158
|
+
and exporter carry its records and spans. Each record has a fixed message and
|
|
159
|
+
its values as `extra` fields: identifiers (`tenant`, `approval_id`,
|
|
160
|
+
`resource`, `ps`) and enumerated values (`step`, `decision`, `error`), never a
|
|
161
|
+
token, a person's identity or a request body. Federation is traced as
|
|
162
|
+
`person_server.federate`, with a child span for each exchange with the Access
|
|
163
|
+
Server (`.metadata`, `.request`, `.poll`, `.delivery`); reading an R3
|
|
164
|
+
proposal is `aauth.r3.read`.
|
|
165
|
+
|
|
166
|
+
## Not served
|
|
167
|
+
|
|
168
|
+
As in the hosted Person Server: `requirement=claims` and `clarification`,
|
|
169
|
+
payment (`402`, answered `403 denied`), step-up with an auth token,
|
|
170
|
+
sub-agents and call chaining (`subagent_token`, `upstream_token`), and
|
|
171
|
+
token revocation.
|
|
172
|
+
|
|
173
|
+
## Example
|
|
174
|
+
|
|
175
|
+
`examples/introspection_examples/aauth/four_party.py` runs the four-party
|
|
176
|
+
flow in one process:
|
|
177
|
+
|
|
178
|
+
```bash
|
|
179
|
+
cd examples && uv run -m introspection_examples.aauth.four_party
|
|
180
|
+
```
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
# introspection-aauth
|
|
2
|
+
|
|
3
|
+
An AAuth Person Server and Access Server for Python, implementing
|
|
4
|
+
[draft-hardt-oauth-aauth-protocol -11](https://github.com/dickhardt/AAuth):
|
|
5
|
+
missions, person and auth tokens, budgets, approvals, and four-party
|
|
6
|
+
federation (`#access-server-federation`). You provide the store; nothing
|
|
7
|
+
here names a database, a queue or a web framework.
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install introspection-aauth # the servers
|
|
11
|
+
pip install 'introspection-aauth[fastapi]' # and FastAPI routers for them
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Layout
|
|
15
|
+
|
|
16
|
+
| Module | Holds |
|
|
17
|
+
| --- | --- |
|
|
18
|
+
| `introspection_aauth.protocol` | What both servers share, written once: `AAuthError`, a subclass per AAuth error code (`InvalidRequest`, `InvalidToken`, `InvalidCode`, …), and their problem+json; Ed25519 signing keys (current and previous) and Ed25519/ES256 verification; RFC 9421 signing and verification with `Signature-Key`; AAuth's tokens; discovery of metadata and keys, cached for a bounded time; budgets; and the server plumbing both use: the `Server` base, verifying an agent's or a server's signed request, the `202` pending answer, reading an R3 proposal. |
|
|
19
|
+
| `introspection_aauth.person_server` | `PersonServer`, its `Store` and `Directory` protocols, a `MemoryStore`, and `AccessServerClient`, its client for a resource's own Access Server. |
|
|
20
|
+
| `introspection_aauth.access_server` | `AccessServer`, its policy `Verdict`s, its `Store` protocol and a `MemoryStore`. |
|
|
21
|
+
| `introspection_aauth.fastapi` | `person_server_router` and `access_server_router`, and `*_well_known_router` for the documents alone (the `fastapi` extra). Each takes an `APIRouter` of yours for its tags, dependencies, responses or `include_in_schema`. |
|
|
22
|
+
|
|
23
|
+
Neither server imports the other, and `protocol` imports neither.
|
|
24
|
+
|
|
25
|
+
Every body either server sends or reads is a pydantic model in
|
|
26
|
+
`protocol.wire`, and every token's claims a model in `protocol.claims`
|
|
27
|
+
that checks what the token must be on its own: `exp` after `iat`, a
|
|
28
|
+
lifetime of at most an hour where the protocol caps it, a `cnf` that is a
|
|
29
|
+
public key, a budget of non-negative integers. Whether a token that
|
|
30
|
+
verified is the one a caller expected is an expectation's `failures`,
|
|
31
|
+
which names every check it fails (`["sub", "tenant"]`). Discovery reads
|
|
32
|
+
only AAuth server identifiers (`https://` and a lowercase host, nothing
|
|
33
|
+
more), requires an https `jwks_uri`, and follows no redirect. An agent's
|
|
34
|
+
request is signed `sig=jwt` and a server's `sig=jwks_uri`; any other scheme,
|
|
35
|
+
server or `dwk` is refused before anything is fetched. An R3 proposal is
|
|
36
|
+
read only from its resource's own https origin. An approved auth token is
|
|
37
|
+
collected once; a second poll is `410 invalid_code`.
|
|
38
|
+
|
|
39
|
+
## Dependencies
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
introspection-aauth
|
|
43
|
+
├── cryptography Ed25519 and ES256, JWK thumbprints, PEM keys
|
|
44
|
+
├── http-sfv RFC 9651 structured fields: Signature-Input, Signature, Signature-Key, AAuth-Requirement
|
|
45
|
+
├── httpx2 discovery, federation and R3 fetches
|
|
46
|
+
├── pydantic models and request bodies
|
|
47
|
+
└── fastapi (extra: fastapi) the routers
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
JWS is done here, on `cryptography`: AAuth's tokens use fully-specified
|
|
51
|
+
algorithms (`alg: Ed25519`, RFC 9864), and every claim check is the
|
|
52
|
+
protocol's own, so a JWT library would add nothing but a dependency.
|
|
53
|
+
|
|
54
|
+
## A Person Server
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
import httpx2 as httpx
|
|
58
|
+
from introspection_aauth.fastapi import person_server_router
|
|
59
|
+
from introspection_aauth.person_server import MemoryStore, PersonServer
|
|
60
|
+
from introspection_aauth.protocol import SigningKey
|
|
61
|
+
|
|
62
|
+
person_server = PersonServer(
|
|
63
|
+
"https://ps.example",
|
|
64
|
+
SigningKey.from_pem(open("ps.pem").read()),
|
|
65
|
+
MemoryStore(),
|
|
66
|
+
subject_secret=b"...", # keys each person's directed `sub`
|
|
67
|
+
agent_providers=["https://agents.example"],
|
|
68
|
+
http=httpx.AsyncClient(),
|
|
69
|
+
endpoint_base="https://ps.example/aauth",
|
|
70
|
+
default_tenant="acme",
|
|
71
|
+
)
|
|
72
|
+
app.include_router(person_server_router(person_server))
|
|
73
|
+
# Or with your own router: its prefix is the start of the endpoint base's
|
|
74
|
+
# path, and the well-known documents are mounted at the root on their own.
|
|
75
|
+
# app.include_router(person_server_router(person_server, APIRouter(prefix="/aauth", tags=["AAuth"])))
|
|
76
|
+
# app.include_router(person_server_well_known_router(person_server))
|
|
77
|
+
|
|
78
|
+
# Your approval app answers what it asks:
|
|
79
|
+
await person_server.decide(tenant, approval_id, ApprovalStatus.APPROVED,
|
|
80
|
+
decided_by="dana", budget=Budget(amount=200_000, unit="USD", decimals=2))
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
`subject_secret` is separate from the signing key, so rotating the key
|
|
84
|
+
changes no one's identifier. Pass `previous_keys` to keep a rotated key
|
|
85
|
+
published until what it signed has expired.
|
|
86
|
+
|
|
87
|
+
## An Access Server
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
def policy(request: AccessRequest) -> Verdict:
|
|
91
|
+
if request.tenant == "acme":
|
|
92
|
+
return Verdict.allow() # or allow(scope=..., budget=...) for less
|
|
93
|
+
return Verdict.approval() # wait; settle it with decide()
|
|
94
|
+
|
|
95
|
+
access_server = AccessServer("https://as.example", key, policy,
|
|
96
|
+
resources=["https://booking.example"],
|
|
97
|
+
person_servers=["https://ps.example"],
|
|
98
|
+
agent_providers=["https://agents.example"],
|
|
99
|
+
http=httpx.AsyncClient())
|
|
100
|
+
app.include_router(access_server_router(access_server))
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Bring your own store
|
|
104
|
+
|
|
105
|
+
`person_server.Store` is the Person Server's state in logical operations,
|
|
106
|
+
named by their CRUD verb: `select_binding` and `insert_binding` (bind a key
|
|
107
|
+
to the first person it names), `select_mission`, `insert_mission`,
|
|
108
|
+
`update_spend` (spend only if it fits, atomically), `update_mission_log`,
|
|
109
|
+
`update_mission_end`, `select_approval`, `insert_approval`, and
|
|
110
|
+
`transition_approval`, which replaces an approval only if its status and
|
|
111
|
+
version have not changed. `transaction()` groups the writes that commit together: a decision
|
|
112
|
+
with the mission it creates or spends, and a federated auth token with the
|
|
113
|
+
spend it pays for. `transaction()` yields a store scoped to it; pass it as
|
|
114
|
+
`decide(..., store=tx)` to make a decision part of a unit of work of your
|
|
115
|
+
own, and call `decided` once that commits. Whether a store encrypts what it keeps is its own
|
|
116
|
+
choice. `access_server.Store` is `select_pending`, `insert_pending` and `transition_pending`.
|
|
117
|
+
|
|
118
|
+
## Durable federation
|
|
119
|
+
|
|
120
|
+
`PersonServer(on_federate=...)` is told of each approved request a
|
|
121
|
+
resource's Access Server must decide. Unset, `PersonServer.federate` drives
|
|
122
|
+
it in this process. A host with a durable executor journals the steps
|
|
123
|
+
itself: `federation_due`, `AccessServerClient.discover`, `.request`,
|
|
124
|
+
`record_federation`, wait `Outcome.poll_delay()`, `.poll`,
|
|
125
|
+
`record_federation`, and so on until `record_federation` returns False.
|
|
126
|
+
|
|
127
|
+
The server makes every call through the `httpx.AsyncClient` it is given, so
|
|
128
|
+
retrying a dropped connection is that client's: pass one with
|
|
129
|
+
`transport=httpx.AsyncHTTPTransport(retries=3)` to retry, or a mock transport
|
|
130
|
+
in tests.
|
|
131
|
+
|
|
132
|
+
## Logging and tracing
|
|
133
|
+
|
|
134
|
+
The package configures no logging and no tracer provider; it writes through
|
|
135
|
+
`logging.getLogger(__name__)` and the OpenTelemetry API, so your formatter
|
|
136
|
+
and exporter carry its records and spans. Each record has a fixed message and
|
|
137
|
+
its values as `extra` fields: identifiers (`tenant`, `approval_id`,
|
|
138
|
+
`resource`, `ps`) and enumerated values (`step`, `decision`, `error`), never a
|
|
139
|
+
token, a person's identity or a request body. Federation is traced as
|
|
140
|
+
`person_server.federate`, with a child span for each exchange with the Access
|
|
141
|
+
Server (`.metadata`, `.request`, `.poll`, `.delivery`); reading an R3
|
|
142
|
+
proposal is `aauth.r3.read`.
|
|
143
|
+
|
|
144
|
+
## Not served
|
|
145
|
+
|
|
146
|
+
As in the hosted Person Server: `requirement=claims` and `clarification`,
|
|
147
|
+
payment (`402`, answered `403 denied`), step-up with an auth token,
|
|
148
|
+
sub-agents and call chaining (`subagent_token`, `upstream_token`), and
|
|
149
|
+
token revocation.
|
|
150
|
+
|
|
151
|
+
## Example
|
|
152
|
+
|
|
153
|
+
`examples/introspection_examples/aauth/four_party.py` runs the four-party
|
|
154
|
+
flow in one process:
|
|
155
|
+
|
|
156
|
+
```bash
|
|
157
|
+
cd examples && uv run -m introspection_examples.aauth.four_party
|
|
158
|
+
```
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"""An AAuth Person Server and Access Server, over a store you provide.
|
|
2
|
+
|
|
3
|
+
- `introspection_aauth.protocol`: what both servers share.
|
|
4
|
+
- `introspection_aauth.person_server`: `PersonServer`.
|
|
5
|
+
- `introspection_aauth.access_server`: `AccessServer`.
|
|
6
|
+
- `introspection_aauth.fastapi`: routers for either (the `fastapi` extra).
|
|
7
|
+
"""
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"""An AAuth Access Server: a resource's own policy over the auth tokens a
|
|
2
|
+
Person Server redeems for it."""
|
|
3
|
+
|
|
4
|
+
from introspection_aauth.access_server.hooks import Policy
|
|
5
|
+
from introspection_aauth.access_server.models import (
|
|
6
|
+
AccessRequest,
|
|
7
|
+
PendingAccess,
|
|
8
|
+
PendingStatus,
|
|
9
|
+
Verdict,
|
|
10
|
+
)
|
|
11
|
+
from introspection_aauth.access_server.server import AccessServer
|
|
12
|
+
from introspection_aauth.access_server.store import MemoryStore, Store
|
|
13
|
+
|
|
14
|
+
__all__ = [
|
|
15
|
+
"AccessRequest",
|
|
16
|
+
"AccessServer",
|
|
17
|
+
"MemoryStore",
|
|
18
|
+
"PendingAccess",
|
|
19
|
+
"PendingStatus",
|
|
20
|
+
"Policy",
|
|
21
|
+
"Store",
|
|
22
|
+
"Verdict",
|
|
23
|
+
]
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"""What an Access Server calls back into its host: the policy that decides a
|
|
2
|
+
request, and a hook for each one left pending."""
|
|
3
|
+
|
|
4
|
+
from collections.abc import Awaitable
|
|
5
|
+
from typing import Protocol
|
|
6
|
+
|
|
7
|
+
from introspection_aauth.access_server.models import (
|
|
8
|
+
AccessRequest,
|
|
9
|
+
PendingAccess,
|
|
10
|
+
Verdict,
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class Policy(Protocol):
|
|
15
|
+
"""A resource's policy: its verdict on one request, now or awaited."""
|
|
16
|
+
|
|
17
|
+
def __call__(
|
|
18
|
+
self, request: AccessRequest, /
|
|
19
|
+
) -> Verdict | Awaitable[Verdict]: ...
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class PendingHook(Protocol):
|
|
23
|
+
"""Told of each request the policy waits on."""
|
|
24
|
+
|
|
25
|
+
def __call__(self, pending: PendingAccess, /) -> Awaitable[None]: ...
|