llama-stack/llama_stack/distribution
Ashwin Bharambe 5b39d5a76a
feat(auth, rfc): Add support for Bearer (api_key) Authentication (#1626)
This PR adds support (or is a proposal for) for supporting API KEY
authentication on the Llama Stack server end. `llama-stack-client`
already supports accepting an api_key parameter and passes it down
through every request as an `Authentication: ` header.

Currently, Llama Stack does not propose APIs for handling authentication
or authorization for resources of any kind. Given that, and the fact
that any deployment will typically have _some_ authentication system
present, we simply adopt a delegation mechanism: delegate to an HTTPS
endpoint performing key management / authentication.

It is configured via: 
```yaml
server: 
   auth:
     endpoint: <...>
```

in the run.yaml configuration.


## How It Works

When authentication is enabled:

1. Every API request must include an `Authorization: Bearer <token>`
header
2. The server will send a _POST_ validation request to the configured
endpoint with the following payload:
   ```json
   {
     "api_key": "<token>",
     "request": {
       "path": "/api/path",
       "headers": { "header1": "value1", ... },
       "params": { "param1": "value1", ... }
     }
   }
   ```
3. If the authentication endpoint returns a 200 status code, the request
is allowed to proceed
4. If the authentication endpoint returns any other status code, a 401
Unauthorized response is returned

## Test Plan

Unit tests
2025-03-18 16:24:18 -07:00
..
routers fix: return 4xx for non-existent resources in GET requests (#1635) 2025-03-18 14:06:53 -07:00
server feat(auth, rfc): Add support for Bearer (api_key) Authentication (#1626) 2025-03-18 16:24:18 -07:00
store refactor: move a few tests to top-level tests/ directory 2025-03-03 17:33:39 -08:00
ui fix: Fixed import errors for UI and playground (#1666) 2025-03-18 15:00:48 -07:00
utils refactor: simplify command execution and remove PTY handling (#1641) 2025-03-17 15:03:14 -07:00
__init__.py API Updates (#73) 2024-09-17 19:51:35 -07:00
build.py refactor: simplify command execution and remove PTY handling (#1641) 2025-03-17 15:03:14 -07:00
build_conda_env.sh chore: remove straggler references to llama-models (#1345) 2025-03-01 14:26:03 -08:00
build_container.sh fix: build distribution with podman (#1671) 2025-03-17 14:30:06 -07:00
build_venv.sh chore: remove straggler references to llama-models (#1345) 2025-03-01 14:26:03 -08:00
client.py chore: move all Llama Stack types from llama-models to llama-stack (#1098) 2025-02-14 09:10:59 -08:00
common.sh fix: Fixing some small issues with the build scripts (#1132) 2025-02-19 22:20:49 -08:00
configure.py feat: add provider API for listing and inspecting provider info (#1429) 2025-03-13 15:07:21 -07:00
datatypes.py feat(auth, rfc): Add support for Bearer (api_key) Authentication (#1626) 2025-03-18 16:24:18 -07:00
distribution.py feat: add provider API for listing and inspecting provider info (#1429) 2025-03-13 15:07:21 -07:00
inspect.py fix: improve signal handling and update dependencies (#1044) 2025-02-13 08:07:59 -08:00
library_client.py feat: Add back inference metrics and preserve context variables across asyncio boundary (#1552) 2025-03-12 12:01:03 -07:00
providers.py fix: add shutdown method for ProviderImpl (#1670) 2025-03-17 14:55:40 -07:00
request_headers.py feat: Add back inference metrics and preserve context variables across asyncio boundary (#1552) 2025-03-12 12:01:03 -07:00
resolver.py feat: add provider API for listing and inspecting provider info (#1429) 2025-03-13 15:07:21 -07:00
stack.py feat: add provider API for listing and inspecting provider info (#1429) 2025-03-13 15:07:21 -07:00
start_stack.sh feat(logging): implement category-based logging (#1362) 2025-03-07 11:34:30 -08:00