fix(security): Restore CORS functionality broken in EdgeX 3.0 #4638
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #4627
When Kong and security-proxy-setup was removed in EdgeX 3.0,
the ability to support CORS through the API gateway was also inadvertently removed.
This PR -- which fixes the Docker deployment only (snap support forthcoming) --
statically includes the common configuration CORS settings and uses those to
enable CORS for all proxied services or none at all,
according to the common config or EDGEX_SERVICE_CORSCONFIGURATION_* overrides,
which may be set on the security-proxy-setup container
via docker-compose. These changes also introduce a new stage gate,
that block NGINX startup until security-proxy-setup has been completed.
(In EdgeX 2.x, Kong started first and security-proxy-setup after that.
To complete the CORS configuration for NGINX, we need to reverse that order.)
PR Checklist
Please check if your PR fulfills the following requirements:
BREAKING CHANGE:
describing the break)<link to docs PR>
Testing Instructions
Testing is somewhat involved.
First, create the following file on disk:
index.html
Note: Content-Type is required to trigger CORS preflight. See https://auth0.com/blog/cors-tutorial-a-guide-to-cross-origin-resource-sharing/
Launch an http server for it using
python -m http.server --directory . 8888
Next, make the following changes to the docker-compose scripts
Launch the new containers with
(be sure to
make docker
in edgex-go first)Next, in the browser, open the following page:
https://cors-errors.info/header-checker
This page allows pasting of request and response headers to validate the CORS request is being correctly handled.
Once more, in the browser, open:
https://localhost:8443
Accept the temporary certificate served by NGINX. You will need to re-accept the cert everytime you do a
make clean
in edgex-compose.Finally, hit
http://localhost:8888/
in the browser and open the developer tools, network tab and console.
Refresh the browser with F5.
Inspect the OPTIONS CORS preflight request in the network traffic bar.
Paste the raw request and response headers into the CORS validation web site.
Verify that the protocols are correctly followed.
Next, do the same for the CORS GET request.
The site should report no protocol violations.
To do the same with an authenticated request, run
make get-token
and modify the HTML above to include the header:Repeat the test and ensure you get a 200 OK response from the CORS ping command.
Note that the
SERVICE_CORSCONFIGURATION_CORSMAXAGE: '1'
setting affects the browser's caching of CORS information. If CORS information has been cached in the browser, the OPTIONS request will not be made, which makes the testing invalid. In that case, clear the browser cache, introduce this change, and start over.New Dependency Instructions (If applicable)