Skip to content

feat(files): file providers per file config - #287

Merged
rgodha24 merged 3 commits into
mainfrom
rohan/file-provider-per-config
Nov 17, 2026
Merged

rgodha24 merged 3 commits into
mainfrom
rohan/file-provider-per-config

Conversation

@rgodha24

@rgodha24 rgodha24 commented Nov 17, 2026 •

Copy link
Copy Markdown
Member
clank context (clickme)

Fixes #244. Follow-ups: GTBitsOfGood/juno-sdk#88, GTBitsOfGood/juno-dashboard#113.

What was wrong

File providers sat in one global namespace keyed by name. Any API key could list every provider with its credentials (GET /file/provider/all), overwrite another team's provider by registering the same name (create was an upsert), or delete it (DELETE /file/provider/:name).

Fix

  • Schema: FileProvider now has an autoincrement id PK. name is a normal column, and configId + configEnv FK to FileServiceConfig (onDelete: Cascade), with @@unique([name, configId, configEnv]). FileServiceBucket points at the provider through (fileProviderName, configId, configEnv), so the DB guarantees a bucket can only use a provider from its own config. Every proto field and request shape that references providers by name keeps working.
  • Proto: FileProvider gains id, config_id, config_env. Get/create/update/delete/register/remove requests carry the config. New getProvidersByConfigId on both FileProviderDbService and FileProviderFileService.
  • file-service: every provider lookup (bucket register/remove/list, upload, download, delete) passes the bucket's/request's config.
  • gateway: routes are scoped the same way as the email/analytics routes. @ProjectId() resolves the project (API key project, or x-project-id checked against x-user-jwt), and the config is (projectId, apiKey.environment) because a file config's id is its project id.
    • POST /file/provider registers into the caller's config. It returns 400 with a clear message if file services aren't set up yet.
    • GET /file/provider/config/:configId is new. It returns 403 unless configId is the caller's project.
    • DELETE /file/provider/:name only deletes within the caller's config.
    • GET /file/provider/all is now superadmin only (superadmin x-user-jwt), otherwise 403. Breaking change for anyone who listed all providers. The dash moves to the by-config route in the follow-up PR.
    • @ProjectId() can return the API key's project id as a protobuf Long, and in an int32 field that would silently encode as 0. toConfigId normalizes it.

Migration / backfill

20261117230000_file_provider_per_config:

  1. Swap the PK to id SERIAL and add nullable configId/configEnv.
  2. For each provider, insert one copy into every config that has a bucket using it, then delete the unowned original. Every existing bucket keeps resolving to an identical provider, so prod uploads/downloads/deletes behave exactly as before. A provider that several projects share becomes one copy per project, which is the ownership model we want anyway.
  3. Providers that no bucket uses can't be attributed to any project. They're kept with a NULL config instead of deleted: hidden from every project-scoped route, visible to a superadmin through /all, and nobody loses credentials. That's the only reason the columns are nullable. Once someone has looked at the orphans in prod (select id, name from "FileProvider" where "configId" is null) and assigned or dropped them, a follow-up can tighten the columns to NOT NULL.
  4. Add the unique index and both FKs.

Deploy note: ship the dashboard PR at the same time. The current dash calls /all, which now returns 403.

Not in this PR

Test plan

  • New e2e tests:
    • db-service file_provider: id/config returned on create, same name allowed in two configs, by-config listing returns only that config, cross-config get and delete fail, missing config is FAILED_PRECONDITION, missing env is INVALID_ARGUMENT.
    • file-service file_provider: register is linked to the config, getProvidersByConfigId works, remove fails through another config.
    • gateway file_provider, against two projects with configs plus one without:
      • register links to the key's project and returns 400 when the project has no config
      • by-config listing returns only that project's providers
      • another project's config returns 403
      • x-user-jwt + x-project-id returns 200 for a linked project and 401 for an unlinked one
      • re-registering a name in B doesn't touch A
      • B can't delete A's provider
      • own delete works
      • /all returns 403 for non-superadmins and 200 for a superadmin
  • Existing provider fixtures in the bucket/upload/download/delete specs now pass the seed config (0, prod). file_service expects the provider register to fail (400) when the config was never set up.
  • Ran on tesser:
    • format:check passes, lint passes, and tsc passes for every package touched. analytics-service tsc fails on the box from a shared prisma client generated for a different schema, which this PR doesn't change.
    • pnpm test:e2e:db-service: 9/9 suites, 87/87 tests.
    • gateway file_provider + project_id specs pass. In file_bucket, the 2 tests that create real Backblaze buckets fail on tesser because the box has no S3 secrets. CI has them and covers those tests plus the file-service suite.
  • Not run against a copy of prod data. The backfill SQL was checked against the schema with prisma migrate diff.

@greptile-apps

greptile-apps Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Disclaimer: This comment was AI-generated and is not necessarily completely accurate. Please take code comments with a grain of salt.

RetriggerView in GreptileConfidence Score: 4/5

[Critical impact] Provider credential management now follows project boundaries across the file workflows.

Fix the migration’s live-write race before merging.

Findings

  1. P1 Backfill races live bucket creation ▶

Summary

This PR gives each file config its own providers and scopes provider routes to the caller’s project and environment.

  • Each file provider belongs to one project's file config.
  • Provider routes use the caller's project and environment.
  • File operations find providers through the matching config.

Checklist improvement: Handle live writes during the migration before merging. Score: 85/100.

rgodha24 explicitly identifies the /all dashboard break as intentional and requires a coordinated release. rgodha24 also defers ownership checks on bucket and file routes, plus SDK and dashboard updates.

Static review only; tests and lint were not run.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[API key and optional user JWT] --> B[Check caller project]
  B --> C[Provider route]
  C --> D[Config ID and key environment]
  D --> E[Scoped provider query]
  F[Bucket config and provider name] --> E
  E --> G[Storage provider]
Loading

Reviews (1) · Last reviewed commit: "feat(files): file providers per file con..." · Reviewed by Greptile

@rgodha24
rgodha24 merged commit be88aef into main Nov 17, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Spring 2026] File Provider per File Config

1 participant