docs(plans): incorporate /grill-me decisions into linux-connector architectural plan

This commit is contained in:
soda64 committed 2026-10-03 07:01:34 +02:00
1 parent 6b9455c90e
commit f06f495255
5 files changed
+148 -74

No files matched your search

+13 -6
View File
@@ -6,12 +6,12 @@
- Gate 4 — Slice Plan: in progress
## Slices
- [ ] Slice 1 — tracer bullet: minimal end-to-end wire (CLI + OpenSSH config parser + TCP socket probe + execvp ssh launcher)
- [ ] Slice 2 — rich inventory engine (merging `~/.ssh/config`, `/etc/ssh/ssh_config`, and custom `hosts.yaml` with groups & tags)
- [ ] Slice 3 — interactive terminal launcher (pure ANSI keyboard navigation + fuzzy filtering + optional `fzf` auto-detection)
- [ ] Slice 4 — parallel remote command runner (`exec` engine replacing `massAct.sh` with live prefixed output streaming and exit summary)
- [ ] Slice 5 — fleet health & connectivity matrix (`status` command probing TCP/22, SSH banners, and latency across homelab nodes)
- [ ] Slice 6 — tunnel & port forwarding helper (`tunnel` command automating local/remote port forwarding and ProxyJump bastions)
- [ ] Slice 1 — tracer bullet: minimal end-to-end wire (CLI + OpenSSH config parser + direct SSH handover)
- [ ] Slice 2 — pluggable inventory engine (local OpenSSH configs, YAML/JSON, remote URL cache, Proxmox VE API, K3s API, and custom plugins)
- [ ] Slice 3 — interactive terminal TUI (instant fuzzy host search without ping delay, group filtering, multi-host selection, direct jump on argument)
- [ ] Slice 4 — parallel fleet command runner (`exec` engine with output modes: -b/--block default, -s/--stream, -t/--table, failure policies: continue, --fail-fast, --ask)
- [ ] Slice 5 — privilege & authentication engine (passwordless sudo default, --sudo interactive one-time prompt + stdin streaming)
- [ ] Slice 6 — fleet connectivity matrix (`status` on-demand TCP/22 & SSH banner probe) & tunnel helper (foreground default, --detach, list/kill)
- [ ] Slice 7 — packaging & distribution (.deb, .rpm, .tar.gz standalone)
- [ ] Slice 8 — full documentation (user, admin & developer guides), man page (Section 1), CLI -h/--help, shell tab completion (Bash/Zsh) & Gitea Actions CI/CD release workflow
@@ -22,6 +22,13 @@
- Platforms: Client runs on macOS, Fedora, Debian/Ubuntu, RHEL 8/9, Arch Linux. Targets any standard SSH daemon.
- Target Python runtime: Python >= 3.6 (RHEL 8 compatibility).
- Dependencies: Standard library core (uses system OpenSSH client binary for native keys, agent, and FIDO2). `paramiko` and `cryptography` permitted for programmatic parallel execution, SFTP, and key handling.
- Key Design Decisions from /grill-me Alignment:
1. Inventory: Pluggable provider architecture (`FileProvider` for `~/.ssh/config` + `/etc/ssh/ssh_config` + `hosts.yaml`; `RemoteUrlProvider` for Gitea/HTTP; `ProxmoxProvider` for PVE API nodes/VMs; `K3sProvider` for K3s nodes; `PluginProvider` for `/etc/linux-connector/plugins/`).
2. Interactive Behavior: `linux-connector <host>` immediately opens native SSH session without menu. `linux-connector` launches instant fuzzy TUI (no automatic blocking ping). TUI also supports multi-selecting hosts to execute commands.
3. Parallel Output Modes: Selectable via flag or TUI: `-b`/`--block` (default, grouped per host), `-s`/`--stream` (live interleaved with `[host]`), `-t`/`--table` (live status table, logs on error or `-v`), plus `--json`.
4. Failure Handling: Continue-to-end by default; `--fail-fast` aborts on first failure; `--ask` pauses and prompts operator. All selectable via CLI flags or TUI.
5. Sudo Elevation: Assumes passwordless sudo (`NOPASSWD: ALL`) or root by default. `--sudo` / `-S` prompts once securely locally and streams password via stdin (`sudo -S -p ''`).
6. Tunnel: Foreground mode by default with live status and clean Ctrl+C termination. `--detach` for background with `tunnel list` and `tunnel kill`. SOCKS5 proxy deferred to v2.0 roadmap.
- Shell Tab Completion Standard (Bash & Zsh):
- Subcommands and flags auto-completion (`connect`, `exec`, `status`, `tunnel`, `completion`).
- Dynamic host completion: `linux-connector [connect] <Tab>` automatically completes host aliases parsed from `~/.ssh/config` and inventory.
+55 -19
View File
@@ -42,23 +42,33 @@ In modern Linux homelabs and enterprise clusters, engineers manage dozens of phy
## 4. Screens & CLI Commands
```text
# 1. Interactive Host Launcher (Default / psh replacement):
$ linux-connector
? Select host to connect:
> pve-01.wired.intra [192.168.10.11:22] (tags: pve, hypervisor) [ONLINE 1.2ms]
pve-02.wired.intra [192.168.10.12:22] (tags: pve, hypervisor) [ONLINE 1.4ms]
k8s-master-01 [192.168.10.21:22] (tags: k8s, control) [ONLINE 2.1ms]
k8s-worker-01 [192.168.10.31:22] (tags: k8s, worker) [ONLINE 1.9ms]
nas.wired.intra [192.168.10.2:22] (tags: storage) [ONLINE 0.8ms]
[Filter: k8s- ]
Connecting to root@192.168.10.21 (k8s-master-01)...
# 1. Direct Host Jump (Instant bypass):
$ linux-connector pve-01
Connecting to root@192.168.10.11 (pve-01)...
Linux pve-01 6.8.4-2-pve #1 SMP PREEMPT_DYNAMIC ...
# 2. Parallel Command Execution (massAct replacement):
# 2. Interactive Host Launcher & Multi-Runner TUI (No arguments):
$ linux-connector
? Select target host or press [Space] to multi-select:
> [ ] pve-01.wired.intra [192.168.10.11:22] (tags: pve, hypervisor)
[ ] pve-02.wired.intra [192.168.10.12:22] (tags: pve, hypervisor)
[ ] k8s-master-01 [192.168.10.21:22] (tags: k8s, control)
[ ] k8s-worker-01 [192.168.10.31:22] (tags: k8s, worker)
[ ] nas.wired.intra [192.168.10.2:22] (tags: storage)
[Filter: k8s- ] [Enter: Connect | Space: Select | R: Run Command]
# 3. Parallel Fleet Execution (Default: Grouped Blocks -b):
$ linux-connector exec -g k8s "uptime"
[INFO] Executing 'uptime' on 3 hosts (concurrency: 10)...
[k8s-master-01] 21:16:01 up 14 days, 3:12, 0 users, load average: 0.12, 0.18, 0.15
[k8s-worker-01] 21:16:01 up 14 days, 3:11, 0 users, load average: 0.45, 0.52, 0.49
[k8s-worker-02] 21:16:01 up 14 days, 3:10, 0 users, load average: 0.38, 0.41, 0.40
[INFO] Executing 'uptime' across 3 hosts (mode: block, failure-policy: continue)...
--- [k8s-master-01] (exit: 0, 0.28s) ---
21:16:01 up 14 days, 3:12, 0 users, load average: 0.12, 0.18, 0.15
--- [k8s-worker-01] (exit: 0, 0.31s) ---
21:16:01 up 14 days, 3:11, 0 users, load average: 0.45, 0.52, 0.49
--- [k8s-worker-02] (exit: 0, 0.30s) ---
21:16:01 up 14 days, 3:10, 0 users, load average: 0.38, 0.41, 0.40
============================= Execution Summary =============================
HOST STATUS EXIT CODE DURATION
@@ -66,9 +76,24 @@ k8s-master-01 SUCCESS 0 0.28s
k8s-worker-01 SUCCESS 0 0.31s
k8s-worker-02 SUCCESS 0 0.30s
-----------------------------------------------------------------------------
Total: 3 hosts | Succeeded: 3 | Failed: 0 | Execution Time: 0.34s
Total: 3 hosts | Succeeded: 3 | Failed: 0 | Total Duration: 0.34s
# 3. Fleet Connectivity Matrix:
# 4. Parallel Fleet Execution with Real-Time Streaming (-s):
$ linux-connector exec -g k8s -s "linux-updater check"
[k8s-master-01] [INFO] Checking system updates via APT...
[k8s-worker-01] [INFO] Checking system updates via APT...
[k8s-master-01] 2 packages can be upgraded: libssl3, openssl
[k8s-worker-01] All packages are up to date.
# 5. Privileged Execution with One-Time Local Sudo Prompt (--sudo):
$ linux-connector exec -g pve --sudo "systemctl restart pveproxy"
[sudo] Enter password for remote elevation: ********
[INFO] Dispatched securely via stdin to 3 hosts...
--- [pve-01] (exit: 0, 0.42s) ---
--- [pve-02] (exit: 0, 0.39s) ---
--- [pve-03] (exit: 0, 0.41s) ---
# 6. Fleet Connectivity Matrix (On-demand port/socket probe):
$ linux-connector status -g all
+-------------------+-----------------+-------+----------+---------------+
| HOST | IP ADDRESS | PORT | STATUS | LATENCY (ms) |
@@ -79,17 +104,28 @@ $ linux-connector status -g all
| old-backup-vm | 192.168.10.99 | 22 | TIMEOUT | --- |
+-------------------+-----------------+-------+----------+---------------+
# 4. SSH Tunnel Helper:
# 7. SSH Tunnel Helper (Foreground default, --detach support):
$ linux-connector tunnel pve-01 8006:localhost:8006
[INFO] Forwarding local port 8006 -> pve-01:8006 (Press Ctrl+C to terminate)
$ linux-connector tunnel pve-01 8006:localhost:8006 --detach
[INFO] Background tunnel established (PID: 49210, ID: tun_pve01_8006)
$ linux-connector tunnel list
$ linux-connector tunnel kill tun_pve01_8006
```
---
## 5. Scope & Constraints
- **Client Environments:** macOS and Linux (Debian, Ubuntu, Fedora, RHEL, Arch).
- **Security:** Strict Zero-Secrets policy. Passwords in plaintext files are forbidden. Authentication relies on SSH keys, SSH agent forwarding, or interactive prompt.
- **Pluggable Inventory Providers:**
- `FileProvider`: Parses `~/.ssh/config`, `/etc/ssh/ssh_config`, and `hosts.yaml` (user and system).
- `RemoteUrlProvider`: Fetches and caches shared inventory over HTTPS/Gitea.
- `ProxmoxProvider`: Discovers nodes, VMs, and LXC containers via Proxmox VE API.
- `K3sProvider`: Discovers Kubernetes nodes via K3s API or local kubeconfig.
- `PluginProvider`: Executes external discovery scripts in `/etc/linux-connector/plugins/` returning JSON.
- **Terminal Discipline:** Interactive session handover uses `os.execvp("ssh", ...)` so that raw terminal handling, TTY allocation, window resizing (SIGWINCH), and escape sequences remain 100% native to the operating system's OpenSSH client.
- **Security:** Strict Zero-Secrets policy. Plaintext passwords are never persisted. `--sudo` captures passphrases in memory only for the duration of the command stream.
---
+32 -18
View File
@@ -34,16 +34,21 @@
---
## 2. Inventory Model & Discovery Hierarchy
## 2. Pluggable Inventory Architecture & Providers
`linux-connector` loads host definitions hierarchically:
`linux-connector` decouples host resolution behind a pluggable provider pipeline (`BaseInventoryProvider`):
1. **`~/.ssh/config` & `/etc/ssh/ssh_config` (Primary Source):**
- Automatically parsed using an RFC/OpenSSH-compliant lexer.
- Extracts: `Host`, `HostName`, `User`, `Port`, `IdentityFile`, `ProxyJump`, `ForwardAgent`.
2. **`~/.config/linux-connector/hosts.yaml` (or `.json`) (Enrichment Source):**
- Supplements SSH hosts with metadata (groups, environment, human tags, description).
- Also supports standalone host declarations.
1. **`FileProvider` (Default Core):**
- Automatically parses `~/.ssh/config` and `/etc/ssh/ssh_config` with an RFC-compliant lexer.
- Merges tags and groups from `~/.config/linux-connector/hosts.yaml` (user) and `/etc/linux-connector/hosts.yaml` (system).
2. **`RemoteUrlProvider`:**
- Synchronizes remote host definitions over HTTPS/Gitea raw URLs with a configurable TTL local cache (`~/.cache/linux-connector/remote_hosts.json`).
3. **`ProxmoxProvider`:**
- Connects to Proxmox VE API (`/api2/json/nodes` and `/cluster/resources?type=vm`) using API tokens to dynamically register hypervisor nodes, LXCs, and VMs.
4. **`K3sProvider`:**
- Queries K3s/Kubernetes API or local kubeconfig to discover cluster nodes with their internal IPs and node roles.
5. **`PluginProvider`:**
- Executes arbitrary user/admin scripts located in `/etc/linux-connector/plugins/` or `~/.config/linux-connector/plugins/` that output JSON lists conforming to the HostEntry contract.
### Inventory Data Contract
```json
@@ -70,17 +75,26 @@
---
## 3. Execution Engine & Output Streaming
## 3. Execution Engine, Output Modes & Failure Handling
For the `exec` sub-command and interactive TUI multi-run:
- **Concurrency:** Worker pool powered by `concurrent.futures.ThreadPoolExecutor` (default: 10 concurrent streams).
- **Output Presentation Modes:**
1. **Grouped Blocks (`-b` / `--block`, DEFAULT):** Buffers host stdout/stderr and prints clean, uncorrupted, contiguous output blocks per host upon completion.
2. **Live Streaming (`-s` / `--stream`):** Flushes lines immediately as they arrive, stamped with colored `[hostname]` tags (ideal for long-running batch commands).
3. **Live Status Table (`-t` / `--table`):** Clean terminal progress table showing status and timing; logs are suppressed unless a node fails or `-v` is provided.
4. **Machine Structured (`--json`):** Dumps JSON payload containing full execution results, exit codes, and timestamps.
- **Failure Handling Policies:**
1. **`continue` (DEFAULT):** Run remaining hosts regardless of individual failures; print a comprehensive error summary table at the end.
2. **`fail-fast` (`--fail-fast`):** Immediately cancel queued and running tasks on the first non-zero exit code or timeout.
3. **`ask` (`--ask`):** Interactively pause on error and prompt operator: `Host <name> failed. Continue remaining? [Y/n]`.
- **Privilege Elevation (`--sudo`):**
- Assumes passwordless sudo (`NOPASSWD`) or root by default.
- When `--sudo` or `--ask-sudo-pass` is passed, prompts once locally (masked stdin) and streams password securely to remote processes via `sudo -S -p ''`.
- **Tunnel Orchestration:**
- Foreground mode (default) with clean signal traps (`SIGINT`/`SIGTERM`) to kill background `ssh -N -L` child processes.
- Background mode (`--detach` / `-d`) storing active tunnel state in `~/.local/state/linux-connector/tunnels.json` for `tunnel list` and `tunnel kill`.
For the `exec` sub-command:
- Worker pool powered by `concurrent.futures.ThreadPoolExecutor` (or standard `asyncio` subprocess runner).
- Configurable concurrency limit (default: 10 concurrent streams).
- Real-time line streaming: standard output and standard error from each node are consumed non-blockingly, stamped with ANSI color-coded `[hostname]`, and flushed immediately to the terminal.
- Aggregate summary table tracks:
- Host identifier
- Status (`SUCCESS`, `FAILED`, `TIMEOUT`, `UNREACHABLE`)
- Exit code
- Execution duration in seconds.
---
@@ -14,9 +14,16 @@ linux-connector/
│ ├── models.py # HostEntry, HostGroup, ExecResult dataclasses
│ ├── inventory/
│ │ ├── __init__.py
│ │ ├── ssh_config.py # OpenSSH config file parser
│ │ ├── custom_loader.py # YAML/JSON inventory loader
│ │ └── resolver.py # Host & group query resolver
│ │ ├── resolver.py # Host & group query resolver
│ │ ├── ssh_lexer.py # OpenSSH config file lexer/parser
│ │ └── providers/
│ │ ├── __init__.py
│ │ ├── base.py # BaseInventoryProvider interface
│ │ ├── file_provider.py # ~/.ssh/config, /etc/ssh & hosts.yaml
│ │ ├── remote_url.py # HTTP/Gitea raw YAML/JSON with cache
│ │ ├── proxmox.py # Proxmox VE API provider
│ │ ├── k3s.py # K3s / Kubeconfig node provider
│ │ └── plugin.py # Custom discovery script runner (/etc/linux-connector/plugins/)
│ ├── tui/
│ │ ├── __init__.py
│ │ ├── selector.py # Pure ANSI terminal interactive menu
+38 -28
View File
@@ -5,65 +5,75 @@ This roadmap defines the implementation order for `linux-connector` in thin, ind
---
### Slice 1 — Tracer Bullet (Minimal End-to-End Wire)
- **Goal:** Minimal working CLI capable of parsing a simple `~/.ssh/config` file, probing port 22, and dropping the operator into an SSH session.
- **Goal:** Minimal working CLI capable of direct host jumping (`linux-connector <host>`) and simple OpenSSH config resolution with native handover.
- **Components:**
- `bin/linux-connector` launcher and `linux_connector/cli.py`.
- Basic OpenSSH config parser (`inventory/ssh_config.py`).
- Simple non-interactive host select via CLI argument or numbered list.
- Basic OpenSSH config parser (`inventory/ssh_lexer.py`).
- Direct argument bypass: jumps straight to SSH without menu when host alias is provided.
- Process handover using `os.execvp("ssh", ...)`.
- Unit tests verifying CLI parsing and SSH parameter generation.
- **Verification:** `python3 -m unittest tests/test_cli.py` passes 100%.
---
### Slice 2 — Rich Inventory Engine & Resolver
- **Goal:** Comprehensive discovery and filtering supporting standard OpenSSH configurations and custom YAML/JSON inventory.
### Slice 2 — Pluggable Inventory Engine & Providers
- **Goal:** Comprehensive discovery supporting multi-source inventory.
- **Components:**
- Full OpenSSH parser supporting `Host`, `HostName`, `User`, `Port`, `IdentityFile`, `ProxyJump`, and `Include`.
- Custom inventory loader (`inventory/custom_loader.py`) for tags and host groups.
- `BaseInventoryProvider` interface.
- `FileProvider`: Parses `~/.ssh/config`, `/etc/ssh/ssh_config`, and `hosts.yaml`.
- `RemoteUrlProvider`: HTTPS/Gitea raw URL loader with TTL cache.
- `ProxmoxProvider`: Discovers nodes/VMs/LXCs via Proxmox VE API.
- `K3sProvider`: Discovers nodes via K3s API or local kubeconfig.
- `PluginProvider`: Executes external scripts in `/etc/linux-connector/plugins/`.
- Flexible query resolver: query by group (`-g pve`), tag (`--tag k8s`), pattern (`pve-*`), or specific host list.
- **Verification:** Unit tests against realistic complex SSH configs and YAML inventory fixtures.
- **Verification:** Unit tests against realistic complex SSH configs, YAML inventory, mock Proxmox API JSON, and plugin fixtures.
---
### Slice 3 — Interactive Terminal UX (Fuzzy Search & TUI)
- **Goal:** Delightful, fast terminal selection menu.
### Slice 3 — Interactive Terminal TUI & Multi-Selection
- **Goal:** Lightning-fast, keyboard-driven host selection and command launcher.
- **Components:**
- Instant fuzzy search over machines, tags, and groups (no automatic blocking ping on launch).
- Pure ANSI keyboard navigation (`tui/selector.py`) using standard Unix `termios` and `tty`.
- Subsequence fuzzy matching (`tui/fuzzy.py`) with real-time list filtering as user types.
- Background socket probe (`network/prober.py`) displaying live latency and online/offline status badge next to host names.
- Multi-host selection support (`Space` to toggle, `Enter` to connect, `R` to run command).
- Seamless delegation to external `fzf` when present in `$PATH`.
- **Verification:** Terminal smoke tests with ANSI mock sequences and fuzzy scoring tests.
---
### Slice 4 — Parallel Fleet Command Runner (`exec` Engine)
- **Goal:** Modern, robust replacement for `massAct.sh`.
- **Goal:** Modern, robust replacement for `massAct.sh` with flexible output and failure policies.
- **Components:**
- Concurrent multi-host runner (`runner/executor.py`) using `concurrent.futures.ThreadPoolExecutor`.
- Real-time line streaming (`runner/streamer.py`) with colored host prefixes.
- Summary reporter (`runner/summary.py`) with status, exit code, and execution duration table.
- Support for `--concurrency`, `--timeout`, and `--sudo`.
- **Verification:** Mock concurrent tests verifying 10 simultaneous runs, proper output interleaving, and exit code aggregation.
- Three output presentation modes:
- `-b` / `--block` (DEFAULT): Grouped contiguous output blocks per host.
- `-s` / `--stream`: Real-time interleaved streaming with colored `[host]` prefixes.
- `-t` / `--table`: Live progress table; output shown on error or with `-v`.
- `--json`: Structured output.
- Three failure policies:
- `continue` (DEFAULT): Run all hosts, report summary.
- `--fail-fast`: Abort on first non-zero exit code or timeout.
- `--ask`: Pause and interactively prompt operator.
- **Verification:** Mock concurrent tests verifying 10 simultaneous runs, proper output formatting across all 3 modes, and exit code aggregation.
---
### Slice 5 — Fleet Health & Connectivity Matrix (`status` Engine)
- **Goal:** Instant verification of homelab infrastructure reachability.
### Slice 5 — Privilege Elevation & Authentication Engine
- **Goal:** Secure handling of privileged commands and credentials.
- **Components:**
- Fast non-blocking socket prober across all configured nodes.
- SSH banner inspection to identify running OpenSSH versions without full authentication.
- Formatted tabular output and structured `--json` report.
- **Verification:** Unit tests verifying timeout handling and reachability matrix output.
- Passwordless sudo by default (assuming `NOPASSWD: ALL` or root).
- `--sudo` / `-S` / `--ask-sudo-pass`: Prompts once locally in terminal (hidden input) and streams password via stdin (`sudo -S -p ''`).
- SSH key and agent integration verification.
- **Verification:** Mock tests verifying password stream feeding to stdin and error handling on wrong password.
---
### Slice 6 — Tunnel & Port Forwarding Helper (`tunnel` Engine)
- **Goal:** Effortless creation of SSH tunnels into private homelab services.
### Slice 6 — Fleet Connectivity Matrix (`status`) & Tunnel Helper (`tunnel`)
- **Goal:** Instant verification of homelab reachability and effortless port forwarding.
- **Components:**
- `tunnel` CLI sub-command parsing `local_port:remote_host:remote_port`.
- Background SSH tunnel launcher with clean SIGINT termination.
- **Verification:** Test tunnel parameter validation and command construction.
- `status` command: Fast non-blocking socket prober across configured nodes (port 22, SSH banner, latency).
- `tunnel` command: Foreground mode by default with live status and clean Ctrl+C trap; `--detach` / `-d` for background mode with `tunnel list` and `tunnel kill`.
- **Verification:** Test socket timeout handling, reachability matrix output, and tunnel command construction.
---