feat(backend): support access by offline challenge codes replaces the master account
Platform v2 step 1.10 (APPS_PLATFORM D-16, section 6.5).
- POST /api/auth/support/challenge (public): an 8-character challenge, stored 15 min
(support_challenges, revision 0009; at most 5 open). POST /api/auth/support/verify
{challenge, code}: code = base32(HMAC(SUPPORT_SECRET, site_id + challenge))[:10];
single use, 5 wrong codes burn the challenge. Opens a 4 h support session
(client=support, synthetic superadmin) with a hard end: sessions.expires_at.
- core/support_codes.py (stdlib only) is the derivation; tools/support_code.py
(--init, --site-secret <SITE_ID>, <SITE_ID> <CHALLENGE>) uses it on the builder's
machine with the master key in %USERPROFILE%/.xenia/support_master_key.txt.
- MASTER_USERNAME/MASTER_PASSWORD removed (config, login, docker-compose.yml,
.env.example); SUPPORT_SECRET added; install.sh asks for it.
- e2e: backends get SUPPORT_SECRET from a test master key and log in with challenge
codes (lib/support.mjs, license_e2e.py); install.mjs expects the new prompt.
- Pack rule CS-15.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -11,6 +11,7 @@ Starts the cloud on :8101 and the site on :8055, on throwaway databases.
|
||||
python license_e2e.py
|
||||
"""
|
||||
import base64
|
||||
import importlib.util
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
@@ -33,7 +34,12 @@ BACKEND = CS / "local_backend"
|
||||
CLOUD = Path(os.environ.get("CLOUD_DIR", CS.parent / "cloud-service" / "cloud_backend"))
|
||||
OUT = E2E / "out"
|
||||
CLOUD_URL, SITE_URL = "http://127.0.0.1:8101", "http://127.0.0.1:8055"
|
||||
MASTER = {"username": "e2e", "password": "e2e-pass-123"}
|
||||
# Support access (D-16): the site gets a SUPPORT_SECRET derived from this test master key,
|
||||
# and the suite logs in with a challenge code, the way the builder would.
|
||||
SUPPORT_MASTER = "e2e-support-master-key-0000000000"
|
||||
_spec = importlib.util.spec_from_file_location("support_codes", BACKEND / "core" / "support_codes.py")
|
||||
codes = importlib.util.module_from_spec(_spec)
|
||||
_spec.loader.exec_module(codes)
|
||||
|
||||
key = Ed25519PrivateKey.generate()
|
||||
PRIV = base64.b64encode(key.private_bytes(serialization.Encoding.Raw, serialization.PrivateFormat.Raw, serialization.NoEncryption())).decode()
|
||||
@@ -116,7 +122,7 @@ def start_cloud():
|
||||
def start_site(site_id, site_key):
|
||||
env = {**os.environ, "DATABASE_URL": f"sqlite:///{(tmp / 'data' / 'pos.db').as_posix()}", "CLOUD_URL": CLOUD_URL,
|
||||
"SITE_ID": site_id, "SITE_KEY": site_key, "SECRET_KEY": "e2e-site", "LICENSE_MODE": "enforced",
|
||||
"MASTER_USERNAME": MASTER["username"], "MASTER_PASSWORD": MASTER["password"]}
|
||||
"SUPPORT_SECRET": codes.site_secret(SUPPORT_MASTER, site_id)}
|
||||
launcher = (f"import services.license as L; L.LICENSE_PUBLIC_KEY = {PUB!r}; "
|
||||
"import uvicorn; uvicorn.run('main:app', host='127.0.0.1', port=8055)")
|
||||
procs["site"] = subprocess.Popen([sys.executable, "-c", launcher], cwd=BACKEND, env=env,
|
||||
@@ -133,7 +139,9 @@ def stop(name):
|
||||
|
||||
|
||||
def status():
|
||||
_, tok = call(SITE_URL, "POST", "/api/auth/login", MASTER)
|
||||
_, ch = call(SITE_URL, "POST", "/api/auth/support/challenge", {})
|
||||
code = codes.code_for(codes.site_secret(SUPPORT_MASTER, ch["site_id"]), ch["site_id"], ch["challenge"])
|
||||
_, tok = call(SITE_URL, "POST", "/api/auth/support/verify", {"challenge": ch["challenge"], "code": code})
|
||||
return call(SITE_URL, "GET", "/api/system/status", token=tok["access_token"])[1], tok["access_token"]
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user