Skip to content

fix: enhance S3 configuration with region fallback and improved logging#40182

Open
abbiekuma wants to merge 2 commits intoRocketChat:developfrom
abbiekuma:fix/issue-40098
Open

fix: enhance S3 configuration with region fallback and improved logging#40182
abbiekuma wants to merge 2 commits intoRocketChat:developfrom
abbiekuma:fix/issue-40098

Conversation

@abbiekuma
Copy link
Copy Markdown

@abbiekuma abbiekuma commented Apr 16, 2026

Summary

After Rocket.Chat switched the S3 integration to AWS SDK v3, uploads to custom S3-compatible endpoints (notably Cloudflare R2) started failing with “Region is missing” because the client always needs a region for signing, but when Region was left empty the app did not pass a region into the S3 client (and AWS_DEFAULT_REGION did not help in this setup), whereas SDK v2 had been more forgiving; the practical workaround was to set R2’s region to auto.

Proposed changes

  • Admin / settings: Set the package default for FileUpload_S3_Region to us-east-1 and add an i18nDescription so the Region field shows guidance for MinIO, Cloudflare R2, and real AWS regions.
  • i18n: Add FileUpload_S3_Region_desc in English with that guidance.
  • S3 client config: Trim FileUpload_S3_Region and FileUpload_S3_BucketURL. If region is empty after trim but a custom bucket URL is set, default the AWS SDK v3 client region to us-east-1 (fixes “Region is missing” for R2/MinIO-style endpoints). Log an info line when this fallback is used. Leave region unset when there is no custom URL so vanilla AWS behavior is unchanged.
issue-40098-after.mov

Issue

Closes #40098

Steps to test or reproduce

  1. Go to Admin > Settings > File Upload > Storage Type: AmazonS3
  2. Set Bucket URL to any non-AWS S3 endpoint (Cloudflare R2 endpoint / minlO)
  3. Leave Region empty or fill any value
  4. Try to upload a file

Summary by CodeRabbit

  • New Features

    • Added a user-facing description for the S3 Region setting with guidance for MinIO, Cloudflare R2, and Amazon S3.
  • Bug Fixes

    • S3 Region and Bucket URL inputs now trim surrounding whitespace to prevent misconfiguration.
    • If a custom Bucket URL is provided but Region is left blank, the Region will default to "us-east-1" for more reliable uploads.

- Trimmed whitespace from S3 region and bucket URL settings.
- Added fallback to 'us-east-1' for custom endpoints if region is not set.
- Introduced logging for fallback scenario.
- Updated settings to include description for S3 region.
@abbiekuma abbiekuma requested a review from a team as a code owner April 16, 2026 20:41
@dionisio-bot
Copy link
Copy Markdown
Contributor

dionisio-bot Bot commented Apr 16, 2026

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label
  • This PR is missing the required milestone or project

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 16, 2026

CLA assistant check
All committers have signed the CLA.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 16, 2026

⚠️ No Changeset found

Latest commit: 343a0b4

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 16, 2026

Walkthrough

Trimmed S3 settings values and changed region resolution: use the trimmed FileUpload_S3_Region if non-empty; otherwise, when a trimmed FileUpload_S3_BucketURL is present, set region to us-east-1 and emit an info log. Added an i18n description for the region setting.

Changes

Cohort / File(s) Summary
S3 Configuration Logic
apps/meteor/app/file-upload/server/config/AmazonS3.ts
Use SystemLogger; trim FileUpload_S3_Region and FileUpload_S3_BucketURL; compute resolvedRegion (use trimmed region if non-empty; else if trimmed BucketURL present set 'us-east-1' and log info); use trimmed BucketURL for endpoint.
Settings & Localization
apps/meteor/server/settings/file-upload.ts, packages/i18n/src/locales/en.i18n.json
Add i18nDescription (FileUpload_S3_Region_desc) to the FileUpload_S3_Region setting and add the corresponding English translation key/value.

Sequence Diagram(s)

