-
Notifications
You must be signed in to change notification settings - Fork 7
allow custom cors headers for stac #599
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
Changes from 2 commits
7c2a5a9
d1b9f73
aae7483
5369091
8da406a
942cc07
2aa0cae
7d21fd9
b1c62a2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,7 +15,56 @@ | |
| [Unreleased](https://github.com/bird-house/birdhouse-deploy/tree/master) (latest) | ||
| ------------------------------------------------------------------------------------------------------------------ | ||
|
|
||
| [//]: # (list changes here, using '-' for each new entry, remove this when items are added) | ||
| ## Changes | ||
|
|
||
| - Allow each service to specify values for `Access-Control-Allow-Origin` | ||
|
|
||
| Previously, if a `location` block in the `nginx` configuration for a given service included the cors helper | ||
| configuration (with `include /etc/nginx/conf.d/cors.include;`) then all origins were allowed by default. | ||
|
|
||
| This was done by setting the header `Access-Control-Allow-Origin: *` which works well but is a bit too permissive | ||
| since it allowed __all__ origins. | ||
|
|
||
| This change introduces a mechanism to specify specific additional allowed origins by setting the | ||
| `$access_control_allow_origin` nginx variable in the `location` block before including the `cors.include` file. | ||
|
|
||
| For example: | ||
|
|
||
| ``` | ||
| set $access_control_allow_origin http://example.com; | ||
| include /etc/nginx/conf.d/cors.include; | ||
| ``` | ||
|
|
||
| will set the value of the `Access-Control-Allow-Origin` response header to `http://example.com`. | ||
|
|
||
| By default, the header value will be `*` if `$access_control_allow_origin` is not set (to maintain backwards | ||
| compatibility). | ||
|
|
||
| To specify multiple allowed origins, use a `map` directive (see the implementation for `components/stac` for an | ||
| example). | ||
|
|
||
| - Set allowed CORS origins for `stac` through an environment variable | ||
|
|
||
| This change implements this flexibility for the `components/stac` component. By setting the `STAC_CORS_ORIGINS` | ||
| variable a user can specify allowed origins for responses from the `components/stac` component. | ||
|
|
||
| For example, setting the following: | ||
|
|
||
| ``` | ||
mishaschwartz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| export STAC_CORS_ORIGINS='https://example.com ~^https?://(www\.)?other\.example\.com$' | ||
| ``` | ||
|
|
||
| then requests from https://example.com and http://other.example.com will get a response with the | ||
| `Access-Control-Allow-Origin header` set to their origin, but http://example.ca will not. | ||
|
|
||
| Note that this breaks backwards compatibility slightly since previously all origins were allowed for `/stac` by | ||
| default. To keep the backwards compatible behaviour you can set: | ||
|
|
||
| ``` | ||
mishaschwartz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| export STAC_CORS_ORIGINS='~.*' | ||
| ``` | ||
|
Comment on lines
65
to
70
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't I think the The backward incompatibility note might be slightly misleading due to the subtlety of CORS. Before,
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure I can update that to keep the default. I've also updated the STAC and STAC Browser documentation since it was out of date.
I don't think so. Previously, the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Even if it was included and set with
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe that was the intention originally but it wasn't actually hidden. proxy_hide_header only hides header values set by the upstream server, not by nginx (#599 (comment)). Would you rather that we remain backwards compatible with the intended behaviour (no
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is fine with |
||
|
|
||
| to match all origins. | ||
mishaschwartz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| [2.18.7](https://github.com/bird-house/birdhouse-deploy/tree/2.18.7) (2025-10-17) | ||
| ------------------------------------------------------------------------------------------------------------------ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| config/magpie/config.yml | ||
| config/proxy/conf.extra-service.d/stac.conf | ||
| config/proxy/conf.extra-directives.d/stac.conf | ||
| config/canarie-api/canarie_api_monitoring.py | ||
| service-config.json |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| map $http_origin $stac_origin_allowed { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remind me what the Nginx This block means if the
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's mostly right... This block creates a new variable |
||
| # default should not be set to the empty string because the cors.include file will interpret | ||
| # that as "unset" and will change it to * by default. To get around this, set this to birdhouse's | ||
| # own origin (which has the same effect as being unset since same-origin requests are already allowed). | ||
| default ${BIRDHOUSE_PROXY_SCHEME}://${BIRDHOUSE_FQDN_PUBLIC}; | ||
| ${STAC_ADDITIONAL_CORS_ORIGINS} | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,9 @@ | |
| proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
| proxy_set_header X-Forwarded-Host $host:$server_port; | ||
| proxy_buffering off; | ||
| set $access_control_allow_origin $stac_origin_allowed; | ||
| include /etc/nginx/conf.d/cors.include; | ||
| add_header Vary Origin; | ||
|
||
| } | ||
|
|
||
| # Automatically redirect to /stac/stac and exclude redirect when already using /stac | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,6 +45,15 @@ export STAC_POPULATOR_BACKUP_IMAGE='${STAC_POPULATOR_BACKUP_DOCKER}:${STAC_POPUL | |
| # This must match the "stac_version" value in the current STAC catalog. | ||
| export PYSTAC_STAC_VERSION_OVERRIDE=1.0.0 | ||
|
|
||
| # Add additional origins that are allowed to access the /stac endpoint (other than the same origin) according to CORS rules. | ||
| # The values in the space delimited list set by STAC_CORS_ORIGINS are origins that will be allowed to access responses | ||
| # from /stac. These values can either be strings which will be matched directly or regular expressions prefixed by ~. | ||
| # | ||
| # For example, if STAC_CORS_ORIGINS='https://example.com ~^https?://(www\.)?other\.example\.com$' then requests from | ||
| # https://example.com and http://other.example.com will get a response with the Access-Control-Allow-Origin header set | ||
| # to their origin, but http://example.ca will not. | ||
| export STAC_ADDITIONAL_CORS_ORIGINS='$(for origin in $STAC_CORS_ORIGINS; do echo "$origin \$http_origin;"; done;)' | ||
|
|
||
| # add any new variables not already in 'VARS' or 'OPTIONAL_VARS' that must be replaced in templates here | ||
| # single quotes are important in below list to keep variable names intact until 'birdhouse-compose' parses them | ||
| EXTRA_VARS=' | ||
|
|
@@ -71,6 +80,7 @@ export DELAYED_EVAL=" | |
| STAC_MIGRATION_DOCKER | ||
| STAC_MIGRATION_IMAGE | ||
| STAC_POPULATOR_BACKUP_IMAGE | ||
| STAC_ADDITIONAL_CORS_ORIGINS | ||
| " | ||
|
|
||
| OPTIONAL_VARS=" | ||
|
|
@@ -86,4 +96,6 @@ OPTIONAL_VARS=" | |
| \$STAC_MIGRATION_TAGGED | ||
| \$STAC_MIGRATION_DOCKER | ||
| \$STAC_MIGRATION_IMAGE | ||
| \$STAC_ADDITIONAL_CORS_ORIGINS | ||
| \$STAC_CORS_ORIGIN_ALLOW_ALL | ||
|
||
| " | ||
Uh oh!
There was an error while loading. Please reload this page.