Commit d15bc88
feat(AGX1-263): migrate agent_api_keys routes to FGAC with 404 collapse and two-factor mutations
Mirrors AGX1-275 (PR #249) for agent_api_keys. Wires Spark AuthZ checks
into every api_key route, collapses denials to 404 (so name/id probes
can't distinguish "present in another tenant" from "absent"), and relies
on SpiceDB's transitive expansion of api_key.{update,delete} (= editor &
parent_agent->update & tenant_gate) for two-factor mutations rather than
issuing two explicit checks at the route layer.
- src/utils/agent_api_key_authorization.py (new):
_check_api_key_or_collapse_to_404 — catches AuthorizationError, raises
ItemDoesNotExist. Same shape as Asher's task helper.
- src/utils/authorization_shortcuts.py: DAuthorizedId routes
AgentexResourceType.api_key through the wrap. (DAuthorizedName isn't
used for api_keys; the name lookup is (agent_id, name, api_key_type),
not a single globally-unique path param — the route handlers call the
collapse helper inline instead.)
- src/api/routes/agent_api_keys.py:
* POST: explicit agent.update on parent (no api_key resource yet).
* GET list: DAuthorizedResourceIds + filter; None passes through.
* GET /name/{name}: inline collapse helper.
* GET /{id}: DAuthorizedId(api_key, read).
* DELETE /{id}: DAuthorizedId(api_key, delete). Two-factor via SpiceDB
schema (api_key.delete expands to parent_agent.update); no second
route-layer check.
* DELETE /name/{api_key_name}: inline collapse helper.
- tests/unit/api/test_agent_api_keys_authz.py (new): 12 tests, all pass.
Stacked on dhruv/agx1-272-agent-api-keys-dual-write (PR A). Does NOT
touch dual-write logic. Does NOT modify agentex-auth.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>1 parent 9668f1a commit d15bc88
4 files changed
Lines changed: 504 additions & 0 deletions
File tree
- agentex
- src
- api/routes
- utils
- tests/unit/api
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
10 | 15 | | |
11 | 16 | | |
12 | 17 | | |
13 | 18 | | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
14 | 24 | | |
15 | 25 | | |
16 | 26 | | |
| |||
42 | 52 | | |
43 | 53 | | |
44 | 54 | | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
45 | 65 | | |
46 | 66 | | |
47 | 67 | | |
| |||
81 | 101 | | |
82 | 102 | | |
83 | 103 | | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
84 | 107 | | |
85 | 108 | | |
86 | 109 | | |
| |||
100 | 123 | | |
101 | 124 | | |
102 | 125 | | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
103 | 131 | | |
104 | 132 | | |
105 | 133 | | |
| |||
116 | 144 | | |
117 | 145 | | |
118 | 146 | | |
| 147 | + | |
119 | 148 | | |
120 | 149 | | |
121 | 150 | | |
| |||
139 | 168 | | |
140 | 169 | | |
141 | 170 | | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
142 | 180 | | |
143 | 181 | | |
144 | 182 | | |
| |||
151 | 189 | | |
152 | 190 | | |
153 | 191 | | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
154 | 197 | | |
155 | 198 | | |
156 | 199 | | |
| |||
166 | 209 | | |
167 | 210 | | |
168 | 211 | | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
169 | 217 | | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
170 | 224 | | |
171 | 225 | | |
172 | 226 | | |
| |||
198 | 252 | | |
199 | 253 | | |
200 | 254 | | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
201 | 274 | | |
202 | 275 | | |
203 | 276 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
55 | 56 | | |
56 | 57 | | |
57 | 58 | | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
58 | 65 | | |
59 | 66 | | |
60 | 67 | | |
| |||
0 commit comments