Fix admin password read at import time
Browse filesChange ADMIN_PASSWORD from a module-level constant to a dynamic
_get_admin_password() function that reads the env var at call time.
This matches the pattern used for _get_master_key() and ensures the
Space picks up the secret even if it was set after the process started.
app.py
CHANGED
|
@@ -41,8 +41,9 @@ from validation.validate import (
|
|
| 41 |
|
| 42 |
logger = logging.getLogger(__name__)
|
| 43 |
|
| 44 |
-
|
| 45 |
-
|
|
|
|
| 46 |
|
| 47 |
# Master secret env var name — used to derive per-user signing keys.
|
| 48 |
# Set as HF Space secret — never exposed publicly.
|
|
@@ -751,9 +752,10 @@ def process_upload(file):
|
|
| 751 |
|
| 752 |
def admin_remove_submission(agent_id: str, password: str):
|
| 753 |
"""Remove a submission by agent_id (admin only)."""
|
| 754 |
-
|
|
|
|
| 755 |
return "Admin password not configured. Set ADMIN_PASSWORD in Space secrets."
|
| 756 |
-
if password !=
|
| 757 |
return "Invalid admin password."
|
| 758 |
if not agent_id or not agent_id.strip():
|
| 759 |
return "Please enter an agent_id."
|
|
@@ -773,9 +775,10 @@ def admin_remove_submission(agent_id: str, password: str):
|
|
| 773 |
|
| 774 |
def admin_view_key_requests(password: str) -> str:
|
| 775 |
"""Show all key requests (admin only)."""
|
| 776 |
-
|
|
|
|
| 777 |
return "Admin password not configured. Set ADMIN_PASSWORD in Space secrets."
|
| 778 |
-
if password !=
|
| 779 |
return "Invalid admin password."
|
| 780 |
|
| 781 |
requests = _load_key_requests()
|
|
|
|
| 41 |
|
| 42 |
logger = logging.getLogger(__name__)
|
| 43 |
|
| 44 |
+
def _get_admin_password() -> str:
|
| 45 |
+
"""Read admin password at call time (not import time) so Space picks up secret changes."""
|
| 46 |
+
return os.environ.get("ADMIN_PASSWORD", "")
|
| 47 |
|
| 48 |
# Master secret env var name — used to derive per-user signing keys.
|
| 49 |
# Set as HF Space secret — never exposed publicly.
|
|
|
|
| 752 |
|
| 753 |
def admin_remove_submission(agent_id: str, password: str):
|
| 754 |
"""Remove a submission by agent_id (admin only)."""
|
| 755 |
+
admin_pw = _get_admin_password()
|
| 756 |
+
if not admin_pw:
|
| 757 |
return "Admin password not configured. Set ADMIN_PASSWORD in Space secrets."
|
| 758 |
+
if password != admin_pw:
|
| 759 |
return "Invalid admin password."
|
| 760 |
if not agent_id or not agent_id.strip():
|
| 761 |
return "Please enter an agent_id."
|
|
|
|
| 775 |
|
| 776 |
def admin_view_key_requests(password: str) -> str:
|
| 777 |
"""Show all key requests (admin only)."""
|
| 778 |
+
admin_pw = _get_admin_password()
|
| 779 |
+
if not admin_pw:
|
| 780 |
return "Admin password not configured. Set ADMIN_PASSWORD in Space secrets."
|
| 781 |
+
if password != admin_pw:
|
| 782 |
return "Invalid admin password."
|
| 783 |
|
| 784 |
requests = _load_key_requests()
|