Skip to content

Basic Authentication not working as intended #310

Closed
@pedro-cf

Description

@pedro-cf

Describe the bug
The Basic Authentication implementation in stac-fastapi-elasticsearch is not working as expected. When configuring multiple user credentials through STAC_FASTAPI_ROUTE_DEPENDENCIES, the authentication fails even with valid credentials.

To Reproduce
Steps to reproduce the behavior:

  1. Configure basic auth with multiple users in docker-compose.yml:
- STAC_FASTAPI_ROUTE_DEPENDENCIES=[{"routes":[{"method":"*","path":"*"}],"dependencies":[{"method":"stac_fastapi.core.basic_auth.BasicAuth","kwargs":{"credentials":[{"username":"admin","password":"admin"}]}}]},{"routes":[{"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"]}],"dependencies":[{"method":"stac_fastapi.core.basic_auth.BasicAuth","kwargs":{"credentials":[{"username":"reader","password":"reader"}]}}]}]
  1. Start the stac-fastapi-elasticsearch service with basic auth configuration:
docker-compose up -d
  1. Try to access the root endpoint with valid credentials:
curl --request GET \
  --url http://localhost:8080/ \
  --header 'Authorization: Basic YWRtaW46YWRtaW4='
curl --request GET \
  --url http://localhost:8080/ \
  --header 'Authorization: Basic cmVhZGVyOnJlYWRlcg=='
  1. Receive error response:
{"detail":"Incorrect username or password"}

Expected behavior

  • The API should accept valid credentials from any user configured in the route dependencies
  • Both "admin:admin" and "reader:reader" credentials should work for their respective configured routes
  • When a route is configured for multiple users, any of their credentials should work

Environment:

  • OS: Ubuntu 22.04.4 LTS
  • Docker version: Docker version 27.1.1, build 6312585
  • stac-fastapi-elasticsearch version: 3.2.0
  • Python version: 3.10

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions