Repository navigation
feat(attachments): Add S3-compatible attachment storage - #2325
Merged
Merged
Conversation
Add an S3 adapter for attachment storage, chosen with JUNIOR_ATTACHMENT_STORAGE_PROVIDER=s3 and JUNIOR_S3_* settings. The adapter signs requests with aws4fetch and uses path-style URLs, so it works with local S3 servers such as versitygw and with AWS S3. Attachment storage settings move to chat/attachments/config.ts. Chat config keeps the parsed result, and createAttachmentStorage() now takes that config. Vercel Blob stays the default, so deployments that do not set the new variables do not change. Co-Authored-By: Thomas Jiang <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
S3StorageConfig and the JUNIOR_S3_* parsing move into s3.ts, next to the adapter. config.ts now only reads the provider and switches to the provider module for its settings.
Contributor
|
1 screenshot change — 1 changed · 0 added · 0 removed Review screenshots in Frameshift
|
Add a versitygw service to compose.yaml and to the Junior test CI job. The new integration test stores an attachment through S3, serves it from the attachment API, and deletes it during garbage collection. It also checks that rejected credentials fail without exposing the key.
URL parsing removes . and .. segments, also in %2e form. An attachment filename such as ../../artifacts/x.png could make the S3 adapter write or delete an object outside the attachment prefix. The adapter now rejects such keys. The S3 integration test checks that an existing object stays unchanged.
Sentry Evalsjunior-behavioral
Base commit junior-integration
Base commit |
Postgres and Redis keep their data in named volumes. versitygw wrote objects to /tmp in the container, so docker compose down lost them while the attachment rows stayed in Postgres. Co-Authored-By: Thomas Jiang <[email protected]>
thomasjiangcy
approved these changes
Oct 29, 2026
thomasjiangcy
enabled auto-merge (squash)
October 29, 2026 06:04
thomasjiangcy
added a commit
that referenced
this pull request
Oct 29, 2026
Local dev now stores attachments and published images in the compose `s3` service (versitygw) instead of the shared dev Vercel Blob store. This is the follow-up to #2325. It changes no product code. `apps/example/.env.example` sets `JUNIOR_ATTACHMENT_STORAGE_PROVIDER=s3` and the `JUNIOR_S3_*` values for the compose service. `pnpm dev`, `pnpm cli` and `acp-local` read these as defaults. Deployed apps, tests and evals do not read this file, so production stays on Vercel Blob. The `s3` service now creates the `junior-attachments` bucket at startup. With the posix backend, a bucket is just a folder, so the service runs `mkdir -p` and then the image's normal entrypoint. The command is safe to repeat, so restarts and the named volume keep working. CI is unchanged, because the S3 test creates its own bucket. The README now starts `s3` with `postgres redis` and explains how to opt out. If `s3` is not running, `sendFiles`, `publishImage` and web messages with images fail. To keep using Vercel Blob, set `JUNIOR_ATTACHMENT_STORAGE_PROVIDER=vercel-blob` in `apps/example/.env`. `.env.local` does not work for this, because the env loader lets `.env` override it. Attachments already stored in Blob are not visible after the switch, because reads filter by provider. <!-- junior-request-attribution:start --> via @thomasjiangcy. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:slack%3AC0CCUMX7ET0%3A1793248918.684709 --> -- [View Junior Session](https://junior-prod.sentry.dev/conversations/slack%3AC0CCUMX7ET0%3A1793248918.684709) [[Sentry]](https://sentry.sentry.io/explore/conversations/slack%3AC0CCUMX7ET0%3A1793248918.684709/?project=4510944073809921) <!-- junior-session-footer:end --> --------- Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: Thomas Jiang <[email protected]>
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is the second step toward local object storage, after #2324. It adds an S3 adapter for attachment storage, and a
versitygwS3-compatible server incompose.yamland CI to test it.What changes
chat/attachments/s3.ts: a new adapter that implementsAttachmentStoragewith three requests.putis a PUT,getis a GET (a 404 returnsnull), anddeletesends one DELETE for each key (a 404 counts as deleted). It signs requests withaws4fetchand uses path-style URLs (<endpoint>/<bucket>/<key>), so it works with local S3 servers and with AWS S3. The storedstorage_providervalue iss3.chat/attachments/config.ts: new. It readsJUNIOR_ATTACHMENT_STORAGE_PROVIDERand switches to the provider module for its settings.s3.tsownsS3StorageConfigand reads theJUNIOR_S3_*settings itself:JUNIOR_ATTACHMENT_STORAGE_PROVIDER:vercel-blob(the default) ors3JUNIOR_S3_ENDPOINT,JUNIOR_S3_BUCKET,JUNIOR_S3_ACCESS_KEY_ID,JUNIOR_S3_SECRET_ACCESS_KEY: required fors3JUNIOR_S3_REGION: optional, defaults tous-east-1An invalid provider or a missing S3 setting fails at config load, the same way an invalid
JUNIOR_DATABASE_DRIVERdoes.createAttachmentStorage()now takes the wholeattachmentStorageconfig, not only the provider name, and switches to the S3 adapter fors3. The four entry points passgetChatConfig().attachmentStorage.I moved the attachment storage types and parsing out of
chat/config.tsand intochat/attachments/. Provider-specific settings stay in their provider module.chat/config.tsstays under the 1,000-line limit.Key safety: the adapter rejects keys with
.or..segments. URL parsing removes them (also in%2eform), so a filename like../../artifacts/x.pngcould otherwise write or delete an object outside the attachment prefix.Tests:
compose.yamland the Junior test CI job get ans3service (versity/versitygw:v1.10.0, host port 7072).tests/integration/attachment-s3-storage.test.tsruns against it: it stores an attachment with symbols in the filename, serves it from the attachment API, deletes it during garbage collection, rejects a path-traversal filename without changing the target object, and checks that rejected credentials fail without showing the key. Run it locally withdocker compose up -d s3.Docs: new rows in
reference/config-and-env.mdand an update to the attachmentsREADME.md.Dependency:
aws4fetch@^1.0.20, added as a direct dependency. It was already in the lockfile as an optional peer ofunstorage. pnpm also rewrote two unrelated snapshot lines inpnpm-lock.yaml.Behavior: nothing changes unless
JUNIOR_ATTACHMENT_STORAGE_PROVIDER=s3is set. Vercel Blob stays the default.Error messages: S3 errors give only the operation and HTTP status, for example
S3 put failed with status 403. Object keys and S3 error bodies can contain user filenames, so the messages leave them out.Checks run
tsc --noEmitand the full rootpnpm lint: file length, migration metadata, test architecture, oxlint, depcruise, ast-grep, and package lint.vitest run: the config tests (with four new cases), the artifact, retention, send-files, and load-attachment tests, and every test that usesreadChatConfig. Against the local compose Postgres, 300 tests passed.tests/integration/attachment-s3-storage.test.tsagainst the composeversitygwservice: 3 passed. Without the dot-segment check, the traversal case fails because the target object is overwritten.versitygwv1.10.0 container, with a scratch test that I did not commit:é,+,#, and?; the file appeared on disknullpublishImageand the public artifact route work end to end with real SQLNotes
response.body.cancel()hangs under the test MSW interceptor. The adapter reads small response bodies to the end instead. The S3 integration test runs under the same interceptor.--
View Junior Session [Sentry]