Replace S3 presigned urls in favor of Cloudfront#29
Open
GianniCarlo wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces CloudFront signed URLs for download (GET) access to library objects (replacing S3 presigned URLs) behind a global configs toggle and a per-user allowlist, while keeping uploads (PUT) on S3 presigned URLs.
Changes:
- Add
CloudFrontServicefor issuing signed CloudFront URLs and wire it intoLibraryServicedownload URL generation with S3 fallback. - Add
ConfigService+ConfigDBto read a newuse_cloudfront_downloadsconfig flag (Redis read-through cached). - Add migration + deployment/env updates, plus unit tests for the new flagging/signing behavior.
Reviewed changes
Copilot reviewed 12 out of 13 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
package.json |
Adds @aws-sdk/cloudfront-signer dependency. |
yarn.lock |
Locks new CloudFront signer + smithy deps. |
src/services/LibraryService.ts |
Routes download URL resolution through CloudFront signer with S3 fallback, plus allowlist/global-flag logic. |
src/services/CloudFrontService.ts |
New service to generate CloudFront signed URLs with configurable TTL. |
src/services/ConfigService.ts |
New config flag reader with Redis read-through caching and safe fallbacks. |
src/services/db/ConfigDB.ts |
New DB access layer for configs table reads. |
src/database/migrations/20260607120000_add_use_cloudfront_downloads_config.ts |
Adds new enum value and seeds use_cloudfront_downloads config row. |
src/config/envs.ts |
Adds CloudFront-related env validation. |
docker/ecs/task-definition.json |
Adds CloudFront env + secrets to ECS task definition. |
development.env.template |
Adds CloudFront env placeholders for local development. |
src/__tests__/services/LibraryServiceDownloadUrl.test.ts |
Tests CloudFront vs S3 decision logic + fallback behavior. |
src/__tests__/services/ConfigService.test.ts |
Tests config caching, type mismatch handling, and fail-safe behavior. |
src/__tests__/services/CloudFrontService.test.ts |
Tests signing output shape, path encoding, and TTL behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+45
to
+49
| .prop('CLOUDFRONT_URL', S.string().required()) | ||
| .prop('CLOUDFRONT_KEY_PAIR_ID', S.string().required()) | ||
| .prop('CLOUDFRONT_PRIVATE_KEY', S.string().required()) | ||
| .prop('CLOUDFRONT_ALLOWLIST', S.string()) | ||
| .prop('CLOUDFRONT_EXPIRY_SECONDS', S.string()) |
Comment on lines
+51
to
+54
| const useCloudFront = | ||
| this.isCloudFrontAllowlisted(user) || | ||
| (await this._config.getBoolean(ConfigKey.UseCloudFrontDownloads)); | ||
| if (useCloudFront) { |
Comment on lines
+45
to
+47
| { "name": "CLOUDFRONT_URL", "value": "https://library.bookplayer.app" }, | ||
| { "name": "CLOUDFRONT_ALLOWLIST", "value": "29" }, | ||
| { "name": "CLOUDFRONT_EXPIRY_SECONDS", "value": "120" } |
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.
No description provided.