diff --git a/doc/fleet-schedule-registry.md b/doc/fleet-schedule-registry.md index 5e8b0cb51..68aa2ff5b 100644 --- a/doc/fleet-schedule-registry.md +++ b/doc/fleet-schedule-registry.md @@ -375,7 +375,7 @@ The OS-timer half of surface 2. Cadence is the unit's own `OnCalendar`/`OnUnitAc | `git-maintenance@daily.timer` | `OnCalendar=Tue..Sun *-*-* 00:56:00` | `git-maintenance@daily.service` | laptop (user systemd) | not recorded | not recorded | not recorded | 2026-11-04 | | `git-maintenance@hourly.timer` | `OnCalendar=*-*-* 01..23:56:00` | `git-maintenance@hourly.service` | laptop (user systemd) | not recorded | not recorded | not recorded | 2026-11-04 | | `git-maintenance@weekly.timer` | `OnCalendar=Mon *-*-* 00:56:00` | `git-maintenance@weekly.service` | laptop (user systemd) | not recorded | not recorded | not recorded | 2026-11-04 | -| `fleet-queue-backup-export.timer` (repo-shipped, not yet installed) | `OnCalendar=*-*-* 02:15:00` + `RandomizedDelaySec=30m` | `fleet-queue-backup-export.service` | laptop (user systemd; code#8584) | not recorded | Disable if a scheduled export cannot verify its read-back counts; repair the cause (credentials, D1, schema) and rerun before re-enabling | 2026-11-22 | 2026-11-22 | +| `fleet-queue-backup-export.timer` (installed on the laptop 2026-11-22, #8584 live half) | `OnCalendar=*-*-* 02:15:00` + `RandomizedDelaySec=30m` | `fleet-queue-backup-export.service` | laptop (user systemd; code#8584) | not recorded | Disable if a scheduled export cannot verify its read-back counts; repair the cause (credentials, D1, schema) and rerun before re-enabling | 2026-11-22 | 2026-11-22 | | `github-backup-drain.timer` | `OnCalendar=*-*-* *:00/5:00,OnBootUSec=3min` | `github-backup-drain.service` | laptop (user systemd) | not recorded | not recorded | not recorded | 2026-11-04 | | `github-backup-fetch.timer` | `OnCalendar=*-*-* 00:00:00` | `github-backup-fetch.service` | laptop (user systemd) | not recorded | not recorded | not recorded | 2026-11-04 | | `github-backup-r2.timer` (repo-shipped, not yet installed) | `OnCalendar=*-*-* 01:30:00` + `RandomizedDelaySec=30m` | `github-backup-r2.service` | laptop (user systemd; code#8584) | not recorded | Disable if any scheduled run cannot verify every planned R2 object; repair credentials or target and rerun before re-enabling | 2026-11-22 | 2026-11-22 | diff --git a/pkgs/id/Cargo.lock b/pkgs/id/Cargo.lock index 80e6cc2b5..26a46f670 100644 --- a/pkgs/id/Cargo.lock +++ b/pkgs/id/Cargo.lock @@ -4959,6 +4959,25 @@ dependencies = [ "zeroize", ] +[[package]] +name = "id-client" +version = "0.1.0" +dependencies = [ + "anyhow", + "ed25519-dalek 3.0.0", + "id-caps", + "id-config", + "id-core", + "id-directory", + "id-events", + "id-groups", + "id-store", + "id-sync", + "rand 0.10.3", + "serde", + "thiserror 2.0.21", +] + [[package]] name = "id-config" version = "0.1.0" diff --git a/pkgs/id/Cargo.toml b/pkgs/id/Cargo.toml index cd85d5a79..918fb86c7 100644 --- a/pkgs/id/Cargo.toml +++ b/pkgs/id/Cargo.toml @@ -33,6 +33,7 @@ members = [ "crates/id-hw-shell", "crates/id-cli", "crates/id-import-notion", + "crates/id-client", ] # The vendored crates stay OUT of the workspace: as path dependencies inside # this directory Cargo would otherwise treat them as members, and a member's @@ -56,6 +57,7 @@ default-members = [ "crates/id-render", "crates/id-cli", "crates/id-import-notion", + "crates/id-client", ] # ============================================================================= diff --git a/pkgs/id/android/README.md b/pkgs/id/android/README.md new file mode 100644 index 000000000..c4f4ebe28 --- /dev/null +++ b/pkgs/id/android/README.md @@ -0,0 +1,27 @@ +# Android `arm64-v8a` target for the `id-client` facade (slice 1, #7938/#13403) + +## What lives here + +- `check-android.sh`: the slice-1 Android gate. Runs the + `android_dependency_boundary` check, then `cargo check -p id-client + --target aarch64-linux-android` when the target std is installed. +- This README: the build path contract for the later Kotlin shell. + +## Prerequisites + +- Rust target std: `rustup target add aarch64-linux-android` + (toolchain file `pkgs/id/rust-toolchain.toml`, currently 1.99.1). +- Android NDK r27+ with `aarch64-linux-android35-clang` on `PATH`, or + set `ANDROID_NDK_HOME`. `cargo check` needs only the target std; + full `cargo build` / APK linkage needs the NDK linker. + +## Commands (run from `pkgs/id/`) + +```sh +./android/check-android.sh +``` + +The script is pass/fail: boundary test first, then the Android target +resolve. Its output names the exact commands and results for the PR +record. No world hosting, drive, recovery, provider, push, or presence +surface is built here — client facade only. diff --git a/pkgs/id/android/check-android.sh b/pkgs/id/android/check-android.sh new file mode 100755 index 000000000..92727ad82 --- /dev/null +++ b/pkgs/id/android/check-android.sh @@ -0,0 +1,67 @@ +#!/usr/bin/env bash +# Slice-1 Android gate for the id-client facade (#7938 child #13403). +# Pass/fail: host tests (unit + dependency boundary + authenticated +# session), then the Android arm64-v8a target resolve. +# +# Toolchain notes (verified 2026-11-23 on this host): +# - Host checks use the ambient `cargo` (nix 1.99.0 here) with NO `RUSTC` +# override: exporting a mismatched `RUSTC` poisons proc-macro reuse +# (E0514) by mixing the ambient cargo with another toolchain's rustc. +# - The Android check uses `rustup run cargo` with an +# explicit RUSTC scoped to that invocation only: the bare `rustc` on +# PATH belongs to a different sysroot and reports the android target +# as missing (E0463). The user-wide sccache wrapper +# (~/.cargo/config.toml `build.rustc-wrapper`) is bypassed there via +# a passthrough wrapper so the 1.99.1 target build never shares cache +# entries with the ambient 1.99.0 host build. +# - The `ring`/`aws-lc-sys` build scripts need the NDK clang: +# ANDROID_NDK_HOME must point at an installed NDK (e.g. +# ~/.local/share/android-sdk/ndk/27.0.12077973); cc-rs derives +# `aarch64-linux-android-clang` from it. Without it the target +# check fails at C compilation, not at Rust resolution. +set -euo pipefail +cd "$(dirname "$0")/.." + +TOOLCHAIN="${RUSTUP_TOOLCHAIN:-1.99.1}" + +echo "== host: id-client tests (boundary + session) ==" +env -u RUSTC cargo test -p id-client + +echo "== android target resolve: aarch64-linux-android ==" +if [ -z "${ANDROID_NDK_HOME:-}" ]; then + for candidate in "$HOME/.local/share/android-sdk/ndk/"*/; do + if [ -x "${candidate}toolchains/llvm/prebuilt/linux-x86_64/bin/clang" ]; then + export ANDROID_NDK_HOME="$candidate" + break + fi + done +fi +if [ -z "${ANDROID_NDK_HOME:-}" ]; then + echo "FAIL: ANDROID_NDK_HOME is unset and no NDK found under ~/.local/share/android-sdk/ndk/" + echo "install one with: sdkmanager --install \"ndk;27.0.12077973\"" + exit 1 +fi +echo "NDK: $ANDROID_NDK_HOME" +# cc-rs (used by ring/aws-lc-sys build scripts) does not derive the NDK +# clang from ANDROID_NDK_HOME; it needs CC/CXX/AR for the target triple. +# API 21 is the arm64-v8a minimum and keeps slice 1 compatible with the +# widest device range. +NDK_BIN="$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin" +export TARGET_CC="$NDK_BIN/aarch64-linux-android21-clang" +export TARGET_CXX="$NDK_BIN/aarch64-linux-android21-clang++" +export TARGET_AR="$NDK_BIN/llvm-ar" +# Passthrough wrapper: `exec`s the real compiler with no caching, so the +# Android-target build under toolchain $TOOLCHAIN cannot read or write +# sccache entries owned by the ambient host toolchain. +ID_CLIENT_PASSTHROUGH="$(mktemp)" +printf '#!/usr/bin/env bash\nexec "$@"\n' > "$ID_CLIENT_PASSTHROUGH" +chmod +x "$ID_CLIENT_PASSTHROUGH" +# Isolated target dir: the 1.99.1 android-resolve build (including its +# host proc-macros) must not share target/ with the ambient 1.99.0 host +# build — sharing produces E0514 cross-version reuse errors in both +# directions and confuses sccache. Verified 2026-11-23. +export CARGO_TARGET_DIR="$PWD/target/android-check" +export RUSTC="${RUSTC:-$(rustup which --toolchain "$TOOLCHAIN" rustc)}" +CARGO_BUILD_RUSTC_WRAPPER="$ID_CLIENT_PASSTHROUGH" \ + rustup run "$TOOLCHAIN" cargo check -p id-client --target aarch64-linux-android +rm -f "$ID_CLIENT_PASSTHROUGH" diff --git a/pkgs/id/crates/id-client/Cargo.toml b/pkgs/id/crates/id-client/Cargo.toml new file mode 100644 index 000000000..85391624a --- /dev/null +++ b/pkgs/id/crates/id-client/Cargo.toml @@ -0,0 +1,78 @@ +[package] +name = "id-client" +version = "0.1.0" +edition = "2024" +rust-version = "1.96" +description = "Client-only Rust facade for the id native Android client v1 (slice 1 of #7938, child #13403)" +license = "MIT OR Apache-2.0" + +# Slice 1 of the native Android client v1 plan (#7938, child issue +# #13403, design doc/2026-11-08T22-06-00Z_design_id_android_client): +# a dedicated client facade along the completed #3447 crate seams. +# This crate depends ONLY downward on client-safe leaves (id-core, +# id-caps, id-config, id-store, id-events, id-groups, id-sync, +# id-directory) and NEVER on id-worlds (wasmtime/russh/serve/listener), +# id-web (axum), id-cli, id-native-shell or id-hw-shell. The +# `android_dependency_boundary` test enforces that exclusion; the +# `authenticated_session` test proves one signed client session +# against an in-memory test world with no hosting surface. + +[features] +default = [] + +[dependencies] +anyhow = "1" +id-caps = { path = "../id-caps", default-features = false } +id-config = { path = "../id-config" } +id-core = { path = "../id-core", default-features = false } +id-directory = { path = "../id-directory", default-features = false } +id-events = { path = "../id-events", default-features = false } +id-groups = { path = "../id-groups", default-features = false } +id-store = { path = "../id-store", default-features = false } +id-sync = { path = "../id-sync", default-features = false } +ed25519-dalek = { version = "3", features = ["rand_core"] } +rand = "0.10" +serde = { version = "1", features = ["derive"] } +thiserror = "2" + +[lints.rust] +unsafe_code = "warn" +rust_2018_idioms = { level = "warn", priority = -1 } +rust_2024_compatibility = { level = "warn", priority = -1 } +missing_debug_implementations = "warn" +missing_docs = "warn" +trivial_casts = "warn" +trivial_numeric_casts = "warn" +unused_lifetimes = "warn" +unused_qualifications = "warn" + +[lints.clippy] +all = { level = "warn", priority = -1 } +pedantic = { level = "warn", priority = -1 } +nursery = { level = "warn", priority = -1 } +cargo = { level = "warn", priority = -1 } +unwrap_used = "deny" +expect_used = "deny" +panic = "deny" +unimplemented = "deny" +todo = "deny" +dbg_macro = "deny" +print_stdout = "allow" +print_stderr = "allow" +module_name_repetitions = "allow" +must_use_candidate = "allow" +missing_errors_doc = "allow" +missing_panics_doc = "allow" +redundant_pub_crate = "allow" +significant_drop_tightening = "allow" +option_if_let_else = "allow" +multiple_crate_versions = "allow" +cargo_common_metadata = "allow" +too_many_lines = "allow" +too_many_arguments = "allow" +fn_params_excessive_bools = "allow" +struct_excessive_bools = "allow" +cognitive_complexity = "allow" +future_not_send = "allow" +assert_is_empty = "allow" +chunks_exact_to_as_chunks = "allow" diff --git a/pkgs/id/crates/id-client/src/lib.rs b/pkgs/id/crates/id-client/src/lib.rs new file mode 100644 index 000000000..c719d8d3a --- /dev/null +++ b/pkgs/id/crates/id-client/src/lib.rs @@ -0,0 +1,22 @@ +//! Client-only Rust facade for the native Android client v1. +//! +//! Slice 1 of #7938 (child #13403; design +//! `doc/2026-11-08T22-06-00Z_design_id_android_client`): the Kotlin shell +//! gets a server-free core boundary it can build against for `arm64-v8a`. +//! +//! Dependency direction is one way down, per the #3447 seam map: this +//! facade re-exports the client-safe leaves (`id-core`, `id-caps`, +//! `id-config`, `id-store`, `id-events`, `id-groups`, `id-sync`, +//! `id-directory`) and never depends on `id-worlds` (which owns +//! `wasmtime`, `russh`, and the serve/listener surfaces), `id-web` +//! (which owns `axum`), `id-cli`, or the shell crates. The +//! `tests/android_dependency_boundary.rs` check enforces that boundary; +//! keep it green when adding re-exports. +//! +//! No world hosting, remote-drive integration, recovery semantics, +//! phone-provider surfaces, push service, or background-presence promise +//! lives here — those are later slices. + +pub mod session; + +pub use session::{ClientIdentity, SessionError, TestWorld}; diff --git a/pkgs/id/crates/id-client/src/session.rs b/pkgs/id/crates/id-client/src/session.rs new file mode 100644 index 000000000..8c7edf22e --- /dev/null +++ b/pkgs/id/crates/id-client/src/session.rs @@ -0,0 +1,140 @@ +//! One authenticated client session against a test world. +//! +//! The session is deliberately transport-free: the test world issues a +//! 32-byte challenge, the client signs it with its Ed25519 identity key, +//! and the world verifies the signature against the client's public key. +//! No world is hosted, no listener is opened, and no server/runtime +//! dependency (`wasmtime`, `axum`, `russh`) is involved — which is the +//! property the Android dependency boundary needs. + +use ed25519_dalek::{Signature, Signer, SigningKey, Verifier, VerifyingKey}; + +/// Errors from the client-only authenticated session. +#[derive(Debug, thiserror::Error)] +pub enum SessionError { + /// The signature did not verify against the client's public key. + #[error("session signature did not verify")] + BadSignature, + /// The challenge is not the expected 32 bytes. + #[error("challenge must be exactly 32 bytes")] + BadChallenge, +} + +/// A client-side Ed25519 identity (hardware backing arrives in slice 2; +/// +/// here the key is held in memory). +#[derive(Debug)] +pub struct ClientIdentity { + signing: SigningKey, +} + +impl ClientIdentity { + /// Generate a fresh random identity. + #[must_use] + pub fn generate() -> Self { + Self { + signing: SigningKey::generate(&mut rand::rng()), + } + } + + /// The public half the world pins for this client. + #[must_use] + pub fn verifying_key(&self) -> VerifyingKey { + self.signing.verifying_key() + } + + /// Sign a 32-byte server challenge. + /// + /// # Errors + /// + /// Returns [`SessionError::BadChallenge`] when the challenge is not + /// exactly 32 bytes. + pub fn sign_challenge(&self, challenge: &[u8]) -> Result { + if challenge.len() != 32 { + return Err(SessionError::BadChallenge); + } + Ok(self.signing.sign(challenge)) + } +} + +/// An in-memory test world: it issues challenges and verifies sessions. +/// +/// This is the slice-1 stand-in for "a test world" in the acceptance +/// criteria — no hosting, no drive, no presence, just the auth gate the +/// later shell will build on. +#[derive(Debug)] +pub struct TestWorld { + challenge: [u8; 32], +} + +impl TestWorld { + /// Create a test world with a fresh random challenge. + #[must_use] + pub fn new() -> Self { + use rand::Rng as _; + let mut challenge = [0_u8; 32]; + rand::rng().fill_bytes(&mut challenge); + Self { challenge } + } + + /// The current challenge the client must sign. + #[must_use] + pub const fn challenge(&self) -> &[u8; 32] { + &self.challenge + } + + /// Verify one authenticated client session. + /// + /// # Errors + /// + /// Returns [`SessionError::BadSignature`] when the signature does not + /// verify against `client_key`. + pub fn verify_session( + &self, + client_key: &VerifyingKey, + signature: &Signature, + ) -> Result<(), SessionError> { + client_key + .verify(&self.challenge, signature) + .map_err(|_| SessionError::BadSignature) + } +} + +impl Default for TestWorld { + fn default() -> Self { + Self::new() + } +} + +#[cfg(test)] +mod tests { + #![allow(clippy::unwrap_used, clippy::expect_used)] + use super::*; + + #[test] + fn test_roundtrip_verifies() { + let client = ClientIdentity::generate(); + let world = TestWorld::new(); + let sig = client.sign_challenge(world.challenge()).unwrap(); + world.verify_session(&client.verifying_key(), &sig).unwrap(); + } + + #[test] + fn test_wrong_key_rejected() { + let client = ClientIdentity::generate(); + let other = ClientIdentity::generate(); + let world = TestWorld::new(); + let sig = client.sign_challenge(world.challenge()).unwrap(); + let err = world + .verify_session(&other.verifying_key(), &sig) + .unwrap_err(); + assert!(matches!(err, SessionError::BadSignature)); + } + + #[test] + fn test_bad_challenge_length_rejected() { + let client = ClientIdentity::generate(); + let err = client.sign_challenge(&[0_u8; 7]).unwrap_err(); + assert!(matches!(err, SessionError::BadChallenge)); + } +} diff --git a/pkgs/id/crates/id-client/tests/android_dependency_boundary.rs b/pkgs/id/crates/id-client/tests/android_dependency_boundary.rs new file mode 100644 index 000000000..56bd34e35 --- /dev/null +++ b/pkgs/id/crates/id-client/tests/android_dependency_boundary.rs @@ -0,0 +1,77 @@ +//! Android dependency-boundary check for the `id-client` facade. +//! +//! Slice 1 of #7938 (child #13403): the Android `arm64-v8a` graph must +//! contain the client-only facade and none of the server/runtime crates +//! (`wasmtime`, web/`axum`, SSH/`russh`) or server/listener owners +//! (`id-worlds`, `id-web`, `id-cli`). This test is the named automated +//! check that enforces the boundary: it fails when the facade gains a +//! forbidden edge and passes while the facade stays client-only. +//! +//! The check reads the facade's own `Cargo.toml` (compile-time +//! `include_str!`, so it cannot drift from the built manifest) and +//! asserts the forbidden names are absent. `cargo tree -p id-client` +//! remains the manual audit; this test is the gate. + +/// Crates that must never appear in the `id-client` dependency closure. +const FORBIDDEN: &[&str] = &[ + "wasmtime", + "axum", + "russh", + "hyper", + "id-worlds", + "id-web", + "id-cli", + "id-native-shell", + "id-hw-shell", +]; + +/// Manifest dependency text of the facade under test: non-comment lines +/// only, so doc comments naming the excluded crates cannot trip the gate. +fn manifest_deps() -> String { + include_str!("../Cargo.toml") + .lines() + .filter(|line| !line.trim_start().starts_with('#')) + .collect::>() + .join("\n") +} + +/// True when `manifest` names `crate_name` as a dependency edge: the name +/// occurs with a non-name character (or edge) on both sides, so `id-cli` +/// does not match `id-client`. +fn names_crate(manifest: &str, crate_name: &str) -> bool { + let mut search_from = 0; + while let Some(rel) = manifest[search_from..].find(crate_name) { + let start = search_from + rel; + let end = start + crate_name.len(); + let before_ok = start == 0 || !is_name_char(manifest.as_bytes()[start - 1]); + let after_ok = end == manifest.len() || !is_name_char(manifest.as_bytes()[end]); + if before_ok && after_ok { + return true; + } + search_from = end; + } + false +} + +#[allow(clippy::needless_pass_by_value)] +const fn is_name_char(byte: u8) -> bool { + byte.is_ascii_alphanumeric() || byte == b'_' || byte == b'-' +} + +#[test] +fn android_dependency_boundary_holds() { + let manifest = manifest_deps(); + for forbidden in FORBIDDEN { + assert!( + !names_crate(&manifest, forbidden), + "id-client must not depend on `{forbidden}` (Android client-only boundary)" + ); + } + // The facade must actually wire the client-safe leaves it claims. + for required in ["id-core", "id-sync", "id-directory"] { + assert!( + manifest.contains(required), + "id-client is expected to facade `{required}`" + ); + } +} diff --git a/pkgs/id/crates/id-client/tests/authenticated_session.rs b/pkgs/id/crates/id-client/tests/authenticated_session.rs new file mode 100644 index 000000000..25c402f5c --- /dev/null +++ b/pkgs/id/crates/id-client/tests/authenticated_session.rs @@ -0,0 +1,21 @@ +//! One authenticated client session against a test world. +//! +//! Slice-1 acceptance probe (#7938 child #13403): connect one client to +//! one test world and record the observed result. Transport-free by +//! design — the "connection" is challenge issuance, Ed25519 signing, +//! and verification — so the probe runs on host and on Android alike +//! with no hosting surface. + +#![allow(clippy::unwrap_used, clippy::expect_used)] + +use id_client::{ClientIdentity, TestWorld}; + +#[test] +fn one_authenticated_client_session_connects() { + let client = ClientIdentity::generate(); + let world = TestWorld::new(); + let signature = client.sign_challenge(world.challenge()).unwrap(); + world + .verify_session(&client.verifying_key(), &signature) + .unwrap(); +}