Skip to content

Commit db03850

Browse files
committed
in progress
1 parent d2b270f commit db03850

File tree

14 files changed

+191
-100
lines changed

14 files changed

+191
-100
lines changed

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ STAC Auth Proxy is a proxy API that mediates between the client and your interna
99

1010
## ✨Features✨
1111

12-
- 🔐 Authentication: Selectively apply [OpenID Connect (OIDC)](https://openid.net/developers/how-connect-works/) auth\*n token validation & optional scope requirements to some or all endpoints & methods
13-
- 🛂 Content Filtering: Apply CQL2 filters to client requests, utilizing the [Filter Extension](https://github.com/stac-api-extensions/filter?tab=readme-ov-file) to filter API content based on user context
14-
- 🧩 Authentication Extension: Integrate the [Authentication Extension](https://github.com/stac-extensions/authentication) into API responses
15-
- 📘 OpenAPI Augmentation: Update API's [OpenAPI document](https://swagger.io/specification/) with security requirements, keeping auto-generated docs/UIs accurate (e.g. [Swagger UI](https://swagger.io/tools/swagger-ui/))
16-
- 🗜️ Response compression: Compress API responses via [`starlette-cramjam`](https://github.com/developmentseed/starlette-cramjam/)
12+
- **🔐 Authentication:** Apply [OpenID Connect (OIDC)](https://openid.net/developers/how-connect-works/) token validation and optional scope checks to specified endpoints and methods
13+
- **🛂 Content Filtering:** Use CQL2 filters via the [Filter Extension](https://github.com/stac-api-extensions/filter?tab=readme-ov-file) to tailor API responses based on user context
14+
- **🤝 External Policy Integration:** Integrate with externalsystems (e.g. [Open Policy Agent (OPA)](https://www.openpolicyagent.org/)) to generate CQL2 filters dynamically from policy decisions
15+
- **🧩 Authentication Extension:** Add the [Authentication Extension](https://github.com/stac-extensions/authentication) to API responses to expose auth-related metadata
16+
- **📘 OpenAPI Augmentation:** Enhance the [OpenAPI spec](https://swagger.io/specification/) with security details to keep auto-generated docs and UIs (e.g., [Swagger UI](https://swagger.io/tools/swagger-ui/)) accurate
17+
- **🗜️ Response Compression:** Optimize response sizes using [`starlette-cramjam`](https://github.com/developmentseed/starlette-cramjam/)
1718

1819
## Usage
1920

File renamed without changes.
File renamed without changes.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Open Policy Agent (OPA) Integration
2+
3+
This example demonstrates how to integrate with an Open Policy Agent (OPA) to authorize requests to a STAC API.
4+
5+
## Running the Example
6+
7+
From the root directory, run:
8+
9+
```sh
10+
docker compose -f docker-compose.yaml -f examples/opa/docker-compose.yaml up
11+
```
12+
13+
## Testing OPA
14+
15+
```sh
16+
▶ curl -X POST "http://localhost:8181/v1/data/stac/cql2" \
17+
-H "Content-Type: application/json" \
18+
-d '{"input":{"payload": null}}'
19+
{"result":"private = true"}
20+
```
21+
22+
```sh
23+
▶ curl -X POST "http://localhost:8181/v1/data/stac/cql2" \
24+
-H "Content-Type: application/json" \
25+
-d '{"input":{"payload": {"sub": "user1"}}}'
26+
{"result":"1=1"}
27+
```
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
services:
2+
proxy:
3+
depends_on:
4+
- stac
5+
- opa
6+
build:
7+
context: examples/opa
8+
# environment:
9+
# UPSTREAM_URL: ${UPSTREAM_URL:-http://stac:8001}
10+
# OIDC_DISCOVERY_URL: ${OIDC_DISCOVERY_URL:-http://localhost:8888/.well-known/openid-configuration}
11+
# OIDC_DISCOVERY_INTERNAL_URL: ${OIDC_DISCOVERY_INTERNAL_URL:-http://oidc:8888/.well-known/openid-configuration}
12+
# ITEMS_FILTER_CLS: opa_integration:OpaIntegration
13+
# ITEMS_FILTER_ARGS: '["http://opa:8181", "stac/cql2"]'
14+
env_file:
15+
- path: .env
16+
required: false
17+
ports:
18+
- "8000:8000"
19+
volumes:
20+
- ./src:/app/src
21+
22+
opa:
23+
image: openpolicyagent/opa:latest
24+
command: "run --server --addr=:8181 --watch /policies"
25+
ports:
26+
- "8181:8181"
27+
volumes:
28+
- ./examples/opa/policies:/policies
29+
depends_on:
30+
- stac
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package stac
2+
3+
default cql2 := "private = true"
4+
5+
cql2 := "1=1" if {
6+
input.payload.sub != null
7+
}

examples/opa/pyproject.toml renamed to examples/custom-integration/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[project]
2-
name = "opa_integration"
2+
name = "custom_integration"
33
version = "0.1.0"
44
description = "Add your description here"
55
readme = "README.md"

examples/opa/docker-compose.yaml

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,8 @@
11
services:
22
proxy:
3-
depends_on:
4-
- stac
5-
- opa
6-
build:
7-
context: examples/opa
83
environment:
9-
UPSTREAM_URL: ${UPSTREAM_URL:-http://stac:8001}
10-
OIDC_DISCOVERY_URL: ${OIDC_DISCOVERY_URL:-http://localhost:8888/.well-known/openid-configuration}
11-
OIDC_DISCOVERY_INTERNAL_URL: ${OIDC_DISCOVERY_INTERNAL_URL:-http://oidc:8888/.well-known/openid-configuration}
12-
ITEMS_FILTER_CLS: opa_integration:OpaIntegration
4+
ITEMS_FILTER_CLS: stac_auth_proxy.filters:Opa
135
ITEMS_FILTER_ARGS: '["http://opa:8181", "stac/cql2"]'
14-
env_file:
15-
- path: .env
16-
required: false
17-
ports:
18-
- "8000:8000"
19-
volumes:
20-
- ./src:/app/src
216

227
opa:
238
image: openpolicyagent/opa:latest
@@ -26,5 +11,3 @@ services:
2611
- "8181:8181"
2712
volumes:
2813
- ./examples/opa/policies:/policies
29-
depends_on:
30-
- stac

examples/opa/policies/stac/policy.rego

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package stac
22

3-
default cql2 := "private = true"
3+
default cql2 := "\"naip:year\" = 2021"
44

55
cql2 := "1=1" if {
66
input.payload.sub != null

examples/opa/src/opa_integration.py

Lines changed: 0 additions & 70 deletions
This file was deleted.

0 commit comments

Comments
 (0)