refactor(auth): remove bot owner linkage and enforce bot-level permissions

This commit is contained in:
2026-04-03 13:21:03 +00:00
parent 6998936858
commit aeb4f10fd0
12 changed files with 104 additions and 43 deletions
+3 -3
View File
@@ -363,8 +363,8 @@ curl -X POST "http://localhost:8000/auth/bots" \
-H "Authorization: Bearer <ADMIN_TOKEN>" \
-H "Content-Type: application/json" \
-d '{
"owner_user_id": "user-1",
"name": "market-bot",
"permission": "trade-write",
"description": "External trading bot"
}'
```
@@ -374,8 +374,8 @@ Response 201:
```json
{
"id": "bot-1",
"owner_user_id": "user-1",
"name": "market-bot",
"permission": "trade-write",
"description": "External trading bot",
"is_active": true,
"created_at": "2026-04-03T00:00:00Z",
@@ -466,8 +466,8 @@ Response 200:
```json
{
"id": "bot-1",
"owner_user_id": "user-1",
"name": "market-bot",
"permission": "trade-write",
"description": "External trading bot",
"is_active": false,
"created_at": "2026-04-03T00:00:00Z",
+4 -2
View File
@@ -5,7 +5,7 @@
This document defines the database schema in an AI-agent-friendly format.
- Source of truth: Alembic revisions in `migrations/versions`
- Current baseline revision: `20260403_0006`
- Current baseline revision: `20260403_0007`
- Baseline files:
- `migrations/versions/20260403_0001_initial_portfolio_schema.py`
- `migrations/versions/20260403_0002_strategy_set_columns.py`
@@ -13,6 +13,7 @@ This document defines the database schema in an AI-agent-friendly format.
- `migrations/versions/20260403_0004_users_table.py`
- `migrations/versions/20260403_0005_auth_user_fields_and_tokens.py`
- `migrations/versions/20260403_0006_bot_principals_and_bot_tokens.py`
- `migrations/versions/20260403_0007_bot_principal_permission_only.py`
## 2. Scope
@@ -101,8 +102,8 @@ Columns:
| Column | Type | Null | Default | Constraints / Notes |
|---|---|---|---|---|
| id | Text | NO | - | Primary Key |
| owner_user_id | Text | NO | - | Logical owner reference to users.id |
| name | Text | NO | - | Unique bot name |
| permission | Text | NO | - | Bot permission ceiling |
| description | Text | YES | - | Optional operator description |
| is_active | Boolean | NO | TRUE | When false, bot tokens are rejected |
| created_at | DateTime(timezone=True) | NO | NOW() | Creation timestamp |
@@ -292,3 +293,4 @@ When schema changes:
| 20260403_0004 | migrations/versions/20260403_0004_users_table.py | Add `users` table with unique username/email and created_at index |
| 20260403_0005 | migrations/versions/20260403_0005_auth_user_fields_and_tokens.py | Add password/permission/login fields to `users` and create `auth_tokens` table |
| 20260403_0006 | migrations/versions/20260403_0006_bot_principals_and_bot_tokens.py | Add `bot_principals` table and `auth_tokens.bot_principal_id` for bot API key management |
| 20260403_0007 | migrations/versions/20260403_0007_bot_principal_permission_only.py | Remove `bot_principals.owner_user_id` and enforce bot-local `permission` model |
+2 -2
View File
@@ -441,8 +441,8 @@ Bootstrap rule:
`CreateBotPrincipalRequest`
- `owner_user_id: str`
- `name: str`
- `permission: "read" | "trade-write" | "admin"`
- `description: str | null`
`CreateBotTokenRequest`
@@ -529,8 +529,8 @@ Bootstrap rule:
`BotPrincipalResponse`
- `id: str`
- `owner_user_id: str`
- `name: str`
- `permission: "read" | "trade-write" | "admin"`
- `description: str | null`
- `is_active: bool`
- `created_at: datetime | null`