Repository navigation
feat: enforce API key authentication on all data routes - #45
Merged
Merged
Conversation
Add auth_middleware that intercepts every request when REASONDB_AUTH_ENABLED=true. Public paths (/health, /metrics, /swagger-ui, /api-docs) bypass auth so monitoring stays accessible. All /v1/* routes now require a valid API key or the master key. - Add auth_middleware (axum from_fn_with_state) with header extraction for both Authorization: Bearer and X-API-Key - Add FromRequestParts impl for AuthenticatedKey (async_trait, axum 0.7) - Add async-trait dependency to reasondb-server - Wire middleware into create_server before rate limiting - Add auth_enabled and master_key Terraform variables - Pass REASONDB_AUTH_ENABLED and REASONDB_MASTER_KEY through user_data.sh.tpl
Add a null_resource with remote-exec provisioner so terraform apply updates the running Docker container whenever the image tag, LLM config, or auth settings change — without recreating the EC2 instance. Triggers on: reasondb_image, llm_provider, llm_model, llm_base_url, auth_enabled, master_key hash, llm_api_key hash, instance_id. Also adds ssh_private_key_path variable (default ~/.ssh/id_ed25519) used by the provisioner SSH connection.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
/v1/*routes now require a valid API key or master key whenREASONDB_AUTH_ENABLED=true. Public paths (/health,/metrics,/swagger-ui,/api-docs) bypass auth so monitoring and docs stay accessibleFromRequestPartsimpl:AuthenticatedKeycan be used as an axum extractor in route handlers directlynull_resourceupdater:terraform applynow SSHes into the running instance and hot-swaps the Docker container wheneverreasondb_image, LLM config, or auth settings change — no need to taint/recreate the EC2 instanceauth_enabled(bool),master_key(sensitive),ssh_private_key_pathHow auth works
Test plan
REASONDB_AUTH_ENABLED=false— all routes still work without a key (backward compatible)REASONDB_AUTH_ENABLED=true, no key →401on any/v1/*routeREASONDB_AUTH_ENABLED=true, wrong key →401REASONDB_AUTH_ENABLED=true, master key →200REASONDB_AUTH_ENABLED=true, valid API key →200/health,/metrics,/swagger-uiaccessible without any key when auth is enabledterraform applyafter changingreasondb_imagein tfvars SSHes in and restarts the container