Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ ATX power/reset controls are available on supported boards. **Wake-on-LAN** incl
- **Wi-Fi access point**: under **Network → Wi-Fi → Access point**, the device serves a Wi-Fi network of its own instead of joining one, until it is turned off.
- **Shared STUN/TURN settings** under Network for browser WebRTC video/audio and RustDesk: use the default or custom STUN servers, disable STUN, or configure an authenticated TURN relay.
- **Bluetooth controller switch** on supported AIC8800 boards, off by default. Enable it under Network; turning it on or off leaves Wi-Fi unaffected. This is a controller switch, not a peripheral-pairing interface.
- A single **VPN** menu entry for **WireGuard, OpenVPN 2, Tailscale and NetBird**, with installation state, version and connection/profile controls. OpenVPN is installed with the system; Tailscale and NetBird are optional APK installations.
- A single **VPN** menu entry for **WireGuard, OpenVPN 2, Tailscale, NetBird and ZeroTier**, with installation state, version and connection/profile controls. OpenVPN is installed with the system; Tailscale and NetBird are optional APK installations from Alpine, ZeroTier the optional `nanokvm-zerotier` add-on.
- **WireGuard `.conf` profiles** with an explicit Route Allowed IPs option; **OpenVPN TUN and TAP `.ovpn` profiles**, including referenced certificate/key files in the same upload.
- **HTTPS from first boot** with a unique device certificate and HTTP redirect. Newly generated certificates use ECDSA P-256; existing certificates are preserved. A **custom certificate** (your own CA or a public one) can be uploaded in Settings → System → Security and takes effect for new connections without a restart; a custom pair that cannot be loaded never blocks start-up (the generated one stands in). **Let's Encrypt / ZeroSSL / Buypass / Google** certificates through **acme.sh**, installed from its latest release on demand: HTTP-01 on port 80 or DNS-01 with every DNS provider acme.sh ships, renewed from the server and served without a restart. The web server's HTTPS and HTTP ports accept at most 256 connections in total and 64 from one address (one IPv6 /64), closing the rest before any TLS work, and run at most 16 TLS handshakes at a time; local add-ons on the loopback address are not limited. SSH can be enabled from settings; administrators can [import public SSH keys](docs/SSH-KEYS.md) from a file or pasted text.

Expand Down
6 changes: 3 additions & 3 deletions docs/SOFTWARE-PACKAGE-UPDATES.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ installed package: a model that needs a later NanoKVM OS would otherwise
update the whole OS as a side effect.

ZeroTier (`nanokvm-zerotier`) is an optional add-on too, installed on request
and not part of `nanokvm-release`. Its own workflow (`zerotier.yml`) builds it
from ZeroTier's release archive pinned in its recipe; once installed, its new
versions arrive with package updates.
from Settings > VPN > ZeroTier and not part of `nanokvm-release`. Its own
workflow (`zerotier.yml`) builds it from ZeroTier's release archive pinned in
its recipe; once installed, its new versions arrive with package updates.

Before the add-on repository index is signed, every package in it is checked:
it may declare only its own files, dependencies and lifecycle scripts. A
Expand Down
40 changes: 20 additions & 20 deletions docs/VPN.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# VPN profiles

Settings → VPN contains WireGuard, OpenVPN and Tailscale submenus. Each page
Settings → VPN contains WireGuard, OpenVPN, Tailscale, NetBird and ZeroTier submenus. Each page
shows its component version. WireGuard and OpenVPN each allow one enabled
profile; enabled profiles are restored after restart. Import alone does not
connect. Avoid overlapping routes when using multiple VPN clients.
Expand Down Expand Up @@ -46,26 +46,26 @@ Open the Tailscale submenu to use its existing installation/login controls.

## ZeroTier

ZeroTier is the optional `nanokvm-zerotier` add-on from the NanoKVM
repository. Install and start it over SSH:

