Skip to content

feat: implement the IMPROVEMENTS.md items (SSH, recipe safety, service, CI and more) - #36

Merged
skalvinnathan merged 14 commits into
mainfrom
feat/improvements-impl
Nov 19, 2026
Merged

skalvinnathan merged 14 commits into
mainfrom
feat/improvements-impl

Conversation

@skalvinnathan

@skalvinnathan skalvinnathan commented Nov 15, 2026 •

Copy link
Copy Markdown
Member

This implements the items listed in IMPROVEMENTS.md (#35). It is stacked on #34 (fix/code-review-2026-11). Merge #34 first; this PR's diff is against that branch. Each item is in its own commit.

Items

# Item Status
1 Per-install SSH credentials Done
2 Community recipe safety Done (app); validate.js is in AI2TH/linxr-marketplace (AI2TH/linxr-marketplace#2)
4 Disk resize end-to-end test Done, not run (needs a device)
5 Real size for "Auto" disk Done
6 k3s after VM reboot Done
7 Foreground service type and restarts Done (kept dataSync, see below)
8 Offer recipe ports as forwards Done
10 Alpine/kernel versions in About Partly done: versions are shown; the kernel version-string patch is not dropped or explained (not in scope)
11 apk mirror picker Done
15 CI Done (all jobs green on this PR)
3, 9, 12, 13, 14 — Not done, as agreed. 3 is left to feat/desktop-gui-reliability; 9, 12, 13 and 14 are measurements and releases

1. Per-install SSH credentials (P0)

  • SecretStore.kt: the app generates a random 20-character root password and encrypts it with an AES-256-GCM key in Android Keystore. It goes to the guest through QEMU -fw_cfg name=opt/root_password (not the kernel command line) and is redacted from the logged QEMU command.
  • New images: /sbin/init sets the password, generates the Dropbear ed25519 host key on first boot and then starts Dropbear with -r for that key. The image build no longer bakes host keys.
  • Older images: init_bootstrap.sh does the same early in boot. It removes the baked RSA/ECDSA keys and restarts only the listening Dropbear, so open sessions stay connected.
  • SshCredentials.connect (terminal and status ping) logs in with the per-install password or the app key. If the guest still accepts only alpine (a kernel without fw_cfg), the app logs in with that once and runs chpasswd to set the per-install password.
  • Settings → Security → SSH access shows the password, hidden until revealed, with a copy button.
  • Key-only login is a switch in the same card. POST /ssh/app-key creates a key pair in the guest. The guest keeps the public key in authorized_keys, returns the private key and deletes its copy. The app stores the private key with the Keystore key. Dropbear gets -s from the next start. Key-only is passed to the guest only when the app holds a key, so the app cannot lock itself out.
  • The instrumentation tests log in with the per-install password.

2. Community recipes (P0)

  • A remote recipe can never replace a built-in id; it is dropped. Remote recipes are labelled and filterable as "Community".
  • recipes.json is checked against a detached Ed25519 signature recipes.json.sig, using the public key embedded in recipe_signature.dart (pinenacl, already a dartssh2 dependency).
    • A bad signature is always rejected.
    • An unsigned catalog loads with a warning while "Require signed community recipes" is off. It is off by default until linxr-marketplace signs.
  • A script recipe shows its full script before the first run, and again when the script changes. It warns if the script switches apk to http.
  • Built-in native recipes and the bootstrap no longer switch apk to http.
  • Operator: the matching private key was generated locally and is not in any repository. It has to go to the marketplace maintainer, who signs with crypto.sign(null, data, key) and publishes the base64 result as recipes.json.sig.

7. Why dataSync and not specialUse

specialUse needs a Play Console declaration and review, and a rejected or pending declaration would block releases. dataSync needs no new review.

  • At Android 15's 6-hour limit, onTimeout stops the service cleanly and notifies the user.
  • MainActivity.onResume starts the service again. Bringing the app to the foreground resets the limit.
  • A START_STICKY restart without a running VM stops the service instead of showing "VM is running".
  • The manifest comment explains how to switch to specialUse later.

Other items

  • 5: "Auto" shows the size the app really creates (4 GB, from getDeviceInfo().autoDiskGb). A set size shows the free-storage cap.

  • 6: init_bootstrap.sh starts k3s server when /usr/local/bin/k3s exists and no server is running. It uses k3s.env (GODEBUG) and adds --disable traefik when the installed service has it.

  • 8: after a deploy, the app offers to add the recipe's ports as forwards. It skips forwards that already exist and reports collisions (host port in use, a duplicate, or reserved 2222/7081). The dialog notes that UDP, for example SIP on 5060, is not forwarded. Forwards apply after a VM restart.

  • 10: GET /system/release reads /etc/linxr-release, with a fallback for older images. It is shown in Settings → About.

  • 11: Settings → Package mirror offers the Alpine CDN (default), kernel.org, Aliyun and TUNA. The choice goes to the guest through fw_cfg opt/apk_mirror and is validated on both sides; only https is accepted. The image build also defaults to the CDN.

  • 15: .github/workflows/ci.yml runs:

    • flutter analyze --no-fatal-infos and flutter test
    • shellcheck (warning level) on scripts/*.sh and init_bootstrap.sh, and pyflakes on api_server.py
    • ./gradlew compileDebugKotlin compileDebugAndroidTestKotlin. The build does not need the VM assets that are not in the repository.

    A separate commit fixes the existing analyzer, shellcheck and pyflakes warnings so the checks start green.

  • 4: VmDiskResizeTest sets a 16 GB disk, boots, and asserts /dev/vda is 16 GB and df / is over 15 GB. It is skipped with less than 18 GB free.

Overlap with feat/desktop-gui-reliability

That branch did not exist on the remote when this PR was opened. This PR does not touch linxr-desktop.sh, the /desktop endpoints, desktop_screen.dart or desktop_service.dart. It does edit files that also hold desktop code, in other sections:

  • api_server.py: new /ssh/app-key and /system/release
  • VmManager.kt, MainActivity.kt, VmApiClient.kt: new methods
  • init_bootstrap.sh: the desktop install block is unchanged
  • main.dart: one line in _SshInfoCard

CI skips linxr-desktop.sh for now.

Checks run

Run locally on the PR head:

  • flutter analyze --no-fatal-infos (Flutter 3.44, Docker ghcr.io/cirruslabs/flutter:stable): 0 errors, 0 warnings, 118 infos (all existing withOpacity-style deprecations). Exit code 0.
  • flutter test: 27 tests passed, including the new recipe_safety_test.dart (signature, merge rule, http detection) and port_forward_planner_test.dart.
  • shellcheck 0.11 (-S warning) on scripts/*.sh and init_bootstrap.sh: clean. The generated /sbin/init was extracted and checked: one existing note-level unused variable.
  • pyflakes on api_server.py: clean.
  • api_server.py smoke test in alpine:3.20:
    • /health returns 200.
    • POST /ssh/app-key without a token returns 401.
    • With the token it returns an OpenSSH private key and writes authorized_keys (0600, in a 0700 directory). A second call replaces the key; it does not add a second one.
    • GET /system/release parses a sample /etc/linxr-release and falls back without one.
  • The signing format was checked end to end: a catalog signed with Node crypto.sign verifies in the Dart test against the embedded key.
  • Kotlin compile: passes in this PR's CI. The kotlin job runs :app:compileDebugKotlin :app:compileDebugAndroidTestKotlin on ubuntu-latest, which compiles the new and changed app and instrumentation-test Kotlin. It could not run on the local arm64 Mac because AAPT2 is x86-64 only.
  • GitHub Actions: all three jobs pass. Two follow-up commits made the Kotlin job work:
    • Flutter is pinned to 3.44.0, because 3.50 needs Gradle 9.3.1 and the wrapper is 8.11.1.
    • The Gradle tasks are scoped to :app, because a plugin's test manifest fails to merge.

Device test checklist (not run: no device available)

  • Fresh install: the VM boots, the terminal connects, and Settings → SSH access shows a password that works from ssh root@localhost -p 2222. alpine is rejected.
  • Upgrade from an image with baked keys: the host key changes once (the first boot regenerates it), then stays the same across reboots. /etc/dropbear has only the ed25519 key.
  • ls /sys/firmware/qemu_fw_cfg/by_name/opt/ shows root_password, ssh_key_only and apk_mirror. If fw_cfg is missing, the app's chpasswd fallback still moves the guest off alpine.
  • Key-only: turn it on while the VM runs, then restart. The terminal connects with the key, and password login is refused. Turn it off, restart, and password login works again.
  • Marketplace: the catalog shows "Unsigned catalog". Only build_essentials, grafana and mosquitto are listed under Community. Turning on "Require signed" hides them.
  • A script recipe shows its script once. Built-in native recipes (nginx-native etc.) install over https apk.
  • Deploying a recipe with ports offers forwards. After a VM restart, the port answers on the phone.
  • Install k3s, reboot the VM: kubectl get nodes works without a manual start.
  • Settings → About shows the Alpine and kernel versions. Disk "Auto" says 4 GB.
  • Package mirror: switch to kernel.org, restart, and check /etc/apk/repositories and apk update.
  • Android 15: the time-limit notification appears after 6 h in the background, and opening the app restores the service notification. Force-stopping the app and letting the sticky restart run leaves no "VM is running" notification.
  • ./gradlew connectedDebugAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=com.ai2th.linxr.VmDiskResizeTest
  • Release note: shipping the rebuilt base image needs the ASSETS_VERSION bump (item 14, not in this PR).

Every install used the root/alpine password and the Dropbear host keys
baked into base.qcow2.

- The app generates a random root password on first use, keeps it
  encrypted with an Android Keystore AES-GCM key (SecretStore.kt) and
  passes it to the guest through QEMU fw_cfg (opt/root_password), like
  the API token. It is redacted from the logged QEMU command line.
- /sbin/init (new images) and init_bootstrap.sh (older images) apply it
  with chpasswd, generate an ed25519 host key on first boot, delete the
  baked RSA/ECDSA keys and restart only the listening Dropbear.
- The image build no longer bakes host keys.
- The terminal and the SSH status ping log in with the per-install
  password through SshCredentials.connect. If the guest still accepts
  only the legacy password (kernel without fw_cfg), the app logs in with
  it once and sets the per-install password.
- Settings > Security > SSH access shows the password (hidden, with
  copy) and a key-only switch: the guest creates an app key pair
  (POST /ssh/app-key), the private key is stored with the Keystore key,
  and Dropbear runs with -s from the next VM start. Key-only is only
  passed to the guest when the app holds a key.
- Instrumentation tests log in with the per-install password.
Recipes from AI2TH/linxr-marketplace run as root and could replace a
built-in recipe with the same id, over an unauthenticated channel.

- A community recipe can no longer replace a built-in id; such entries
  are dropped. Remote recipes are marked and filterable as "Community".
- recipes.json is checked against a detached Ed25519 signature
  (recipes.json.sig, base64 of the raw 64-byte signature) with the
  public key embedded in the app (pinenacl, already used by dartssh2).
  A bad signature is always rejected. An unsigned catalog loads with a
  warning unless Settings > Security > "Require signed community
  recipes" is on (off by default until linxr-marketplace signs).
- A script recipe shows its full script, with a warning if it switches
  apk to http, before its first run and again when the script changes.
- Built-in native recipes no longer rewrite apk repositories to http.
Settings showed "Auto" as free storage minus 2 GB, but VmManager creates
user.qcow2 at the base image size (4 GB) when no size is set. Show the
real size, passed from VmManager.getDeviceInfo (autoDiskGb), and show a
set size after the same free-storage cap VmManager applies.
The custom /sbin/init never runs OpenRC, so the k3s service registered by
the installer did not start after a reboot. init_bootstrap.sh now starts
"k3s server" in the background when /usr/local/bin/k3s exists and no
server is running, with /etc/rancher/k3s/k3s.env (GODEBUG=tlsmlkem=0)
exported and --disable traefik when the installed service uses it. Log:
/var/log/k3s.log.
Keep foregroundServiceType="dataSync" rather than moving to specialUse:
specialUse needs a Play Console declaration and review, and a rejected
or pending one would block Play releases. The manifest comment explains
how to switch later.

- onTimeout (Android 15's 6 h in 24 limit) still stops the service
  cleanly and now posts a notification telling the user to open Linxr.
  MainActivity.onResume starts the service again while the VM runs,
  since bringing the app to the foreground resets the limit.
- A START_STICKY restart (null intent, after Android killed the app
  process) re-checks the VM: without a running VM the service stops
  instead of showing "VM is running". startForeground is still called
  first so a startForegroundService() start never times out.
After a recipe deploys, the app lists its declared ports and offers to
add them as custom host -> guest forwards. PortForwardPlanner skips
ports Linxr already forwards to the same guest port and reports
collisions (host port forwarded elsewhere, used twice by the recipe, or
reserved for SSH/API). The guest port is the container port for script
recipes and host-network containers, and the published port otherwise.

UDP ports are not supported (SLIRP hostfwd is set up for TCP only); the
dialog says so, and notes it for well-known UDP services such as SIP on
5060. Forwards apply after the VM restarts.
The API server gets GET /system/release, which reads /etc/linxr-release
(written by the image build since #34) and falls back to
/etc/alpine-release and the running kernel for older images. Settings
gets an About section with the app version, Alpine version, kernel
version and image build date, read when the VM is running.
Settings > Package mirror offers the Alpine CDN (default), kernel.org,
Aliyun and Tsinghua TUNA. VmManager passes the choice to the guest
through QEMU fw_cfg (opt/apk_mirror), accepting only https URLs of
plain URL characters, and init_bootstrap.sh writes /etc/apk/repositories
from it on every boot (validated again, falling back to the CDN). The
repositories now use https instead of http. The image build also
defaults to the CDN instead of mirrors.aliyun.com.
VmDiskResizeTest sets a 16 GB disk, resets storage, boots the VM and
asserts that /dev/vda is 16 GB and that df / reports more than 15 GB once
init_bootstrap.sh has grown the filesystem (polled for up to 10 minutes,
since resize2fs runs in the background). It is skipped on devices with
less than 18 GB free, because VmManager caps the disk to free storage
minus 2 GB. Needs a device and the VM assets; not run in CI.
So the new CI checks start green:
- flutter analyze: document and silence the non-const IconData in
  MarketplaceItem (builds use --no-tree-shake-icons), drop an
  unnecessary cast, and use the Disk Cap card's note to show when a set
  size is capped by free storage.
- shellcheck: find the -virt kernel directory with a glob instead of
  ls | grep, and fix the quoting of an echo in build_qcow2.sh.
- pyflakes: remove an unused import and an unused exception variable in
  api_server.py.
On pushes to main and on pull requests:
- flutter analyze (infos are not fatal) and flutter test;
- shellcheck at warning level on scripts/*.sh and init_bootstrap.sh
  (linxr-desktop.sh is left out while the desktop is being rewritten),
  and pyflakes on api_server.py;
- ./gradlew compileDebugKotlin compileDebugAndroidTestKotlin. The VM
  assets that are not in the repository (kernel, initramfs, base image,
  QEMU libraries) are not needed to compile.
Covers per-install SSH credentials, recipe safety, the Auto disk size,
k3s after reboot, the foreground service, recipe port forwards, the VM
versions in About, the apk mirror picker, CI and the disk resize test.
Flutter 3.50 (the current stable) refuses to apply its Gradle plugin with
a Gradle version below 9.3.1, so the Kotlin compile job failed while
configuring the project. Pin both Flutter jobs to 3.44.0, the version
the analyzer and tests were run with, until the wrapper is upgraded.
Running compileDebugAndroidTestKotlin from the root also built the
plugin modules' test variants, and package_info_plus's test manifest
(minSdk 19) fails to merge with androidx.exifinterface (minSdk 21).
Run :app:compileDebugKotlin and :app:compileDebugAndroidTestKotlin.
@skalvinnathan
skalvinnathan changed the base branch from fix/code-review-2026-11 to main November 19, 2026 09:18
@skalvinnathan
skalvinnathan merged commit 56bdb83 into main Nov 19, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant