Skip to content

Commit 9bbf03b

Browse files
authored
Merge pull request #232 from pedro-cf/basic_auth
Basic auth
2 parents b089e6d + fe05aab commit 9bbf03b

File tree

10 files changed

+560
-0
lines changed

10 files changed

+560
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Added option to include Basic Auth [#232](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/232)
13+
1014
### Fixed
1115

1216
- Fixed `POST /collections/test-collection/items` returning an item with an empty links array [#236](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/236)

README.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,3 +272,83 @@ curl -X "POST" "http://localhost:9200/_aliases" \
272272
```
273273

274274
The modified Items with lowercase identifiers will now be visible to users accessing `my-collection` in the STAC API.
275+
276+
277+
## Basic Auth
278+
279+
#### Environment Variable Configuration
280+
281+
Basic authentication is an optional feature. You can enable it by setting the environment variable `BASIC_AUTH` as a JSON string.
282+
283+
Example:
284+
```
285+
BASIC_AUTH={"users":[{"username":"user","password":"pass","permissions":"*"}]}
286+
```
287+
288+
### User Permissions Configuration
289+
290+
In order to set endpoints with specific access permissions, you can configure the `users` key with a list of user objects. Each user object should contain the username, password, and their respective permissions.
291+
292+
Example: This example illustrates the configuration for two users: an **admin** user with full permissions (*) and a **reader** user with limited permissions to specific read-only endpoints.
293+
```json
294+
{
295+
"users": [
296+
{
297+
"username": "admin",
298+
"password": "admin",
299+
"permissions": "*"
300+
},
301+
{
302+
"username": "reader",
303+
"password": "reader",
304+
"permissions": [
305+
{"path": "/", "method": ["GET"]},
306+
{"path": "/conformance", "method": ["GET"]},
307+
{"path": "/collections/{collection_id}/items/{item_id}", "method": ["GET"]},
308+
{"path": "/search", "method": ["GET", "POST"]},
309+
{"path": "/collections", "method": ["GET"]},
310+
{"path": "/collections/{collection_id}", "method": ["GET"]},
311+
{"path": "/collections/{collection_id}/items", "method": ["GET"]},
312+
{"path": "/queryables", "method": ["GET"]},
313+
{"path": "/queryables/collections/{collection_id}/queryables", "method": ["GET"]},
314+
{"path": "/_mgmt/ping", "method": ["GET"]}
315+
]
316+
}
317+
]
318+
}
319+
```
320+
321+
322+
### Public Endpoints Configuration
323+
324+
In order to set endpoints with public access, you can configure the public_endpoints key with a list of endpoint objects. Each endpoint object should specify the path and method of the endpoint.
325+
326+
Example: This example demonstrates the configuration for public endpoints, allowing access without authentication to read-only endpoints.
327+
```json
328+
{
329+
"public_endpoints": [
330+
{"path": "/", "method": "GET"},
331+
{"path": "/conformance", "method": "GET"},
332+
{"path": "/collections/{collection_id}/items/{item_id}", "method": "GET"},
333+
{"path": "/search", "method": "GET"},
334+
{"path": "/search", "method": "POST"},
335+
{"path": "/collections", "method": "GET"},
336+
{"path": "/collections/{collection_id}", "method": "GET"},
337+
{"path": "/collections/{collection_id}/items", "method": "GET"},
338+
{"path": "/queryables", "method": "GET"},
339+
{"path": "/queryables/collections/{collection_id}/queryables", "method": "GET"},
340+
{"path": "/_mgmt/ping", "method": "GET"}
341+
],
342+
"users": [
343+
{
344+
"username": "admin",
345+
"password": "admin",
346+
"permissions": "*"
347+
}
348+
]
349+
}
350+
```
351+
352+
### Docker Compose Configurations
353+
354+
See `docker-compose.basic_auth_protected.yml` and `docker-compose.basic_auth_public.yml` for basic authentication configurations.
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
version: '3.9'
2+
3+
services:
4+
app-elasticsearch:
5+
container_name: stac-fastapi-es
6+
image: stac-utils/stac-fastapi-es
7+
restart: always
8+
build:
9+
context: .
10+
dockerfile: dockerfiles/Dockerfile.dev.es
11+
environment:
12+
- STAC_FASTAPI_TITLE=stac-fastapi-elasticsearch
13+
- STAC_FASTAPI_DESCRIPTION=A STAC FastAPI with an Elasticsearch backend
14+
- STAC_FASTAPI_VERSION=2.1
15+
- APP_HOST=0.0.0.0
16+
- APP_PORT=8080
17+
- RELOAD=true
18+
- ENVIRONMENT=local
19+
- WEB_CONCURRENCY=10
20+
- ES_HOST=elasticsearch
21+
- ES_PORT=9200
22+
- ES_USE_SSL=false
23+
- ES_VERIFY_CERTS=false
24+
- BACKEND=elasticsearch
25+
- BASIC_AUTH={"users":[{"username":"admin","password":"admin","permissions":"*"},{"username":"reader","password":"reader","permissions":[{"path":"/","method":["GET"]},{"path":"/conformance","method":["GET"]},{"path":"/collections/{collection_id}/items/{item_id}","method":["GET"]},{"path":"/search","method":["GET","POST"]},{"path":"/collections","method":["GET"]},{"path":"/collections/{collection_id}","method":["GET"]},{"path":"/collections/{collection_id}/items","method":["GET"]},{"path":"/queryables","method":["GET"]},{"path":"/queryables/collections/{collection_id}/queryables","method":["GET"]},{"path":"/_mgmt/ping","method":["GET"]}]}]}
26+
ports:
27+
- "8080:8080"
28+
volumes:
29+
- ./stac_fastapi:/app/stac_fastapi
30+
- ./scripts:/app/scripts
31+
- ./esdata:/usr/share/elasticsearch/data
32+
depends_on:
33+
- elasticsearch
34+
command:
35+
bash -c "./scripts/wait-for-it-es.sh es-container:9200 && python -m stac_fastapi.elasticsearch.app"
36+
37+
app-opensearch:
38+
container_name: stac-fastapi-os
39+
image: stac-utils/stac-fastapi-os
40+
restart: always
41+
build:
42+
context: .
43+
dockerfile: dockerfiles/Dockerfile.dev.os
44+
environment:
45+
- STAC_FASTAPI_TITLE=stac-fastapi-opensearch
46+
- STAC_FASTAPI_DESCRIPTION=A STAC FastAPI with an Opensearch backend
47+
- STAC_FASTAPI_VERSION=2.1
48+
- APP_HOST=0.0.0.0
49+
- APP_PORT=8082
50+
- RELOAD=true
51+
- ENVIRONMENT=local
52+
- WEB_CONCURRENCY=10
53+
- ES_HOST=opensearch
54+
- ES_PORT=9202
55+
- ES_USE_SSL=false
56+
- ES_VERIFY_CERTS=false
57+
- BACKEND=opensearch
58+
- BASIC_AUTH={"users":[{"username":"admin","password":"admin","permissions":"*"},{"username":"reader","password":"reader","permissions":[{"path":"/","method":["GET"]},{"path":"/conformance","method":["GET"]},{"path":"/collections/{collection_id}/items/{item_id}","method":["GET"]},{"path":"/search","method":["GET","POST"]},{"path":"/collections","method":["GET"]},{"path":"/collections/{collection_id}","method":["GET"]},{"path":"/collections/{collection_id}/items","method":["GET"]},{"path":"/queryables","method":["GET"]},{"path":"/queryables/collections/{collection_id}/queryables","method":["GET"]},{"path":"/_mgmt/ping","method":["GET"]}]}]}
59+
ports:
60+
- "8082:8082"
61+
volumes:
62+
- ./stac_fastapi:/app/stac_fastapi
63+
- ./scripts:/app/scripts
64+
- ./osdata:/usr/share/opensearch/data
65+
depends_on:
66+
- opensearch
67+
command:
68+
bash -c "./scripts/wait-for-it-es.sh os-container:9202 && python -m stac_fastapi.opensearch.app"
69+
70+
elasticsearch:
71+
container_name: es-container
72+
image: docker.elastic.co/elasticsearch/elasticsearch:${ELASTICSEARCH_VERSION:-8.11.0}
73+
hostname: elasticsearch
74+
environment:
75+
ES_JAVA_OPTS: -Xms512m -Xmx1g
76+
volumes:
77+
- ./elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
78+
- ./elasticsearch/snapshots:/usr/share/elasticsearch/snapshots
79+
ports:
80+
- "9200:9200"
81+
82+
opensearch:
83+
container_name: os-container
84+
image: opensearchproject/opensearch:${OPENSEARCH_VERSION:-2.11.1}
85+
hostname: opensearch
86+
environment:
87+
- discovery.type=single-node
88+
- plugins.security.disabled=true
89+
- OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m
90+
volumes:
91+
- ./opensearch/config/opensearch.yml:/usr/share/opensearch/config/opensearch.yml
92+
- ./opensearch/snapshots:/usr/share/opensearch/snapshots
93+
ports:
94+
- "9202:9202"

docker-compose.basic_auth_public.yml

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
version: '3.9'
2+
3+
services:
4+
app-elasticsearch:
5+
container_name: stac-fastapi-es
6+
image: stac-utils/stac-fastapi-es
7+
restart: always
8+
build:
9+
context: .
10+
dockerfile: dockerfiles/Dockerfile.dev.es
11+
environment:
12+
- STAC_FASTAPI_TITLE=stac-fastapi-elasticsearch
13+
- STAC_FASTAPI_DESCRIPTION=A STAC FastAPI with an Elasticsearch backend
14+
- STAC_FASTAPI_VERSION=2.1
15+
- APP_HOST=0.0.0.0
16+
- APP_PORT=8080
17+
- RELOAD=true
18+
- ENVIRONMENT=local
19+
- WEB_CONCURRENCY=10
20+
- ES_HOST=elasticsearch
21+
- ES_PORT=9200
22+
- ES_USE_SSL=false
23+
- ES_VERIFY_CERTS=false
24+
- BACKEND=elasticsearch
25+
- BASIC_AUTH={"public_endpoints":[{"path":"/","method":"GET"},{"path":"/conformance","method":"GET"},{"path":"/collections/{collection_id}/items/{item_id}","method":"GET"},{"path":"/search","method":"GET"},{"path":"/search","method":"POST"},{"path":"/collections","method":"GET"},{"path":"/collections/{collection_id}","method":"GET"},{"path":"/collections/{collection_id}/items","method":"GET"},{"path":"/queryables","method":"GET"},{"path":"/queryables/collections/{collection_id}/queryables","method":"GET"},{"path":"/_mgmt/ping","method":"GET"}],"users":[{"username":"admin","password":"admin","permissions":[{"path":"/","method":["GET"]},{"path":"/conformance","method":["GET"]},{"path":"/collections/{collection_id}/items/{item_id}","method":["GET","POST","PUT","DELETE"]},{"path":"/search","method":["GET","POST"]},{"path":"/collections","method":["GET","PUT","POST"]},{"path":"/collections/{collection_id}","method":["GET","DELETE"]},{"path":"/collections/{collection_id}/items","method":["GET","POST"]},{"path":"/queryables","method":["GET"]},{"path":"/queryables/collections/{collection_id}/queryables","method":["GET"]},{"path":"/_mgmt/ping","method":["GET"]}]}]}
26+
ports:
27+
- "8080:8080"
28+
volumes:
29+
- ./stac_fastapi:/app/stac_fastapi
30+
- ./scripts:/app/scripts
31+
- ./esdata:/usr/share/elasticsearch/data
32+
depends_on:
33+
- elasticsearch
34+
command:
35+
bash -c "./scripts/wait-for-it-es.sh es-container:9200 && python -m stac_fastapi.elasticsearch.app"
36+
37+
app-opensearch:
38+
container_name: stac-fastapi-os
39+
image: stac-utils/stac-fastapi-os
40+
restart: always
41+
build:
42+
context: .
43+
dockerfile: dockerfiles/Dockerfile.dev.os
44+
environment:
45+
- STAC_FASTAPI_TITLE=stac-fastapi-opensearch
46+
- STAC_FASTAPI_DESCRIPTION=A STAC FastAPI with an Opensearch backend
47+
- STAC_FASTAPI_VERSION=2.1
48+
- APP_HOST=0.0.0.0
49+
- APP_PORT=8082
50+
- RELOAD=true
51+
- ENVIRONMENT=local
52+
- WEB_CONCURRENCY=10
53+
- ES_HOST=opensearch
54+
- ES_PORT=9202
55+
- ES_USE_SSL=false
56+
- ES_VERIFY_CERTS=false
57+
- BACKEND=opensearch
58+
- BASIC_AUTH={"public_endpoints":[{"path":"/","method":"GET"},{"path":"/conformance","method":"GET"},{"path":"/collections/{collection_id}/items/{item_id}","method":"GET"},{"path":"/search","method":"GET"},{"path":"/search","method":"POST"},{"path":"/collections","method":"GET"},{"path":"/collections/{collection_id}","method":"GET"},{"path":"/collections/{collection_id}/items","method":"GET"},{"path":"/queryables","method":"GET"},{"path":"/queryables/collections/{collection_id}/queryables","method":"GET"},{"path":"/_mgmt/ping","method":"GET"}],"users":[{"username":"admin","password":"admin","permissions":[{"path":"/","method":["GET"]},{"path":"/conformance","method":["GET"]},{"path":"/collections/{collection_id}/items/{item_id}","method":["GET","POST","PUT","DELETE"]},{"path":"/search","method":["GET","POST"]},{"path":"/collections","method":["GET","PUT","POST"]},{"path":"/collections/{collection_id}","method":["GET","DELETE"]},{"path":"/collections/{collection_id}/items","method":["GET","POST"]},{"path":"/queryables","method":["GET"]},{"path":"/queryables/collections/{collection_id}/queryables","method":["GET"]},{"path":"/_mgmt/ping","method":["GET"]}]}]}
59+
ports:
60+
- "8082:8082"
61+
volumes:
62+
- ./stac_fastapi:/app/stac_fastapi
63+
- ./scripts:/app/scripts
64+
- ./osdata:/usr/share/opensearch/data
65+
depends_on:
66+
- opensearch
67+
command:
68+
bash -c "./scripts/wait-for-it-es.sh os-container:9202 && python -m stac_fastapi.opensearch.app"
69+
70+
elasticsearch:
71+
container_name: es-container
72+
image: docker.elastic.co/elasticsearch/elasticsearch:${ELASTICSEARCH_VERSION:-8.11.0}
73+
hostname: elasticsearch
74+
environment:
75+
ES_JAVA_OPTS: -Xms512m -Xmx1g
76+
volumes:
77+
- ./elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
78+
- ./elasticsearch/snapshots:/usr/share/elasticsearch/snapshots
79+
ports:
80+
- "9200:9200"
81+
82+
opensearch:
83+
container_name: os-container
84+
image: opensearchproject/opensearch:${OPENSEARCH_VERSION:-2.11.1}
85+
hostname: opensearch
86+
environment:
87+
- discovery.type=single-node
88+
- plugins.security.disabled=true
89+
- OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m
90+
volumes:
91+
- ./opensearch/config/opensearch.yml:/usr/share/opensearch/config/opensearch.yml
92+
- ./opensearch/snapshots:/usr/share/opensearch/snapshots
93+
ports:
94+
- "9202:9202"

stac_fastapi/core/setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"overrides",
1919
"geojson-pydantic",
2020
"pygeofilter==0.2.1",
21+
"typing_extensions==4.4.0",
2122
]
2223

2324
setup(

0 commit comments

Comments
 (0)