fix: persist workspace Python environments

This commit is contained in:
wuyang
2026-07-26 20:20:37 +08:00
parent bc30a480ad
commit 2fbb5698ac
14 changed files with 170 additions and 20 deletions
+23
View File
@@ -1,6 +1,7 @@
from __future__ import annotations
import hmac
import time
from dataclasses import dataclass
from typing import Annotated
@@ -18,6 +19,28 @@ class UserIdentity:
role: str
def issue_internal_identity(identity: UserIdentity, secret: str, ttl_seconds: int = 300) -> str:
"""Mint a fresh, short-lived identity for a trusted internal service hop."""
if not secret:
raise ValueError("Identity signing secret is not configured")
if ttl_seconds < 1:
raise ValueError("Identity lifetime must be positive")
now = int(time.time())
return jwt.encode(
{
"sub": identity.user_id,
"email": identity.email,
"name": identity.name,
"role": identity.role,
"iss": "open-webui",
"iat": now,
"exp": now + ttl_seconds,
},
secret,
algorithm="HS256",
)
def verify_service_bearer(authorization: str | None, expected: str) -> None:
if not expected:
raise HTTPException(status_code=status.HTTP_503_SERVICE_UNAVAILABLE, detail="Service secret is not configured")