Skip to content

Commit 2a38097

Browse files
allow custom cors headers for stac (#599)
## Overview - 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: ``` 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: ``` export STAC_CORS_ORIGINS='~.*' ``` to match all origins. ## Changes **Non-breaking changes** - Adds mechanism to allow services to have more control over CORS headers **Breaking changes** - responses from `/stac` no longer set `Access-Control-Allow-Origin: *` by default ## Related Issue / Discussion - As discussed in #450 ## Additional Information ## CI Operations <!-- The test suite can be run using a different DACCS config with ``birdhouse_daccs_configs_branch: branch_name`` in the PR description. To globally skip the test suite regardless of the commit message use ``birdhouse_skip_ci`` set to ``true`` in the PR description. Using ``[<cmd>]`` (with the brackets) where ``<cmd> = skip ci`` in the commit message will override ``birdhouse_skip_ci`` from the PR description. Such commit command can be used to override the PR description behavior for a specific commit update. However, a commit message cannot 'force run' a PR which the description turns off the CI. To run the CI, the PR should instead be updated with a ``true`` value, and a running message can be posted in following PR comments to trigger tests once again. --> birdhouse_daccs_configs_branch: master birdhouse_skip_ci: false
2 parents e56c9bb + b1c62a2 commit 2a38097

File tree

17 files changed

+154
-35
lines changed

17 files changed

+154
-35
lines changed

.bumpversion.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tool.bumpversion]
2-
current_version = "2.18.9"
2+
current_version = "2.18.10"
33
commit = true
44
tag = false
55
tag_name = "{new_version}"

CHANGES.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,58 @@
1717

