Repository navigation
Dev images: SSH over the USB cable only - #2
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A dev image (
MOARCHY_SSH_KEY=<pubkey> ./scripts/build-image.sh) now gets SSH over the USB cable only. Before, the key enabled sshd on every interface, debug images turned mDNS back on to advertise it, and the Wi-Fi preseed enabled sshd too.Change
image/configure.sh: withMOARCHY_SSH_KEY, installsauthorized_keysandmoarchy-usbnet, a configfs NCM gadget that puts the phone at 10.66.0.2/30 with fixed MAC addresses so the PC side can be a static 10.66.0.1 profile. The gadget script is safe to rerun after any partial failure, refuses an interface not namedusb0, and turns IPv6 off on the link so the USB host cannot become the phone's router. sshd requires that unit, listens on 10.66.0.2 only, and admitsmoarchy@10.66.0.1only. Because Linux accepts a packet for any local address on any interface, sshd's cgroup also passes only usb0 traffic to and from 10.66.0.1 (RestrictNetworkInterfaces=usb0,IPAddressDeny=any,IPAddressAllow=10.66.0.1). systemd starts a unit unfiltered when it cannot load those BPF programs, so anExecStartPrecheck requires a loopback connect from sshd's cgroup to time out before sshd binds anything. NetworkManager leaves the link alone, matched by its fixed MAC. The Wi-Fi preseed no longer enables sshd, and the debug mDNS re-enable is gone.image/verify.sh: release images must have no SSH key, sshd off and none of the five USB link files.DEV_IMAGE=1instead requires a public-key-onlyauthorized_keys, sshd enabled, all five files, and sshd's drop-in byte for byte asconfigure.shwrites it. It fails on anything else that could reset or widen the filter: anothersshd.servicedrop-in, a replacementsshd.service, asystem.controldrop-in, type-wideservice.dor slice drop-ins naming the filter settings, or an enabled ssh socket unit. It also requires IPv6 off and NetworkManager's unmanaged rule. It checks sshd's effective configuration withsshd -Tin the image, as seen from 10.66.0.1 and from a LAN address, sokeyword=value, quoting,IncludeandMatchare all accounted for:ListenAddress 10.66.0.2:22only,AllowUsers moarchy@10.66.0.1only, no password auth. A dev run ends with a NOT PUBLISHABLE line.scripts/verify-image.shpassesDEV_IMAGEthrough.image/negative-test.sh: a twelfth plant, the USB link's sshd drop-in in a release image. WithDEV_IMAGE=1it plants ten dev-image defects instead: a secondListenAddress=0.0.0.0, aMatchblock opening sshd to the LAN, the filter widened towlan0, ansshd.servicedrop-in resetting it, a type-wide drop-in resetting it, a slice drop-in withIPAddressAllow=any, a replacementsshd.service, IPv6 left on, NetworkManager allowed to manage the link, and a socket-activated sshd..github/workflows/image.yml: builds a dev image with a throwaway key, runsDEV_IMAGE=1verify and the dev negative test on it. It is never uploaded.install-on-device.shscripts default tomoarchy@10.66.0.2.docs/structure.mdI5 and I6 are updated, andmoarchygoes to pkgrel 10.Testing
Built in an isolated VM. The release image passed verify and the negative test caught all 12 plants. The dev image passed
DEV_IMAGE=1verify and the dev negative test caught all 13 plants. Both verifies pass apart from the online resize2fs check, which needs a native arm64 kernel and runs in CI.Flashed to a Pixel 3a. SSH over the cable worked on first boot with no setup, and the host key fingerprint matched the one shown on the device. sshd started after its pre-start filter check timed out, as it should with the filters loaded, and systemd reports the three filter settings on the unit.
ssshows sshd only on 10.66.0.2:22, nothing listens on 5353 or 5355,usb0has IPv6 disabled and is unmanaged, and no units failed. On an earlier build with the same filter, Wi-Fi peers could not reach sshd with either filter alone. The pre-start check failing closed when the filters are absent was not exercised on the device.