Repository navigation
feat: attachments through a feedback-uploads service - #38
Conversation
CRDs can't take file uploads, so feedback-uploads accepts them with the caller's Milo token: a TokenReview says who they are and a SubjectAccessReview whether they may create (or get) the resource in the context they name. Files are type-checked and stored per user and purpose. The attachments webhook checks each uploadRef is the owner's upload and sets its name and type; the operator copies attached files under the submission, with a finalizer that deletes them with it.
Register gocloud's s3blob driver, so --attachments-bucket accepts s3://BUCKET URLs, with endpoint, region and use_path_style for stores outside AWS such as Cloudflare R2 or MinIO. Add the s3-attachments kustomize component, which gives the operator and feedback-uploads credentials from the feedback-attachments-s3 Secret. Run the attachment store tests against an in-process S3-compatible fake as well as memory, and against FEEDBACK_TEST_S3_URL when it is set.
|
Please address before exposing the public route: downloads load the whole file into memory, and Stream downloads instead, use timeouts that do not buffer the response, and cap concurrent transfers. This is a production-readiness follow-up to the approval, not a cross-user access issue. |
…tHandler Downloads now stream from the bucket to the client instead of reading the whole file into memory, and http.TimeoutHandler, which buffered every reply again, is replaced by connection deadlines: ReadHeaderTimeout, ReadTimeout, WriteTimeout and IdleTimeout on the server, extended per transfer with http.ResponseController to a deadline sized for the file (30s plus the file at 64 KiB/s), with a matching context deadline on the bucket read or write. Uploads and downloads each take a slot from a per-replica semaphore (--max-concurrent-uploads, default 4; --max-concurrent-downloads, default 32) and get 503 with Retry-After when none is free. Uploads still buffer, up to the size limit via MaxBytesReader, because Check needs the bytes. The Deployment sets GOMEMLIMIT under its 256Mi limit.
feedback-uploads never bound the zap flags, so --zap-encoder=json from its Deployment made it exit with "unknown flag" and crash-loop. Bind them as the operator does, and test that every Deployment's args parse with its command.
# Conflicts: # internal/webhook/submission.go
|
Fixed in 289fbd5, before the public route:
154ef89 fixes a crash loop the kind tests in #42 found: the uploads command didn't bind the zap flags its Deployment passes. A new test parses every Deployment's args against its command. |
The base branch was changed.
|
The memory-exhaustion and startup issues are fixed. One low-severity hardening item remains: transfer limits are shared across each replica, so one signed-in user can occupy all four upload slots with slow requests, temporarily giving other users 503 “busy” responses. Please add a per-user concurrent-transfer limit alongside the replica-wide cap, with a test showing that one user cannot consume all slots. This was previously considered a non-blocking follow-up, not a critical bug; it is the remaining reason the stricter automated review has not renewed approval. |
The replica-wide transfer caps were shared by everyone, so one signed-in user could hold all four upload slots with slow requests and give every other user 503s until their deadlines ran out. Each user may now hold at most --max-concurrent-uploads-per-user (default 2) and --max-concurrent-downloads-per-user (default 8) transfers on a replica. Past that they get 429 with Retry-After, before taking a replica slot or spending rate-limit quota. The service refuses to start with a per-user cap that isn't below the replica's, so one user can never take every slot. TestOneUserCannotTakeEverySlot holds two of one user's uploads open mid-body and checks that user's third gets 429 while another user's upload succeeds.
|
Thanks, added in d8d8c50.
|
Part of #8. Stacked on #37.
CRDs can't take file uploads, so this adds the
feedback-uploadsservice from the design. Submissions and security reports can now carry attachments.feedback uploadsA new command and Deployment. Clients send the same bearer token they use for Milo.
TokenReview, made assystem:feedback-uploads@feedback.miloapis.com.SubjectAccessReviewfor create (upload) or get (download) on that resource. For the user paths it carries the same parent extras Milo adds in a user's own context.spec.userRef.--attachment-max-size). Each user gets a per-minute limit (--uploads-per-minute,--uploads-burst; in memory, per replica). Unverified emails are refused.Content-Disposition: attachment,nosniff, a sandboxing CSP, andno-store.Admission and the operator
attachmentsmutating webhook, on creates of submissions and security reports:uploadRefmust be the caller's own upload for that purpose, in their own user context;submissions/<name>/and adds thefeedback.miloapis.com/attachmentsfinalizer. On delete it removes the files, then the finalizer. Downloads fall back to the original upload until the copy exists.uploads/after a day.Config
config/base/uploads: Deployment, Service and ServiceAccount.feedback-configConfigMap: holdsattachments-bucket, shared with the operator (mem://in base).milo-integration: mounts the uploads client certificate, trust bundle and Milo kubeconfig.update/patchon submissions, for the finalizer only.The public route, the GCS bucket, its lifecycle rule and workload identity are deployment work (#13).
Not covered
Tests
mem://:task test,go vet ./...,task generatewith no diff, andkustomize buildof base and overlay