0ef5fcb1c5
Security / Dependency audit (pip-audit) (push) Has been cancelled
Security / CodeQL (javascript-typescript) (push) Has been cancelled
Security / CodeQL (python) (push) Has been cancelled
Security / Secret scan (gitleaks) (push) Has been cancelled
rust / test (ubuntu) (push) Has been cancelled
rust / simulator e2e (macos-latest) (push) Has been cancelled
rust / simulator e2e (ubuntu-latest) (push) Has been cancelled
rust / simulator e2e (windows-latest) (push) Has been cancelled
rust / wheels (aarch64-apple-darwin) (push) Has been cancelled
rust / wheels (x86_64-unknown-linux-gnu) (push) Has been cancelled
rust / wheels (x86_64-apple-darwin) (push) Has been cancelled
rust / audit (push) Has been cancelled
rust / parity (nightly, allowed to fail during Phase 0) (push) Has been cancelled
CI / commitlint (push) Has been skipped
Dev Containers / validate (.devcontainer/devcontainer.json, default) (push) Failing after 0s
Dev Containers / validate (.devcontainer/memory-stack/devcontainer.json, memory-stack) (push) Failing after 0s
Dev Containers / validate-worktree (push) Failing after 0s
CI / changes (push) Failing after 4s
Deploy Documentation / validate (push) Has been skipped
Deploy Documentation / deploy (push) Failing after 1s
Init Native E2E / init-native (ubuntu-latest, claude) (push) Failing after 1s
Init Native E2E / init-native (ubuntu-latest, codex) (push) Failing after 1s
Install Native E2E / install-native (ubuntu-latest) (push) Failing after 1s
OpenCode Plugin / typecheck + build + test (push) Failing after 1s
Init Native E2E / init-native (ubuntu-latest, copilot) (push) Failing after 1s
Release Please / release-please (push) Failing after 1s
Wrap E2E / docker-wrap-e2e (push) Failing after 1s
Wrap Native E2E / wrap-native (ubuntu-latest) (push) Failing after 1s
Init E2E / docker-init-e2e (push) Failing after 4s
Merge Conflicts / merge-conflicts (push) Failing after 4s
CI / lint (push) Has been cancelled
CI / build-wheel (push) Has been cancelled
CI / build-wheel-windows (push) Has been cancelled
CI / prefetch-model (push) Has been cancelled
CI / test-dashboard-ui (push) Has been cancelled
CI / test (1) (push) Has been cancelled
CI / test (2) (push) Has been cancelled
CI / test (3) (push) Has been cancelled
CI / test (4) (push) Has been cancelled
CI / test-extras (push) Has been cancelled
CI / test-agno (push) Has been cancelled
CI / build (push) Has been cancelled
CI / workflow-validation (push) Has been cancelled
CI / docker-native-e2e (push) Has been cancelled
CI / windows-native-wrapper (push) Has been cancelled
CI / macos-native-wrapper (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-code-nonroot name:code-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-code-slim name:code-slim]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-code-slim-nonroot name:code-slim-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-nonroot name:nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-slim name:slim]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-slim-nonroot name:slim-nonroot]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime name:]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-code name:code]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-code-nonroot name:code-nonroot]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-code-slim name:code-slim]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-code-slim-nonroot name:code-slim-nonroot]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-nonroot name:nonroot]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-slim name:slim]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-slim-nonroot name:slim-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime name:]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-code name:code]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-code-nonroot name:code-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-code-slim name:code-slim]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-code-slim-nonroot name:code-slim-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-nonroot name:nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-slim name:slim]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-slim-nonroot name:slim-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime name:]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-code name:code]) (push) Has been cancelled
Docker / promote-latest (push) Has been cancelled
Init Native E2E / init-native (macos-latest, claude) (push) Has been cancelled
Init Native E2E / init-native (macos-latest, codex) (push) Has been cancelled
Init Native E2E / init-native (macos-latest, copilot) (push) Has been cancelled
Install Native E2E / install-native (macos-latest) (push) Has been cancelled
Wrap Native E2E / wrap-native (macos-latest) (push) Has been cancelled
112 lines
3.0 KiB
Python
112 lines
3.0 KiB
Python
"""Pure auth-mode and client classification policy."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import enum
|
|
from dataclasses import dataclass
|
|
|
|
|
|
class AuthMode(str, enum.Enum):
|
|
"""Auth-mode classes Headroom routes compression policy through."""
|
|
|
|
PAYG = "payg"
|
|
OAUTH = "oauth"
|
|
SUBSCRIPTION = "subscription"
|
|
|
|
|
|
SUBSCRIPTION_UA_PREFIXES: tuple[str, ...] = (
|
|
"claude-cli/",
|
|
"claude-code/",
|
|
"codex-cli/",
|
|
"cursor/",
|
|
"claude-vscode/",
|
|
"github-copilot/",
|
|
"anthropic-cli/",
|
|
"antigravity/",
|
|
)
|
|
|
|
|
|
CLIENT_UA_MAP: tuple[tuple[str, str], ...] = (
|
|
("claude-code/", "claude-code"),
|
|
("claude-cli/", "claude-code"),
|
|
("claude-vscode/", "claude-vscode"),
|
|
("anthropic-cli/", "anthropic-cli"),
|
|
("codex-cli/", "codex"),
|
|
("cursor/", "cursor"),
|
|
("zed/", "zed"),
|
|
("aider/", "aider"),
|
|
("droid/", "droid"),
|
|
("opencode/", "opencode"),
|
|
("github-copilot/", "copilot"),
|
|
("antigravity/", "antigravity"),
|
|
("strands-agents/", "strands"),
|
|
)
|
|
|
|
|
|
CODEX_RESPONSES_PATH = "/v1/responses"
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class AuthSignals:
|
|
"""Normalized header signals used by pure auth/client classifiers."""
|
|
|
|
user_agent: str = ""
|
|
authorization: str = ""
|
|
x_api_key: str = ""
|
|
x_goog_api_key: str = ""
|
|
x_client: str = ""
|
|
|
|
@property
|
|
def user_agent_lower(self) -> str:
|
|
return self.user_agent.lower()
|
|
|
|
|
|
def classify_auth_signals(signals: AuthSignals) -> AuthMode:
|
|
"""Classify auth mode from normalized header values."""
|
|
ua_lower = signals.user_agent_lower
|
|
for prefix in SUBSCRIPTION_UA_PREFIXES:
|
|
if prefix in ua_lower:
|
|
return AuthMode.SUBSCRIPTION
|
|
|
|
auth = signals.authorization
|
|
if auth.startswith("Bearer "):
|
|
token = auth[len("Bearer ") :]
|
|
if token.startswith("sk-ant-oat"):
|
|
return AuthMode.OAUTH
|
|
if token.startswith("sk-ant-api") or token.startswith("sk-"):
|
|
return AuthMode.PAYG
|
|
if len(token.split(".")) >= 3:
|
|
return AuthMode.OAUTH
|
|
elif auth:
|
|
return AuthMode.OAUTH
|
|
|
|
if signals.x_api_key:
|
|
return AuthMode.PAYG
|
|
if signals.x_goog_api_key:
|
|
return AuthMode.PAYG
|
|
return AuthMode.PAYG
|
|
|
|
|
|
def classify_client_signals(signals: AuthSignals, *, default: str | None = None) -> str | None:
|
|
"""Identify the client harness from normalized client signals."""
|
|
explicit = signals.x_client.strip().lower()
|
|
if explicit:
|
|
return explicit
|
|
ua_lower = signals.user_agent_lower
|
|
if not ua_lower:
|
|
return None
|
|
for needle, name in CLIENT_UA_MAP:
|
|
if needle in ua_lower:
|
|
return name
|
|
return default
|
|
|
|
|
|
def is_codex_responses_path(path: str) -> bool:
|
|
"""Return True for the OpenAI Responses endpoint and its subpaths."""
|
|
return path == CODEX_RESPONSES_PATH or path.startswith(CODEX_RESPONSES_PATH + "/")
|
|
|
|
|
|
def should_stamp_codex_client_signals(path: str, signals: AuthSignals) -> bool:
|
|
"""Whether an unidentified Responses caller should be stamped as Codex."""
|
|
return is_codex_responses_path(path) and classify_client_signals(signals) is None
|