mirror of
https://github.com/open-webui/terminals.git
synced 2026-11-22 21:50:42 -05:00
refac
This commit is contained in:
1 parent
1c2897ced9
commit
87d2ea7b42
3 files changed
+15
-3
No files matched your search
@@ -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
|
||||
|
||||
@@ -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"),
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user