sequenceDiagram
    participant AdminSettings
    participant ConfigLoader
    participant SystemLogger
    participant S3Client

    AdminSettings->>ConfigLoader: provide FileUpload_S3_Region, FileUpload_S3_BucketURL
    ConfigLoader->>ConfigLoader: trim Region and BucketURL
    alt trimmed Region non-empty
        ConfigLoader->>S3Client: set region = trimmed Region, endpoint = trimmed BucketURL
    else trimmed Region empty and trimmed BucketURL present
        ConfigLoader->>SystemLogger: info("using us-east-1 for custom endpoint")
        ConfigLoader->>S3Client: set region = "us-east-1", endpoint = trimmed BucketURL
    else neither present
        ConfigLoader->>S3Client: set region = trimmed Region (empty) / default behavior
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Suggested labels

type: bug

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed All coding objectives from #40098 are met: region trimming and fallback to 'us-east-1' when empty, logging added, guidance provided via i18n, and custom endpoint handling restored.
Out of Scope Changes check ✅ Passed All changes directly address #40098 requirements: S3 config updates, i18n descriptions, and region fallback logic. No unrelated or extraneous changes detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title accurately summarizes the main change: adding a region fallback mechanism and improved logging for S3 configuration to fix uploads to S3-compatible endpoints.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@abbiekuma abbiekuma changed the title feat: enhance S3 configuration with region fallback and improved logging fix(issue-40098): enhance S3 configuration with region fallback and improved logging Apr 16, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
apps/meteor/server/settings/file-upload.ts (1)

160-167: ⚠️ Potential issue | 🟡 Minor

Default region now applies to all AWS S3 setups, not just custom endpoints.

Changing the package default from '' to 'us-east-1' affects fresh installs using real AWS S3 as well, not only custom endpoints (R2/MinIO). For AWS users whose bucket is in another region, the client will now be initialized with us-east-1 instead of being left unset. This should be transparently handled by followRegionRedirects: true in AmazonS3.ts, but it's a subtle behavior change worth confirming — in particular, the fallback/logging branch in AmazonS3.ts (lines 95-102) is now effectively dead for fresh installs because trimmedRegion will be 'us-east-1' by default and the else if (trimmedBucketURL) branch won't be reached unless the admin explicitly clears the region field.

If the intent is to only fall back for custom endpoints, consider keeping the package default as '' and relying solely on the runtime fallback in AmazonS3.ts. Otherwise, the current approach is fine but the info log will rarely fire.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/meteor/server/settings/file-upload.ts` around lines 160 - 167, The
change sets the FileUpload_S3_Region default to 'us-east-1', which causes
trimmedRegion to be non-empty and prevents the custom-endpoint fallback in
AmazonS3.ts from running; either revert the package default for
FileUpload_S3_Region back to '' so real AWS installs without a chosen region
still trigger the runtime fallback in AmazonS3 (keep symbol
FileUpload_S3_Region), or if you want 'us-east-1' as the package default, update
AmazonS3.ts logic (the trimmedRegion / trimmedBucketURL checks and the
followRegionRedirects behavior) to treat the default value as unset for the
purpose of triggering the custom-endpoint fallback and logging (adjust the code
paths referencing trimmedRegion, trimmedBucketURL, and followRegionRedirects
accordingly).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@apps/meteor/server/settings/file-upload.ts`:
- Around line 160-167: The change sets the FileUpload_S3_Region default to
'us-east-1', which causes trimmedRegion to be non-empty and prevents the
custom-endpoint fallback in AmazonS3.ts from running; either revert the package
default for FileUpload_S3_Region back to '' so real AWS installs without a
chosen region still trigger the runtime fallback in AmazonS3 (keep symbol
FileUpload_S3_Region), or if you want 'us-east-1' as the package default, update
AmazonS3.ts logic (the trimmedRegion / trimmedBucketURL checks and the
followRegionRedirects behavior) to treat the default value as unset for the
purpose of triggering the custom-endpoint fallback and logging (adjust the code
paths referencing trimmedRegion, trimmedBucketURL, and followRegionRedirects
accordingly).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c08dd38d-ca46-4390-b43f-0530d6a1f663

📥 Commits

