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

feat: multiple-cors-allow-origin support #7134

Merged

Conversation

tokers
Copy link
Contributor

@tokers tokers commented May 14, 2021

What this PR does / why we need it:

This Pull Request extended the "nginx.ingress.kubernetes.io/cors-allow-origin" annotation to accept multiple origin values.

It doesn't break the backward compatibility, "nginx.ingress.kubernetes.io/cors-allow-origin" still can accept a single origin. Each value in this annotation will be checked and as long as one of them is invalid, default value "*" for "nginx.ingress.kubernetes.io/cors-allow-origin" will be applied.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Which issue/s this PR fixes

#5496

How Has This Been Tested?

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I've read the CONTRIBUTION guide
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label May 14, 2021
@k8s-ci-robot
Copy link
Contributor

Hi @tokers. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label May 14, 2021
@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label May 14, 2021
Copy link
Member

@tao12345666333 tao12345666333 left a comment

Choose a reason for hiding this comment

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

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels May 14, 2021
Copy link
Member

@tao12345666333 tao12345666333 left a comment

Choose a reason for hiding this comment

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

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 15, 2021
@rjvim
Copy link

rjvim commented May 21, 2021

+1

@rikatz
Copy link
Contributor

rikatz commented May 23, 2021

/lgtm
/approve

Thank you!!

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: rikatz, tao12345666333, tokers

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 23, 2021
@k8s-ci-robot k8s-ci-robot merged commit 8a55801 into kubernetes:master May 23, 2021
@tokers tokers deleted the feat/multiple-cors-allow-origins branch May 24, 2021 01:32
@arianvp
Copy link

arianvp commented May 25, 2021

This implementation is incorrect. Access-Control-Allow-Origin header doesn't support multiple values like this. You can only return one Origin in the header. The server should decide whether the client's Origin matches a predefined list and then return only one.

See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin

Specifies an origin. Only a single origin can be specified. If the server supports clients from multiple origins, it must return the origin for the specific client making the request.

In nginx this should be implemented by checking $http_origin against a predefined list and then returning Access-Control-Allow-Origin: $http_origin

This can be accomplished with a map expression:

map $http_origin $cors_header {
  default "";
  "https://a.example.com" $http_origin;
  "https://b.example.com" $http_origin;
}
more_set_headers "Access-Control-Allow-Origin: $cors_header";

@tokers
Copy link
Contributor Author

tokers commented May 26, 2021

@arianvp Thanks for your report, I have created a new issue #7162 to track this problem.

rikatz added a commit to rikatz/ingress-nginx that referenced this pull request May 26, 2021
k8s-ci-robot pushed a commit that referenced this pull request May 27, 2021
carnei-ro pushed a commit to carnei-ro/ingress-nginx that referenced this pull request Jun 7, 2021
carnei-ro pushed a commit to carnei-ro/ingress-nginx that referenced this pull request Jun 7, 2021
qiqizjl pushed a commit to qiqizjl/ingress-nginx that referenced this pull request Jul 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants