Repository navigation
reef: rgw: match CORS rules like Amazon S3 - #69649
RaminNietzsche wants to merge 6 commits into
Conversation
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)
|
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
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
|
thanks very much for the fix and backports |
…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]>
Summary
Backport of #69190 to reef.
RGW previously selected a CORS rule with
host_name_rule()(origin only), thenvalidated method/headers on that single rule. Bucket configs with multiple
CORSRuleelements sharing the sameAllowedOriginbut differentAllowedMethodvalues 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 usesmatch_rule().Parent tracker: https://tracker.ceph.com/issues/77575
Testing
unittest_rgw_cors(from main PR)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
xbetween the brackets:[x]. Spaces and capitalization matter when checking off items this way.Checklist
Fixes: https://tracker.ceph.com/issues/77582