Reviewing files that changed from the base of the PR and between d9f4c86 and 89a2ddc.

📒 Files selected for processing (3)
  • apps/meteor/app/file-upload/server/config/AmazonS3.ts
  • apps/meteor/server/settings/file-upload.ts
  • packages/i18n/src/locales/en.i18n.json
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: cubic · AI code reviewer
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • apps/meteor/server/settings/file-upload.ts
  • apps/meteor/app/file-upload/server/config/AmazonS3.ts
🧠 Learnings (5)
📚 Learning: 2026-04-10T22:42:05.539Z
Learnt from: dougfabris
Repo: RocketChat/Rocket.Chat PR: 40075
File: apps/meteor/client/views/room/modals/FileUploadModal/FileUploadModal.tsx:69-71
Timestamp: 2026-04-10T22:42:05.539Z
Learning: In `apps/meteor/client/views/room/modals/FileUploadModal/FileUploadModal.tsx`, the submit handler converts an empty/whitespace-only description to `undefined` (`description?.trim() || undefined`) intentionally. All downstream image-rendering components (`AttachmentImage`, `ImagePreview`, `ImageItem`, `ImageGallery`) default `undefined` alt to `''`, so the `<img alt="">` attribute is always present. Do not flag this `undefined` conversion as a bug preventing alt text from being cleared.

Applied to files:

  • apps/meteor/server/settings/file-upload.ts
  • apps/meteor/app/file-upload/server/config/AmazonS3.ts
📚 Learning: 2026-03-12T17:12:49.121Z
Learnt from: dougfabris
Repo: RocketChat/Rocket.Chat PR: 39425
File: apps/meteor/client/lib/chats/flows/uploadFiles.ts:28-33
Timestamp: 2026-03-12T17:12:49.121Z
Learning: Rocket.Chat — apps/meteor/client/lib/chats/flows/uploadFiles.ts: When E2E_Enable_Encrypt_Files is disabled, plaintext file uploads are allowed in E2E rooms; this fallback is expected and should not be flagged as a security regression.

Applied to files:

  • apps/meteor/server/settings/file-upload.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.

Applied to files:

  • apps/meteor/server/settings/file-upload.ts
  • apps/meteor/app/file-upload/server/config/AmazonS3.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.

Applied to files:

  • apps/meteor/server/settings/file-upload.ts
  • apps/meteor/app/file-upload/server/config/AmazonS3.ts
📚 Learning: 2025-11-19T12:32:29.696Z
Learnt from: d-gubert
Repo: RocketChat/Rocket.Chat PR: 37547
File: packages/i18n/src/locales/en.i18n.json:634-634
Timestamp: 2025-11-19T12:32:29.696Z
Learning: Repo: RocketChat/Rocket.Chat
Context: i18n workflow
Learning: In this repository, new translation keys should be added to packages/i18n/src/locales/en.i18n.json only; other locale files are populated via the external translation pipeline and/or fall back to English. Do not request adding the same key to all locale files in future reviews.

Applied to files:

  • packages/i18n/src/locales/en.i18n.json
🔇 Additional comments (2)
packages/i18n/src/locales/en.i18n.json (1)

2333-2333: Looks good — clear and correctly scoped i18n guidance.

The new description is concise and gives the exact expected values for MinIO, Cloudflare R2, and Amazon S3, matching the PR intent.

Based on learnings: new translation keys should be added to packages/i18n/src/locales/en.i18n.json only.

apps/meteor/app/file-upload/server/config/AmazonS3.ts (1)

94-102: The fallback branch is reachable for existing installations.

The new default 'us-east-1' applies only to new settings; the add() method preserves existing stored values without modification. Existing installations with an empty-string FileUpload_S3_Region will continue to have trimmedRegion = '' (falsy), making the else if (trimmedBucketURL) fallback reachable as intended. This provides the upgrade safety net you intended.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 3 files

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 2 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="apps/meteor/server/settings/file-upload.ts">

