Skip to content

Replace S3 presigned urls in favor of Cloudfront#29

Open
GianniCarlo wants to merge 1 commit into
mainfrom
feat/cloudfront-urls
Open

Replace S3 presigned urls in favor of Cloudfront#29
GianniCarlo wants to merge 1 commit into
mainfrom
feat/cloudfront-urls

Conversation

@GianniCarlo

Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 CloudFrontService for issuing signed CloudFront URLs and wire it into LibraryService download URL generation with S3 fallback.
  • Add ConfigService + ConfigDB to read a new use_cloudfront_downloads config 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 thread src/config/envs.ts
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" }
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.

2 participants