How it works
On this page
The parts
home workstation
┌────────────────────┐ ┌────────────────────┐
│ starmole daemon │◀════════ QUIC, direct ═══════════▶│ starmole daemon │
│ identity.key │ (TLS bound to node keys) │ identity.key │
│ cert (member) │ │ cert (member) │
│ config (rules) │ │ config (rules) │
└──┬──────────────┬──┘ └──┬──────────────┬──┘
│ publish, │ fallback path, │ │
│ look up │ encrypted packets only │ │
▼ ▼ ▼ ▼
┌────────────────────┐ ┌────────────────────┐
│ address lookup │ │ relay │ helpers for finding each other
│ (DNS / pkarr) │ │ │ and getting packets through
└────────────────────┘ └────────────────────┘
Four questions get answered when one machine connects to another, each by a different part:
- Which machine is this? Its key. A node id is a public key, and the QUIC connection proves the other side holds the private half.
- How do we reach it? Address lookup, relays, hole punching and port mapping. They help packets get through and decide nothing else.
- Is it one of ours? Its certificate, signed by the network key, checked locally against the network id in config.toml.
- What may it do here? This machine's
[[allow]]rules, matched against the certificate.
Only the machines themselves take part in 1, 3 and 4. See What each part is trusted with.
Machines are keys
Every machine has an ed25519 key pair (identity.key).
The public key is its node id, and that's the only address anything
uses: you dial a node id, never an IP. Connections are QUIC with TLS
bound to those keys, so when a connection is up, each side knows exactly
which key is on the other end. Nothing else, such as passwords or
certificates in the TLS sense, is involved in that part.
Getting through NAT
Connections go through iroh:
- Each daemon keeps an outbound connection to a relay server, and publishes its relay and current addresses under its node id to a DNS service (n0's by default, over pkarr).
- To reach a node id, a daemon looks it up and connects through the relay first. That always works, since both sides only made outbound connections.
- Meanwhile the two sides try each other's addresses (hole punching). When a direct path works, traffic moves to it; the relay stays as a fallback.
- The daemon also asks the router for a port mapping over UPnP, PCP or NAT-PMP, which makes direct paths possible behind NATs that would otherwise block them.
- A port mapping only helps if the machine itself takes the packets.
Where the daemon may change the firewall (root, or
CAP_NET_ADMIN, plusCAP_NET_RAWwhere the firewall's rules match ipsets), it lets its own UDP port in: on Linux with one iptables rule per address family, removed when it stops, and on macOS by allowing the starmole binary in the application firewall. Without that, a peer behind a NAT that picks a new port for each destination, common at work and on mobile networks, stays on the relay. The port only speaks QUIC, and every connection has to prove its node key before anything else happens.[network] firewall = falseturns it off. Firewalls run only through nftables, like firewalld or NixOS withnetworking.nftables, aren't handled yet.
The relay only ever sees encrypted QUIC packets.
starmole status and starmole ping show whether
a connection is direct or relayed. starmole status also
lists members it isn't connected to, and when each was last
connected.
Protocols
Each feature is a separate QUIC protocol (ALPN) on the same
connection machinery: starmole/shell/1,
starmole/exec/1, starmole/fwd/1,
starmole/tun/1 and starmole/svc/1 for
services, plus starmole/echo/0 for
starmole ping. Members also speak
starmole/cert/2 and starmole/certsync/5 to
learn each other's certificates. Two protocols are open to machines that
aren't members yet: starmole/enroll/1 for redeeming an
invite, and starmole/exchange/1 for signing in at an auth
service.
Shells, commands and forwards use streams. The tun device sends IP packets as QUIC datagrams, so a lost packet is just lost, as it would be on a normal link, and TCP inside the tunnel handles it.
The CLI doesn't make connections itself. It asks the daemon over a Unix socket, and the daemon hands it a stream to the peer.
Who may connect
Before any protocol code runs, the daemon checks that the peer is a
member: it has a valid certificate for this network, an SSH certificate
from a CA in [network] ssh_ca, or it's listed in a
[[peer]] entry. Unknown peers are dropped right after the
handshake.
Certificates
The network is named by the public half of its network key. A member
certificate says "in network N, node K is called
workstation, has tags server, may use
100.64.0.2", is valid for a time window, and is signed by the network
key. Any machine can check that against the network id in its config,
without asking anyone.
Certificates are small, binary, and text when you need to paste them
(starmolecert1:...). The network key can also sign an
issuer certificate for another machine, with limits on the names, tags,
groups, addresses and lifetimes it may hand out. A member certificate
from that issuer travels with the issuer's certificate, and verifiers
check both.
A machine can also prove membership with an OpenSSH user certificate
for its key, from a CA the verifying machine lists in
[network] ssh_ca. Its key id becomes the machine's name and
its principals what principal: rules match. Rules don't
care which kind a member presented; both end up as the same set of
claims.
Learning each other's certificates
When two machines meet, they swap certificates over
starmole/cert/2. The side that's asked only answers after
the asker's certificate checks out, so a stranger learns nothing.
Members also keep each other up to date over
starmole/certsync/5: every few minutes each daemon syncs
with a few other members. It first sends a hash of everything it knows
(all certificates and the revocation list). If the other side has the
same hash, that's it, which is what happens most rounds. Otherwise they
swap everything. So a machine knows the node ids, names and tun
addresses of members it has never talked to, and keeps knowing them
across restarts, since it saves what it learned to
~/.config/starmole/peers. A machine that knows no other
members yet, such as a fresh one or one that lost that file, syncs with
its issuer ([network] issuer) first. Every member does the
same, so the issuer soon knows everyone. Whenever a machine learns about
a new member it syncs again right away, so a new machine reaches
everyone in seconds. If nobody answers, as when a laptop starts before
its network is up, it tries again after a second, then two, and so on up
to a minute.
Network addresses aren't synced. Where a node id can be reached
always comes from the address lookup, or from addrs in
config.
Access rules
Membership only means "may connect". What a member may do on a
machine comes from that machine's [[allow]] rules, matched
against the claims in the member's certificate. Each request is checked:
a shell needs shell, a forward needs forward
and a target that [expose] allows, a tun connection needs
tun.
A daemon running as a normal user runs shells and commands as itself.
One running as root runs them as a local user from the as
list of the rule that granted them, and refuses when there is none. Root
is one of those users only when a rule lists it. It switches user in the
child process before the shell starts, the way sshd does, starting in
the user's home directory, or / if they can't enter it. The
socket it opens for agent forwarding belongs to that user.
Joining
An invite token holds the network id, the issuer's node id and relay,
a random secret and an expiry. The issuer keeps the secret's hash
together with the name and tags it promised. starmole join
connects to the issuer over starmole/enroll/1 and sends the
secret; the issuer checks it, signs a certificate for the key that
connected, and forgets the secret. The private key of the new machine
never moves, and the token can't be edited to ask for more.
Renewal uses the same protocol: a machine with a valid certificate asks its issuer for a new one at two thirds of the lifetime, and gets the claims on record for its name. An expired certificate can't be renewed; that machine needs a new invite. An issuer only renews certificates it signed itself, so a short certificate from one issuer can't be turned into a long one by another.
Revocation
The issuer holding the network key keeps a signed revocation list: node keys that are no longer members, each until its last certificate would have expired anyway. A new list has a higher serial number and replaces older ones. It spreads through the same sync as the certificates, and is pushed as soon as it changes. A machine that gets it drops the revoked certificates, removes their tun routes and closes their connections.
If you restore network.key on a new machine, let it sync
once before revoking anything: it picks up the newest list and policy
from the network and carries on from there. Serials never go below the
current time, so its lists replace the old ones either way.
From a few machines to many
A small network needs nothing beyond what's above: the network key on one machine, invites, and rules by tag and name. Nobody signs in, and no server is involved. When more people join, or you want access to follow your identity provider, you add to that in steps. The machines keep their keys, names and addresses all along.
An auth service. starmole net auth add
on the machine with the network key picks a node to be an auth service.
It gets an issuer certificate with limits: which names, tags and groups
it may hand out, whether it may name users, and for how long. That
certificate goes into the network policy, a small document the network
key signs. The policy spreads like the revocation list: numbered, so a
newer one replaces an older one, and signed, so nobody can forge or roll
one back. starmole net auth list on any machine shows
it.
Signing in. On a laptop, starmole login
connects to the auth service and shows it proof: an SSH certificate, or
whatever its verifiers take. A verifier is a program on the auth service
that checks the proof and says which user and groups it's worth. The
auth service keeps the laptop's name, tags and addresses from its
current certificate, adds the user and groups, cuts everything down to
its limits and signs a certificate for 12 hours or less. Every other
machine checks that certificate offline, like any other, so the auth
service only has to be up while someone signs in.
Requiring it.
starmole net auth require --from 2027-01-01 changes what
rules see. From that date, user:, group: and
principal: only match on a certificate an auth service
signed; names, tags, node: rules and [[peer]]
entries keep working, so servers don't notice. Until then, machines log
policy.would_refuse for each connection that would be
refused, and starmole status reminds people who haven't
signed in. Leave out --from to require it right away. A
machine with [policy] follow = false ignores all of this
and keeps to its own rules.
Rules for many machines. Writing the same
[[allow]] rule on every server gets old.
starmole net rules add --on tag:server --from tag:admin --caps shell
signs the rule into the network policy, and it spreads with it. A
machine takes signed rules only with
[policy] signed_rules = true, and then only those whose
--on matches its own certificate, after its own rules. A
signed rule can't run sessions as root, and a machine that doesn't know
a cap in one skips that rule.
Until a machine turns on signed rules, what a peer may do there is
that machine's own [[allow]] rules, and the policy and the
auth service only decide who a peer is. Turning them on means whoever
holds the network key can grant access there too, so leave it off on
machines where only their own config should decide.
Older machines. The policy is passed around exactly as the network key signed it, so a machine running an older starmole passes on a newer policy whole, parts it doesn't know included. It uses what it can read. When a newer policy has something an older machine mustn't ignore, the policy says so, and that machine keeps using the last policy it could read until it's upgraded. Its log says which version it's waiting on.
Services
A service is something a machine offers by name: a web app, a
database, a socket. The machine lists it under
[services.<name>] with where to connect, and rules
grant service:<name>. Another member runs
starmole open workstation/grafana and gets a local port
that leads to it. With identity = true, the program behind
the service first gets a line of JSON with who's connecting (name, user,
groups, tags), so it can tell people apart without a login of its own. A
service a peer may not open looks the same to it as one that doesn't
exist.
The tun device
Every member gets an IPv6 address in a /48 derived from the network id, with the rest derived from its node id, so nobody hands out addresses and collisions are vanishingly unlikely. A machine routes the whole /48 to its device. Packets to an address go to the peer it belongs to, and packets from a peer are only accepted if their source address belongs to that peer.
Routes come from [[peer]] entries and from members'
certificates, and change as members join, leave or are revoked. Subnets
a machine exposes are announced to peers when the tun connection comes
up.
What each part is trusted with
| Part | Run by | Sees | Can it let someone in? | If it fails or lies |
|---|---|---|---|---|
| Relay | n0, or you | Encrypted QUIC packets, which node ids talk, when, how much | No | Relayed connections fail; direct ones carry on |
| Address lookup (DNS, pkarr) | n0, or you | Each node's relay and addresses | No: records are signed by the node's key, and a wrong address only reaches a machine that can't prove the key | New connections may not find a peer; ones with addrs in
config still connect |
| Router port mapping | Your router | A port request | No | Fewer direct paths |
| Network key | You, offline | Nothing at runtime | Yes, by signing certificates; that's its job | Keep it offline; it's only needed to invite and revoke |
| Issuer | A machine you choose | Invites, names it issued | Yes, within the limits the network key gave it | Revoke its issuer certificate |
| Auth service | A machine you choose | The proof people sign in with | Yes, within its limits, for as long as its certificates last | Sign-ins fail and certificates it signed run out;
net auth remove revokes them at once |
| Each machine's rules | That machine | Its own connections | Only to itself | Only that machine is affected |
The relay and the lookup service are infrastructure in the middle, like the internet routers between two ssh hosts. A connection's TLS is bound to node keys, so a relay or a forged DNS answer can't stand in for a machine. The worst they can do is keep machines from finding each other, and see who talks to whom.
When n0's relays and lookup service are unreachable, connections that
are up keep going, peers with addrs in config.toml still
connect directly, and certificates, revocations and rules all keep
working, since every check is local. To depend on nothing outside your
own machines, run your own relay and lookup server (see setup).
Files
Everything lives in ~/.config/starmole (or
$XDG_CONFIG_HOME/starmole, or --config-dir),
or /etc/starmole for a daemon running as root:
| File | What |
|---|---|
identity.key |
This machine's private key. |
config.toml |
Settings and access rules. See config.md. |
cert |
This machine's certificate chain. |
ssh.cert |
An SSH certificate for this machine's key, used when there's no
cert. |
peers |
Certificates and the revocation list learned from other members. |
connections.log |
Who connected and what they did; starmole log shows it.
Moves to connections.log.1 at 1 MiB. |
network.key |
The network key, on the machine that ran
starmole net init. |
issuer.cert |
An issuer certificate, on a machine the network key delegated to. |
issuer |
Open invites, issued names and the revocation list, on issuers. |
The daemon's socket is
$XDG_RUNTIME_DIR/starmole/daemon.sock, or
~/.local/state/starmole/daemon.sock where
XDG_RUNTIME_DIR isn't set, as on macOS. Only its user can
open it. A system daemon (as root, or as a service user like the NixOS
module's) listens on /var/run/starmole/daemon.sock, which
every local user can open; it asks the kernel who is on the other end of
each connection and lets only root and the
[daemon] operators do more than look.