Repository navigation
rgw: match CORS rules like Amazon S3 - #69190
Conversation
|
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. |
16 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. |
|
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. |
|
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. |
d557a8a to
06ab220
Compare
|
@cbodley Hi, Could you please review this MR and share your feedback? Thanks! |
AliMasarweh
left a comment
There was a problem hiding this comment.
nice job
I have a few comments
| bool RGWCORSRule::matches_method(const char *req_meth) | ||
| { | ||
| if (!req_meth || !*req_meth) { | ||
| return true; |
There was a problem hiding this comment.
should return false not true in case of a null or an empty string for method and add a logging info
There was a problem hiding this comment.
Thanks for the review.
I'll change this to return false and log at level 5, matching the old
validate_cors_rule_method() behavior.
| if (!req_meth || !*req_meth) { | ||
| return true; | ||
| } | ||
| const uint8_t flags = get_multi_cors_method_flags(req_meth); |
There was a problem hiding this comment.
you need to check if req_meth is wildcard or not first
There was a problem hiding this comment.
I'll add an explicit check for AllowedMethod * before the flag lookup. Thanks!
| bool RGWCORSRule::matches_preflight_headers(const char *req_hdrs) | ||
| { | ||
| if (!req_hdrs || !*req_hdrs) { | ||
| return true; |
There was a problem hiding this comment.
should return false not true in case of a null or an empty string for header and add a logging info
There was a problem hiding this comment.
Thanks! I'm keeping return true here — if there's no
Access-Control-Request-Headers, we skip the header check (same as the old
validator). Returning false would break valid preflights.
To ensure proper output for debugging, I added the appropriate log in this section.
There was a problem hiding this comment.
@cbodley can you confirm that preflights requests with an empty header are valid?
or is that an issue and we shouldn't keep it?
| const char *req_meth_inner = s->info.env->get("HTTP_ACCESS_CONTROL_REQUEST_METHOD"); | ||
| if (!req_meth_inner) { | ||
| req_meth_inner = s->info.method; |
There was a problem hiding this comment.
duplicate code, I suggest we pass it to is_allowed_to_generate_rule_cors_header in the parameter arguments
There was a problem hiding this comment.
Yep, leftover from the refactor — I'll read req_meth and req_hdrs once at
the top and pass them into the lambda. Thanks!
|
|
||
| /* CORS 6.2.4. */ | ||
| const char *req_hdrs = s->info.env->get("HTTP_ACCESS_CONTROL_REQUEST_HEADERS"); | ||
| const char *req_hdrs_inner = s->info.env->get("HTTP_ACCESS_CONTROL_REQUEST_HEADERS"); |
There was a problem hiding this comment.
also we should pass this one to the arguments
| return -ENOENT; | ||
| } | ||
|
|
||
| if (!validate_cors_rule_method(this, rule, req_meth)) { |
There was a problem hiding this comment.
we should delete validate_cors_rule_method as it is not used anymore
There was a problem hiding this comment.
Agreed. I removed, it's dead code now that we use match_rule(). The logging
moved into matches_method(). Thanks!
| return -ENOENT; | ||
| } | ||
|
|
||
| if (!validate_cors_rule_header(this, rule, req_hdrs)) { |
There was a problem hiding this comment.
we should delete validate_cors_rule_header as it is not used anymore
There was a problem hiding this comment.
Same, removed validate_cors_rule_header() too.
| get_str_vec(req_hdrs, hdrs); | ||
| for (const auto& hdr : hdrs) { | ||
| if (!is_header_allowed(hdr.c_str(), hdr.length())) { | ||
| return false; |
There was a problem hiding this comment.
we should log what header wasn't allowed
There was a problem hiding this comment.
Good point
added a log for disallowed headers in the loop, same as the
old validator. Thanks!
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]>
Signed-off-by: ramin.najarbashi <[email protected]>
ed68af8 to
bbec695
Compare
Signed-off-by: ramin.najarbashi <[email protected]>
- 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
|
ok to test |
|
Great job but I would like Casey to take a look at my question |
Thank you for taking the time to review this request. |
|
oops! It's my mistake. I'm fixing the problem and will definitely run the testing process again before submitting. |
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]>
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]>
AliMasarweh
left a comment
There was a problem hiding this comment.
I looked it up and found that Access-Control-Request-Headers is not mandotory in preflight requests
So the PR is good, I will mark it for testing and once they verify it we can merge it
|
pr testing completed and approved by @ivancich , more details : https://tracker.ceph.com/issues/77460. |
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 tentacle 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 #69190 review feedback).
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 tentacle 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).
…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]>
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 squid 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 #69190 review feedback).
Amazon S3 evaluates bucket CORS configuration by selecting the first
CORSRulefor which all of the following match the incoming request:Originmatches anAllowedOriginin the rule;Access-Control-Request-Methodon preflightOPTIONS) matches anAllowedMethodin the rule;Access-Control-Request-Headersmatches anAllowedHeaderin the rule.RGW previously called
host_name_rule(), which matched origin only, thenvalidated method and headers on that single rule. If two
<CORSRule>elementsshared the same origin but allowed different methods (e.g. rule 1: GET, rule 2:
PUT), only the first rule was ever considered; a
PUTpreflight could faileven when a later rule allowed it.
This change adds
RGWCORSRule::matches()andRGWCORSConfiguration::match_rule()to walk rules in configuration order andreturn the first fully matching rule.
generate_cors_headers()andRGWOptionsCORSusematch_rule()for bucket CORS; global CORS(
optional_global_cors) usesRGWCORSRule::matches()before applyingheaders.
host_name_rule()is unchanged for origin-only paths such aserase_host_name_rule().Unit tests in
unittest_rgw_corscover same-origin rules with differentmethods and preflight header selection.
Testing
unittest_rgw_cors(new)PutBucketCorswith two rules, sameAllowedOrigin, differentAllowedMethod; verifyOPTIONSpreflight for the second method succeeds.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
Show available Jenkins commands
jenkins test classic perfJenkins Job | Jenkins Job Definitionjenkins test crimson perfJenkins Job | Jenkins Job Definitionjenkins test signedJenkins Job | Jenkins Job Definitionjenkins test make checkJenkins Job | Jenkins Job Definitionjenkins test make check arm64Jenkins Job | Jenkins Job Definitionjenkins test submodulesJenkins Job | Jenkins Job Definitionjenkins test dashboardJenkins Job | Jenkins Job Definitionjenkins test dashboard cephadmJenkins Job | Jenkins Job Definitionjenkins test apiJenkins Job | Jenkins Job Definitionjenkins test docsReadTheDocs | Github Workflow Definitionjenkins test ceph-volume allJenkins Jobs | Jenkins Jobs Definitionjenkins test windowsJenkins Job | Jenkins Job Definitionjenkins test rook e2eJenkins Job | Jenkins Job DefinitionYou must only issue one Jenkins command per-comment. Jenkins does not understand
comments with more than one command.