```sh
apk add nanokvm-zerotier
rc-update add zerotier-one default
rc-service zerotier-one start
zerotier-cli info
zerotier-cli join NETWORK_ID
```

Then authorize the node ID that `zerotier-cli info` shows in the network's
controller (ZeroTier Central or your own); until then `zerotier-cli
listnetworks` shows the network as `ACCESS_DENIED`. ZeroTier can run alongside
the other VPNs; avoid overlapping routes.
The ZeroTier submenu installs the optional `nanokvm-zerotier` add-on from the
NanoKVM repository and then offers to start the `zerotier-one` service;
starting it also adds it to the boot runlevel, and stopping it takes it out.
Once it runs, the submenu shows the node ID, whether the node has reached
ZeroTier's root servers, and the joined networks with their state and
addresses. Join a network with its 16-digit ID, then authorize the node ID in
that network's controller (ZeroTier Central or your own); until then the
network shows **Not authorized**. Leave removes the network from this device
only. ZeroTier can run alongside the other VPNs; avoid overlapping routes.

The add-on is ZeroTier One's agent (MPL-2.0), built from ZeroTier's release
for musl and the C906, without ZeroTier's network controller, which is
source-available and not part of the package. A controller is not needed to
join networks. The identity and joined networks live in
source-available and not part of the package. A controller is not needed
to join networks. The identity and joined networks live in
`/var/lib/zerotier-one`, the same place as other ZeroTier installations, so
an identity copied there before starting keeps its node ID. `apk del
nanokvm-zerotier` stops the service and keeps that directory.
an identity copied there before starting keeps its node ID. They are kept on
uninstall unless you choose to delete them, and the settings backup includes
them for **Restore this device**, never for migration: two devices with one
identity disrupt each other. A backup taken before ZeroTier first started
holds only its `local.conf`, not network files preseeded in `networks.d`;
restoring it keeps the current identity and networks. Managed routes are
applied; default-route and DNS settings pushed by a network are not
(ZeroTier does not set DNS on Linux).
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
rc-service --ifstarted zerotier-one stop >/dev/null 2>&1 || true
rc-update del zerotier-one default >/dev/null 2>&1 || true
# /var/lib/zerotier-one holds the identity and the joined networks: user
# state, preserved by apk del.
# state, preserved by apk del (Settings > VPN > ZeroTier can delete it).
exit 0
40 changes: 40 additions & 0 deletions server/osupdate/apk.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,46 @@ func OtherInstallChanges(simulation string, names []string) []string {
return changed
}

// KeptByRemoval reports the packages of names that an `apk del --simulate`
// does not purge: apk exits 0 and keeps a package that another selected
// package still needs, after taking it out of the world.
func KeptByRemoval(simulation string, names []string) []string {
purged := map[string]bool{}
for _, line := range strings.Split(simulation, "\n") {
if action, name, _, ok := parseAPKStep(line); ok && action == "Purging" {
purged[name] = true
}
}
var kept []string
for _, name := range names {
if !purged[name] {
kept = append(kept, name)
}
}
return kept
}

// Installed lists the named packages that the installed database records. A
// database that cannot be read, or that records no package at all, proves
// nothing about the names and is an error.
func Installed(names ...string) ([]string, error) {
data, err := os.ReadFile(installedDBPath)
if err != nil {
return nil, err
}
versions := parseInstalledDB(string(data))
if len(versions) == 0 {
return nil, errors.New("the APK installed database records no package")
}
var installed []string
for _, name := range names {
if _, ok := versions[name]; ok {
installed = append(installed, name)
}
}
return installed, nil
}

// InstalledChanges reports the APK transaction steps that change an installed
// package: every step but installing a new package or reinstalling one of
// reinstall (a package `apk fix` repairs). An unrecognized numbered step also
Expand Down
36 changes: 36 additions & 0 deletions server/osupdate/apk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,39 @@ func TestPackageStateReportsRecordedButBroken(t *testing.T) {
t.Fatalf("broken: %s", got)
}
}

