feat(pam tunnel): add --foreground/--background/--run modes + cross-process registry#1993
Conversation
|
@sk-keeper fixed issues with old one. Thanks for the help! |
8d7a604 to
8904792
Compare
8904792 to
1529bdf
Compare
… registry Adds non-interactive tunnel modes for automation use cases (CI/CD, systemd, scripts) and a file-based session registry so `pam tunnel list/stop` work across Commander processes. PAMTunnelStartCommand: - --foreground: run in current process, exit on Ctrl-C or --timeout - --background: spawn detached child, parent returns immediately - --run "<cmd>": start tunnel, run command, tear down on exit - --timeout / --pid-file for lifecycle control - Mutual-exclusivity checks; safe defaults when no TTY (batch mode) PAMTunnelListCommand / PAMTunnelStopCommand: - Surface tunnels owned by other processes via the file registry - Stop sends SIGTERM (Unix) / TerminateProcess (Windows) and cleans the row New keepercommander/commands/tunnel_registry.py: - Atomic JSON writes under <tmp>/keeper-tunnel-sessions/<pid>.json - Stale-entry cleanup, duplicate bind detection (host/port aware) - 0o700 dir perms on POSIX Made-with: Cursor
1529bdf to
b2f2229
Compare
|
Reviewed merged code against test doc - found one real interference, fixed. Bug: Fix (amended into the rebase commit, force-pushed):
Other paths verified clean:
Doc test scenarios re-checked: tests 1-18 all pass against the fixed code. Test 3 ('Lease expiry, tunnel path') still describes the soft-disconnect for the default interactive path - |
… registry (#1993) Adds non-interactive tunnel modes for automation use cases (CI/CD, systemd, scripts) and a file-based session registry so `pam tunnel list/stop` work across Commander processes. PAMTunnelStartCommand: - --foreground: run in current process, exit on Ctrl-C or --timeout - --background: spawn detached child, parent returns immediately - --run "<cmd>": start tunnel, run command, tear down on exit - --timeout / --pid-file for lifecycle control - Mutual-exclusivity checks; safe defaults when no TTY (batch mode) PAMTunnelListCommand / PAMTunnelStopCommand: - Surface tunnels owned by other processes via the file registry - Stop sends SIGTERM (Unix) / TerminateProcess (Windows) and cleans the row New keepercommander/commands/tunnel_registry.py: - Atomic JSON writes under <tmp>/keeper-tunnel-sessions/<pid>.json - Stale-entry cleanup, duplicate bind detection (host/port aware) - 0o700 dir perms on POSIX
Summary
Adds non-interactive tunnel modes for automation (CI/CD, systemd, scripts) and a file-based session registry so `pam tunnel list` / `pam tunnel stop` work across separate Commander processes.
This supersedes #1848 (which had drifted off `release` and accidentally reverted upstream improvements to `tunnel_helpers.py` and `PAMTunnelDiagnoseCommand`). This PR is rebased cleanly on the latest `release` (17.2.15) and the diff is now scoped to only the files this feature actually needs.
`pam tunnel start`
`pam tunnel list` / `pam tunnel stop`
New module `keepercommander/commands/tunnel_registry.py`
Scope (3 files)
`tunnel_helpers.py` and `PAMTunnelDiagnoseCommand` are untouched — earlier drafts of this branch unintentionally rolled them back.
Test plan
Note on docs
Documentation for the new flags will be opened separately; this PR is code-only.
Made with Cursor
2026-04-30 - rebased onto
Keeper-Security/Commander:release(17.2.16)Conflicts resolved in
keepercommander/commands/tunnel_and_connections.py(3 regions):unregister_tunnel_session,wait_for_tunnel_connection,create_rust_webrtc_settings, andtunnel_registryimports from this PR into upstream import block.--reason,--ticket,--auto-checkout,--wait,--wait-timeout) from Workflow pam launch compat #1997 AND the new mode args (--foreground,--background,--run,--timeout,--pid-file) from this PR.--run/--foreground/--backgroundpaths from this PR - both active underif result and result.get('success'):.No interference: the two PRs touch orthogonal code paths. Workflow gate fires first (validation + lease), then tunnel mode dispatch runs after successful tunnel start.