Skip to content

Commit 5e7f6a7

Browse files
gkorlandCopilot
andauthored
fix: remove SECRET_TOKEN static API key requirement (#479)
Users create their own API tokens via /tokens/generate (stored in FalkorDB), so the static SECRET_TOKEN env var is redundant. Removes: - The SECRET_TOKEN module-level variable and hmac check in validate_user - The hmac import (no longer needed) - All references in .env.example, CI workflows, and test conftest Reverts the hard requirement introduced in #476. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 015ad95 commit 5e7f6a7

4 files changed

Lines changed: 3 additions & 29 deletions

File tree

.env.example

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ FALKORDB_URL=redis://localhost:6379/0 # REQUIRED - change to your FalkorDB URL
4444
# -----------------------------
4545
# API / secret tokens
4646
# -----------------------------
47-
# REQUIRED: static bearer token for internal / programmatic API access.
48-
# The server refuses to start when this is missing.
49-
SECRET_TOKEN=your_secret_token
47+
# Optional: static bearer token for internal / programmatic API access.
48+
# When set, this token is accepted as a "master" API key.
49+
# When unset, only user-generated tokens are accepted.
5050
# SECRET_TOKEN_ERP=your_erp_token
5151

5252
# -----------------------------

.github/workflows/playwright.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ jobs:
136136
env:
137137
PYTHONUNBUFFERED: 1
138138
FASTAPI_SECRET_KEY: test-secret-key-for-ci
139-
SECRET_TOKEN: test-secret-token-for-ci
140139
APP_ENV: development
141140
FASTAPI_DEBUG: False
142141
FALKORDB_URL: redis://localhost:6379

api/auth/user_management.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""User management and authentication functions for text2sql API."""
22

33
import base64
4-
import hmac
54
import logging
65
import os
76
import secrets
@@ -20,16 +19,6 @@
2019
"FASTAPI_SECRET_KEY not set, using generated key. Set this in production!"
2120
)
2221

23-
# Static API token for internal / programmatic access.
24-
# REQUIRED: the server refuses to start when this is missing so that
25-
# an unconfigured deployment never silently disables authentication.
26-
SECRET_TOKEN: str = os.environ.get("SECRET_TOKEN", "")
27-
if not SECRET_TOKEN:
28-
raise RuntimeError(
29-
"SECRET_TOKEN environment variable is required but not set. "
30-
"Set it to a strong, random value before starting the server."
31-
)
32-
3322

3423
class IdentityInfo(BaseModel):
3524
"""
@@ -249,15 +238,6 @@ async def validate_user(request: Request) -> Tuple[Optional[Dict[str, Any]], boo
249238
if not api_token:
250239
return None, False
251240

252-
# Accept the static SECRET_TOKEN for internal / programmatic access.
253-
# Uses constant-time comparison to prevent timing attacks.
254-
if hmac.compare_digest(api_token, SECRET_TOKEN):
255-
return {
256-
"email": "api@internal",
257-
"name": "API",
258-
"picture": None,
259-
}, True
260-
261241
db_info = await _get_user_info(api_token)
262242

263243
if db_info:

tests/conftest.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44
import subprocess
55
import time
66

7-
# SECRET_TOKEN must be set before any test imports api.index (which triggers
8-
# app creation and the startup SECRET_TOKEN requirement check).
9-
os.environ.setdefault("SECRET_TOKEN", "test-secret-token")
10-
117
import pytest # pylint: disable=wrong-import-position
128
import requests # pylint: disable=wrong-import-position
139

@@ -31,7 +27,6 @@ def fastapi_app():
3127
'GOOGLE_CLIENT_SECRET': 'test-google-client-secret',
3228
'GITHUB_CLIENT_ID': 'test-github-client-id',
3329
'GITHUB_CLIENT_SECRET': 'test-github-client-secret',
34-
'SECRET_TOKEN': 'test-secret-token',
3530
'ENABLE_TEST_AUTH': 'true', # Enable test auth bypass for E2E tests
3631
}
3732
for var, default in env_defaults.items():

0 commit comments

Comments
 (0)