// apk del exits 0 and keeps a package another selected package needs: only a
// Purging step shows that it goes.
// Only a readable database that records packages shows which of the names
// are installed: an unreadable or empty one is an error, not an absence.
func TestInstalledNeedsTheDatabase(t *testing.T) {
t.Cleanup(func() { _ = os.Remove(installedDBPath) })
_ = os.Remove(installedDBPath)
if _, err := Installed("nanokvm-zerotier"); err == nil {
t.Fatal("missing database read as no package installed")
}
if err := os.WriteFile(installedDBPath, nil, 0600); err != nil {
t.Fatal(err)
}
if _, err := Installed("nanokvm-zerotier"); err == nil {
t.Fatal("empty database read as no package installed")
}
db := "C:Q1a=\nP:nanokvm-zerotier\nV:1.16.2-r1\n\nC:Q1b=\nP:musl\nV:1.2.5-r10\n"
if err := os.WriteFile(installedDBPath, []byte(db), 0600); err != nil {
t.Fatal(err)
}
if got, err := Installed("nanokvm-zerotier", "absent"); err != nil || strings.Join(got, ",") != "nanokvm-zerotier" {
t.Fatalf("installed %v, %v", got, err)
}
}

func TestKeptByRemoval(t *testing.T) {
purged := "(1/1) Purging nanokvm-zerotier (1.16.2-r1)\nOK: 130.6 MiB in 174 packages\n"
if kept := KeptByRemoval(purged, []string{"nanokvm-zerotier"}); len(kept) != 0 {
t.Fatalf("kept %v", kept)
}
retained := "World updated, but the following packages are not removed due to:\n nanokvm-zerotier: example\n\nOK: 130.6 MiB in 174 packages\n"
if kept := KeptByRemoval(retained, []string{"nanokvm-zerotier"}); len(kept) != 1 || kept[0] != "nanokvm-zerotier" {
t.Fatalf("kept %v", kept)
}
}
32 changes: 32 additions & 0 deletions server/proto/zerotier.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package proto

type ZerotierState string

const (
ZerotierNotInstall ZerotierState = "notInstall"
ZerotierNotRunning ZerotierState = "notRunning"
// The service runs but has not reached the root servers yet.
ZerotierConnecting ZerotierState = "connecting"
ZerotierRunning ZerotierState = "running"
)

type ZerotierNetwork struct {
ID string `json:"id"`
Name string `json:"name"`
Status string `json:"status"`
Type string `json:"type"`
Device string `json:"device"`
Addresses []string `json:"addresses"`
}

type GetZerotierStatusRsp struct {
State ZerotierState `json:"state"`
Address string `json:"address,omitempty"`
IP string `json:"ip,omitempty"`
Version string `json:"version,omitempty"`
Networks []ZerotierNetwork `json:"networks,omitempty"`
}

type ZerotierNetworkReq struct {
Network string `json:"network"`
}
4 changes: 4 additions & 0 deletions server/recovery/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ type Archive struct {
Files []File `json:"files"`
Packages []string `json:"packages"`
RootHash string `json:"rootHash,omitempty"`
// The settings groups (groups in policy.go) the archive covers: those of
// which the device had state (see coveredGroups). Archives made before
// groups existed have none.
Covers []string `json:"covers,omitempty"`
}

