Skip to content
Closed
13 changes: 9 additions & 4 deletions .github/test-suite-registry.json
Original file line number Diff line number Diff line change
Expand Up @@ -1861,10 +1861,15 @@
{
"id": "nixos.services.keyring-auto-unlock",
"paths": ["nixos/services/keyring-auto-unlock/keyring-auto-unlock.test.sh"],
"invocation": "bash nixos/services/keyring-auto-unlock/keyring-auto-unlock.test.sh",
"venue": null,
"status": "uncovered",
"notes": "Wiring attempted by #17799 (split from #17747): with dbus/keyutils/gnome-keyring installed the suite starts and its addressing leg passes, but leg 1's locked-fresh-default-collection state does not reproduce under Ubuntu's gnome-keyring (run 46531762776). Split to #17824 (locked-login fixture or deployed-package venue); do not wire it red.",
"invocation": "bash nixos/services/keyring-auto-unlock/keyring-auto-unlock.ci.sh",
"venue": {
"workflow": ".github/workflows/nix-ci.yml",
"job_step": "host-eval / Test the keyring auto-unlock mechanism (#17824)",
"state": "active",
"dispatchable": true
},
"status": "mapped",
"notes": "Wired by #17824 (split from #17799 / #17747): the CI runner provides the nixpkgs gnome-keyring/dbus/keyutils/systemd via nix shell in nix-ci's nix-provided host-eval job, because Ubuntu's packaged gnome-keyring does not present a fresh default collection as locked (run 46531762776) while the deployed package family does. The runner also shims dbus-run-session with the nix store session.conf and materialises the shebang-less packaged stash/unlock scripts for the suite's STASH_BIN/UNLOCK_BIN knobs.",
"related_issues": [17824, 17799, 17747, 10724]
},
{
Expand Down
11 changes: 11 additions & 0 deletions .github/workflows/nix-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,17 @@ jobs:
run: |
test -f nixos/services/pm-stack/follow-main-timer.test.sh
bash nixos/services/pm-stack/follow-main-timer.test.sh
# The keyring-auto-unlock suite (#17824, split from #17799) needs
# a gnome-keyring whose fresh-state behaviour matches the
# deployed NixOS system; its CI runner provides the nixpkgs
# gnome-keyring/dbus/keyutils via nix shell in this nix-provided
# job (Ubuntu's packaged gnome-keyring does not present a fresh
# default collection as locked — run 46531762776).
- name: Test the keyring auto-unlock mechanism (#17824)
run: |
test -f nixos/services/keyring-auto-unlock/keyring-auto-unlock.test.sh
test -f nixos/services/keyring-auto-unlock/keyring-auto-unlock.ci.sh
bash nixos/services/keyring-auto-unlock/keyring-auto-unlock.ci.sh

flake-check:
name: "full (main tier): Nix flake evaluation"
Expand Down
56 changes: 56 additions & 0 deletions nixos/services/keyring-auto-unlock/ci-probe.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env bash
# ci-probe.sh — lane 0900-HE probe for #17824: can a login.keyring be
# minted headlessly (gnome-keyring-daemon --login) as a non-root user?
set -uo pipefail
cd "$(dirname "$0")/../../.." || exit 2
if [ "${PROBE_INNER:-0}" != "1" ]; then
echo "PROBE_START $(date -u +%FT%TZ) uid=$(id -u)"
id tester >/dev/null 2>&1 || useradd -m tester
mkdir -p /tmp/probe-work && cp -r nixos/services/keyring-auto-unlock /tmp/probe-work/ && chmod -R a+rX /tmp/probe-work
set -o pipefail
PROBE_INNER=1 nix shell nixpkgs#gnome-keyring nixpkgs#dbus nixpkgs#keyutils nixpkgs#systemd --command bash nixos/services/keyring-auto-unlock/ci-probe.sh 2>&1 | tail -50
echo "PROBE_RC=${PIPESTATUS[0]}"
exit 0
fi
# Inner (root in the nix shell): hand off to tester for the daemon work.
SHIM_DIR="$(mktemp -d)"
REAL_DRS="$(command -v dbus-run-session)"
SESSION_CONF="$(cd "$(dirname "${REAL_DRS}")/../share/dbus-1" && pwd)/session.conf"
{
printf '#!/usr/bin/env bash\n'
printf 'exec %s --config-file %s "$@"\n' "${REAL_DRS}" "${SESSION_CONF}"
} > "${SHIM_DIR}/dbus-run-session"
chmod 755 "${SHIM_DIR}"
chmod +x "${SHIM_DIR}/dbus-run-session"
GK_SHARE="$(cd "$(dirname "$(command -v gnome-keyring-daemon)")/../share" && pwd)"
cat > /tmp/probe-work/as-tester.sh <<EOF
#!/usr/bin/env bash
set -uo pipefail
export XDG_DATA_DIRS="${GK_SHARE}:\${XDG_DATA_DIRS:-/usr/local/share:/usr/share}"
export PATH="${SHIM_DIR}:${PATH}"
T="\$(mktemp -d)"
mkdir -p "\${T}/home" "\${T}/run"
chmod 700 "\${T}/run" "\${T}/home"
cat > "\${T}/inner.sh" <<'INNER'
set -uo pipefail
echo "inner uid=\$(id -u) home=\${HOME}"
export G_MESSAGES_DEBUG=all
printf 'probe-password-17824\n' | gnome-keyring-daemon --login --components=secrets >"\${T}/login.out" 2>"\${T}/login.err"; echo "login rc=\$?"
echo "--- login.out ---"; cat "\${T}/login.out"
echo "--- login.err ---"; cat "\${T}/login.err"
echo "--- keyrings dir ---"; ls -la "\${HOME}/.local/share/keyrings/" 2>&1
pkill -f gnome-keyring-daemon || true
sleep 1
gnome-keyring-daemon --foreground --components=secrets >"\${T}/daemon.log" 2>&1 &
sleep 2
COL="\$(busctl --user call org.freedesktop.secrets /org/freedesktop/secrets org.freedesktop.Secret.Service ReadAlias s default 2>/dev/null | sed -n 's/^o \"\(.*\)\"$/\1/p')"
echo "default collection: \${COL}"
echo "locked: \$(busctl --user get-property org.freedesktop.secrets "\${COL}" org.freedesktop.Secret.Collection Locked 2>/dev/null | awk '{print \$2}')"
echo "--- daemon log ---"; cat "\${T}/daemon.log"; echo "--- ps ---"; ps aux | grep -i keyring | grep -v grep; echo "--- runtime tree ---"; ls -laR "\${XDG_RUNTIME_DIR}" 2>&1 | head -20
INNER
env HOME="\${T}/home" XDG_RUNTIME_DIR="\${T}/run" T="\${T}" dbus-run-session -- bash "\${T}/inner.sh"
EOF
chmod +x /tmp/probe-work/as-tester.sh
cp /tmp/probe-work/as-tester.sh "${SHIM_DIR}/as-tester.sh"
su tester -c "bash /tmp/probe-work/as-tester.sh"
echo "PROBE_INNER_DONE"
71 changes: 71 additions & 0 deletions nixos/services/keyring-auto-unlock/keyring-auto-unlock.ci.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/usr/bin/env bash
# keyring-auto-unlock.ci.sh — CI runner for keyring-auto-unlock.test.sh
# (code#17824, split from #17799 / #17747).
#
# Command line: no arguments. Anything else is a usage error (exit 2),
# declared up front per the operator-script argument contract (#3352).
#
# Why this runner exists: the suite needs dbus-run-session, keyctl and
# a gnome-keyring daemon whose fresh-state behaviour matches the
# deployed NixOS system. Ubuntu's packaged gnome-keyring does not
# present a fresh default collection as locked (run 46531762776, on
# #17799), so the suite runs under the nixpkgs gnome-keyring — the
# deployed package family — provided by `nix shell`, in the nix-ci
# host-eval job (ubuntu-latest, where nix is already installed and the
# job runs as the non-root runner user; gnome-keyring-daemon aborts
# dropping capabilities when run as root).
#
# Two venue shims, both confined to a mktemp dir:
# - The packaged stash/unlock scripts carry no shebang (default.nix
# wraps them with writeShellApplication on the deployed system), so
# the runner materialises them with a bash shebang for STASH_BIN /
# UNLOCK_BIN, the suite's documented CI knobs.
# - The nix dbus-run-session looks for /etc/dbus-1/session.conf, which
# the stock runner does not carry; a PATH shim passes the nix store
# session.conf via --config-file instead. The gnome-keyring share
# dir joins XDG_DATA_DIRS so the Secret Service name is visible.
set -euo pipefail

if [ $# -ne 0 ]; then
echo "usage: keyring-auto-unlock.ci.sh (no arguments)" >&2
exit 2
fi

cd "$(dirname "$0")/../../.."

if [ "${KEYRING_CI_INNER:-0}" != "1" ]; then
command -v nix >/dev/null || {
echo "need nix on PATH (the nix-ci host-eval job provides it)" >&2
exit 2
}
BIN_DIR="$(mktemp -d)"
trap 'rm -rf "${BIN_DIR}"' EXIT
for pair in "keyring-password-stash.sh keyring-password-stash" "keyring-auto-unlock.sh keyring-auto-unlock"; do
set -- $pair
{ printf '#!/usr/bin/env bash\n'; cat "nixos/services/keyring-auto-unlock/$1"; } > "${BIN_DIR}/$2"
chmod +x "${BIN_DIR}/$2"
done
export STASH_BIN="${BIN_DIR}/keyring-password-stash"
export UNLOCK_BIN="${BIN_DIR}/keyring-auto-unlock"
KEYRING_CI_INNER=1 exec nix shell nixpkgs#gnome-keyring nixpkgs#dbus nixpkgs#keyutils nixpkgs#systemd \
--command bash nixos/services/keyring-auto-unlock/keyring-auto-unlock.ci.sh
fi

# Inner: inside the nix shell.
SHIM_DIR="$(mktemp -d)"
trap 'rm -rf "${SHIM_DIR}"' EXIT
REAL_DRS="$(command -v dbus-run-session)"
SESSION_CONF="$(cd "$(dirname "${REAL_DRS}")/../share/dbus-1" && pwd)/session.conf"
[ -f "${SESSION_CONF}" ] || {
echo "no nix session.conf at ${SESSION_CONF}" >&2
exit 2
}
{
printf '#!/usr/bin/env bash\n'
printf 'exec %s --config-file %s "$@"\n' "${REAL_DRS}" "${SESSION_CONF}"
} > "${SHIM_DIR}/dbus-run-session"
chmod +x "${SHIM_DIR}/dbus-run-session"
GK_SHARE="$(cd "$(dirname "$(command -v gnome-keyring-daemon)")/../share" && pwd)"
export XDG_DATA_DIRS="${GK_SHARE}:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}"
export PATH="${SHIM_DIR}:${PATH}"
exec bash nixos/services/keyring-auto-unlock/keyring-auto-unlock.test.sh