tai42-accounts-postgres 0.1.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.
- tai42_accounts_postgres-0.1.1/LICENSE +202 -0
- tai42_accounts_postgres-0.1.1/MANIFEST.in +3 -0
- tai42_accounts_postgres-0.1.1/NOTICE +5 -0
- tai42_accounts_postgres-0.1.1/PKG-INFO +250 -0
- tai42_accounts_postgres-0.1.1/README.md +218 -0
- tai42_accounts_postgres-0.1.1/pyproject.toml +107 -0
- tai42_accounts_postgres-0.1.1/setup.cfg +4 -0
- tai42_accounts_postgres-0.1.1/src/tai42_accounts_postgres/__init__.py +15 -0
- tai42_accounts_postgres-0.1.1/src/tai42_accounts_postgres/db.py +81 -0
- tai42_accounts_postgres-0.1.1/src/tai42_accounts_postgres/hashing.py +106 -0
- tai42_accounts_postgres-0.1.1/src/tai42_accounts_postgres/provider.py +197 -0
- tai42_accounts_postgres-0.1.1/src/tai42_accounts_postgres/py.typed +0 -0
- tai42_accounts_postgres-0.1.1/src/tai42_accounts_postgres/rate_limit.py +100 -0
- tai42_accounts_postgres-0.1.1/src/tai42_accounts_postgres/routes_login.py +285 -0
- tai42_accounts_postgres-0.1.1/src/tai42_accounts_postgres/routes_users.py +377 -0
- tai42_accounts_postgres-0.1.1/src/tai42_accounts_postgres/service.py +214 -0
- tai42_accounts_postgres-0.1.1/src/tai42_accounts_postgres/settings.py +105 -0
- tai42_accounts_postgres-0.1.1/src/tai42_accounts_postgres/sql/accounts.init.sql +67 -0
- tai42_accounts_postgres-0.1.1/src/tai42_accounts_postgres/stores.py +406 -0
- tai42_accounts_postgres-0.1.1/src/tai42_accounts_postgres/studio/studio-manifest.json +17 -0
- tai42_accounts_postgres-0.1.1/src/tai42_accounts_postgres/studio/tai42-accounts-postgres-CUNscC8H.js +414 -0
- tai42_accounts_postgres-0.1.1/src/tai42_accounts_postgres/studio/tai42-accounts-postgres-Ulk7-WS7.css +1 -0
- tai42_accounts_postgres-0.1.1/src/tai42_accounts_postgres.egg-info/PKG-INFO +250 -0
- tai42_accounts_postgres-0.1.1/src/tai42_accounts_postgres.egg-info/SOURCES.txt +25 -0
- tai42_accounts_postgres-0.1.1/src/tai42_accounts_postgres.egg-info/dependency_links.txt +1 -0
- tai42_accounts_postgres-0.1.1/src/tai42_accounts_postgres.egg-info/requires.txt +10 -0
- tai42_accounts_postgres-0.1.1/src/tai42_accounts_postgres.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,202 @@
|
|
|
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 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 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 those 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
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tai42-accounts-postgres
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: Postgres-backed accounts provider for the TAI ecosystem: an installable plugin that owns user accounts, password login, sessions, and invites, registers itself as the "accounts-postgres" provider, and ships a Studio users-admin UI.
|
|
5
|
+
Author-email: tai42 <oss@tai42.ai>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://tai42.ai
|
|
8
|
+
Project-URL: Repository, https://github.com/tai42ai/tai-accounts-postgres
|
|
9
|
+
Project-URL: Issues, https://github.com/tai42ai/tai-accounts-postgres/issues
|
|
10
|
+
Project-URL: Changelog, https://github.com/tai42ai/tai-accounts-postgres/blob/main/CHANGELOG.md
|
|
11
|
+
Keywords: tai,accounts,authentication,login,sessions,postgres,access-control
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Typing :: Typed
|
|
18
|
+
Requires-Python: >=3.13
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
License-File: NOTICE
|
|
22
|
+
Requires-Dist: tai42-contract<0.2,>=0.1
|
|
23
|
+
Requires-Dist: tai42-kit[postgres,redis]<0.2,>=0.1
|
|
24
|
+
Requires-Dist: argon2-cffi>=23
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
27
|
+
Requires-Dist: pytest-asyncio>=1.3; extra == "dev"
|
|
28
|
+
Requires-Dist: pytest-cov>=5; extra == "dev"
|
|
29
|
+
Requires-Dist: ruff>=0.6; extra == "dev"
|
|
30
|
+
Requires-Dist: pyright>=1.1.389; extra == "dev"
|
|
31
|
+
Dynamic: license-file
|
|
32
|
+
|
|
33
|
+
# tai42-accounts-postgres
|
|
34
|
+
|
|
35
|
+
[](https://github.com/tai42ai/tai-accounts-postgres/actions/workflows/ci.yml)
|
|
36
|
+
[](LICENSE)
|
|
37
|
+
|
|
38
|
+
The Postgres-backed **accounts provider** for the TAI ecosystem — an installable
|
|
39
|
+
plugin that owns human user accounts, password login, sessions, and invites, and
|
|
40
|
+
ships a Studio users-admin UI. It registers itself as the `"accounts-postgres"`
|
|
41
|
+
provider and mints/validates its own `tai-sess-…` session tokens.
|
|
42
|
+
|
|
43
|
+
Importing the package registers the provider in `tai42-contract`'s module-level
|
|
44
|
+
accounts registry (`register_accounts_provider("accounts-postgres", ...)`), which
|
|
45
|
+
ALSO lands the factory in the identity registry under the same name — an accounts
|
|
46
|
+
provider is the token answerer for its own sessions, so one registration keeps
|
|
47
|
+
sessions both mintable and validatable. No `tai42_app` handle is involved, so it
|
|
48
|
+
registers in any process that imports it. A deployment selects it by including
|
|
49
|
+
`accounts-postgres` in the access-control `auth_providers` list.
|
|
50
|
+
|
|
51
|
+
Its only tai-* dependencies are `tai42-contract` (the accounts ABC, the injected
|
|
52
|
+
admin-services and settings Protocols, the login-method metadata models, and the
|
|
53
|
+
registry it registers through) and `tai42-kit` (the Postgres and Redis clients and
|
|
54
|
+
the session/invite hash). It **never** imports the skeleton — the plugin is
|
|
55
|
+
contract-facing, and the import is banned by ruff.
|
|
56
|
+
|
|
57
|
+
## The TAI ecosystem
|
|
58
|
+
|
|
59
|
+
TAI is an open-source runtime for MCP tools, agents, and workflows. An accounts
|
|
60
|
+
provider owns human sign-in: it authenticates a person, mints the session token
|
|
61
|
+
their browser carries, and answers that token back as an identity on every later
|
|
62
|
+
call. This package is one such provider (Postgres-backed accounts with password
|
|
63
|
+
login, sessions, and invites); any package can back the same contract, so this
|
|
64
|
+
repo is this provider's own full doc home, and the documentation site covers the
|
|
65
|
+
platform-level story:
|
|
66
|
+
|
|
67
|
+
- Accounts concept: https://tai42.ai/concepts/accounts
|
|
68
|
+
- Build an accounts provider (author guide): https://tai42.ai/guides/authors/accounts-provider
|
|
69
|
+
- Ecosystem catalog: https://tai42.ai/reference/catalog
|
|
70
|
+
|
|
71
|
+
## What it stores
|
|
72
|
+
|
|
73
|
+
Three plugin-owned tables in the platform database (its own DDL, its own apply
|
|
74
|
+
step):
|
|
75
|
+
|
|
76
|
+
- `accounts_users` — one row per human user: the opaque, stable `user_id`
|
|
77
|
+
(`usr-…`), the normalized email, the argon2id password hash (NULL until an
|
|
78
|
+
invite is accepted), the role-template name, and the disabled flag.
|
|
79
|
+
- `accounts_sessions` — one row per live login: the SHA-256 hash of the
|
|
80
|
+
`tai-sess-…` token (the raw token is never stored), with sliding-idle
|
|
81
|
+
(`last_seen_at`) and absolute (`absolute_expires_at`) expiry.
|
|
82
|
+
- `accounts_invites` — one pending invite per user: the SHA-256 hash of the
|
|
83
|
+
`tai-inv-…` token, its TTL, and its single-use consumption marker.
|
|
84
|
+
|
|
85
|
+
Rate-limit counters and the shared bootstrap token live in Redis (reached through
|
|
86
|
+
the injected `settings.redis`), namespaced per deployment.
|
|
87
|
+
|
|
88
|
+
The plugin NEVER touches the skeleton's `access_control_policies` /
|
|
89
|
+
`access_control_routes` tables or any `ac:*` Redis key directly — all policy and
|
|
90
|
+
role writes go through the injected `AccountsAdminServices`
|
|
91
|
+
(`apply_role` / `remove_policy` / `set_user_disabled`).
|
|
92
|
+
|
|
93
|
+
## HTTP surface
|
|
94
|
+
|
|
95
|
+
Public (`/api/login/*`, always-public prefix):
|
|
96
|
+
|
|
97
|
+
| Route | Does |
|
|
98
|
+
|---|---|
|
|
99
|
+
| `POST /api/login/password` | Verify email + password, mint a session. Failures-only throttling; uniform 401; argon2 verify on every attempt (503 load-shed under a hash flood). |
|
|
100
|
+
| `POST /api/login/bootstrap` | Create the first owner behind the secure-by-default gate. |
|
|
101
|
+
| `POST /api/login/invite/accept` | Consume an invite, set the first password, mint a session. |
|
|
102
|
+
|
|
103
|
+
Authed (`/api/auth/users*`, reserved prefix, admin-fenced by the seeded role
|
|
104
|
+
conditions — except `PUT /users/me/password`, self-service):
|
|
105
|
+
|
|
106
|
+
| Route | Does |
|
|
107
|
+
|---|---|
|
|
108
|
+
| `GET /api/auth/users` | List accounts (never a hash, never a token). |
|
|
109
|
+
| `POST /api/auth/users` | Create a user with a NULL password and a one-time invite. |
|
|
110
|
+
| `PUT /api/auth/users/{user_id}` | Change role and/or disabled state (credentials-die-first on disable; last-admin guard). |
|
|
111
|
+
| `DELETE /api/auth/users/{user_id}` | Delete a user (policy first, then plugin rows; last-admin guard). |
|
|
112
|
+
| `POST /api/auth/users/{user_id}/invite` | Regenerate the invite (only while the password is unset). |
|
|
113
|
+
| `PUT /api/auth/users/me/password` | Change your own password; every OTHER session is revoked. |
|
|
114
|
+
|
|
115
|
+
Logout is NOT here — the skeleton owns the single `POST /api/auth/logout`
|
|
116
|
+
dispatcher; this plugin contributes `revoke_session`.
|
|
117
|
+
|
|
118
|
+
## Configuration
|
|
119
|
+
|
|
120
|
+
All from the plugin's own `TAI_ACCOUNTS_*` namespace (the plugin never reads
|
|
121
|
+
skeleton config):
|
|
122
|
+
|
|
123
|
+
| Env var | Default | Meaning |
|
|
124
|
+
|---|---|---|
|
|
125
|
+
| `TAI_ACCOUNTS_PG_PG_HOST` / `_PG_PORT` / `_PG_DB` / `_PG_USER` / `_PG_PASSWORD` | `localhost` / `5432` / `tai` / `postgres` / (empty) | Postgres connection for the plugin's tables. |
|
|
126
|
+
| `TAI_ACCOUNTS_SESSION_IDLE_SECONDS` | `86400` | Sliding-idle session expiry. |
|
|
127
|
+
| `TAI_ACCOUNTS_SESSION_ABSOLUTE_SECONDS` | `2592000` | Absolute session cap from mint. |
|
|
128
|
+
| `TAI_ACCOUNTS_INVITE_TTL_SECONDS` | `259200` | Invite validity from mint. |
|
|
129
|
+
| `TAI_ACCOUNTS_LOGIN_BACKOFF_THRESHOLD` | `5` | Consecutive per-account failures before backoff. |
|
|
130
|
+
| `TAI_ACCOUNTS_LOGIN_BACKOFF_CAP_SECONDS` | `900` | Max per-account backoff lock. |
|
|
131
|
+
| `TAI_ACCOUNTS_LOGIN_IP_MAX_ATTEMPTS` | `30` | Per-IP failed attempts per window. |
|
|
132
|
+
| `TAI_ACCOUNTS_LOGIN_IP_WINDOW_SECONDS` | `900` | Per-IP fixed window. |
|
|
133
|
+
| `TAI_ACCOUNTS_LOGIN_HASH_CONCURRENCY` | `2 × CPU count` | Max concurrent argon2 verifies (load-shed above). |
|
|
134
|
+
| `TAI_ACCOUNTS_LOGIN_HASH_WAIT_SECONDS` | `2.0` | Wait before a login sheds with 503 under hash saturation. |
|
|
135
|
+
| `TAI_ACCOUNTS_BOOTSTRAP_TOKEN` | (unset) | Operator-supplied first-owner token; overrides the auto-token. |
|
|
136
|
+
| `TAI_ACCOUNTS_BOOTSTRAP_OPEN` | `false` | Local/dev opt-out that DISABLES the gate (never the default). |
|
|
137
|
+
| `TAI_ACCOUNTS_REDIS_KEY_PREFIX` | = `pg_db` | Per-deployment Redis namespace (derived from `pg_db` when unset). |
|
|
138
|
+
|
|
139
|
+
**First-owner bootstrap gate (secure by default).** With neither
|
|
140
|
+
`TAI_ACCOUNTS_BOOTSTRAP_TOKEN` nor `TAI_ACCOUNTS_BOOTSTRAP_OPEN` set, the gate is
|
|
141
|
+
ON and the effective token is auto-generated ONCE at startup and printed to the
|
|
142
|
+
server log. It is shared across all processes through Redis (`SET NX`): the first
|
|
143
|
+
worker or replica to start wins the write and logs it; every other process reads
|
|
144
|
+
the same value — so the default gate is deterministic under BOTH multiple uvicorn
|
|
145
|
+
workers AND multiple replicas, with no explicit token. An explicit
|
|
146
|
+
`TAI_ACCOUNTS_BOOTSTRAP_TOKEN` still overrides it. `TAI_ACCOUNTS_BOOTSTRAP_OPEN=true`
|
|
147
|
+
is the only ungated configuration and logs a loud open-window warning every boot
|
|
148
|
+
while no owner exists.
|
|
149
|
+
|
|
150
|
+
> **Shared Redis / shared `pg_db`:** two deployments that share one Redis AND one
|
|
151
|
+
> `pg_db` must set distinct `TAI_ACCOUNTS_REDIS_KEY_PREFIX` values, or they will
|
|
152
|
+
> cross-read each other's rate-limit counters and bootstrap token.
|
|
153
|
+
|
|
154
|
+
> **Proxies:** the per-IP throttle reads the direct peer — there is no
|
|
155
|
+
> `X-Forwarded-For` parsing. A deployment behind a shared proxy must throttle at
|
|
156
|
+
> its ingress, or all callers collapse to one throttled IP.
|
|
157
|
+
|
|
158
|
+
## Schema apply + startup guard
|
|
159
|
+
|
|
160
|
+
The plugin cannot ride the skeleton's `tai db` CLI (it never imports the
|
|
161
|
+
skeleton), so it applies its own DDL:
|
|
162
|
+
|
|
163
|
+
```bash
|
|
164
|
+
python -m tai42_accounts_postgres.db apply # create the three tables (idempotent)
|
|
165
|
+
python -m tai42_accounts_postgres.db tables # list the tables the DDL declares
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
`apply` connects through `TAI_ACCOUNTS_PG_*`. The provider's boot healthcheck
|
|
169
|
+
verifies the schema exists and, if it is missing, fails startup loudly naming the
|
|
170
|
+
apply command above — it NEVER auto-applies.
|
|
171
|
+
|
|
172
|
+
The accounts kind requires access control ENABLED. If the routes are mounted while
|
|
173
|
+
`ACCESS_CONTROL_ENABLE=false` (so the provider is never instantiated and the admin
|
|
174
|
+
services are never injected), boot fails loudly rather than serving a broken door.
|
|
175
|
+
|
|
176
|
+
## Deployment wiring
|
|
177
|
+
|
|
178
|
+
In the deployment manifest:
|
|
179
|
+
|
|
180
|
+
```yaml
|
|
181
|
+
lifecycle_modules: ["tai42_accounts_postgres"] # provider registration
|
|
182
|
+
routers_modules: ["tai42_accounts_postgres.routes_login",
|
|
183
|
+
"tai42_accounts_postgres.routes_users"] # the HTTP surface
|
|
184
|
+
studio_plugins: ["tai42_accounts_postgres"] # the users-admin UI
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
and in access control (example alongside the api-key provider):
|
|
188
|
+
|
|
189
|
+
```
|
|
190
|
+
ACCESS_CONTROL_ENABLE=true
|
|
191
|
+
ACCESS_CONTROL_AUTH_PROVIDERS=["accounts-postgres","redis"]
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
## Security model
|
|
195
|
+
|
|
196
|
+
- **argon2id** password hashing (RFC 9106 library defaults), with
|
|
197
|
+
rehash-on-login so parameter upgrades propagate without a migration.
|
|
198
|
+
- **Hashed at rest:** session and invite tokens are stored only as their SHA-256
|
|
199
|
+
hash; the raw token appears exactly once, in the response that mints it.
|
|
200
|
+
- **Uniform login failure:** unknown email and wrong password return a
|
|
201
|
+
byte-identical generic 401, and BOTH run a real argon2 verify (a dummy-hash
|
|
202
|
+
verify on unknown email) so timing does not enumerate users.
|
|
203
|
+
- **Failures-only rate limiting:** a correct password is never blocked — only a
|
|
204
|
+
failed attempt records against the per-account and per-IP counters (the per-IP
|
|
205
|
+
dimension reads the direct peer; proxied deployments throttle at ingress). The
|
|
206
|
+
argon2 verify is additionally bounded by a concurrency semaphore that sheds
|
|
207
|
+
with a 503 under a hash flood. Redis being down fails the throttle CLOSED.
|
|
208
|
+
- **No-email invites:** the plugin returns an origin-relative `login_path` for the
|
|
209
|
+
admin to hand over; it never sends email and never fabricates an absolute URL.
|
|
210
|
+
- **Secure-by-default bootstrap:** the first-owner gate is ON by default via an
|
|
211
|
+
auto-generated one-time token (shared across processes through Redis), compared
|
|
212
|
+
constant-time; the only open configuration is explicit and logs a loud warning.
|
|
213
|
+
|
|
214
|
+
Invite and session tokens are **shown once** — the create/regenerate response is
|
|
215
|
+
the only place the raw invite link or session token appears.
|
|
216
|
+
|
|
217
|
+
## Requirements
|
|
218
|
+
|
|
219
|
+
Requires **Python 3.13+**, a Postgres reachable through `TAI_ACCOUNTS_PG_*`, and a
|
|
220
|
+
Redis reachable through the injected access-control Redis. Apply the schema with
|
|
221
|
+
`python -m tai42_accounts_postgres.db apply` before first serve; a missing schema is
|
|
222
|
+
caught loudly at boot.
|
|
223
|
+
|
|
224
|
+
## Install
|
|
225
|
+
|
|
226
|
+
Nothing is on PyPI yet, so install from source — clone this repo and add it as an
|
|
227
|
+
editable dependency of the environment that runs the server:
|
|
228
|
+
|
|
229
|
+
```bash
|
|
230
|
+
git clone https://github.com/tai42ai/tai-accounts-postgres
|
|
231
|
+
cd tai-skeleton # or your own app checkout
|
|
232
|
+
uv add --editable ../tai-accounts-postgres # once published: uv add tai42-accounts-postgres
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
## Development
|
|
236
|
+
|
|
237
|
+
```bash
|
|
238
|
+
uv sync --extra dev
|
|
239
|
+
uv run ruff check .
|
|
240
|
+
uv run ruff format --check .
|
|
241
|
+
uv run pyright
|
|
242
|
+
uv run pytest
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
`[tool.uv.sources]` resolves `tai42-contract` and `tai42-kit` from sibling checkouts
|
|
246
|
+
for local development; the published wheel floors them from the index.
|
|
247
|
+
|
|
248
|
+
## License
|
|
249
|
+
|
|
250
|
+
Apache-2.0. See `LICENSE` and `NOTICE`.
|