-
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 3 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 | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -698,31 +698,60 @@ information. | |||||||||||||||||||
| Usage | ||||||||||||||||||||
| ----- | ||||||||||||||||||||
|
|
||||||||||||||||||||
| The STAC API can be browsed via the ``stac-browser`` component. By default, the browser will point to the STAC API | ||||||||||||||||||||
| exposed by the current stack instance. Once this component is enabled, STAC API will be accessible at | ||||||||||||||||||||
| ``https://<BIRDHOUSE_FQDN_PUBLIC>/stac`` endpoint and the STAC browser will be available at | ||||||||||||||||||||
| ``https://<BIRDHOUSE_FQDN_PUBLIC>/stac-browser`` endpoint. In order to make the STAC browser the default entrypoint, | ||||||||||||||||||||
| define the following in the ``env.local`` file:: | ||||||||||||||||||||
|
|
||||||||||||||||||||
| export BIRDHOUSE_PROXY_ROOT_LOCATION='return 302 ${BIRDHOUSE_PROXY_SCHEME}://\$host/stac-browser;' | ||||||||||||||||||||
| The STAC API can be browsed via the ``stac-browser`` component. Once this component is enabled, STAC API | ||||||||||||||||||||
| will be accessible at the ``https://<BIRDHOUSE_FQDN_PUBLIC>/stac``. | ||||||||||||||||||||
|
|
||||||||||||||||||||
| Here is a sample search query using a CLI:: | ||||||||||||||||||||
| Here is a sample search query using a the ``pystac-client`` python CLI: | ||||||||||||||||||||
|
|
||||||||||||||||||||
| .. code-block:: shell | ||||||||||||||||||||
|
|
||||||||||||||||||||
| pip install pystac-client | ||||||||||||||||||||
| stac-client search $PAVIS_FQDN/stac -q "variable_id=txgt_32" "scenario=ssp585" | ||||||||||||||||||||
| stac-client search $BIRDHOUSE_FQDN_PUBLIC/stac -q "variable_id=txgt_32" "scenario=ssp585" | ||||||||||||||||||||
|
|
||||||||||||||||||||
| Calls to the STAC API pass through Twitcher in order to validate authorization. Unauthenticated users will have | ||||||||||||||||||||
| read-only access by default to STAC API resources while members of the `stac-admin` group can create and modify | ||||||||||||||||||||
| resources. STAC Browser is not protected by any authorization mechanism. | ||||||||||||||||||||
| read-only access to STAC API resources while members of the `stac-admin` group can create and modify | ||||||||||||||||||||
| resources if the ``optional-components/stac-public-access`` component is enabled. | ||||||||||||||||||||
|
||||||||||||||||||||
| permissions: | |
| # create a default 'stac' resource under 'stac' service | |
| # because of the '/stac/stac' path prefix required to resolve the API links properly, | |
| # all permissions must be nested under this 'stac' resource for requests and permissions to be resolved accordingly | |
| - service: stac | |
| resource: /stac | |
| permission: read | |
| group: administrator # they already have access, just using admins to create the resource by default | |
| action: create |
| 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,17 @@ 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. | ||
| # By default all origins are allowed. Set STAC_CORS_ORIGINS in the local environment file to limit the allowed origins. | ||
| export STAC_CORS_ORIGINS="~.*" | ||
| 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 +82,7 @@ export DELAYED_EVAL=" | |
| STAC_MIGRATION_DOCKER | ||
| STAC_MIGRATION_IMAGE | ||
| STAC_POPULATOR_BACKUP_IMAGE | ||
| STAC_ADDITIONAL_CORS_ORIGINS | ||
| " | ||
|
|
||
| OPTIONAL_VARS=" | ||
|
|
@@ -86,4 +98,6 @@ OPTIONAL_VARS=" | |
| \$STAC_MIGRATION_TAGGED | ||
| \$STAC_MIGRATION_DOCKER | ||
| \$STAC_MIGRATION_IMAGE | ||
| \$STAC_ADDITIONAL_CORS_ORIGINS | ||
| \$STAC_CORS_ORIGIN_ALLOW_ALL | ||
|
||
| " | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"STAC Browser is not protected by any authorization mechanism", this part is not true anymore, that's why it is removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's technically true but it's misleading. Access to the stac-browser endpoint is not checked by twitcher but if the user doesn't have permissions to read the stac data (because the stac endpoint is protected by twitcher) then the stac-browser page shows a 403 error anyway.
So from the user's perspective it is protected by an authorization mechanism, it's the same one that protects the stac endpoint.