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
6 changes: 2 additions & 4 deletions configs/waybar/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -204,16 +204,14 @@ tooltip {

/* custom/sy-syauth — compact phone-as-key pill rendered by
* `sy syauth --waybar` (see crates/sy-auth/src/syauth.rs::render_pill). Text is
* always the 🔑 emoji (pair flow adds the 6-digit code beside it).
* always the key glyph (pair flow adds the 6-digit code beside it).
* Color carries the state; full status goes to the tooltip.
* .ok — phone reachable / in-flight challenge → cyan
* .reconnecting — recent transport-error or timeout → yellow
* .ok — daemon ready / in-flight challenge → cyan
* .degraded — daemon down OR permanent denied → red
* .unpaired — no phone is bonded yet → red
* .pending — LESC pair confirmation awaiting accept → green
*/
#custom-sy-syauth.ok { color: @aqua; }
#custom-sy-syauth.reconnecting { color: @yellow; }
#custom-sy-syauth.degraded { color: @red; }
#custom-sy-syauth.unpaired { color: @red; }
#custom-sy-syauth.pending { color: @green; font-weight: bold; }
Expand Down
84 changes: 38 additions & 46 deletions crates/sy-auth/src/syauth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,7 @@ pub fn parse_doctor_json(src: &str) -> Result<DoctorSummary, serde_json::Error>

/// Rendered waybar slot output. The waybar `custom/` module consumes
/// `{text, tooltip, class}`; we keep the struct narrow so the
/// emitter can decide whether to omit `class` (no class hook needed
/// when no bond is in play and the CSS table only carries the five
/// step-2 states).
/// emitter can describe daemon readiness separately from request history.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct WaybarPill {
pub text: String,
Expand All @@ -199,13 +197,10 @@ pub struct WaybarPill {
/// the state-driven color never showed through. Requires
/// `JetBrainsMono Nerd Font` (the bar's default — see
/// `configs/waybar/style.css` font-family).
const PILL_GLYPH_KEY: char = '\u{F084}'; //
const PILL_GLYPH_KEY: char = '\u{F084}';

/// "Recent" cutoff for last-audit-outcome → pill state. The window
/// must outlive a single sudo + biometric reaction (≈3 s) but be
/// short enough that an old denied row doesn't permanently stick
/// the pill red. 10 minutes mirrors the operator-facing
/// troubleshooting threshold in `docs/syauth-setup.md`.
/// Show confirmed authorization failures in red for ten minutes.
/// Unanswered requests and transport failures remain in history only.
const PILL_RECENT_OUTCOME_MS: u64 = 10 * 60 * 1000;

/// Render the pill from a parsed status + doctor pair + last audit
Expand All @@ -214,9 +209,9 @@ const PILL_RECENT_OUTCOME_MS: u64 = 10 * 60 * 1000;
/// `audit_log_tail` row (if any), and a wall-clock `now_ms` through.
///
/// State precedence:
/// `degraded` > `unpaired` > `active` > `ok`.
/// Daemon-down / recent-denied is the operator's most actionable
/// signal, so it wins. Pair-pending pre-empts everything earlier in
/// `degraded` > `unpaired` > `ok`.
/// Daemon-down and confirmed authorization errors need attention.
/// Pair-pending pre-empts everything earlier in
/// the call chain; this fn never sees a pending request — the caller
/// branches on the request file first, mirroring the existing
/// `waybar_out` path.
Expand All @@ -235,7 +230,7 @@ pub fn render_pill(
) -> WaybarPill {
let icon = PILL_GLYPH_KEY.to_string();
let recent_denied = last_outcome.and_then(|o| {
let denied = matches!(o.kind, OutcomeKind::Denied(_));
let denied = matches!(&o.kind, OutcomeKind::Denied(r) if !denied_is_transient(r));
let age_ms = now_ms.saturating_sub(o.t_end_ms);
if denied && age_ms <= PILL_RECENT_OUTCOME_MS {
Some(o)
Expand All @@ -248,25 +243,19 @@ pub fn render_pill(
} else if !status.has_peer() {
("unpaired", "no phone bonded".to_string())
} else if let Some(o) = recent_denied {
let (class, label) = match &o.kind {
OutcomeKind::Denied(r) if denied_is_transient(r) => ("reconnecting", "reconnecting"),
OutcomeKind::Denied(_) => ("degraded", "phone away"),
OutcomeKind::Ok => ("ok", "phone reachable"),
};
let reason = match &o.kind {
OutcomeKind::Denied(r) => denied_reason_text(r),
OutcomeKind::Ok => "ok",
};
(class, format!("{label} · last {reason}"))
("degraded", format!("last authentication failed · {reason}"))
} else if in_flight > 0 {
// In-flight challenge is the "phone is being used right now"
// state — the operator's mental model is "cyan because sudo
// works". Surface the activity in the headline; keep the
// color cyan so a healthy sudo doesn't flash yellow every
// 2-3 s.
// A pending request does not establish whether the phone is nearby.
("ok", format!("authenticating · {in_flight} in flight"))
} else {
("ok", "phone reachable".to_string())
(
"ok",
"daemon ready · phone availability unknown".to_string(),
)
};
let tip = build_pill_tooltip(status, doctor, last_outcome, now_ms, host, &headline);
WaybarPill {
Expand All @@ -282,15 +271,15 @@ fn denied_reason_text(r: &DeniedReason) -> &'static str {
DeniedReason::NoBond => "no bond",
DeniedReason::AuthError => "auth error",
DeniedReason::TransportError => "transport error",
DeniedReason::Other(reason) if reason == "response-timeout" => {
"approval timed out (phone may be away)"
}
DeniedReason::Other(_) => "denied",
}
}

/// Whether a denied outcome looks transient (yellow / reconnecting)
/// or permanent (red / degraded). Transport-error and any unknown
/// reason are transient — the daemon will likely succeed on the
/// next attempt once the phone reconnects. Peer-revoked / no-bond /
/// auth-error are operator-actionable problems.
/// Unanswered requests, transport failures, and unknown outcomes do not
/// establish an ongoing fault. Known authorization errors need attention.
fn denied_is_transient(r: &DeniedReason) -> bool {
matches!(r, DeniedReason::TransportError | DeniedReason::Other(_))
}
Expand All @@ -308,7 +297,7 @@ fn build_pill_tooltip(
Some(pid) => {
let head: String = pid.chars().take(8).collect();
let suffix = match status.last_connect_ms_ago {
Some(ms) => format!(" · last connect {} ago", humanize_ms_ago(ms)),
Some(ms) => format!(" · last request {} ago", humanize_ms_ago(ms)),
None => String::new(),
};
lines.push(format!("peer {head}\u{2026}{suffix}"));
Expand Down Expand Up @@ -967,8 +956,8 @@ fn waybar_out() -> Result<()> {
println!("{}", emit_pill_json(&text, "pending", &tip));
return Ok(());
}
// No pending pair request: render the live four-class pill
// (red / aqua / yellow + pending-green). Failures of either
// No pending pair request: render daemon readiness and request history.
// Failures of either
// upstream probe fall through to `degraded` (red) so the bar
// never goes blank.
let outcomes = live_audit_outcomes();
Expand Down Expand Up @@ -1704,7 +1693,9 @@ mod tests {
pill.tooltip.contains("fedora"),
"tooltip carries host: {pill:?}"
);
assert!(pill.tooltip.contains("phone reachable"), "got: {pill:?}");
assert!(pill.tooltip.contains("daemon ready"), "got: {pill:?}");
assert!(!pill.tooltip.contains("phone reachable"), "got: {pill:?}");
assert!(!pill.tooltip.contains("last connect"), "got: {pill:?}");
}

#[test]
Expand Down Expand Up @@ -1772,9 +1763,7 @@ mod tests {
}

#[test]
fn waybar_renders_reconnecting_on_recent_transient_denied() {
// response-timeout (parsed as DeniedReason::Other) and
// transport-error are both transient → yellow, not red.
fn waybar_stays_ok_after_an_unanswered_approval() {
let s = parse_status_json(FIXTURE_BONDED).expect("fixture parses");
let now: u64 = 1_779_200_000_000;
let timeout = UnlockOutcome {
Expand All @@ -1785,8 +1774,11 @@ mod tests {
kind: OutcomeKind::Denied(DeniedReason::Other("response-timeout".to_string())),
};
let pill = render_pill(&s, 0, &doctor_unknown(), Some(&timeout), now, "fedora");
assert_eq!(pill.class, "reconnecting", "got: {pill:?}");
assert!(pill.tooltip.contains("reconnecting"), "got: {pill:?}");
assert_eq!(pill.class, "ok", "got: {pill:?}");
assert!(!pill.tooltip.contains("reconnecting"), "got: {pill:?}");
assert!(pill.tooltip.contains("approval timed out"), "got: {pill:?}");
let next = render_pill(&s, 1, &doctor_unknown(), Some(&timeout), now, "fedora");
assert!(next.tooltip.contains("authenticating · 1 in flight"));
}

#[test]
Expand All @@ -1804,16 +1796,15 @@ mod tests {
};
let pill = render_pill(&s, 0, &doctor_unknown(), Some(&revoked), now, "fedora");
assert_eq!(pill.class, "degraded", "got: {pill:?}");
assert!(pill.tooltip.contains("phone away"), "got: {pill:?}");
assert!(
pill.tooltip.contains("last authentication failed"),
"got: {pill:?}"
);
assert!(pill.tooltip.contains("peer revoked"), "got: {pill:?}");
}

#[test]
fn waybar_renders_reconnecting_when_recent_unlock_was_transport_error() {
// The operator-facing "trying to reach phone" signal is a
// recent transport-error in the audit log. Inside the 10-min
// window the pill goes yellow (reconnecting); outside, it
// stays cyan.
fn waybar_keeps_transport_failure_in_history_without_claiming_reconnection() {
let s = parse_status_json(FIXTURE_BONDED).expect("fixture parses");
let now: u64 = 1_779_200_000_000;
let recent = UnlockOutcome {
Expand All @@ -1824,7 +1815,8 @@ mod tests {
kind: OutcomeKind::Denied(DeniedReason::TransportError),
};
let pill = render_pill(&s, 0, &doctor_unknown(), Some(&recent), now, "fedora");
assert_eq!(pill.class, "reconnecting", "got: {pill:?}");
assert_eq!(pill.class, "ok", "got: {pill:?}");
assert!(!pill.tooltip.contains("reconnecting"), "got: {pill:?}");
assert!(pill.tooltip.contains("transport error"), "got: {pill:?}");
}

Expand Down
41 changes: 41 additions & 0 deletions crates/sy-auth/tests/standalone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,44 @@ fn auth_accepts_launcher_global_paths() {
String::from_utf8_lossy(&output.stderr)
);
}

#[test]
fn unanswered_phone_approval_keeps_the_applet_ready() {
use std::{fs, os::unix::fs::PermissionsExt, time::SystemTime};

let root = tempfile::tempdir().unwrap();
let upstream = root.path().join("syauth");
fs::write(
&upstream,
"#!/bin/sh\nprintf '%s\\n' '{\"daemon\":{\"state\":\"up\",\"peers\":[{\"peer_id\":\"phone\",\"in_flight_challenges\":0}]},\"bluez_adapter\":\"unknown\"}'\n",
)
.unwrap();
fs::set_permissions(&upstream, fs::Permissions::from_mode(0o700)).unwrap();
let now_ms = SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.unwrap()
.as_millis();
let audit = root.path().join("audit.log");
fs::write(
&audit,
format!("phone,nonce,{now_ms},{now_ms},response-timeout,response-timeout\n"),
)
.unwrap();
let output = Command::new(env!("CARGO_BIN_EXE_sy-system-auth"))
.args(["syauth", "--waybar"])
.env("SY_SYAUTH_BIN", &upstream)
.env("SY_SYAUTH_AUDIT_LOG", &audit)
.env("XDG_RUNTIME_DIR", root.path())
.env("XDG_STATE_HOME", root.path())
.env("DBUS_SESSION_BUS_ADDRESS", "unix:path=/nonexistent")
.output()
.unwrap();
assert!(output.status.success());
let pill: serde_json::Value = serde_json::from_slice(&output.stdout).unwrap();
assert_eq!(pill["class"], "ok");
let tooltip = pill["tooltip"].as_str().unwrap();
assert!(tooltip.contains("daemon ready"));
assert!(tooltip.contains("approval timed out (phone may be away)"));
assert!(!tooltip.contains("reconnecting"));
assert!(!tooltip.contains("phone reachable"));
}
36 changes: 36 additions & 0 deletions docs/how-to/troubleshoot-syauth.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,42 @@ working state.

## Steps

### A request times out while the phone is away

An unanswered approval records a timeout for that request. The key stays cyan
while the daemon runs and has a phone bond. Hover over the key to see
`approval timed out (phone may be away)` in the request history. Transport errors
also appear in that history.

The `daemon ready` message describes the local service. That status doesn't confirm
the phone's availability. A successful approval confirms the connection for
that request. Red marks a stopped daemon, a missing bond, or an authorization
error. A new request shows `authenticating` even after an earlier timeout.
Keep the existing pairing and service running when an approval expires.

### Bluetooth is on but the phone can't discover the desktop

Check both the desktop advertisement and the daemon process:

```bash
bluetoothctl show
journalctl --user -u syauth-presenced.service -n 25 --no-pager
```

Zero `ActiveInstances` together with repeated `rotation failed` and
`target object was either not present or removed` indicates a missing desktop
advertisement. The controller can be renumbered from `hci0` to `hci1` after
reinitialization. Older daemons hardcode `hci0`, so restarting the same build
can leave only its RPC socket running with `orchestrator not started` in the
journal. A daemon status of `up` alone does not establish Bluetooth readiness.

The adapter-selection repair uses BlueZ's available default controller at
startup. After installing that repair, restart `syauth-presenced.service` and
verify advertising and a fresh phone subscription. Keep the existing bond;
pairing again does not repair an absent desktop adapter. See the
[adapter investigation](../../specs/bugs/BUG-20261031-1221.md) for validation
and deployment status.

### Desktop apps skip phone and FIDO authentication

PolicyKit authenticates through `polkit-1`, while sudo uses `sudo`.
Expand Down
36 changes: 36 additions & 0 deletions llms-full.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1876,6 +1876,42 @@ working state.

### Steps

#### A request times out while the phone is away

An unanswered approval records a timeout for that request. The key stays cyan
while the daemon runs and has a phone bond. Hover over the key to see
`approval timed out (phone may be away)` in the request history. Transport errors
also appear in that history.

The `daemon ready` message describes the local service. That status doesn't confirm
the phone's availability. A successful approval confirms the connection for
that request. Red marks a stopped daemon, a missing bond, or an authorization
error. A new request shows `authenticating` even after an earlier timeout.
Keep the existing pairing and service running when an approval expires.

#### Bluetooth is on but the phone can't discover the desktop

Check both the desktop advertisement and the daemon process:

```bash
bluetoothctl show
journalctl --user -u syauth-presenced.service -n 25 --no-pager
```

Zero `ActiveInstances` together with repeated `rotation failed` and
`target object was either not present or removed` indicates a missing desktop
advertisement. The controller can be renumbered from `hci0` to `hci1` after
reinitialization. Older daemons hardcode `hci0`, so restarting the same build
can leave only its RPC socket running with `orchestrator not started` in the
journal. A daemon status of `up` alone does not establish Bluetooth readiness.

The adapter-selection repair uses BlueZ's available default controller at
startup. After installing that repair, restart `syauth-presenced.service` and
verify advertising and a fresh phone subscription. Keep the existing bond;
pairing again does not repair an absent desktop adapter. See the
[adapter investigation](../../specs/bugs/BUG-20261031-1221.md) for validation
and deployment status.

#### Desktop apps skip phone and FIDO authentication

PolicyKit authenticates through `polkit-1`, while sudo uses `sudo`.
Expand Down
5 changes: 5 additions & 0 deletions packaging/sy.spec
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
%global debug_package %{nil}
# Release packages strip symbols; omit unused DWARF during compilation too.
%global rustflags_debuginfo 0

Name: sy
Version: 0.1.0
Expand All @@ -8,6 +10,8 @@ License: MIT
URL: https://github.com/dmytrogajewski/sy
Source0: %{name}-%{version}.tar.gz
BuildRequires: cargo
BuildRequires: binutils
BuildRequires: python3
BuildRequires: rust
BuildRequires: gcc
BuildRequires: gcc-c++
Expand Down Expand Up @@ -121,6 +125,7 @@ cargo build --release --locked --workspace --bins
cp target/release/sy target/release/sy-all

%check
python3 tests/rpm_build_flags.py
SY_FEATURE_BIN_DIR=/nonexistent target/release/sy-launcher --help | grep -q 'Optional packages'
SY_FEATURE_BIN_DIR=target/release target/release/sy-launcher --help | grep -q 'apply'
SY_FEATURE_BIN_DIR=target/release target/release/sy-launcher --help | grep -q '^Usage: sy '
Expand Down
4 changes: 2 additions & 2 deletions scripts/build-rpms.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ for fedora in "${releases[@]}"; do
cp "$repo_root/packaging/sy.spec" "$work/sy.spec"
tar -C "$repo_root" --transform="s,^,sy-$version/," \
-czf "$work/SOURCES/sy-$version.tar.gz" \
Cargo.toml Cargo.lock LICENSE README.md src crates configs themes scripts packaging/sy.1 packaging/default-sy.toml
Cargo.toml Cargo.lock LICENSE README.md src crates configs themes scripts tests/rpm_build_flags.py packaging/sy.1 packaging/default-sy.toml
if [[ $native == true ]]; then
rpmbuild -ba "$work/sy.spec" --define "_topdir $work" \
--define "_rpmdir $work/RPMS" --define "_srcrpmdir $work/SRPMS"
Expand Down Expand Up @@ -88,7 +88,7 @@ for fedora in "${releases[@]}"; do
--setopt=keepcache=True \
--setopt=max_parallel_downloads=8 \
--setopt=timeout=120 --setopt=minrate=1 --setopt=retries=20 \
"${repo_args[@]}" install -y rpm-build cargo rust gcc gcc-c++ cmake pkgconf-pkg-config \
"${repo_args[@]}" install -y rpm-build cargo rust gcc gcc-c++ cmake pkgconf-pkg-config python3 \
alsa-lib-devel openssl-devel systemd-devel libxkbcommon-devel
rpmbuild -ba /build/sy.spec --define "_topdir /build" \
--define "_rpmdir /build/RPMS" --define "_srcrpmdir /build/SRPMS"
Expand Down
Loading
Loading