Skip to content
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

Append elements on match, instead of removing for cors-annotations #8185

Merged
merged 2 commits into from
Feb 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions internal/ingress/annotations/cors/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,19 +121,22 @@ func (c cors) Parse(ing *networking.Ingress) (interface{}, error) {
config.CorsEnabled = false
}

config.CorsAllowOrigin = []string{}
unparsedOrigins, err := parser.GetStringAnnotation("cors-allow-origin", ing)
if err == nil {
config.CorsAllowOrigin = strings.Split(unparsedOrigins, ",")
for i, origin := range config.CorsAllowOrigin {
origins := strings.Split(unparsedOrigins, ",")
for _, origin := range origins {
origin = strings.TrimSpace(origin)
if origin == "*" {
config.CorsAllowOrigin = []string{"*"}
break
}

if !corsOriginRegex.MatchString(origin) {
klog.Errorf("Error parsing cors-allow-origin parameters. Supplied incorrect origin: %s. Skipping.", origin)
config.CorsAllowOrigin = append(config.CorsAllowOrigin[:i], config.CorsAllowOrigin[i+1:]...)
continue
}
config.CorsAllowOrigin = append(config.CorsAllowOrigin, origin)
klog.Infof("Current config.corsAllowOrigin %v", config.CorsAllowOrigin)
Copy link
Contributor

@larivierec larivierec Jan 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this has nothing to do with the review (nice catch)
we could change this to the current origin instead of the whole list as well.

just a thought

Copy link
Contributor Author

@L1ghtman2k L1ghtman2k Jan 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might be misinterpreting, but that was adjusted in this commit to use the current origin:
config.CorsAllowOrigin = append(config.CorsAllowOrigin, origin)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably, i'm referring to this here: klog.Infof("Current config.corsAllowOrigin %v", config.CorsAllowOrigin) sorry about that :)

}
} else {
Expand Down