-
Notifications
You must be signed in to change notification settings - Fork 365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(cors): Allowed more wildcard options #2453
Conversation
api/v1alpha1/cors_types.go
Outdated
// Origin is defined by the scheme (protocol), hostname (domain), and port of | ||
// the URL used to access it. The hostname can be “precise” which is just the | ||
// domain name or “wildcard” which is a domain name prefixed with a single | ||
// wildcard label such as “*.example.com”. | ||
// wildcard label such as “*.example.com”. The optional port can be a wildcard |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// wildcard label such as “*.example.com”. The optional port can be a wildcard | |
// wildcard label such as "*.example.com". The optional port can be a wildcard |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there're still some quotes that in the wrong character encoding, can you please help fixing them? thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@jaynis can sign your commits and repush ? DCO is failing |
Signed-off-by: jaynis <kranz.jannis@googlemail.com>
Signed-off-by: jaynis <kranz.jannis@googlemail.com>
7058e37
to
a675625
Compare
Signed-off-by: jaynis <kranz.jannis@googlemail.com>
aa343f9
to
23d0e80
Compare
Signed-off-by: jaynis <kranz.jannis@googlemail.com>
Signed-off-by: jaynis <kranz.jannis@googlemail.com>
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2453 +/- ##
=======================================
Coverage 64.71% 64.71%
=======================================
Files 115 115
Lines 17431 17431
=======================================
Hits 11281 11281
Misses 5433 5433
Partials 717 717 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jaynis Thanks for the improvement in the wildcard host matching. The implementation looks good to me.
I only have a little hesitation about the port wildcard matching. Suffix/Port wildcard matching is not a common practice for hostnames. In your use case, do you have many ports for a given hostname?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, defer to @zhaohuabing
Thank you for your review @zhaohuabing.
The port range matching was solely meant to be a dev feature so that one can configure CORS for a host (e.g. localhost) regardless of the port the application runs on. But this scenario could be covered by the general wildcard as well, therefore I would also be fine with deleting it again if you think it is not required. Just let me know your preference. |
Prefer to remove the suffix matching to keep it aligned with the common practice. Thanks. |
Signed-off-by: jaynis <kranz.jannis@googlemail.com>
Signed-off-by: jaynis <kranz.jannis@googlemail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks!
* allowed more CORS wildcard options Signed-off-by: jaynis <kranz.jannis@googlemail.com> * fixed quotes with wrong character encoding Signed-off-by: jaynis <kranz.jannis@googlemail.com> * generated manifests Signed-off-by: jaynis <kranz.jannis@googlemail.com> * gofmt Signed-off-by: jaynis <kranz.jannis@googlemail.com> * fixed regex escape characters in cel validation Signed-off-by: jaynis <kranz.jannis@googlemail.com> * fixed cel validation test Signed-off-by: jaynis <kranz.jannis@googlemail.com> * removed wildcard port matching Signed-off-by: jaynis <kranz.jannis@googlemail.com> * removed wildcard port test Signed-off-by: jaynis <kranz.jannis@googlemail.com> --------- Signed-off-by: jaynis <kranz.jannis@googlemail.com> Co-authored-by: Huabing Zhao <zhaohuabing@gmail.com> Signed-off-by: A3bz <zeng921359373@163.com>
A few weeks ago the allowed CORS origins have been changed from a regex to a wildcard notation (#2389). Implementation wise all kinds of wildcards are supported, however, the validation regex on the
SecurityPolicy
CRD limits the CORS options to hostnames prefixed with an wildcard followed by a dot, allowing all subdomains of that host. This reduces the freedom when allowing cross origins a lot compared to how it was before. This PR aims to relax the validation regex a bit to enable the following use cases:https://*
)*
)http://localhost:*
)While allowing all hosts in the context of CORS might sound a bit hacky, this is sometimes required. For instance when a web service provides an API which is consumed by many third-party web applications hosted under arbitrary domains not under the control of the maintainer of aforementioned web service. In addition to that it can be very useful during application development. This is why I have added the option to allow all ports of a specific host as well.
Review the new and the old validation regexes.