diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8d451d1..c358771 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -73,7 +73,7 @@ jobs: - uses: gradle/actions/setup-gradle@8da46b539cd8fe6ab27ca75128919a18d757604c # v6.4.1 - name: Unit tests and APKs - run: ./gradlew --console=plain testDebugUnitTest assembleDebug assembleRelease + run: ./gradlew --console=plain testDebugUnitTest assembleDebug assembleDebugAndroidTest assembleRelease # The release workflow builds this for Google Play; it must not check # dl.bellterm.app for updates. @@ -85,10 +85,117 @@ jobs: - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: name: bellterm-apks - path: app/build/outputs/apk/*/*.apk + path: | + app/build/outputs/apk/*/*.apk + app/build/outputs/apk/androidTest/debug/*.apk if-no-files-found: error retention-days: 14 + # Issue #29: Herdr's own client switches to the machines its host saved with + # `herdr machine add`; Bellterm lists them and attaches through the host's + # ssh. Host and machine are two Herdr sessions behind one local sshd. + saved-machine: + name: Saved machine through its host + needs: android + runs-on: ubuntu-24.04 + timeout-minutes: 45 + permissions: + contents: read + steps: + - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 + with: + name: live-ssh + path: live + + - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 + with: + name: bellterm-apks + path: apks + + - name: sshd, Herdr, and a saved machine + run: | + [ -x /usr/sbin/sshd ] || sudo apt-get install -y openssh-server > /dev/null + sudo mkdir -p /run/sshd + mkdir -p ~/.ssh ~/sshd && chmod 700 ~/.ssh + ssh-keygen -q -t ed25519 -N '' -f ~/sshd/host + ssh-keygen -q -t ed25519 -N '' -f ~/.ssh/id_ed25519 + ssh-keygen -q -t ed25519 -N '' -f ~/bellterm-key + cat ~/.ssh/id_ed25519.pub ~/bellterm-key.pub >> ~/.ssh/authorized_keys + chmod 600 ~/.ssh/authorized_keys + printf '%s\n' 'Port 2222' 'ListenAddress 127.0.0.1' "HostKey $HOME/sshd/host" \ + "PidFile $HOME/sshd/pid" 'UsePAM no' 'PasswordAuthentication no' 'StrictModes no' > ~/sshd/config + /usr/sbin/sshd -f ~/sshd/config -E ~/sshd/log + ssh-keyscan -p 2222 -t ed25519 127.0.0.1 >> ~/.ssh/known_hosts 2> /dev/null + curl -fsSL https://herdr.dev/install.sh | sh + export PATH="$HOME/.local/bin:$PATH" + herdr machine add "ssh://$(id -un)@127.0.0.1:2222" --remote-session machine --label b-machine < /dev/null + herdr --session machine workspace create --label on-b --no-focus + herdr machine list --json + # The host's own session, which the app attaches to first. + nohup herdr server > ~/herdr-host.log 2>&1 & + for _ in $(seq 30); do herdr status server --json | grep -q '"running":true' && break; sleep 1; done + echo "FINGERPRINT=$(ssh-keygen -lf ~/sshd/host.pub | awk '{print $2}')" >> "$GITHUB_ENV" + + - name: List the machine and attach through its host + run: | + export BELLTERM_LIVE_HOST=127.0.0.1 BELLTERM_LIVE_PORT=2222 BELLTERM_LIVE_USER="$(id -un)" + export BELLTERM_LIVE_KEY="$HOME/bellterm-key" + export BELLTERM_LIVE_MACHINE=b-machine BELLTERM_LIVE_MACHINE_WORKSPACE=on-b + chmod +x live/live_ssh + RUST_BACKTRACE=1 live/live_ssh --ignored --nocapture --exact attaches_to_a_saved_machine_through_its_host + + - name: Enable KVM + run: | + echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules + sudo udevadm control --reload-rules + sudo udevadm trigger --name-match=kvm + + # The app itself on an emulator, which reaches the runner's sshd as + # 10.0.2.2: the drawer lists the machine, and switching to it attaches. + - name: Emulator script + run: | + cat > "$RUNNER_TEMP/emulator.sh" <<'SCRIPT' + set -u + trap 'adb pull /sdcard/Android/data/app.bellterm/files/e2e "$RUNNER_TEMP/screens" > /dev/null' EXIT + adb install -r -g apks/debug/app-debug.apk + adb install -r -g apks/androidTest/debug/app-debug-androidTest.apk + # am instrument exits 0 on failures, and a skipped test (code -4) still + # reads OK, so both are checked in its output. + instrument() { + adb shell am instrument -w -r "$@" app.bellterm.test/androidx.test.runner.AndroidJUnitRunner > "$RUNNER_TEMP/instrument.log" + cat "$RUNNER_TEMP/instrument.log" + grep -q '^OK (' "$RUNNER_TEMP/instrument.log" && ! grep -q 'INSTRUMENTATION_STATUS_CODE: -4' "$RUNNER_TEMP/instrument.log" + } + test=app.bellterm.e2e.GlassUiTest + instrument -e publish_key 1 -e class "$test#t0_publishesDeviceKey" || exit 1 + adb shell cat /sdcard/Android/data/app.bellterm/files/e2e/device.pub >> ~/.ssh/authorized_keys + instrument -e host 10.0.2.2 -e port 2222 -e user "$(id -un)" -e fingerprint "$FINGERPRINT" \ + -e machine b-machine -e machine_workspace on-b -e class "$test#t8_switchesToSavedMachine" + SCRIPT + + - uses: reactivecircus/android-emulator-runner@a421e43855164a8197daf9d8d40fe71c6996bb0d # v2.38.0 + with: + api-level: 35 + arch: x86_64 + target: google_apis + disable-animations: true + script: bash "$RUNNER_TEMP/emulator.sh" + + - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + if: always() + with: + name: saved-machine-screens + path: ${{ runner.temp }}/screens + if-no-files-found: warn + retention-days: 14 + + - name: sshd and Herdr state + if: failure() + run: | + cat ~/sshd/log || true + cat ~/herdr-host.log || true + PATH="$HOME/.local/bin:$PATH" herdr machine status --json || true + # Issue #25: a Windows OpenSSH host runs cmd.exe or PowerShell, never # /bin/sh. A fresh admin user without Herdr goes through the app's flow: # install prompt, install over SSH, attach, update, attach. diff --git a/README.md b/README.md index ab985b4..fa56839 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,15 @@ loader only supports from Android 10. - **Jump hosts.** A node can name another node as its jump host, which can have its own, as `ssh -J a,b host` does. Every hop's host key is checked and trusted separately; the trust prompt names the hop. +- **Herdr's saved machines.** When Herdr on a host has saved SSH machines + with `herdr machine add`, the session drawer lists them under **Machines** + with the host itself, as Herdr's own sidebar does. Tapping one opens its + session, reached through the host: the host's own `ssh` signs in to the + machine with its keys, configuration, and known hosts, so the machine needs + nothing new from the phone. Each machine is saved as a node shown *via* its + host, removed along with the host. Running `herdr --remote` inside a pane + instead shows the other server only as that pane's terminal, since + Bellterm's workspaces are those of the server it attached to. - **Keys and certificates.** **Keys & certificates** (the lock icon) holds the device key generated on the phone, generated keys, and imported OpenSSH private keys (RSA, ECDSA, Ed25519; a passphrase is used once to decrypt). @@ -312,6 +321,13 @@ again. CI runs it against Windows OpenSSH on a `windows-2025` runner, once with `cmd.exe` and once with PowerShell as the default shell. The test binary is built on Linux and runs in WSL there, which shares the runner's localhost. +`attaches_to_a_saved_machine_through_its_host` needs the host's Herdr to have +saved a machine labelled `BELLTERM_LIVE_MACHINE`, whose session has a +workspace labelled `BELLTERM_LIVE_MACHINE_WORKSPACE`: it lists the host's +machines, attaches to that one through the host, and checks that an +unreachable target reports the host's `ssh` error. CI runs it with the host +and the machine as two Herdr sessions behind one local sshd. + Set `BELLTERM_LIVE_JUMP_PORT` to reach the target through a jump host on the same address, and `BELLTERM_LIVE_CERT` to a certificate for the key to sign in with it (point the target's `TrustedUserCAKeys` at the CA and its diff --git a/app/src/androidTest/java/app/bellterm/e2e/GlassUiTest.kt b/app/src/androidTest/java/app/bellterm/e2e/GlassUiTest.kt index bcdf289..2219e8b 100644 --- a/app/src/androidTest/java/app/bellterm/e2e/GlassUiTest.kt +++ b/app/src/androidTest/java/app/bellterm/e2e/GlassUiTest.kt @@ -36,6 +36,11 @@ import org.junit.runners.MethodSorters * adb shell am instrument -w -e host 192.168.0.100 -e port 2200 -e user me \ * app.bellterm.test/androidx.test.runner.AndroidJUnitRunner * + * Add `-e machine