Security model
teaport’s services run as an ordinary user, the run user, not as root. The agent runs as that user too. So anything the run user can do, a compromised agent can do as well. This page describes the few things the run user can ask root to do, and how the device’s administrator login comes to exist.
The run user and root
Section titled “The run user and root”The brain, the engine, Wi-Fi setup, and the agent run as the run user. That user can’t
change system files or other users by itself. For the few changes it needs, it calls a
root helper through sudo, one rule per helper. Each helper is a small script, owned by
root, in /usr/lib/teaport/. It runs on the system Python, never the brain’s own
environment. The teaport-brain package installs the helpers, and
/usr/lib/teaport/sudoers-sync writes their rules into /etc/sudoers.d/teaport-config.
| Helper | What the run user can ask it to do |
|---|---|
config_apply.py |
Write one of the settings files in /etc/teaport/, and restart or stop a teaport service. |
wifi_apply.py |
Change the Wi-Fi: the setup network, joining a Wi-Fi network, and putting the old one back. It takes Wi-Fi requests only. |
login_apply.py |
Create the owner’s login, one time only, on a device that ships ready to set up. |
license_accept.py |
Record the owner’s acceptance of the engine license, from the email address they typed, while setup is unfinished: one time, or again in place of the first until it is linked. |
license_link.py |
Link the recorded acceptance to the device’s license key, while setup is unfinished. |
Each helper refuses any request outside that list. A helper that takes a password reads it on standard input, never on a command line, where any user could read it.
The settings in /etc/teaport/ are written on the run user’s behalf, so no command
that runs as root takes its environment from them.
The run user’s only other rights come through polkit: it can scan for Wi-Fi networks,
and it can start teaport-update.service, the root unit that teaport update starts.
That unit takes no arguments and reads from the release manifest what to install, so
the run user decides when an update runs, never what it installs. An update doesn’t
need the run user to have sudo.
The owner’s login
Section titled “The owner’s login”The run user must never be able to make itself an administrator. So a device that
ships ready to set up has no login at all, and the owner creates it during setup: an
account named teaport with a home folder, a Bash shell, and sudo rights. It is
never the run user’s own account.
login_apply.py creates it one time only, and only on a device that asked for it:
- The step that prepares a device for shipping writes a pending marker,
/var/lib/teaport-owner/pending, in a folder only root can open. The marker means that the device has no owner login yet. It is outside every folder the run user can write, including/etc/teaportand teaport’s state folder. Neither the installer nor the package writes it. - Without the marker, the helper creates nothing. A device that you install yourself never has one, so it never offers the step.
- A marker that the run user could have written, in a folder it can write or owned by another user, counts as no marker.
- Without the marker, an existing
teaportaccount is the owner’s, and the helper refuses. It removes the marker when it creates the login. - If a step fails, the helper undoes the steps before it. While the marker is there, a
teaportaccount that is plainly what a create left behind, for example after a power cut between its steps, is finished by the next create: no password was ever set on it, its full name isTeaport owner, and its home folder is missing or is its own folder with no.sshin it. The next create makes the home folder if it has none (as a new account gets one, from/etc/skel, with the mode that/etc/login.defssets), gives the account itssudorights, sets the password last, and removes the marker. - Any other
teaportaccount, marker or not, is someone’s login: the helper refuses, and the owner sees that the device already has a login. An account that someone prepared, with a password or SSH keys of their own, is never handed to the owner. - The helper also refuses when a group named
teaport, or a/home/teaportfolder, exists without the account: the new account can’t get a group of its own name, and a folder it didn’t make isn’t its to take over. The device then doesn’t offer the step.
The helper finishes what it starts. It blocks every signal it can, and it runs the
create in a process of its own session, apart from the one that sudo started. sudo
can end its command, for example when the run user sends sudo an alarm signal, and
then stops the command’s whole process group with SIGKILL; the create goes on
regardless, through to removing the marker. The create still belongs to the service
that asked for it, though, and takes about a second: stopping that service (after its
stop timeout), the out-of-memory killer, a restart of the device, or a power cut can
stop it partway. The next create usually finishes what it left, when that is plainly a
leftover; see The device already has a login
for when it doesn’t. The helper leaves no core dump that could hold the password.
The password goes from the setup page or the settings to the helper, and from the
helper to chpasswd on standard input. It is never written to a log, the journal,
the Wi-Fi setup status file, an error message, or a command line. Where sudo can log what its commands read
(classic sudo, with input logging on), the helper’s sudo rule says NOLOG_INPUT, so
sudo doesn’t keep the password. sudo-rs, which newer Ubuntu releases use, has no such
logging and doesn’t accept the tag, so the rule leaves it out there. On its way it is held in a wrapper that hides it from an error report
that prints variables. A password is at
least 12 characters and at most 256 bytes, without control or invisible characters.
The setup page’s form can create the administrator account, so the page answers only
under its own names: the setup network’s address and its .local name. A request for
any other name, such as a captive-portal check (captive.apple.com) or a name that a
site has pointed at the device, is sent to the setup address instead, which is the
usual captive-portal redirect. The page accepts the form only under those names, and
only from its own pages: it refuses a post that a page from another site sends, for
example from a tab that the phone loaded over its mobile data. A post that names no
origin is accepted. One whose origin is null, which some captive browsers send but so
does a sandboxed frame on any site, is accepted only when the browser also says the post
comes from the page itself.
The setup page answers only devices on the setup network itself, whose addresses are in
its subnet (10.42.0.0/24). Listening on the setup address alone isn’t enough: a device
on your home network could route that address to the device and reach the page
over the home network, for example while the device is online over Ethernet and in setup
mode. The page drops any connection from outside the subnet before it reads anything.
The rule that sends port 80 to the page doesn’t name the setup network’s interface,
because the code picks the Wi-Fi device when setup runs.
Teaspoon AI’s provisioning, which runs outside this repository when it prepares a
Teaspoon AI device for shipping, writes the marker, refuses a device that already has a
teaport account, group, or home folder, removes the run user from the sudo group and sets aside
its other sudo rules (only the helpers’ rules in /etc/sudoers.d/teaport-config
stay), locks the run user’s password, removes its SSH keys, and makes sure that SSH
accepts passwords. The paper insert carries no login. So on such a device, until the
owner creates the login, nobody can sign in. This repository’s code doesn’t enforce
these steps; the helper only relies on the marker.
The owner’s acceptance of the engine license
Section titled “The owner’s acceptance of the engine license”A device that ships ready to set up has its engine license key, but no one’s acceptance of the engine license: the owner accepts it during setup. The run user must not be able to put an acceptance on the device that the owner didn’t see, so neither helper takes an acceptance ID, and both talk only to Teaspoon AI’s license server at https://get.teaspoon.tech/api, which is built into them. They ignore any other address in the installed release manifest or in a record on the device, and send nothing to it.
license_accept.pytakes the owner’s email address and the hash of the license text that the page showed. It sends the acceptance to Teaspoon AI itself, and records the ID that Teaspoon AI returns in/var/lib/teaport/eula-accepted.json, which only root can write. Offline, it keeps the email address in/var/lib/teaport/eula-queued.json, also root’s, and sends it after the device is online. It works only while the setup marker/var/lib/teaport-owner/license-pendingis there. It replaces an acceptance that is recorded or waiting only when the request asks for that, and only until the acceptance is linked.license_link.pytakes nothing. It reads the recorded acceptance, the license key/etc/teaport/license.json, and the link secret/etc/teaport/license-link.secret, which only root can read, and asks Teaspoon AI to link the acceptance to the key. The key file holds no secret, and the run user can read it, so the secret is what proves that the request comes from the device. For the run user, the helper works only while the setup marker is there; linking removes it. The settings’ phone session can’t stand in: it is signed with a key that the run user can read. Root, and an administrator who signs in and runs it withsudo, can always run it.
A device that ships ready to set up comes with a Commercial License, its license key. Only the link records who owns the device: Teaspoon AI takes an acceptance from anyone, so the owner’s acceptance is for personal use with no license ID, says whether the device is for personal use or for a business, and names no license key, and the device’s owner is the acceptance that the device itself linked to its key, with its secret. No helper that the run user reaches writes, renames, or removes the license key, the revocation list /etc/teaport/license-revocations.json, or the link secret.
The window before the link
Section titled “The window before the link”Until the device links an acceptance to its key, software that runs as the run user, such as a compromised agent, can accept the license first, with any email address. While the owner’s login doesn’t exist yet, it can also put its own acceptance in place of the owner’s, as the owner can put theirs in place of it: the window is the login’s (see The known window). After the login exists, only an administrator who signs in and runs the helpers with sudo, giving their password, can replace an acceptance and link it, after the link too. After the link, nothing that runs as the run user replaces it.
The setup page and the settings show whose acceptance is recorded until setup finishes, with the part before the @ hidden except for its first and last character, one * for each character in between, and the whole domain: owner@example.com shows as o***r@example.com, and a look-alike such as ox@ex.com shows as o*@ex.com. A domain with letters from another script shows in its ASCII form (xn--...). An address with an invisible, control, or compatibility character, such as a fullwidth letter or a Kelvin sign, is refused. This also refuses the zero-width joiner and non-joiner that some Persian and Indic domain names need: an accepted trade-off. The run user never sees the whole address there. The masked address is a hint, not a proof: another address with the same first and last character, the same length, and the same domain looks the same. When in doubt, the remedy is support.
The link needs the license key file and its link secret on the device. While a device doesn’t hold both, nothing links and the setup marker stays: an acceptance recorded before the owner’s login exists can be replaced until then, and after that only with sudo.
The owner’s decision is to accept this window. A device whose acceptance is someone else’s, after the link or after only sudo can change it, is fixed by its owner on the device, with support’s help: possession of the device outranks any record, the sales record included. The owner sees the other acceptance in the setup page or the settings, with its email address partly hidden, and contacts support, who sends these steps. The owner signs in with their login and runs, on the device (sudo asks their password):
# Read the license, and note its sha256.sudo python3 /usr/lib/teaport/license_accept.py text </dev/null \ | python3 -c 'import json,sys; d=json.load(sys.stdin); print(d["text"]); print("sha256:", d["sha256"])' | less# Accept it in place of the acceptance on the device, with your own email address.sudo python3 /usr/lib/teaport/license_accept.py accept <<'EOF'{"email": "owner@example.com", "owner_use": "personal", "eula_sha256": "<the sha256 above>", "replace": true}EOF# Link it to the device's license key.sudo python3 /usr/lib/teaport/license_link.py link </dev/nullUse "owner_use": "business" for a business. The link needs no record of the owner at Teaspoon AI: the device’s link secret, which only root can read, is the proof. Every link replaces that secret, so a copy that someone made while they had root on the device, such as a previous owner, links nothing after the device’s own next link.
While a link waits for the device to confirm its new secret, the previous secret still links, for at most a day, so a device that failed to write the new one, or was unplugged in the middle, isn’t locked out; the device’s timer sends the confirm until it gets through. Before the device’s next link, the copy works as well as the device’s own secret, and whoever links first wins: the holder of a copy can link the device to their acceptance, and the secret they then hold is no longer the device’s. Nothing can tell a copy from the device itself, so the contest is made visible and recoverable. The device notices that its secret, which linked before, is refused, and says that its license link was lost: on the setup page, in the settings, in teaport status, and in its log. Support then decides who the owner is: from the sales record, a proof of purchase, or the owner’s account of the device, with a documented purchase winning between two claimants. Support gives the verified owner a recovery code, valid for 24 hours and for one link. The owner signs in with their login and types the code at the prompt of:
sudo python3 /usr/lib/teaport/license_link.py link --recovery-codeThe code links the device one time, and that link gives the device a new secret, so the copy then links nothing. If the device misses the answer to that link, the code works again until the device confirms its new secret, for at most a day. A device whose secret never linked and is refused, on its first try or a later one, says that its license link failed: it can’t tell why (its secret was set up wrong, its key predates link secrets, someone with a copy of the secret linked first, or the answer to its link was lost), so support finds the cause. Then the owner accepts the license with the earlier commands. Software that runs as the run user and stops the link helper in the middle of a link only keeps the device’s previous secret valid for a while longer, and only the device and root hold that secret, so it gains nothing.
Only when the device can’t reach Teaspoon AI’s license server does support link it from Teaspoon AI’s side, through the sales record and Teaspoon AI’s records of installing the device at the factory. A license ID alone proves nothing, because the run user can read the key file. Teaspoon AI staff check every value the requester sends against a strict pattern before it goes into a statement, handle anything else by hand, and write the statements to a file that they run, never the device. packaging/RELEASING.md in the teaport repository has the procedure.
The engine license key’s files
Section titled “The engine license key’s files”Only root writes the engine license key and its link secret, through license_key.py: the installer runs it from its checkout, and teaport-license-renew.service and teaport update run the package’s copy. No sudo rule names it, so the run user can’t run it as root. It sends Teaspoon AI’s license server, the same one that the other license helpers have built in, the IDs that a key request needs, and nothing else: no audio, no transcripts, and no conversations.
/etc/teaport/license.jsonis root’s, readable by the group of the user that runs the engine, mode 640. The run user, and so the agent, can read it, by design: it holds a license ID, the device ID, dates and a signature, no secret and no personal data, and a copy is useless on other hardware. The run user can’t replace, rename, or remove it, because/etc/teaportis root’s./etc/teaport/license-link.secretis root’s, mode 600, from the moment the file exists: the installer creates it with that mode before it writes the secret. The run user can’t read it. The helper writes it only with the key’s first issue on a device that Teaspoon AI installs. After that, onlylicense_link.pyreplaces it, at every link.- The helper writes each file whole, through a new file in the same folder that it renames into place. It never prints the secret, logs it, or puts it in its state files. Its own record,
/var/lib/teaport/license-key.json, is root’s with mode 600;teaport statusreads a copy without the factory record,license-key-status.json. - It runs the engine’s checks as the user that runs the engine, with that user’s groups. The values in
engine.env, which the run user’s configuration page can change, reach only the engine itself, as its environment: no process that runs as root has them in its environment, and no process has them on its command line, which any user can read.teaport statusandteaport doctorrun the engine the same way. teaport-license-renew.serviceruns it with the rest of the system read-only, except/etc/teaportand/var/lib/teaport, with home folders hidden, a private/tmp, and no way to gain privileges.
The known window
Section titled “The known window”The window lasts until the owner creates the login, not only until the device is set up. For as long as the marker is there, software that runs as the run user, such as a compromised agent, could create the login first. The owner then sees that the device already has a login, in place of the step. Because the setup page and the settings run as the run user, software that was compromised before the owner typed the password could also read the password as it is typed.
Anyone who can reach the setup page or the settings can create the login first, too:
- On the setup network: anyone who knows its password. That password is on the paper insert, on the device’s screen during setup, and spoken aloud by the device when it has no screen or you say “repeat”.
- The setup page is plain HTTP over the setup network’s WPA2 password. Someone who knows that password and recorded the phone joining the network can read what the phone sends, including the login password.
- On a device without a gateway token (
GATEWAY_TOKEN), the configuration page on the device itself,http://127.0.0.1:7861/config, needs no token, so any user or program on the device can create the login there.
The setup page makes the step required, so on a device set up through that page the window ends at setup. The exception is a create that fails because of the device, not the password: the owner can then connect without a login, and the window stays open until they create it in the settings. The same holds when the page can’t ask the helper at the start of setup and shows no step. A device that went online another way offers the step in the settings until the owner creates the login. The marker limits the window to a device whose owner has no login yet; it doesn’t prevent it. See The device already has a login.