Repository navigation
Commit 58940a7
fix(sandbox): report a missing Daytona snapshot permission as 403, not an invalid key (#477)
* fix(sandbox): report a missing Daytona snapshot permission as 403, not an invalid key
Daytona scopes snapshot writes separately from sandbox writes, so an API key can be
entirely valid — able to create sandboxes — and still be refused when TrueForge registers
the release snapshot it clones every sandbox from. That refusal came back as 422 "Daytona
rejected the API key — check the credentials", which points the user at the one thing that
is not wrong. The documented fix is to grant Snapshots (write); the error told them to
replace the key.
The cause is that isDaytonaAuthError treated 401 and 403 as one condition. 401 means the
credentials were not accepted and retrying the same key cannot succeed; 403 means Daytona
authenticated the key and declined the operation. Collapsing them left the PUT handler with
no way to tell "wrong key" from "key missing a permission", so both took the credentials
branch.
isDaytonaAuthError now matches 401 only, and a new isDaytonaPermissionError matches 403.
The settings write maps the permission case to 403 and names write:snapshots in the message,
so the response says which grant is missing rather than implying the key is bad.
putSandboxProviderRoute declares the 403 so the OpenAPI document describes it.
Behaviour change: the forbidden case now answers 403 where it previously answered 422. That
is the correction asked for on the issue. It required updating an existing assertion that
expected 422 for a DaytonaError(403); that test's real subject is that config is not
persisted when the build call fails, and it still asserts the follow-up GET returns 404, so
the coverage is preserved and only the status it waits on moved.
Not addressed here: the report also suggests falling back to running the image directly when
write:snapshots is absent. That decides whether snapshot registration stays mandatory, which
is a product question about the provider's setup contract rather than an error-mapping bug,
and it would change behaviour for keys that work today.
Verified: tests/unit/apis/sandboxProviders.test.ts 13 passed. Full package unit suite 270
passed, 6 failed; those six are LocalSandboxProvider and Code Mode UDS on a Windows host
(unix sockets and 0700 chmod) and fail identically on a clean checkout, which runs 269
passed and the same 6 failed. tsc and eslint clean. The five changed files are Prettier
clean; the repo-wide format:check failure is a CRLF artifact of a Windows checkout and hits
779 files that this change does not touch.
Claude-Session: https://claude.ai/code/session_01XCubdWKdbhQ2vVuDdYu68E
* fix(sandbox): use the review's wording for the Daytona permission error
The 403 body now reads exactly as asked on review:
Daytona denied access: the API key is missing required permissions. Grant
write:sandboxes, write:snapshots, and delete:snapshots on the key in the Daytona
dashboard, then try again.
It names every grant the setup needs and where to add them, instead of only
write:snapshots. Nothing else moved: the 401/403 split, the status mapping, and the
OpenAPI 403 are unchanged. The assertion in tests/unit/apis/sandboxProviders.test.ts
and the changeset text follow the new string.
Verified against a standalone server with the Daytona API pointed at a local stub that
answers POST /snapshots with 403 "Access denied": PUT /api/v1/settings/sandbox-providers
returns 403 with this body, and the Configure Daytona modal renders it as four wrapped
lines above Save, in both light and dark themes, with no truncation or layout shift.
Claude-Session: https://claude.ai/code/session_01Pdf58MEtVwuM2JRD1gxqPt
* remove comment
* fix(sandbox): update error handling for Daytona API key permissions
* fix(sandbox): simplify Daytona API key error message
---------
Co-authored-by: Sujai Kumar Gupta <120925871+thesujai@users.noreply.github.com>
Co-authored-by: thesujai <sujayscience1234@gmail.com>1 parent a3a1395 commit 58940a7
4 files changed
Lines changed: 40 additions & 4 deletions
File tree
- .changeset
- packages/trueforge
- src
- apis
- sandbox
- tests/unit/apis
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
106 | 107 | | |
107 | 108 | | |
108 | 109 | | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
109 | 121 | | |
110 | 122 | | |
111 | 123 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
22 | 26 | | |
23 | 27 | | |
24 | 28 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | | - | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
165 | 166 | | |
166 | 167 | | |
167 | 168 | | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
168 | 183 | | |
169 | 184 | | |
170 | 185 | | |
| |||
0 commit comments