Repository navigation
CORS: HTTPCORSFilter and GEP 1767 clean-ups - #4506
Conversation
Previously, the GEP mentioned allowing "implementatio-specific default methods and headers". It's not obvious what that means, but my understanding is that this would allow implementations to arbitrarily add certain values (not specified by the user) to the headers Access-Control-Allow-Methods and Access-Control-Request-Headers`. It does not seem to be needed. We can revisit this aspect if it turns out otherwise. Signed-off-by: Damian Sawicki <dsawicki@google.com>
It seems that not all changes in GEP 1767 were correctly reflected in apis/v1/httproute_types.go. This is now fixed. Signed-off-by: Damian Sawicki <dsawicki@google.com>
|
Hi @DamianSawicki. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
As per kubernetes-sigs#4494 (comment) Mozilla has an example where in response to an uncredentialed request, the server responds with `Access-Control-Allow-Origin: *`. However, responding with the value of the Origin from the request is also valid (and the only allowed behavior for credentialed requests), and it is the behavior of some implementations as per https://github.com/kubernetes-sigs/gateway-api/blob/b1a7a927b098a4ab99c3bf9983412cb2f1a419fd/conformance/tests/httproute-cors.go#L399-L401 so let's relax the requirement in the GEP to allow it.
As per https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Access-Control-Allow-Methods#syntax wildcard is a valid value for the Access-Control-Allow-Methods header. However, as per * envoyproxy/envoy#8218 * https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Access-Control-Allow-Methods#browser_compatibility the wildcard was not universally supported by browsers in 2019, and hence many implementations don't use the wildcard. Signed-off-by: Damian Sawicki <dsawicki@google.com>
|
/ok-to-test |
| // A wildcard indicates that the requests with all HTTP headers are allowed. | ||
| // The `Access-Control-Allow-Headers` response header can only use `*` | ||
| // wildcard as value when the `AllowCredentials` field is false or omitted. | ||
| // wildcard as value when the request is not credentialed. |
There was a problem hiding this comment.
one information that I got when checking for it was that the behavior of "*" on the Access-Control-Allow-Headers is supported just on modern browsers.
Also, I am wondering if we want to enforce the validation on the API: https://github.com/kubernetes-sigs/gateway-api/blob/main/apis/v1/httproute_types.go#L1483
We can probably say that if the allowCredentials = true on the API, the usage of wildcard is disabled on allow methods and allow headers
There was a problem hiding this comment.
one information that I got when checking for it was that the behavior of "*" on the Access-Control-Allow-Headers is supported just on modern browsers.
Yeah, I've just relaxed that in the following commit 9bf6df2:
Allow specific Allow-Methods despite wildcard
As per
https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Access-Control-Allow-Methods#syntax
wildcard is a valid value for the Access-Control-Allow-Methods header.However, as per
- CORS. Dynamic set access-control-allow-headers from access-control-request-headers envoyproxy/envoy#8218
- https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Access-Control-Allow-Methods#browser_compatibility
the wildcard was not universally supported by browsers in 2019,
and hence many implementations don't use the wildcard.
There was a problem hiding this comment.
Also, I am wondering if we want to enforce the validation on the API: https://github.com/kubernetes-sigs/gateway-api/blob/main/apis/v1/httproute_types.go#L1483
I don't have a strong opinion on that, but I guess I'd keep this validation. It does not really make sense to specify anything else when the wildcard is specified, does it?
There was a problem hiding this comment.
We can probably say that if the allowCredentials = true on the API, the usage of wildcard is disabled on allow methods and allow headers
No. Wildcard is forbidden in Access-Control-Request-Method and Access-Control-Request-Headers when the request is credentialed, not when "allowCredentials = true on the API". This is the fundamental confusion from #3861.
There was a problem hiding this comment.
per Mozilla spec on https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CORS
When responding to a credentialed request:
The server must not specify the * wildcard for the Access-Control-Allow-Origin response-header value, but must instead specify an explicit origin; for example: Access-Control-Allow-Origin: https://example.com
The server must not specify the * wildcard for the Access-Control-Allow-Headers response-header value, but must instead specify an explicit list of header names; for example, Access-Control-Allow-Headers: X-PINGOTHER, Content-Type
The server must not specify the * wildcard for the Access-Control-Allow-Methods response-header value, but must instead specify an explicit list of method names; for example, Access-Control-Allow-Methods: POST, GET
The server must not specify the * wildcard for the Access-Control-Expose-Headers response-header value, but must instead specify an explicit list of header names; for example, Access-Control-Expose-Headers: Content-Encoding, Kuma-Revision
So, I can test here on Envoy, and check if we set the allowCredentials if Envoy will filter out the wildcard methods to the requested method on the preflight or not, my concern is that if it doesn't, it will be very hard to make Envoy define when wildcard should be answered vs when the specific list of headers on the request headers will be used.
There was a problem hiding this comment.
if Envoy will filter out the wildcard methods to the requested method on the preflight or not, my concern is that if it doesn't
It does. See envoyproxy/envoy#8218 quoted above in #4506 (comment) from the commit description. This was addressed by envoyproxy/envoy#19882 (perhaps the PR did more than the Issue asked, but in particular it addressed the issue).
Signed-off-by: Damian Sawicki <dsawicki@google.com>
This uniformizes the validation for allowMethods and allowHeaders by requiring that when '*' appears in allowHeaders, it must be the only value in the list. Signed-off-by: Damian Sawicki <dsawicki@google.com>
Signed-off-by: Damian Sawicki <dsawicki@google.com>
| // When the `MaxAge` field is unspecified, the gateway sets the response | ||
| // header "Access-Control-Max-Age: 5" by default. |
There was a problem hiding this comment.
Isn't this the same as the sentence above?
There was a problem hiding this comment.
I just reconciled the Golang file accordingly; it's been like that in the GEP already.
gateway-api/geps/gep-1767/index.md
Lines 511 to 515 in da309c1
Having that said, I believe these two sentences differ as follows:
- The first sentence means that according to HTTP standards, when
Access-Control-Max-Ageis unset, the browser assumes5 sas the default. - The second sentence says that in order not to rely on browsers, Gateway API requires the proxy to explicitely set
Access-Control-Max-Age: 5when the Gateway user does not specifyHTTPCorsFilter.maxAge.
There was a problem hiding this comment.
The first sentence means that according to HTTP standards, when Access-Control-Max-Age is unset, the browser assumes 5 s as the default.
Oh interesting, I'd interpreted that as meaning the default value of the field to be 5, which it is below. In practice that API-level default means that Gateway implementations don't really need to do anything special for this 5s default to apply.
In any case, although this is slightly confusing/repetitive, all statements are correct, so don't want to block this PR on this.
There was a problem hiding this comment.
I am not sure this is always truth, like NGINX may set a different response. I would probably leave this as "if not set, the proxy will set a default" or whatever
eg.: on NGINX: https://enable-cors.org/server_nginx.html
if you don't set explicitly the answers, it will not send any default.
| configuration the gateway will _not_ include the | ||
| `Access-Control-Allow-Credentials` header in responses. | ||
|
|
||
| ## Wildcard Resolution and Credentials |
There was a problem hiding this comment.
This section is incredibly helpful, thanks for adding this @DamianSawicki!
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: DamianSawicki, robscott The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Signed-off-by: Damian Sawicki <dsawicki@google.com>
|
/lgtm |
|
/release-note-none |
|
/cherry-pick release-1.5 |
|
@rikatz: once the present PR merges, I will cherry-pick it on top of DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
@rikatz: new pull request created: #4510 DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
* Remove implementation-specific methods/headers Previously, the GEP mentioned allowing "implementatio-specific default methods and headers". It's not obvious what that means, but my understanding is that this would allow implementations to arbitrarily add certain values (not specified by the user) to the headers Access-Control-Allow-Methods and Access-Control-Request-Headers`. It does not seem to be needed. We can revisit this aspect if it turns out otherwise. Signed-off-by: Damian Sawicki <dsawicki@google.com> * Unify gep-1767 and httproute_types.go It seems that not all changes in GEP 1767 were correctly reflected in apis/v1/httproute_types.go. This is now fixed. Signed-off-by: Damian Sawicki <dsawicki@google.com> * Allow specific Allow-Origin despite wildcard As per kubernetes-sigs#4494 (comment) Mozilla has an example where in response to an uncredentialed request, the server responds with `Access-Control-Allow-Origin: *`. However, responding with the value of the Origin from the request is also valid (and the only allowed behavior for credentialed requests), and it is the behavior of some implementations as per https://github.com/kubernetes-sigs/gateway-api/blob/b1a7a927b098a4ab99c3bf9983412cb2f1a419fd/conformance/tests/httproute-cors.go#L399-L401 so let's relax the requirement in the GEP to allow it. * Allow specific Allow-Methods despite wildcard As per https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Access-Control-Allow-Methods#syntax wildcard is a valid value for the Access-Control-Allow-Methods header. However, as per * envoyproxy/envoy#8218 * https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Access-Control-Allow-Methods#browser_compatibility the wildcard was not universally supported by browsers in 2019, and hence many implementations don't use the wildcard. Signed-off-by: Damian Sawicki <dsawicki@google.com> * Reword comment for allowHeaders to match methods Signed-off-by: Damian Sawicki <dsawicki@google.com> * Copy validation for * from allowMethods to headers This uniformizes the validation for allowMethods and allowHeaders by requiring that when '*' appears in allowHeaders, it must be the only value in the list. Signed-off-by: Damian Sawicki <dsawicki@google.com> * Add section on wildcards to GEP 1767 Signed-off-by: Damian Sawicki <dsawicki@google.com> * Update GEP 1767 metadata with new PR Signed-off-by: Damian Sawicki <dsawicki@google.com> --------- Signed-off-by: Damian Sawicki <dsawicki@google.com>
What type of PR is this?
/kind gep
What this PR does / why we need it:
This cleans up certain aspects in GEP 1767 and the corresponding
apis/v1/httproute_types.gofile.Access-Control-Allow-MethodsandAccess-Control-Allow-Headersresponse headers even if the corresponding config contains the wildcard and the request is not credentialed. The previous specification was overly restrictive: using specific values seems allowed by standards in such cases and it is actually how some implementations behave.allowMethodsandallowHeaders.Which issue(s) this PR fixes:
Addresses #3861 and #4493.
Does this PR introduce a user-facing change?:
Not sure.