# ssheep — notes for agents # # Version: early prototype. 100% vibecoded — use at your own risk. No independent # audit: a self-review (docs/SECURITY-REVIEW.md) found and fixed six faults, and # docs/THREAT-MODEL.md states what is checked and what is not. The protocol is # still changing. Do not use for anything important. # # This file is the machine-readable version of https://ssheep.xyz — enough for an # agent to operate a flock without reading prose. WHAT IT IS Control machines ("sheep") from a machine you hold ("the master") through a blind relay ("a relay"). - A sheep only ever dials OUT, so it needs no open port and no public address. - A sheep that CAN be reached also runs the relay and offers itself to the flock, so nobody has to pick a relay: every machine tries, the reachable ones are used, and the rest stay sheep. See "AUTOMATIC RELAYING" below. - Everything between master and sheep is end-to-end encrypted (X25519 + AES-GCM). A relay forwards ciphertext it cannot read and cannot forge. - The flock is defined by a small signed file (the roster). The only secret is the flock key, which signs rosters and is needed only to add or remove a machine. - One machine can be in MANY flocks, each with its own key and roster, and one relay can serve several flocks at once. INSTALL curl -fsSL https://ssheep.xyz/install.sh | sh # alternatives: # download: https://github.com/bash3r777/ssheep/releases/latest # source: git clone https://github.com/bash3r777/ssheep && cd ssheep && make build # arch: yay -S ssheep-bin (AUR; also `omarchy pkg add ssheep-bin`) # packages: https://ssheep.xyz/pkg (signed repos; see below) # static binaries, linux/darwin/windows, amd64/arm64. no other dependencies. ssheep also has its own signed repositories, at https://ssheep.xyz/pkg/{apt,rpm,arch}, keyed by the repo key https://ssheep.xyz/ssheep-repo.asc (fingerprint C2D78DD093463EE5D2F18517115453D89FCAD5E4): deb https://ssheep.xyz/pkg/apt -> apt install ssheep rpm https://ssheep.xyz/pkg/rpm -> dnf install ssheep pacman https://ssheep.xyz/pkg/arch -> pacman -S ssheep-bin and a Homebrew tap: brew install bash3r777/ssheep/ssheep (macOS). On Omarchy, a bar widget shows whether the flock is up: omarchy plugin add https://github.com/bash3r777/omarchy-ssheep.git --enable It runs `ssheep top --json --once` on a timer and shows online/total across every flock on the machine; it needs ssheep on PATH. Nothing else in the desktop is touched. The plugin is a git repo with manifest.json + BarWidget.qml. SETUP — ONE COMMAND, THEN ONE LINE 1. on the machine you control from (the "master"): ssheep master flock "myflock" This creates the flock, pre-adds the project's public relay, and prints one line — the shared enroll line: 🐑 run this on every machine you want to be a sheep 🐑 It also reports the flock and accepts any machine that has offered to relay. 2. paste the enroll line on each machine: curl -fsSL https://ssheep.xyz/install.sh | sh -s -- --enroll "" --pin ":" One line works for any number of machines. Each makes its OWN key and asks to be let in; the next ssheep command on the master admits it and names it. A leaked line is not a leaked key, but it is a shared secret until it expires (24h by default), and every machine it admits is named, so a stranger can be forgotten. The installer joins the machine itself, by the full path it just installed to, so it works whether or not that directory is on PATH, and installs the agent as a service so the machine stays in the flock across reboots (--no-service keeps it in the foreground instead). Nothing is run unchecked: the release is verified against the signed SHA256SUMS, and --pin against the hash of the build the master itself runs. Both are signed by the flock key, so a flock cannot be handed a build its master did not choose. --insecure skips the checks on a machine with no gnupg, and says so. 3. on the master: ssheep top <- all flocks, live; also lets in machines that have asked to join (refreshing until you stop it) ssheep run "myflock" -- uptime LINES AGAIN, AND OTHER KINDS ssheep master "myflock" the shared line again (good for 24h) ssheep master "myflock" --masters 1 a spare master ticket ssheep master "myflock" --sheep 3 three sheep tickets, one per machine ssheep master "myflock" --operators 1 an operator ticket Per-machine tickets are for a counted fleet, or a machine that must join with no relay and no later step: a ticket carries that machine's private key, so it joins instantly, and works once, on one machine. A flock with no relay (--private) has nowhere to hold an enrollment, so it prints sheep tickets by default rather than a shared line. A master ticket carries the flock key, so keep it as safe as the master machine. Opinionated defaults, all overridable: public relay relay.ssheep.xyz:7000, pre-added to the roster --relay / --private join line one shared enroll line, any number of machines --sheep N spare masters 0 — ask for one with --masters N (it carries the flock key) relay port 7000 --port AUTOMATIC RELAYING Every machine may relay; whether it can is a question only the network answers. - The sheep starts a relay on its port and, on the connection it already holds to each relay in the flock, offers every address it might be reachable at: a global IPv6 address first, then what a relay sees it as, then its own addresses on the local network. - The master reads the offers, and accepts a machine as a relay only when one of its addresses answers with exactly the certificate the offer claims. The first that answers wins, and the flock keeps ONE relay per machine. - If nothing answers (NAT with no port forwarding, or a closed port), nothing is added and the machine stays a sheep. It tries again later. - A flock keeps a handful of relays, not one per machine: a relay per machine would be a link per machine per relay. Automatic relays that have stopped answering are dropped, so a machine that moved can take the slot. A relay the operator added by hand is not dropped automatically. - A new flock starts with the project's public relay, so the very first machine can be behind anything; as machines join, the reachable ones take over. - `ssheep top` shows which machines are relaying, and asks EVERY relay for presence and merges the answers, so "online" is a fact about the flock. - `--upnp` asks a home router to forward the relay port, so a machine behind NAT can relay with nobody configuring anything. Opt-in, and best-effort: a router that cannot is the normal case. - `run` and `copy` fall back through the flock's other relays when the relay the master is on cannot reach a machine, so several relays behave like one flock. MULTIPLE FLOCKS A machine can be in as many flocks as you like, and holds a SEPARATE KEY in each. Run `ssheep master flock ""` again for a second one. ssheep flock list every flock this machine knows, and its role in each ssheep top every flock, live ssheep top "myflock" one flock ssheep run "myflock" -- CMD run in one flock A machine can be a sheep in one flock and a dedicated relay in another. One relay can serve several flocks at once: one reachable machine, one port. Each flock is entirely separate — its own key, roster, relays and machine names — so being in a second flock cannot leak anything into the first. TARGETING MACHINES Give a machine labels, then pick machines by them: ssheep label --name NAME --set k=v [--unset k] [--clear] ssheep run --tag role=web -- CMD... - --tag works on run, copy, shell and facts; repeat it to require several labels. - --name accepts a glob: --name 'web-*', or --name 'web-[12]'. - Labels live in the signed roster, so they travel with the machine and are revoked with it. There is no inventory file to keep in step. SHELL ssheep shell --name NAME an interactive terminal on one machine ssheep shell --name NAME -- CMD... one command, with a terminal ssheep shell --all [-- CMD...] one input to every machine at once A REAL ssh session — pty, window size, ^C, colours, exit status — but the ssh server runs INSIDE the encrypted tunnel, not on a port: - no sshd installed on the machine, no authorized_keys, no known_hosts, no first-use trust, nothing listening. The machine is whoever the signed roster says it is, and the flock key is what proves it. - ssh's own authentication is deliberately off, because the tunnel already answered who is asking: only a roster-listed master can complete the handshake at all. The ssh host key is invented per connection and thrown away, and the client does not check it — the tunnel is the trust anchor, not a host key, and a second, weaker check would be worse than none. - the shell runs as the user the agent runs as. Run the agent as yourself (a systemd user unit is the tidy way) and a shell here is your own environment. - no terminal asked for, none given: piping a command through gets the bytes exactly as written, with no terminal line endings and no echo. - exit status is passed back out the way ssh does. Linux and macOS only, because it needs a pty. No file transfer, no port forwarding, no agent forwarding, no subsystems: sessions are all it serves. UPGRADING A FLOCK ssheep upgrade [--name N | --tag k=v] [--dry-run] [--rollback] [--from PATH] - Pushes this master's own build to each machine, checks the upload by hash, runs it once there before swapping it in, and keeps the old one as .prev. - Nothing is assumed: each machine is asked where its binary is. The mechanism is copy+run on purpose, so a machine can take the upgrade while still running the old build. - THE RELAY GOES FIRST. A relay newer than a machine refuses it and says so; an older relay still works, and `doctor` reports it as behind. - see/doctor show which build each machine is on, from what each said when it connected (a relay v0.10.0 or newer reports it). MULTIPLE MASTERS A master ticket is the only one that carries the flock key, so the machine that takes it can add and remove machines, mint tickets and accept a machine's offer to relay — exactly as the first master does. A new flock mints none: ask for one with `--masters 1` when you make it, or with `ssheep master "" --masters 1` later. - A master has no service: it connects when you run a command. As it connects it asks a relay for the current roster and adopts it when it is newer, under the same rules a sheep uses, so a master that has been away still sees machines added since. - The cost is real: the flock key then exists in two places. Mint as few master tickets as you can bear, and treat each line as being as sensitive as the master. STATE Everything lives under $SSHEEP_DIR, default ~/.ssheep, one directory per flock: ~/.ssheep/flocks//flock.key.json the flock key. SENSITIVE. Off the relay. Present only where a master ticket put it. ~/.ssheep/flocks//node.key.json this machine's identity in that flock. SENSITIVE. ~/.ssheep/flocks//roster.json the signed roster. Public; safe to share. ~/.ssheep/connector.crt, connector.key this machine's relay identity, shared by every flock it relays for. Public. Once enrolled, a machine needs no arguments: `ssheep serve` knows what it is — and which flocks it is for. (`ssheep sheep` still works; it means the same.) (The old `--dir ` flag still works; it now just sets $SSHEEP_DIR.) ROLES master holds a flock key, mints tickets, sends commands. More than one is fine: a master ticket carries the flock key, so any master can add and remove machines. Keep master lines as safe as the master machine. sheep runs the agent, executes commands, and relays for its flocks when it can be reached. Only ever dials out. relay a machine whose ONLY job is relaying, for when you want to say so out loud. Optional; a sheep relays on its own when it can. operator can run commands and open shells, but holds NO flock key, so it cannot add or remove machines or mint tickets. How a machine is lent to somebody without handing over the flock. `--operators N` mints them. One binary does all of them; the role is a subcommand, or read from the ticket. COMMANDS ssheep master [flock] [--relay H:PORT] [--private] [--sheep N] [--relays N] [--operators N] [--masters N] [--enroll] [--enroll-for 24h] set up a flock; prints the lines to paste. A flock prints its shared enroll line by default, and again later with no flags. --sheep N mints per-machine sheep tickets instead. --masters N mints spare masters (none by default). --relays N and --operators N mint those roles. ssheep join "" take a ticket: install it, then be what it says (sheep and relay serve; master and operator install and report). --install-only to take it and stop; --service to install a systemd service so it survives reboots (--no-service to skip); --upnp to ask the router to forward the relay port ssheep enroll "" join with a shared line: make a key, and keep asking until a master admits this machine ssheep serve carry on being what this machine already is — what the service runs ssheep top [] [--once] [--json] the flocks, live (all of them by default); [--every 2s] also lets in machines that have asked to join, when this machine is a master. Refreshes every 2s; --once prints one view and exits. `ssheep see` is an alias for `top --once`, kept so old lines work. ssheep doctor [] [--json] whether this machine can relay, and why not ssheep run -- CMD... every sheep in one flock. --name NAME for one (globs allowed); --tag k=v to pick by label; --script FILE to ship a local script; --stdin to feed your input to every machine; --timeout 30s; --parallel N; --json ssheep facts what the machines are: OS, kernel, cores, memory, disk, uptime, who relays (--json) ssheep copy SRC DST put a file on every sheep (-r for a whole directory; --name, --tag, --mode, --timeout, --parallel, --json) ssheep pull SRC [DST] bring a file back from one machine (-r for a whole directory) ssheep shell --name NAME an interactive terminal on one machine, with or without -- CMD (Linux, macOS) ssheep shell --all [-- CMD...] one input to every machine at once, output labelled by machine ssheep label --name NAME --set k=v tag a machine, so --tag can pick it (--unset k, --clear) ssheep forget --name NAME revoke a machine, and the relay it ran ssheep upgrade push this build to every machine and restart it (--dry-run, --rollback) ssheep flock list the flocks this machine knows step by step, when you want control: ssheep invite --name N [--role R] mint one ticket (roles: sheep, relay, operator, master) ssheep relay run a relay with no flock of its own ssheep relay add|remove|list manage a flock's relays by hand ssheep pin --addr H:PORT print a relay's fingerprint EXIT CODES AND OUTPUT run exits non-zero when a command fails, and prints ": exited with status N". A machine that is revoked stops with "this machine is no longer in the flock". GOTCHAS WORTH KNOWING - A ticket pins the build the master itself runs. A master built from source — not from a release — prints lines that name a build nothing can download, and the installer says so rather than guessing. Run a released binary on the master. - A new flock starts with the project's public relay (relay.ssheep.xyz:7000) already in its roster, so it works before you have a reachable machine of your own. Use --private to have none. Its fingerprint is compiled into the binary, so creating a flock needs no network and a poisoned name cannot redirect it. - A --enroll line is a bearer credential: whoever holds it can ask to join until it expires. Each machine makes its own key, so a leaked line is not a leaked key, and every machine admitted with it is named. - ^C on run/copy, or --timeout, reaches the far machine and stops the command -- the whole process group, a script's children included. - copy writes to a temporary file and renames it into place, so an interrupted copy never leaves half a file behind. - A machine works out what address it is at by asking the flock what it looks like from outside, and offers every candidate. Behind a NAT with no port forwarding nothing answers, the master says so, and the machine stays a sheep. --addr is there to be told the truth (a router forwarding a different external port). - More than one relay is worth doing: machines try them in roster order and survive losing any of them. A single relay is a single point of failure. - `top` asks every relay and merges the answers, so online means online in the flock, not at one relay. - A machine holds one connection per relay and offers itself on it. Several conversations ride that one connection, each with its own random name, so one command cannot interrupt another. - Two commands from one master machine at the same time both work now. Against a relay older than v0.8.0 they fall back to one at a time — the second fails with "lost the relay" — so upgrade the relay along with the machines. - A relay serves only the flock it was given unless started with --public. - A machine in two flocks needs the ticket for EACH; it does not reuse an identity across flocks, by design. - Revocation is enforced by relays; a machine already in a direct conversation is not interrupted until it reconnects. - Changing a relay's certificate strands its members: they pin the fingerprint and cannot fetch the roster that would tell them the new one. - No port forwarding. `copy` and `pull` move files, and with -r a whole directory tree in either direction. WHAT IT IS NOT - Not audited. Not hardened. Assume bugs. - No accounts, no telemetry, no SaaS. Nothing phones home. - Not affiliated with any other project; it is ~4k lines of Go, standard library only.