Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
3232ae3
Worker: an appliance key's link secret, and POST /api/license/link (#…
teaspoonai Nov 29, 2026
870fa03
Worker tests: the acceptance a box's setup makes is taken, and links …
teaspoonai Nov 29, 2026
e6f7731
Box: the owner's license helpers, to record and link their acceptance…
teaspoonai Nov 29, 2026
eda09eb
Root helpers: none writes, renames or removes the engine's license fi…
teaspoonai Nov 29, 2026
ef1aa3c
Setup: Read the license / I accept, beside Create your login (#465)
teaspoonai Nov 29, 2026
25448e5
install.sh: a factory install keeps the license text for the owner's …
teaspoonai Nov 29, 2026
ed72c41
Docs: the owner accepts the engine license at setup, and its link (#465)
teaspoonai Nov 29, 2026
350d8f2
Worker: /api/license/link answers one 403 before the secret; a move u…
teaspoonai Nov 29, 2026
492ca90
Box: the license helpers pin the license server, lock sends, recover …
teaspoonai Nov 29, 2026
5b050d5
Setup: Not you? Accept again, and Settings' login waits for the licen…
teaspoonai Nov 29, 2026
e18581f
Docs: the window before the link, the only proof of ownership, I1 as …
teaspoonai Nov 29, 2026
e8e9c49
Worker: owner_use (personal or business) for a box's setup; a link al…
teaspoonai Nov 29, 2026
5040bee
Box: Not you? ends with the owner's login; a mask that tells lookalik…
teaspoonai Nov 29, 2026
bb972ed
Docs: the support re-link, personal or business, the login's window (…
teaspoonai Nov 29, 2026
451e5e6
Worker: request_id dedups a resent acceptance; no Cc/Cf in an email; …
teaspoonai Nov 29, 2026
c542c1a
Box: no format characters in an email, IDNA in the mask, a caller tha…
teaspoonai Nov 29, 2026
dbd2faf
Docs: support's re-link ties the key to the requester's box, by facto…
teaspoonai Nov 29, 2026
060516d
Worker: every link rotates the link secret, with a handover; NFKC and…
teaspoonai Nov 29, 2026
bd7ae8b
Box: the link writes the rotated secret and confirms it; the holder o…
teaspoonai Nov 29, 2026
03ad823
Docs: re-link from the box first (possession outranks records); a run…
teaspoonai Nov 29, 2026
f3d42bd
Worker: a one-time recovery code for a box a copy locked out; the re-…
teaspoonai Nov 29, 2026
02fd899
Box: a lost link said, link --recovery-code; a failed replace keeps t…
teaspoonai Nov 29, 2026
27ccb06
Docs: the link contest, the lost state and the recovery code; a runbo…
teaspoonai Nov 29, 2026
4023edf
Worker: a handover's previous secret ends in an hour; a recovery code…
teaspoonai Nov 29, 2026
2efbe81
Box: the timer runs until a link's handover is confirmed, after setup…
teaspoonai Nov 29, 2026
6bdc09c
Docs: the owner's decision of 2026-11-29 as decided; the handover's e…
teaspoonai Nov 29, 2026
7ba1b08
Worker: a day's handover, the recovery code kept as the previous
teaspoonai Nov 29, 2026
385720c
Box: a lost handover said as lost; the handover marker cannot outlive…
teaspoonai Nov 29, 2026
076df9d
Runbook: writes checked by SELECTs; docs for the day's handover
teaspoonai Nov 29, 2026
cac02db
Box: a secret that never linked, refused, is a failed link of unknown…
teaspoonai Nov 29, 2026
be4a528
Box: a first link refused bad_link_secret is a failed link too
teaspoonai Nov 29, 2026
2c66fc5
Docs: what support checks first for a box whose link failed (#465)
teaspoonai Nov 29, 2026
04b3305
Docs: the acceptance's device_id from a box's setup is the serial's h…
teaspoonai Nov 29, 2026
1d758e8
Merge feat/license-issue-474 (main with #480, #482) into feat/owner-a…
teaspoonai Nov 30, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,15 @@ jobs:
/opt/teaport/brain/bin/teaport-brain --help >/dev/null
test -x /usr/bin/teaport && bash -n /usr/bin/teaport
# compile(), not py_compile: that would write a __pycache__ beside the helper.
for p in /usr/lib/teaport/config_apply.py /usr/lib/teaport/update_apply.py /usr/lib/teaport/wifi_apply.py /usr/lib/teaport/login_apply.py; do
for p in /usr/lib/teaport/config_apply.py /usr/lib/teaport/update_apply.py /usr/lib/teaport/wifi_apply.py /usr/lib/teaport/login_apply.py /usr/lib/teaport/license_accept.py /usr/lib/teaport/license_link.py; do
/usr/bin/python3 -I -c 'import sys; p = sys.argv[1]; compile(open(p).read(), p, "exec")' "$p"
done
# The update's unit, as systemd reads it (it is static: nothing enables it).
systemd-analyze verify /usr/lib/systemd/system/teaport-update.service
[ "$(systemctl show -p UnitFileState --value teaport-update.service)" = static ]
# The owner's license retry (#465): enabled by the package's own link.
systemd-analyze verify /usr/lib/systemd/system/teaport-license-owner.service /usr/lib/systemd/system/teaport-license-owner.timer
[ "$(readlink /usr/lib/systemd/system/timers.target.wants/teaport-license-owner.timer)" = /usr/lib/systemd/system/teaport-license-owner.timer ]
- name: dpkg -V is clean, and the package owns every file under its root
run: |
out="$(dpkg -V teaport-brain)"
Expand Down
17 changes: 16 additions & 1 deletion brain/teaport_brain/config_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@
STOPPABLE = ("teaport-wifi-setup",)
MAX_BYTES = 64 * 1024
BACKUPS = 5
# The engine's license files (teaport#474 F1): nothing here writes, renames or removes them,
# whatever a path above comes to name. The same tuple in every root helper the run user
# reaches (license_link.PROTECTED is the one list; tests hold the copies to it).
PROTECTED = ("/etc/teaport/license.json", "/etc/teaport/license-revocations.json",
"/etc/teaport/license-link.secret")


def protected(path: str) -> bool:
"""`path` is one of PROTECTED, by name or through a link."""
return os.path.abspath(path) in PROTECTED or os.path.realpath(path) in PROTECTED


# Only backups THIS code named are ever pruned. Operators keep their own beside
# them (brain.env.bak-gptoss, brain.env.bak-20260901-154338-stopsecs on the dev
# box) and those are not ours to rotate out.
Expand Down Expand Up @@ -102,6 +114,8 @@ def write(name: str, content: str) -> str:
if content and not content.endswith("\n"):
content += "\n"
path = os.path.join(ETC, name)
if protected(path):
raise SystemExit(f"refusing to write {name!r}: it is the engine's license")
mode, uid, gid = 0o640, 0, int(os.environ.get("SUDO_GID", "0"))
if os.path.exists(path):
st = os.stat(path)
Expand Down Expand Up @@ -138,7 +152,8 @@ def _backup(path: str, mode: int, uid: int, gid: int) -> None:
older = sorted(f for f in os.listdir(os.path.dirname(path))
if f.startswith(base + ".bak-") and BACKUP_RE.search(f))
for name in older[:-BACKUPS]:
os.unlink(os.path.join(os.path.dirname(path), name))
if not protected(os.path.join(os.path.dirname(path), name)):
os.unlink(os.path.join(os.path.dirname(path), name))


def restart(unit: str) -> None:
Expand Down
84 changes: 83 additions & 1 deletion brain/teaport_brain/config_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
POST /api/restart {unit} — deferred restart through config_apply
GET /api/login whether the owner's login is pending (#421), and its words
POST /api/login {password, again} — creates it, through owner_login
GET /api/eula whether the owner's license step is pending (#465), the
license's text, and the step's words
POST /api/eula {email, accept, eula_sha256} — the owner accepts it, through
owner_license
GET /licenses the open-source licenses page (static/licenses.html); its data is
GET /api/licenses and GET /api/licenses/{package} (licenses.py)

Expand Down Expand Up @@ -904,14 +908,92 @@ async def login_create(request: Request):
password, again = _login_body(await request.json())
except ValueError:
raise HTTPException(status_code=400, detail="the request is not JSON") from None
t = _reader(request)
# Setup is unfinished until the license is accepted, as on the setup page, where it comes
# first (#465): while it waits, the login waits for it too.
from teaport_brain import owner_license
if await asyncio.to_thread(_owner_license().pending):
logger.info("config: the owner's login not created (the license first) from Settings")
return {"ok": False, "why": "license_first",
"message": owner_license.say(t, owner_license.TEXT["login_first"])}
ok, why = await asyncio.to_thread(_owner_login().create, password, again)
logger.info("config: the owner's login " + ("created" if ok else f"not created ({why})")
+ " from Settings")
t = _reader(request)
msgid = owner_login.TEXT["created"] if ok else owner_login.WHY[why]
return {"ok": ok, "why": why or None, "message": owner_login.say(t, msgid)}


# ------------------------------------------------------------------ the owner's license
# The "Read the license" card (#465), beside "Create your login": offered while setup is
# unfinished on a box provisioning marked for it and nobody has accepted the license there
# yet, for an owner whose box got online without the setup page (or whose setup page had no
# copy of the license to show). Setup finishes only once it is accepted, and the login card
# waits for it (login_create); nothing else on the box does (the engine runs under the box's
# appliance key). An acceptance made, while it may still be replaced, shows its email masked,
# with "Not you? Accept again". The recording is
# owner_license's, through license_accept and license_link as root; the email goes there
# and nowhere else (no log line, no answer).


def _owner_license():
"""Replaced in tests."""
from teaport_brain import owner_license
return owner_license.License()


@router.get("/api/eula")
async def eula_state(request: Request):
"""Whether the card is offered, the license's text when it is, and the card's words in
the reader's language. The text is the helper's (the channel's manifest, checked)."""
from teaport_brain import owner_license
_authorize(request)
t = _reader(request)
lic = _owner_license()
state = await asyncio.to_thread(lic.state)
# Accepted while setup is unfinished: whose email (masked), and whether it may still be
# replaced ("Not you? Accept again"; license_accept.py says why it is shown).
accepted = await asyncio.to_thread(lic.accepted) if state in (owner_license.QUEUED, owner_license.RECORDED) else None
wanted = state == owner_license.PENDING or bool(accepted and accepted["replaceable"])
doc = await asyncio.to_thread(lic.text) if wanted else None
words = {k: owner_license.say(t, v) for k, v in owner_license.TEXT.items() if k != "accepted_as"}
if accepted:
words["accepted_as"] = owner_license.say(t, owner_license.TEXT["accepted_as"], email=accepted["email"])
lost = await asyncio.to_thread(lic.link_lost)
if lost:
words["link_lost"] = owner_license.say(t, owner_license.TEXT[lost])
return {"offered": state == owner_license.PENDING, "state": state, "accepted": accepted, "link_lost": bool(lost),
"license": doc, "lang": t.lang.replace("_", "-"), "dir": t.dir, "text": words,
"why_unavailable": (owner_license.say(t, owner_license.WHY["unavailable"])
if wanted and doc is None else None)}


@router.post("/api/eula")
async def eula_accept(request: Request):
"""{email, accept: true, eula_sha256 (of the text shown), owner_use (personal or
business), replace}: the owner's
acceptance, recorded (or queued) and linked; with replace, in place of the one on the box
while it may still be replaced. {ok, why, state, message}: a refusal is a 200 with ok
false, as the card shows it in place."""
from teaport_brain import owner_license
_authorize(request)
try:
body = await request.json()
except ValueError:
raise HTTPException(status_code=400, detail="the request is not JSON") from None
if not isinstance(body, dict) or not isinstance(body.get("email"), str) \
or not isinstance(body.get("eula_sha256"), str):
raise HTTPException(status_code=400, detail="email and eula_sha256 must be text")
ok, why = await asyncio.to_thread(_owner_license().accept, body["email"], body["eula_sha256"],
body.get("accept") is True, body.get("owner_use"),
body.get("replace") is True)
logger.info("config: the owner's license acceptance " + (why if ok else f"not recorded ({why})")
+ " from Settings")
t = _reader(request)
msgid = owner_license.TEXT[why] if ok else owner_license.WHY[why]
return {"ok": ok, "why": None if ok else why, "state": why if ok else None,
"message": owner_license.say(t, msgid)}


@router.post("/api/restart")
async def restart(request: Request):
_authorize(request)
Expand Down
Loading
Loading