Repository navigation
feat(files): file providers per file config - #287
Conversation
|
Disclaimer: This comment was AI-generated and is not necessarily completely accurate. Please take code comments with a grain of salt.
[Critical impact] Provider credential management now follows project boundaries across the file workflows. Fix the migration’s live-write race before merging. Findings
SummaryThis PR gives each file config its own providers and scopes provider routes to the caller’s project and environment.
Checklist improvement: Handle live writes during the migration before merging. Score: 85/100. rgodha24 explicitly identifies the Static review only; tests and lint were not run.
|
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
FileProvidernow has an autoincrementidPK.nameis a normal column, andconfigId+configEnvFK toFileServiceConfig(onDelete: Cascade), with@@unique([name, configId, configEnv]).FileServiceBucketpoints 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.FileProvidergainsid,config_id,config_env. Get/create/update/delete/register/remove requests carry the config. NewgetProvidersByConfigIdon bothFileProviderDbServiceandFileProviderFileService.@ProjectId()resolves the project (API key project, orx-project-idchecked againstx-user-jwt), and the config is(projectId, apiKey.environment)because a file config's id is its project id.POST /file/providerregisters into the caller's config. It returns 400 with a clear message if file services aren't set up yet.GET /file/provider/config/:configIdis new. It returns 403 unlessconfigIdis the caller's project.DELETE /file/provider/:nameonly deletes within the caller's config.GET /file/provider/allis now superadmin only (superadminx-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 protobufLong, and in an int32 field that would silently encode as 0.toConfigIdnormalizes it.Migration / backfill
20261117230000_file_provider_per_config:id SERIALand add nullableconfigId/configEnv./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 toNOT NULL.Deploy note: ship the dashboard PR at the same time. The current dash calls
/all, which now returns 403.Not in this PR
/file/bucket,/file/upload,/file/download, and/file/deletestill takeconfigIdfrom the request body without checking it against the caller's project. That was already true before. Now a caller can only reach a provider that belongs to the config it names, but it can still name another project's config. Worth a separate fix for the same reason as this one.Test plan
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 isFAILED_PRECONDITION, missing env isINVALID_ARGUMENT.file_provider: register is linked to the config,getProvidersByConfigIdworks, remove fails through another config.file_provider, against two projects with configs plus one without:x-user-jwt+x-project-idreturns 200 for a linked project and 401 for an unlinked one/allreturns 403 for non-superadmins and 200 for a superadmin(0, prod).file_serviceexpects the provider register to fail (400) when the config was never set up.format:checkpasses,lintpasses, andtscpasses 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.file_provider+project_idspecs pass. Infile_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.prisma migrate diff.