<violation number="1" location="apps/meteor/server/settings/file-upload.ts:160">
P2: Removing the default S3 region can leave standard AWS S3 configs without any resolved region, causing AWS SDK v3 request/signing failures when the region setting is left blank.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread apps/meteor/server/settings/file-upload.ts
…ucket URLs

- Modified the S3 region setting to accept an empty value for custom bucket URLs.
- Updated the description for the S3 region to clarify usage for different storage options.
@abbiekuma abbiekuma changed the title fix(issue-40098): enhance S3 configuration with region fallback and improved logging fix: enhance S3 configuration with region fallback and improved logging Apr 18, 2026
@abbiekuma
Copy link
Copy Markdown
Author

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)

apps/meteor/server/settings/file-upload.ts (1)> 160-167: ⚠️ Potential issue | 🟡 Minor

Default region now applies to all AWS S3 setups, not just custom endpoints.
Changing the package default from '' to 'us-east-1' affects fresh installs using real AWS S3 as well, not only custom endpoints (R2/MinIO). For AWS users whose bucket is in another region, the client will now be initialized with us-east-1 instead of being left unset. This should be transparently handled by followRegionRedirects: true in AmazonS3.ts, but it's a subtle behavior change worth confirming — in particular, the fallback/logging branch in AmazonS3.ts (lines 95-102) is now effectively dead for fresh installs because trimmedRegion will be 'us-east-1' by default and the else if (trimmedBucketURL) branch won't be reached unless the admin explicitly clears the region field.
If the intent is to only fall back for custom endpoints, consider keeping the package default as '' and relying solely on the runtime fallback in AmazonS3.ts. Otherwise, the current approach is fine but the info log will rarely fire.

🤖 Prompt for AI Agents

Verify each finding against the current code and only fix it if needed.

In `@apps/meteor/server/settings/file-upload.ts` around lines 160 - 167, The
change sets the FileUpload_S3_Region default to 'us-east-1', which causes
trimmedRegion to be non-empty and prevents the custom-endpoint fallback in
AmazonS3.ts from running; either revert the package default for
FileUpload_S3_Region back to '' so real AWS installs without a chosen region
still trigger the runtime fallback in AmazonS3 (keep symbol
FileUpload_S3_Region), or if you want 'us-east-1' as the package default, update
AmazonS3.ts logic (the trimmedRegion / trimmedBucketURL checks and the
followRegionRedirects behavior) to treat the default value as unset for the
purpose of triggering the custom-endpoint fallback and logging (adjust the code
paths referencing trimmedRegion, trimmedBucketURL, and followRegionRedirects
accordingly).

🤖 Prompt for all review comments with AI agents

Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@apps/meteor/server/settings/file-upload.ts`:
- Around line 160-167: The change sets the FileUpload_S3_Region default to
'us-east-1', which causes trimmedRegion to be non-empty and prevents the
custom-endpoint fallback in AmazonS3.ts from running; either revert the package
default for FileUpload_S3_Region back to '' so real AWS installs without a
chosen region still trigger the runtime fallback in AmazonS3 (keep symbol
FileUpload_S3_Region), or if you want 'us-east-1' as the package default, update
AmazonS3.ts logic (the trimmedRegion / trimmedBucketURL checks and the
followRegionRedirects behavior) to treat the default value as unset for the
purpose of triggering the custom-endpoint fallback and logging (adjust the code
paths referencing trimmedRegion, trimmedBucketURL, and followRegionRedirects
accordingly).

ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c08dd38d-ca46-4390-b43f-0530d6a1f663

📥 Commits
Reviewing files that changed from the base of the PR and between d9f4c86 and 89a2ddc.

📒 Files selected for processing (3)

  • apps/meteor/app/file-upload/server/config/AmazonS3.ts
  • apps/meteor/server/settings/file-upload.ts
  • packages/i18n/src/locales/en.i18n.json

📜 Review details

I've reverted the package default for FileUpload_S3_Region to ''. Runtime handling (including the region fallback when using a custom Bucket URL) stays in AmazonS3.ts.

@abbiekuma
Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 18, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

S3 custom endpoint throws "Region is missing" with AWS SDK v3 on non-AWS providers (Cloudflare R2)

2 participants