From 4c19a907a8e5d1e0e05e469939c394b04002f804 Mon Sep 17 00:00:00 2001 From: Daniel Robbins Date: Wed, 4 Nov 2026 21:13:36 -0500 Subject: [PATCH 1/2] Require full CI on pull requests and refresh platform guidance --- .github/workflows/python-ci.yml | 25 ++++++-------- README.md | 26 +++++++------- tests/test_workflows.py | 60 +++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+), 26 deletions(-) diff --git a/.github/workflows/python-ci.yml b/.github/workflows/python-ci.yml index 6be3fb9..5d0e75c 100644 --- a/.github/workflows/python-ci.yml +++ b/.github/workflows/python-ci.yml @@ -1,9 +1,8 @@ name: python-ci -# Tiered triggering keeps PR feedback fast while still doing a full -# cross-platform sweep on every master push, weekly, and on demand. -# Feature-branch pushes get the fast tier (same as PRs) so contributors -# see CI feedback before opening a PR. +# PRs run the same full cross-platform sweep as master and tag pushes. +# Feature-branch pushes keep the fast tier; weekly and manual runs include +# the full sweep too. on: push: pull_request: @@ -50,15 +49,15 @@ jobs: # ------------------------------------------------------------------------- # Fast tier — runs on every event (PR, push, cron, dispatch). # - # Floor + ceiling on Linux + Windows/macOS-on-ceiling. Rationale: + # Python 3.9 + 3.14 on Linux/macOS, and 3.14 on Windows. Rationale: # - 3.9 (floor) catches usage of features added later. - # - 3.14 (ceiling) catches deprecations and stdlib drift. + # - 3.14 catches deprecations and stdlib drift; the full sweep adds 3.15. # - Windows × 3.14 catches POSIX-only assumptions; OS-portability # bugs almost never differ between Python minor versions, so one - # Windows job is enough for PR-time feedback. + # Windows job gives early feedback before the full sweep finishes. # - macOS × 3.9 catches floor-version Darwin behavior on a key # supported platform. - # - macOS × 3.14 catches ceiling-version Darwin-specific POSIX edges, + # - macOS × 3.14 catches Darwin-specific POSIX edges, # especially AF_UNIX socket path limits that Linux does not share. # ------------------------------------------------------------------------- test-fast: @@ -241,15 +240,12 @@ jobs: ./keychain.pyz help >/dev/null # ------------------------------------------------------------------------- - # Full sweep — runs on master pushes, tags, weekly cron, and manual - # dispatch. *Skipped on PRs and feature-branch pushes* to keep PR and - # day-to-day feedback under a few minutes. If a branch needs the full - # sweep before merge (e.g. touching subprocess wiring, signal handling, - # path resolution), a maintainer can trigger it via the Actions tab → - # "Run workflow". + # Full sweep: required on PRs, master pushes, tags, weekly cron, and + # manual dispatch. Only ordinary feature-branch pushes skip this tier. # ------------------------------------------------------------------------- test-full-sweep: if: >- + github.event_name == 'pull_request' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && github.ref == 'refs/heads/master') || @@ -314,6 +310,7 @@ jobs: TEST_FULL_SWEEP_RESULT: ${{ needs.test-full-sweep.result }} TEST_FULL_SWEEP_REQUIRED: >- ${{ + github.event_name == 'pull_request' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && github.ref == 'refs/heads/master') || diff --git a/README.md b/README.md index 743317b..ed1ca23 100644 --- a/README.md +++ b/README.md @@ -1,22 +1,22 @@ # Keychain 3 -Keychain orchestrates `ssh-agent` and gives you one coordinated, long-running SSH agent per user and host. For GnuPG, Keychain can also auto-warm your signing and encryption keys so they are ready for use. +Keychain orchestrates `ssh-agent` and gives you one coordinated, long-running SSH agent per user and host. For GnuPG, Keychain can also auto-warm your signing and decryption keys so they are ready for use. -Keychain 3 is the evolution of the original Bourne shell-based tool created by Daniel Robbins in 2001. It preserves the single-file deployment model that made Keychain useful for over two decades, while adding modern capabilities: coordinated multi-terminal activation, stable agent sockets, seamless cron and script integration, PKCS#11 hardware key support, explicit GPG credential warm-up, hardened security defaults, and a comprehensive test suite of 700+ unit and integration tests — now written in Python and distributed as a self-contained executable zipapp with no third-party Python dependencies. +Keychain 3 is the evolution of the original Bourne shell-based tool created by Daniel Robbins in 2001. It preserves the single-file deployment model that made Keychain useful for over two decades, while adding modern capabilities: coordinated multi-terminal activation, stable agent sockets, seamless cron and script integration, PKCS#11 hardware key support, explicit GPG credential warm-up, hardened security defaults, and a comprehensive suite of unit and integration tests — now written in Python and distributed as a self-contained executable zipapp with no third-party Python dependencies. For background on the decision to rewrite Keychain in Python, see [Why Keychain 3 Uses Python](https://kernel-seeds.org/projects/keychain/why-python/). ## The Agent Problem Keychain Solves -SSH is amazing, but entering your passphrase every time you open a terminal gets old fast. The standard `ssh-agent` helps, but it has limitations: +SSH is amazing, but entering your passphrase every time you open a terminal gets old fast. The standard `ssh-agent` helps, but sharing it across sessions takes some setup: -- **One agent per login session** — open a new terminal, get a new agent, enter your passphrase again +- **Repeated agents and prompts**: shell startup snippets can start a fresh agent for every terminal - **Cron jobs can't find your agent** — background processes run in a different session - **No ssh-agent coordination** — individual ssh-agent processes are not aware of each other. **Keychain fixes all of this:** -- **One agent per host** — all terminals share the same long-running agent +- **One agent per user and host**: all your terminals share the same long-running agent - **Persistent state** — cron jobs, remote sessions, and background tasks can all reconnect - **Multi-terminal coordination** — when VS Code restores 5 login terminals at once, they cooperate instead of duplicating effort or competing @@ -50,8 +50,8 @@ Keychain 3 ships as a **Python zipapp** — a single executable file with no thi ```bash # Download from https://github.com/danielrobbins/keychain/releases -chmod +x keychain-3.0.0.pyz -sudo cp keychain-3.0.0.pyz /usr/local/bin/keychain +chmod +x keychain-3.0.9.pyz +sudo cp keychain-3.0.9.pyz /usr/local/bin/keychain sudo chmod 755 /usr/local/bin/keychain # Verify installation @@ -70,7 +70,9 @@ No hidden dependencies, no mystery code — everything is right there. ### Platform Support -Keychain 3 is designed for POSIX-like systems with Python 3.9+ and OpenSSH, and optionally GnuPG. That includes Linux, macOS, WSL, Git Bash, the BSDs, Solaris-derived systems, and similar UNIX-like environments. Native Windows is not a supported target yet, but Windows users can run Keychain through WSL or Git Bash. +Keychain 3 is designed for POSIX environments with Python 3.9+ and OpenSSH; GnuPG is optional. Automated CI covers **Linux, macOS, FreeBSD, OpenBSD, OmniOS (illumos), and MSYS2**. **WSL** uses Linux support; **Cygwin and Android/Termux** have platform-specific support and regression tests, but no dedicated CI jobs yet. + +On Windows, use WSL or the POSIX Python and OpenSSH tools provided by MSYS2 or Cygwin. Native Windows Python and Git Bash alone are not supported. ## 60-Second Quick Start @@ -131,7 +133,7 @@ end 2. If not, it starts one for you 3. It loads your private key (prompting for the passphrase once) 4. It writes the agent's connection info to `~/.keychain/` -5. Every new shell after that reconnects automatically — **no more prompts** +5. Every new shell reconnects automatically, without another passphrase prompt while the key remains loaded **Verify it worked:** @@ -171,7 +173,7 @@ Your private key is stored in `~/.ssh/id_ed25519` (or similar). If someone steal **The new problem:** Now the server no longer needs your login password, but your local machine still needs the passphrase that decrypts your private key. Without an agent, that passphrase is needed every time the key is used. Open a new terminal? Enter it again. Run a cron job? It cannot prompt. You *could* remove the passphrase from the private key, but then anyone who steals the file can use it. -**Enter ssh-agent:** `ssh-agent` is distributed with OpenSSH. It's a background process that holds your decrypted private key in memory. You enter the passphrase only once; `ssh-agent` caches your private key, and OpenSSH asks `ssh-agent` for it each time, instead of having to prompt *you*. +**Enter ssh-agent:** `ssh-agent` is distributed with OpenSSH. It's a background process that holds your decrypted private key in memory. You enter the passphrase only once; OpenSSH then asks the agent to sign authentication requests, rather than retrieving the key or prompting *you* again. **The next problem:** `ssh-agent` is just a process with a socket. You still need to start it at the right time, publish its environment to future shells, keep scripts and cron jobs pointed at it, and avoid races when several terminals initialize at once. @@ -254,7 +256,7 @@ Shows: - Parsed preferences and their effective sources - Keychain-relevant environment state - SSH and GPG tool availability -- Agent status and socket locations +- Agent status, socket locations, and process-visibility diagnostics - Keychain directory and pidfile state - Ownership and permission checks - Loaded SSH keys from the best available agent @@ -389,7 +391,7 @@ Need your user services to access the SSH agent? From an interactive terminal, r eval "$(keychain add --eval --systemd ~/.ssh/id_ed25519)" ``` -This pushes the agent environment to `systemctl --user`, making it available to all your user services. +This pushes the agent environment to `systemctl --user`, making it available to user services when they next start. For automatic startup, add `--systemd` to both Keychain invocations in the Bash or fish Quick Start recipe. The non-interactive branch retains `--noask` so it can publish the agent environment without prompting. diff --git a/tests/test_workflows.py b/tests/test_workflows.py index 8ab6088..7884786 100644 --- a/tests/test_workflows.py +++ b/tests/test_workflows.py @@ -1,7 +1,12 @@ # SPDX-License-Identifier: GPL-3.0-only +import os import re +import subprocess +import textwrap from pathlib import Path +import pytest + _WORKFLOWS = Path(__file__).resolve().parents[1] / ".github" / "workflows" @@ -22,3 +27,58 @@ def test_release_build_is_read_only_and_publish_is_narrowly_privileged(): assert "permissions:\n contents: write" in publish assert "actions/checkout@" not in publish assert "actions/setup-python@" not in publish + + +def test_full_sweep_and_merge_gate_require_the_same_events(): + workflow = (_WORKFLOWS / "python-ci.yml").read_text(encoding="utf-8") + sweep = workflow.split("\n test-full-sweep:\n", 1)[1] + condition = sweep.split(" if: >-\n", 1)[1].split(" runs-on:", 1)[0] + gate = workflow.split(" TEST_FULL_SWEEP_REQUIRED: >-\n", 1)[1].split(" steps:", 1)[0] + expected = ( + "github.event_name == 'pull_request' || " + "github.event_name == 'schedule' || " + "github.event_name == 'workflow_dispatch' || " + "(github.event_name == 'push' && github.ref == 'refs/heads/master') || " + "(github.event_name == 'push' && startsWith(github.ref, 'refs/tags/'))" + ) + + assert " ".join(condition.split()) == expected + assert " ".join(gate.replace("${{", "").replace("}}", "").split()) == expected + + +_ALWAYS_REQUIRED_RESULTS = ( + "STATIC_ANALYSIS_RESULT", + "TEST_FAST_RESULT", + "TEST_MSYS2_RESULT", + "TEST_FREEBSD_RESULT", + "TEST_OPENBSD_RESULT", + "TEST_OMNIOS_RESULT", + "TEST_ROCKY8_RESULT", +) + + +@pytest.mark.skipif(os.name != "posix", reason="The aggregate CI job runs in Bash on Linux") +@pytest.mark.parametrize( + "required,changed,result,passes", + [ + (required, "TEST_FULL_SWEEP_RESULT", result, result == "success" or (not required and result == "skipped")) + for required in (True, False) + for result in ("success", "failure", "cancelled", "skipped") + ] + + [ + (False, job, result, False) + for job in _ALWAYS_REQUIRED_RESULTS + for result in ("failure", "cancelled", "skipped") + ], +) +def test_aggregate_ci_status(required, changed, result, passes): + workflow = (_WORKFLOWS / "python-ci.yml").read_text(encoding="utf-8") + gate = workflow.split("\n ci-passing:\n", 1)[1] + script = textwrap.dedent(gate.split(" run: |\n", 1)[1]) + env = dict(os.environ, **dict.fromkeys(_ALWAYS_REQUIRED_RESULTS, "success")) + env.update(TEST_FULL_SWEEP_REQUIRED=str(required).lower(), TEST_FULL_SWEEP_RESULT="skipped") + env[changed] = result + + completed = subprocess.run(["bash", "-e", "-c", script], env=env, capture_output=True, text=True) + + assert completed.returncode == (0 if passes else 1), completed.stdout + completed.stderr From 99b25f1430400a5666e4ab8c74908a5da0f1ac46 Mon Sep 17 00:00:00 2001 From: Daniel Robbins Date: Wed, 4 Nov 2026 21:32:38 -0500 Subject: [PATCH 2/2] Allow transient state-lock contention in wipe integration test --- tests/test_coordination_e2e.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_coordination_e2e.py b/tests/test_coordination_e2e.py index 2f7a844..555e3b9 100644 --- a/tests/test_coordination_e2e.py +++ b/tests/test_coordination_e2e.py @@ -472,6 +472,7 @@ def test_wipe_waits_for_exclusive_access_to_real_agent(activation_session): owner.expect("Enter passphrase") second = session.start() second.expect("Enter passphrase") + # Allow brief state updates by live terminals; this test targets activation-lock contention. command = [ sys.executable, "-m", @@ -482,7 +483,7 @@ def test_wipe_waits_for_exclusive_access_to_real_agent(activation_session): "wipe", "--ssh", "--lockwait", - "0", + "1", ] result = session.run(command) assert result.returncode != 0 and "activation lock" in result.stderr, result.stdout + result.stderr