Skip to content

reef: rgw: match CORS rules like Amazon S3 - #69649

Closed
RaminNietzsche wants to merge 6 commits into
ceph:reeffrom
RaminNietzsche:wip-77582-reef
Closed

RaminNietzsche wants to merge 6 commits into
ceph:reeffrom
RaminNietzsche:wip-77582-reef

Conversation

@RaminNietzsche

@RaminNietzsche RaminNietzsche commented Jun 22, 2026 •

Copy link
Copy Markdown
Member

Summary

Backport of #69190 to reef.

RGW previously selected a CORS rule with host_name_rule() (origin only), then
validated method/headers on that single rule. Bucket configs with multiple
CORSRule elements sharing the same AllowedOrigin but different
AllowedMethod values could fail preflight when a later rule should match.
This aligns rule selection with Amazon S3 (first rule matching origin, method,
and preflight headers).

Why reef: the buggy origin-only matching exists on reef; users running
multi-rule bucket CORS on reef RGW hit the same preflight failures fixed on
main.

Minimal change: cherry-pick of all six commits from PR #69190. On stable
branches without global CORS, conflict resolution drops optional_global_cors
/ validate_global_cors_request() only; bucket CORS uses match_rule().

Parent tracker: https://tracker.ceph.com/issues/77575

Testing

  • Includes unittest_rgw_cors (from main PR)
  • Not run locally on reef yet

Contribution Guidelines

  • To sign and title your commits, please refer to Submitting Patches to Ceph.

  • If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.

  • When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an x between the brackets: [x]. Spaces and capitalization matter when checking off items this way.

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)

Fixes: https://tracker.ceph.com/issues/77582

RaminNietzsche and others added 6 commits June 22, 2026 20:14
Select the first CORSRule whose AllowedOrigin, AllowedMethod, and (for
preflight) AllowedHeader all match the request. Previously host_name_rule
matched origin only, so a second rule with the same origin but different
methods was never used.

Add RGWCORSRule::matches() and RGWCORSConfiguration::match_rule(), wire
generate_cors_headers and RGWOptionsCORS to them (including global CORS), and
add unittest_rgw_cors.

Signed-off-by: ramin.najarbashi <[email protected]>
Co-authored-by: Cursor <[email protected]>
(cherry picked from commit cc1dcec)

Conflicts:
 src/rgw/rgw_op.cc
 Dropped optional_global_cors and validate_global_cors_request() because
 reef does not have global CORS. Applied match_rule() for bucket CORS
 only, with req_meth/req_hdrs captured in the lambda (as in main PR ceph#69190
 review feedback).
Signed-off-by: ramin.najarbashi <[email protected]>
(cherry picked from commit bbec695)
Signed-off-by: ramin.najarbashi <[email protected]>
(cherry picked from commit b5624b6)
- matches_method: reject null/empty method; short-circuit RGW_CORS_ALL
- matches_preflight_headers: add logging for skip and disallowed headers
- generate_cors_headers: capture req_meth/req_hdrs in lambda
- remove unused validate_cors_rule_method/header helpers

Signed-off-by: ramin.najarbashi <[email protected]>

On branch fix/rgw-cors-aws-rule-matching
Changes to be committed:
	modified:   src/rgw/rgw_cors.cc
	modified:   src/rgw/rgw_op.cc

(cherry picked from commit 8b3f907)
get_multi_cors_method_flags() calls ceph::for_each_substr(), but
rgw_cors.h did not include str_list.h. The CORS unit test includes
only this header, so the build failed with an undeclared identifier.
Qualify the call and add the missing include.

Signed-off-by: ramin.najarbashi <[email protected]>
(cherry picked from commit 830f0e5)
unittest_rgw_cors used GMock::Main without global_init, so dout() in
RGWCORSRule::matches() dereferenced a null g_ceph_context and segfaulted
on the first test. Link unit-main like unittest_rgw_compression.

Assisted-by: Cursor:composer-2.5-fast
Signed-off-by: ramin.najarbashi <[email protected]>
Co-authored-by: Cursor <[email protected]>
(cherry picked from commit c147865)
@RaminNietzsche
RaminNietzsche requested a review from a team as a code owner June 22, 2026 16:46
@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

7 similar comments
@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@cbodley

cbodley commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

thanks @RaminNietzsche - but the reef release is end of life and not getting further backports. and now that the umbrella branch has forked, we need to backport there instead. i updated https://tracker.ceph.com/issues/77575 accordingly

@RaminNietzsche

Copy link
Copy Markdown
Member Author

thanks @RaminNietzsche - but the reef release is end of life and not getting further backports. and now that the umbrella branch has forked, we need to backport there instead. i updated https://tracker.ceph.com/issues/77575 accordingly

Thanks for the heads-up — I checked #77575 and see the Backport field now points at umbrella instead of reef. I must’ve been on autopilot: reef slipped my mind even though it’s EOL, so thanks for catching that and updating the tracker.

I’ve opened the umbrella backport here: #69651 from #69190, clean apply on umbrella. I’ll close the reef PR (#69649) so we don’t keep a backport open for a release that’s done.

Sorry for the extra noise, and thanks again for the correction.

@cbodley

cbodley commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

thanks very much for the fix and backports

jhoblitt added a commit to jhoblitt/rgw-go that referenced this pull request Oct 16, 2026
…in matches

At v19.2.7 and v20.2.4, host_name_rule returns the first rule whose
AllowedOrigin matches, and both the preflight and generate_cors_headers
then refuse the request if that rule lacks its method or a requested
header, so a later rule for the same origin is never used. Amazon S3
takes the first rule that matches origin, method and requested headers.

main corrected it with match_rule in cc1dcecee08, from ceph/ceph#69190,
and the tentacle branch carries the backport 5f25f2bb0e2, from
ceph/ceph#69647, in no tag. The squid backport, ceph/ceph#69648, is
open, and the reef one, ceph/ceph#69649, was closed unmerged; trackers
77575, 77584 and 77586 follow them. rgw-go selects rules as main does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

3 participants