This commit is contained in:
Timothy Jaeryang Baek committed 2026-11-05 11:01:39 +09:00
1 parent 1c2897ced9
commit 87d2ea7b42
3 files changed
+15 -3

No files matched your search

+2
View File
@@ -287,6 +287,8 @@ The quick start uses a static `TERMINALS_API_KEY` for both the admin UI and Open
For Open WebUI session authentication, set `TERMINALS_OPEN_WEBUI_URL` and use **Session** auth on the Open WebUI terminal connection. Terminals validates user tokens against that instance. Admin policy and lifecycle APIs still require a separate Terminals admin API key; user JWTs are not enough.
Tool discovery at `/openapi.json` and `/p/{policy_id}/openapi.json` also accepts the Terminals admin API key in Session mode. Terminal operations still require a valid user token.
`terminals serve` generates and prints a key if none is configured. That generated key changes when the service process restarts. Running the ASGI app directly without either authentication setting allows unauthenticated access and is intended only for local development.
## Configuration
+10
View File
@@ -135,6 +135,16 @@ async def verify_admin_api_key(
return None
async def verify_spec_access(
authorization: Optional[str] = Header(None),
) -> Optional[str]:
"""Allow the admin API key for tool discovery before a user is involved."""
scheme, _, token = (authorization or "").partition(" ")
if settings.api_key and scheme.lower() == "bearer" and token == settings.api_key:
return None
return await verify_api_key(authorization)
async def verify_user_id(
verified_id: Optional[str] = Depends(verify_api_key),
x_user_id: str = Header(..., alias="X-User-Id"),
+3 -3
View File
@@ -33,7 +33,7 @@ from terminals.utils.context import (
normalize_context_id,
)
from terminals.utils.policy_specs import PolicyNotFoundError, resolve_policy_spec
from terminals.routers.auth import validate_token, verify_api_key, verify_user_id
from terminals.routers.auth import validate_token, verify_api_key, verify_spec_access, verify_user_id
router = APIRouter()
@@ -406,7 +406,7 @@ async def _get_cached_spec(
@router.get(
"/openapi.json",
dependencies=[Depends(verify_api_key)],
dependencies=[Depends(verify_spec_access)],
)
async def get_openapi_spec(request: Request):
"""Return the open-terminal OpenAPI spec.
@@ -457,7 +457,7 @@ async def _resolve_policy_spec(policy_id: str) -> tuple[str, dict | None]:
@router.get(
"/p/{policy_id}/openapi.json",
dependencies=[Depends(verify_api_key)],
dependencies=[Depends(verify_spec_access)],
)
async def policy_openapi_spec(
policy_id: str,