func passwordOK(password string) error {
Expand Down
42 changes: 41 additions & 1 deletion server/recovery/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"errors"
"fmt"
"os"
"slices"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -37,6 +38,12 @@ type Plan struct {
Options Options `json:"options"`
Changes []Change `json:"changes"`
RemovePackages []string `json:"removePackages"`
// The settings groups (groups in policy.go) the plan may change: those the
// restored archive covers, or all for a reset requested now. A journal
// without them, as a restore or reset queued by a release before groups
// existed, changes no file of any group: neither in the plan nor when the
// boot pass takes inventory again.
Covers []string `json:"covers,omitempty"`
// The source world is checked again at boot: do not execute a stale removal.
World []byte `json:"world"`
}
Expand Down Expand Up @@ -74,6 +81,14 @@ func (e Engine) Snapshot() (Archive, error) {
if err != nil {
return a, err
}
// A group the device had no state of is not covered, and its other files
// stay out: a backup made before ZeroTier started says nothing about an
// identity made later, which no restore could bring back once deleted.
a.Covers = coveredGroups(a.Files)
a.Files = slices.DeleteFunc(a.Files, func(f File) bool {
g := group(f.Path)
return g != "" && !slices.Contains(a.Covers, g)
})
world, err := read(e.Root, "etc/apk/world", MaxFile)
if err != nil {
return a, err
Expand Down Expand Up @@ -143,6 +158,9 @@ func (e Engine) Prepare(a *Archive, o Options) (Plan, Preview, error) {
}
v.Version = a.Version
v.Packages = a.Packages
p.Covers = slices.Clone(a.Covers)
} else {
p.Covers = allGroups()
Comment thread
dormancygrace marked this conversation as resolved.
Resolved
}
current, err := inventory(e.Root)
if err != nil {
Expand All @@ -156,6 +174,9 @@ func (e Engine) Prepare(a *Archive, o Options) (Plan, Preview, error) {
if o.Action == "restore" && o.Mode == "migrate" && !portable(f.Path) {
continue
}
if !p.covers(f.Path) {
continue
}
desired[f.Path] = nil
}
if o.Action == "restore" {
Expand Down Expand Up @@ -384,16 +405,30 @@ func (e Engine) Stage(p Plan) error {
}
return write(e.Root, PendingPath, &File{Data: data, Mode: 0600})
}

// covers reports whether the plan may change a settings path: one outside
// every group, or one in a group the plan covers.
func (p Plan) covers(name string) bool {
g := group(name)
return g == "" || slices.Contains(p.Covers, g)
}

func validatePlan(p Plan) error {
if (p.Options.Action != "restore" && p.Options.Action != "reset") || (p.RollingBack && !p.Started) {
return errors.New("invalid recovery journal")
}
if len(p.Changes) > MaxFiles+8 {
return errors.New("excessive recovery changes")
}
if err := validGroups(p.Covers); err != nil {
return errors.New("invalid recovery journal")
}
seen := map[string]bool{}
total := 0
for _, c := range p.Changes {
if !p.covers(c.Path) {
return errors.New("recovery change outside the plan's settings groups")
}
if (!allowed(c.Path) && c.Path != "etc/shadow" && c.Path != "etc/kvm/.jwt_secret" && c.Path != "etc/kvm/.picoclaw_internal_token") || seen[c.Path] {
return errors.New("invalid recovery destination")
}
Expand Down Expand Up @@ -465,6 +500,11 @@ func (e Engine) Resume(remove func([]string) error) (result error) {
if err != nil {
return err
}
// Prepare covers every group this release knows; a reset changes
// only those recorded when it was queued. One queued before groups
// existed resets none of them.
next.Covers = p.Covers
next.Changes = slices.DeleteFunc(next.Changes, func(c Change) bool { return !next.covers(c.Path) })
next.World = p.World
next.RemovePackages = p.RemovePackages
p = next
Expand All @@ -483,7 +523,7 @@ func (e Engine) Resume(remove func([]string) error) (result error) {
return err
}
for _, f := range current {
if seen[f.Path] || (p.Options.Mode == "migrate" && !portable(f.Path)) {
if seen[f.Path] || (p.Options.Mode == "migrate" && !portable(f.Path)) || !p.covers(f.Path) {
continue
}
p.Changes = append(p.Changes, Change{Path: f.Path, Before: &f})
Expand Down
Loading