1818
[//]: # (list changes here, using '-' for each new entry, remove this when items are added)
1919

20+
[2.18.10](https://github.com/bird-house/birdhouse-deploy/tree/2.18.10) (2025-11-12)
21+
------------------------------------------------------------------------------------------------------------------
22+
23+
## Changes
24+
25+
- Allow each service to specify values for `Access-Control-Allow-Origin`
26+
27+
Previously, if a `location` block in the `nginx` configuration for a given service included the cors helper
28+
configuration (with `include /etc/nginx/conf.d/cors.include;`) then all origins were allowed by default.
29+
30+
This was done by setting the header `Access-Control-Allow-Origin: *` which works well but is a bit too permissive
31+
since it allowed __all__ origins.
32+
33+
This change introduces a mechanism to specify specific additional allowed origins by setting the
34+
`$access_control_allow_origin` nginx variable in the `location` block before including the `cors.include` file.
35+
36+
For example:
37+
38+
```shell
39+
set $access_control_allow_origin http://example.com;
40+
include /etc/nginx/conf.d/cors.include;
41+
```
42+
43+
will set the value of the `Access-Control-Allow-Origin` response header to `http://example.com`.
44+
45+
By default, the header value will be `*` if `$access_control_allow_origin` is not set (to maintain backwards
46+
compatibility).
47+
48+
To specify multiple allowed origins, use a `map` directive (see the implementation for `components/stac` for an
49+
example).
50+
51+
- Set allowed CORS origins for `stac` through an environment variable
52+
53+
This change implements this flexibility for the `components/stac` component. By setting the `STAC_CORS_ORIGINS`
54+
variable a user can specify allowed origins for responses from the `components/stac` component.
55+
56+
For example, setting the following:
57+
58+
```shell
59+
export STAC_CORS_ORIGINS='https://example.com ~^https?://(www\.)?other\.example\.com$'
60+
```
61+
62+
then requests from https://example.com and http://other.example.com will get a response with the
63+
`Access-Control-Allow-Origin header` set to their origin, but http://example.ca will not.
64+
65+
Note that this breaks backwards compatibility slightly since previously all origins were allowed for `/stac` by
66+
default. To match all origins and keep the backwards compatible behaviour you can set:
67+
68+
```shell
69+
export STAC_CORS_ORIGINS='~.*'
70+
```
71+
2072
[2.18.9](https://github.com/bird-house/birdhouse-deploy/tree/2.18.9) (2025-11-10)
2173
------------------------------------------------------------------------------------------------------------------
2274

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ override BIRDHOUSE_MAKE_DIR := $(shell realpath -P $$(dirname $(BIRDHOUSE_MAKE_C
88
# Generic variables
99
override SHELL := bash
1010
override APP_NAME := birdhouse-deploy
11-
override APP_VERSION := 2.18.9
11+
override APP_VERSION := 2.18.10
1212

1313
# utility to remove comments after value of an option variable
1414
override clean_opt = $(shell echo "$(1)" | $(_SED) -r -e "s/[ '$'\t'']+$$//g")

README.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ for a full-fledged production platform.
1818
* - citation
1919
- | |citation|
2020

21-
.. |commits-since| image:: https://img.shields.io/github/commits-since/bird-house/birdhouse-deploy/2.18.9.svg
21+
.. |commits-since| image:: https://img.shields.io/github/commits-since/bird-house/birdhouse-deploy/2.18.10.svg
2222
:alt: Commits since latest release
23-
:target: https://github.com/bird-house/birdhouse-deploy/compare/2.18.9...master
23+
:target: https://github.com/bird-house/birdhouse-deploy/compare/2.18.10...master
2424

25-
.. |latest-version| image:: https://img.shields.io/badge/tag-2.18.9-blue.svg?style=flat
25+
.. |latest-version| image:: https://img.shields.io/badge/tag-2.18.10-blue.svg?style=flat
2626
:alt: Latest Tag
27-
:target: https://github.com/bird-house/birdhouse-deploy/tree/2.18.9
27+
:target: https://github.com/bird-house/birdhouse-deploy/tree/2.18.10
2828

2929
.. |readthedocs| image:: https://readthedocs.org/projects/birdhouse-deploy/badge/?version=latest
3030
:alt: ReadTheDocs Build Status (latest version)

RELEASE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.18.9 2025-11-10T17:14:06Z
1+
2.18.10 2025-11-12T17:25:51Z

birdhouse/components/README.rst

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -698,31 +698,62 @@ information.
698698
Usage
699699
-----
700700
701-
The STAC API can be browsed via the ``stac-browser`` component. By default, the browser will point to the STAC API
702-
exposed by the current stack instance. Once this component is enabled, STAC API will be accessible at
703-
``https://<BIRDHOUSE_FQDN_PUBLIC>/stac`` endpoint and the STAC browser will be available at
704-
``https://<BIRDHOUSE_FQDN_PUBLIC>/stac-browser`` endpoint. In order to make the STAC browser the default entrypoint,
705-
define the following in the ``env.local`` file::
706-
707-
export BIRDHOUSE_PROXY_ROOT_LOCATION='return 302 ${BIRDHOUSE_PROXY_SCHEME}://\$host/stac-browser;'
701+
The STAC API can be browsed via the ``stac-browser`` component. Once this component is enabled, STAC API
702+
will be accessible at the ``https://<BIRDHOUSE_FQDN_PUBLIC>/stac``.
708703
709-
Here is a sample search query using a CLI::
704+
Here is a sample search query using a the ``pystac-client`` python CLI:
710705
711706
.. code-block:: shell
712707
713708
pip install pystac-client
714-
stac-client search $PAVIS_FQDN/stac -q "variable_id=txgt_32" "scenario=ssp585"
709+
stac-client search $BIRDHOUSE_FQDN_PUBLIC/stac -q "variable_id=txgt_32" "scenario=ssp585"
715710
716-
Calls to the STAC API pass through Twitcher in order to validate authorization. Unauthenticated users will have
717-
read-only access by default to STAC API resources while members of the `stac-admin` group can create and modify
718-
resources. STAC Browser is not protected by any authorization mechanism.
711+
Calls to the STAC API pass through Twitcher in order to validate authorization.
712+
By default, only users that belong to the ``administrator`` and ``stac-admin`` groups will have access to STAC
713+
endpoints. Additional access permissions can be set in ``Magpie`` as needed.
714+
To give unauthenticated users read-only access to STAC API resources, enable the ``optional-components/stac-public-access``
715+
component.
719716
720717
How to Enable the Component
721718
---------------------------
722719
723720
- Edit ``env.local`` (a copy of `env.local.example`_)
724721
- Add ``./components/stac`` to ``BIRDHOUSE_EXTRA_CONF_DIRS``.
725722
723+
STAC Browser
724+
============
725+
726+
STAC Browser is a web UI used to interact with the STAC API.
727+
728+
Usage
729+
-----
730+
731+
The STAC API can be browsed via the ``stac-browser`` component. By default, the browser will point to the STAC API
732+
exposed by the current ``components/stac`` service.
733+
Once this component is enabled, the STAC browser will be available at the ``https://<BIRDHOUSE_FQDN_PUBLIC>/stac-browser``
734+
endpoint
735+
736+
If your STAC API contains geojson data, it is recommended to set the ``STAC_CORS_ORIGINS`` value to accept the origin
737+
``https://geojson.io`` since the STAC Browser offers a link to open geojson data at this URL.
738+
Note that you do not need to change the ``STAC_CORS_ORIGINS`` value from the default (which accepts all origins), but
739+
if you have changed it please update it to include this origin as well.
740+
741+
For example:
742+
743+
.. code::shell
744+
745+
# If the STAC_CORS_ORIGINS is currently
746+
export STAC_CORS_ORIGINS='http://example.com ~http:(www|other)\.api\.example\.com'
747+
748+
# you can update it to
749+
export STAC_CORS_ORIGINS='http://example.com ~http:(www|other)\.api\.example\.com https://geojson.io'
750+
751+
How to Enable the Component
752+
---------------------------
753+
754+
- Edit ``env.local`` (a copy of `env.local.example`_)
755+
- Add ``./components/stac-browser`` to ``BIRDHOUSE_EXTRA_CONF_DIRS``.
756+
726757
Canarie-API
727758
===========
728759

birdhouse/components/canarie-api/docker_configuration.py.template

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ SERVICES = {
108108
# NOTE:
109109
# Below version and release time auto-managed by 'make VERSION=x.y.z bump'.
110110
# Do NOT modify it manually. See 'Tagging policy' in 'birdhouse/README.rst'.
111-
'version': '2.18.9',
112-
'releaseTime': '2025-11-10T17:14:06Z',
111+
'version': '2.18.10',
112+
'releaseTime': '2025-11-12T17:25:51Z',
113113
'institution': '${BIRDHOUSE_INSTITUTION}',
114114
'researchSubject': '${BIRDHOUSE_SUBJECT}',
115115
'supportEmail': '${BIRDHOUSE_SUPPORT_EMAIL}',
@@ -141,8 +141,8 @@ PLATFORMS = {
141141
# NOTE:
142142
# Below version and release time auto-managed by 'make VERSION=x.y.z bump'.
143143
# Do NOT modify it manually. See 'Tagging policy' in 'birdhouse/README.rst'.
144-
'version': '2.18.9',
145-
'releaseTime': '2025-11-10T17:14:06Z',
144+
'version': '2.18.10',
145+
'releaseTime': '2025-11-12T17:25:51Z',
146146
'institution': '${BIRDHOUSE_INSTITUTION}',
147147
'researchSubject': '${BIRDHOUSE_SUBJECT}',
148148
'supportEmail': '${BIRDHOUSE_SUPPORT_EMAIL}',

birdhouse/components/proxy/conf.d/cors.include

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
proxy_hide_header 'Access-Control-Allow-Origin';
22

3+
if ( $access_control_allow_origin ~ "^$" ) {
4+
set $access_control_allow_origin '*';
5+
}
6+
7+
set $vary_origin ""; # nginx will omit this header value if set to the empty string
8+
if ( $access_control_allow_origin != '*' ) {
9+
set $vary_origin Origin;
10+
}
11+
312
if ($request_method = 'OPTIONS') {
4-
add_header 'Access-Control-Allow-Origin' '*';
13+
add_header 'Access-Control-Allow-Origin' $access_control_allow_origin;
14+
add_header Vary $vary_origin;
515
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
616
#
717
# Custom headers and headers various browsers *should* be OK with but aren't
@@ -16,13 +26,15 @@
1626
return 204;
1727
}
1828
if ($request_method = 'POST') {
19-
add_header 'Access-Control-Allow-Origin' '*';
29+
add_header 'Access-Control-Allow-Origin' $access_control_allow_origin;
30+
add_header Vary $vary_origin;
2031
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
2132
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
2233
add_header 'Access-Control-Expose-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
2334
}
2435
if ($request_method = 'GET') {
25-
add_header 'Access-Control-Allow-Origin' '*';
36+
add_header 'Access-Control-Allow-Origin' $access_control_allow_origin;
37+
add_header Vary $vary_origin;
2638
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
2739
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
2840
add_header 'Access-Control-Expose-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';

birdhouse/components/proxy/conf.d/frontend.conf.template

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ map $http_x_forwarded_proto $real_scheme {
1414
'' $scheme;
1515
}
1616

17+
include /etc/nginx/conf.extra-directives.d/*/*.conf;
18+
1719
server {
1820
listen 80 ${PROXY_LISTEN_80_PARAMS};
1921
server_name localhost;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
config/magpie/config.yml
22
config/proxy/conf.extra-service.d/stac.conf
3+
config/proxy/conf.extra-directives.d/stac.conf
34
config/canarie-api/canarie_api_monitoring.py
45
service-config.json

0 commit comments

Comments
 (0)