-
Notifications
You must be signed in to change notification settings - Fork 4
feat: Add helm chart auth options. #118
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
Draft
pantierra
wants to merge
1
commit into
main
Choose a base branch
from
feature/helm-filter-configuration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+601
−17
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| # Authorization configuration guide | ||
|
|
||
| The chart provides two levels of authorization: | ||
|
|
||
| 1. **[Route-level authorization](https://developmentseed.org/stac-auth-proxy/user-guide/route-level-auth/)**: Controls which API endpoints are accessible and by whom | ||
| 2. **[Record-level authorization](https://developmentseed.org/stac-auth-proxy/user-guide/record-level-auth/)**: Filters collections and items based on user permissions | ||
|
|
||
| ## Route-Level Authorization | ||
|
|
||
| Configure via `authorization.route` section in `values.yaml`. | ||
|
|
||
| ### Mode: `default` (Recommended) | ||
|
|
||
| Public catalog with protected write operations. This is the most common configuration. | ||
|
|
||
| ```yaml | ||
| authorization: | ||
| route: | ||
| mode: "default" | ||
| ``` | ||
|
|
||
| This automatically sets `DEFAULT_PUBLIC=true`, making all read endpoints public while requiring authentication for write operations. | ||
|
|
||
| ### Mode: `custom` | ||
|
|
||
| Define specific public and private endpoints with custom rules. | ||
|
|
||
| ```yaml | ||
| authorization: | ||
| route: | ||
| mode: "custom" | ||
| publicEndpoints: | ||
| "^/collections$": ["GET"] | ||
| "^/search$": ["GET", "POST"] | ||
| "^/api.html$": ["GET"] | ||
| "^/healthz": ["GET"] | ||
| privateEndpoints: | ||
| "^/collections$": [["POST", "collection:create"]] | ||
| "^/collections/([^/]+)$": [["PUT", "collection:update"], ["DELETE", "collection:delete"]] | ||
| "^/collections/([^/]+)/items$": [["POST", "item:create"]] | ||
| ``` | ||
|
|
||
| **Endpoint format:** | ||
| - `publicEndpoints`: Maps regex paths to HTTP methods arrays | ||
| - `privateEndpoints`: Maps regex paths to HTTP methods or `[method, scope]` tuples | ||
| - Scopes define required OAuth2 scopes for the operation | ||
|
|
||
| ### Mode: `disabled` | ||
|
|
||
| No route-level authorization applied. | ||
|
|
||
| ```yaml | ||
| authorization: | ||
| route: | ||
| mode: "disabled" | ||
| ``` | ||
|
|
||
| ## Record-Level Authorization | ||
|
|
||
| Configure via `authorization.record` section in `values.yaml`. | ||
|
|
||
| ### Mode: `disabled` (Default) | ||
|
|
||
| No record-level filtering applied. All collections and items are visible to authenticated users. | ||
|
|
||
| ```yaml | ||
| authorization: | ||
| record: | ||
| mode: "disabled" | ||
| ``` | ||
|
|
||
| ### Mode: `custom` | ||
|
|
||
| Use Python filter classes to control visibility of collections and items. | ||
|
|
||
| ```yaml | ||
| authorization: | ||
| record: | ||
| mode: "custom" | ||
| custom: | ||
| filtersFile: "data/custom_filters.py" | ||
| ``` | ||
|
|
||
| This automatically: | ||
| - Creates a ConfigMap from your Python file | ||
| - Mounts it at `/app/src/stac_auth_proxy/custom_filters.py` | ||
| - Sets `COLLECTIONS_FILTER_CLS=stac_auth_proxy.custom_filters:CollectionsFilter` | ||
| - Sets `ITEMS_FILTER_CLS=stac_auth_proxy.custom_filters:ItemsFilter` | ||
|
|
||
| Review the stac-auth-proxy [documentation for more information on custom filters](https://developmentseed.org/stac-auth-proxy/user-guide/record-level-auth/#custom-filter-factories). | ||
|
|
||
| ### Mode: `opa` | ||
|
|
||
| Use Open Policy Agent for policy-based filtering. | ||
|
|
||
| ```yaml | ||
| authorization: | ||
| record: | ||
| mode: "opa" | ||
| opa: | ||
| url: "http://opa-service:8181" | ||
| policy: "stac/items/allow" | ||
| ``` | ||
|
|
||
| This sets: | ||
| - `ITEMS_FILTER_CLS=stac_auth_proxy.filters.opa:Opa` | ||
| - `ITEMS_FILTER_ARGS='["http://opa-service:8181", "stac/items/allow"]'` | ||
|
|
||
| ## Some configuration examples | ||
|
|
||
| ### Example 1: Default for public catalog, protected writes | ||
|
|
||
| ```yaml | ||
| authorization: | ||
| route: | ||
| mode: "default" | ||
| record: | ||
| mode: "disabled" | ||
| ``` | ||
|
|
||
| ### Example 2: Fully protected catalog | ||
|
|
||
| ```yaml | ||
| authorization: | ||
| route: | ||
| mode: "custom" | ||
| publicEndpoints: | ||
| "^/healthz": ["GET"] | ||
| privateEndpoints: | ||
| "^/collections$": [["GET", "stac:read"], ["POST", "stac:write"]] | ||
| "^/search$": [["GET", "stac:read"], ["POST", "stac:read"]] | ||
| record: | ||
| mode: "custom" | ||
| custom: | ||
| filtersFile: "data/custom_filters.py" | ||
| ``` | ||
|
|
||
| ## Direct configuration | ||
|
|
||
| Existing charts using `env` variables directly continue to work: | ||
|
|
||
| ```yaml | ||
| env: | ||
| DEFAULT_PUBLIC: "false" | ||
| PUBLIC_ENDPOINTS: '{"^/search$": ["GET"]}' | ||
| PRIVATE_ENDPOINTS: '{"^/collections$": [["POST", "collection:create"]]}' | ||
| ITEMS_FILTER_CLS: "custom.module:Filter" | ||
| ``` | ||
|
|
||
| **Environment variables specified in `env` take precedence over `authorization` settings.** | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| """ | ||
| Sample custom filters for STAC Auth Proxy. | ||
| This file demonstrates the structure needed for custom collection and item filters. | ||
| """ | ||
|
|
||
| import dataclasses | ||
| from typing import Any | ||
|
|
||
|
|
||
| @dataclasses.dataclass | ||
| class CollectionsFilter: | ||
| """Filter collections based on user permissions.""" | ||
|
|
||
| async def __call__(self, context: dict[str, Any]) -> str: | ||
| """Return True if user can access this collection.""" | ||
| # Example: Allow all collections for authenticated users | ||
| return "1=1" | ||
|
|
||
|
|
||
| @dataclasses.dataclass | ||
| class ItemsFilter: | ||
| """Filter items based on user permissions.""" | ||
|
|
||
| async def __call__(self, context: dict[str, Any]) -> str: | ||
| """Return True if user can access this item.""" | ||
| # Example: Allow all items for authenticated users | ||
| return "1=1" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| {{- if and (eq (.Values.authorization.record.mode | default "disabled") "custom") .Values.authorization.record.custom.filtersFile }} | ||
| apiVersion: v1 | ||
| kind: ConfigMap | ||
| metadata: | ||
| name: {{ include "stac-auth-proxy.fullname" . }}-filters | ||
| labels: | ||
| {{- include "stac-auth-proxy.labels" . | nindent 4 }} | ||
| data: | ||
| custom_filters.py: | | ||
| {{ .Files.Get .Values.authorization.record.custom.filtersFile | nindent 4 }} | ||
| {{- end }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should we push this into the docs directory to publish at developmentseed.org/stac-auth-proxy?
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.
This might be a bit out of context. We could move it into the docs but frame it as helm/kubernetes setup and include this.
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.
Aside from the repo, is there anywhere else that this information would be surfaced?
I'd ideally like for people to be able to think about this tool as a packaged product rather than just a codebase, hence my view that docs should be available outside of the repo
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.
Aside from the repo, is there anywhere else that this information would be surfaced?
I'd ideally like for people to be able to think about this tool as a packaged product rather than just a codebase, hence my view that docs should be available outside of the repo
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.
Happy to move it to the docs. Perhaps good to bring in #117 first? After that I can combine README and AUTHORIZATION into one file in the docs.