S17-02 - Install
Purpose: How wb setup installs Wraith Box from its bundle without
administrator rights, and how wb setup --remove takes it out.
Design
Section titled “Design”wb setup installs from the bundle it runs in. It doesn’t need
administrator rights (SEC12-least-privilegeSEC12-least-privilege: Least privilege on the hostNo root or administrator rights at run time and no extra host user accounts.). On macOS it checks the
bundle, then installs the agent and the link below.
The bundle check
Section titled “The bundle check”wb setup resolves its own executable’s real path. It refuses with
setup-not-in-bundle unless that path is Contents/MacOS/wb of a
bundle whose Info.plist has the same WBBuildVersion as wb. An
unstamped wb never matches. It refuses a bundle without
Contents/MacOS/wb-hostd the same way.
It refuses with setup-bundle-location a bundle that isn’t directly
in ~/Applications or /Applications. The agent then never points
into a build directory that a cleanup or a removed worktree deletes.
The agent
Section titled “The agent”wb setup writes ~/Library/LaunchAgents/nl.wraithbox.hostd.plist,
mode 644. It writes a new file and renames it over the old one.
- The agent runs the bundle’s
Contents/MacOS/wb-hostdby absolute path. RunAtLoadandKeepAliveare set, andAbandonProcessGroupisn’t (S04-07-supervisionS04-07-supervision: SupervisionWho starts and restarts each host process, what happens when wb-hostd stops or the bundle is upgraded, and daemon outages., “Who starts whom”).- The label is fixed, so a user has one install.
When the loaded agent’s plist has the same bytes, wb setup leaves
the agent running. Otherwise, replacing the agent stops wb-hostd and
its VMs. So wb setup first asks wb-hostd:
- While a VM runs, it refuses with
setup-vms-running, and names each VM and its sessions. - A
wb-hostdof another build version refuseswb(S04-08-records-and-boundsS04-08-records-and-bounds: Records, Versions and BoundsThe records daemons send wb-hostd, the build version rules between processes, the bounds on host work a guest can cause, and logs., “Version skew”), sowb setupcan’t read its VMs. It then refuses withsetup-vms-runningas well. The message names both versions, and says to stop the VMs with thewbof the running build. - When no
wb-hostdlistens, no VM runs, because VMs stop withwb-hostd(S04-07-supervisionS04-07-supervision: SupervisionWho starts and restarts each host process, what happens when wb-hostd stops or the bundle is upgraded, and daemon outages., “Whenwb-hostdstops”). It goes on.wb setuptakes it that nowb-hostdlistens when there is no socket, or when the connect is refused while no listener holds the endpoint’s lock. A listener with a full backlog refuses a connect too. - Every other answer refuses with
setup-vms-running, because a wrong “no VM runs” stops running VMs and loses their sessions:- a
wb-hostdof the same build that doesn’t list its VMs, as everywb-hostdbefore the VM list is built; - a question that fails, such as a timeout, a failed peer check, or a refused connect while the lock is held.
- a
A refusal for another build, or for a wb-hostd that can’t list its
VMs, also says how to stop wb-hostd once its VMs are stopped.
Without that step, the next run refuses again.
Then it runs launchctl bootout and launchctl bootstrap gui/<uid>.
It runs /bin/launchctl by absolute path, with the environment
PATH=/usr/bin:/bin and nothing else.
The link
Section titled “The link”wb setup links ~/.local/bin/wb to the bundle’s
Contents/MacOS/wb. It makes a missing ~/.local/bin, and renames a
new link over the old one.
A file there is a link into a Wraith Box bundle when all of these hold:
lstatshows a symbolic link;- its target ends in
/Contents/MacOS/wb; - the
Contents/Info.plistof that target’s bundle has aWBBuildVersionkey.
It replaces only such a link. It refuses any other file with
setup-link-exists.
When ~/.local/bin isn’t on PATH, it prints the line to add. It
never edits a shell file.
The Keychain backend
Section titled “The Keychain backend”After it installed the agent and the link, wb setup reads the team
from each helper bundle’s code signature. Whether a profile file is
there doesn’t decide anything.
- No helper has a team signature: the build is ad-hoc signed, and
wb setuprefuses its Keychain backend withkeychain-needs-team(S15-02-secret-storeS15-02-secret-store: The Secret StoreWhere credentials are held: the secret store, its backends, and the guarantees a backend must give., “Ad-hoc signed builds”). - The helpers don’t agree on one team:
wb setuprefuses withkeychain-team-mixed(S12-03-host-prerequisitesS12-03-host-prerequisites: Host PrerequisitesWhat wb setup checks on each host, and how a development build on macOS gets signed., “Team-signed build”). - One team signed every helper, with its profile:
wb setuplogs that decision underkeychain-team. It prints the team’s name from the profile and its ID, and that every program the team signs can reach Wraith Box’s groups (S15-02-secret-storeS15-02-secret-store: The Secret StoreWhere credentials are held: the secret store, its backends, and the guarantees a backend must give., “Team-wide groups in development builds”). The profile’s content isn’t authenticated, becausesecurity cms -Ddoesn’t verify who signed it. Sowb setupuses it only after the signature named the team.
wb setup exits nonzero on either refusal.
Running it again
Section titled “Running it again”Running wb setup again after the bundle moved rewrites the agent and
the link.
Removal
Section titled “Removal”wb setup --remove refuses with setup-vms-running in the same way.
Then it:
- unloads the agent, which stops
wb-hostd(S04-07-supervisionS04-07-supervision: SupervisionWho starts and restarts each host process, what happens when wb-hostd stops or the bundle is upgraded, and daemon outages., “Whenwb-hostdstops”); - deletes the plist and the link.
It keeps <config>, <data>, <logs> and the secret store items. It
prints where they are.
Windows and Linux
Section titled “Windows and Linux”The bundle, location and launchctl rules are macOS rules. On Windows
and Linux, the installer and service unit of S10-tech-stackS10-tech-stack: Technology ChoicesFix languages, libraries, packaging, and repository layout, with the reason for each choice. take the
place of the agent. A file wraithbox-version next to the programs
holds the build version.
Decisions
Section titled “Decisions”A LaunchAgent plist and a link in ~/.local/bin
Section titled “A LaunchAgent plist and a link in ~/.local/bin”wb setup writes the LaunchAgent plist itself, and links wb from
~/.local/bin.
- Rejected:
SMAppService, which needs a Swift or Objective-C call in the registering process and an approval in System Settings. - Rejected: a link in
/usr/local/bin, which needs administrator rights on many Macs.
Status: Draft