196 lines
16 KiB
Markdown
196 lines
16 KiB
Markdown
# Code Review: Wingmate
|
||
|
||
Branch: `main` (whole-repository review; no comparison branch)
|
||
Effort: high
|
||
Context used: [Wingmate README](../README.md), [YAML configuration reference](../wingmate.yaml.md)
|
||
|
||
> This doc is a live tracker. Update the **Status** column/field as findings are triaged, fixed, or dismissed — don't leave the table out of sync with the detail sections below.
|
||
|
||
The review covers the supervisor runtime, helper binaries, privilege boundaries, configuration compatibility, operations, build, and tests.
|
||
|
||
## Status legend
|
||
|
||
| Status | Meaning |
|
||
|---|---|
|
||
| 🔴 Open | Not yet triaged or fixed |
|
||
| 🟡 In progress | Fix underway |
|
||
| 🟢 Fixed | Fix landed on this branch |
|
||
| 🔵 Verified | Independently confirmed real (see Verification note) but not yet fixed |
|
||
| ⚪ Won't fix | Triaged and consciously deferred/rejected, with reason noted |
|
||
|
||
## Tracker
|
||
|
||
| # | Finding | File | Status |
|
||
|---|---|---|---|
|
||
| 1 | P1: Init mode does not enforce its PID 1 operating requirement | `init/signal-pump.go:31` | 🔴 Open |
|
||
| 2 | P1: A missing task command crashes the supervisor | `task/task.go:289` | 🔵 Verified |
|
||
| 3 | P1: A zero cron step can hang startup and exhaust memory | `config/yaml.go:147` | 🔴 Open |
|
||
| 4 | P2: A clean checkout cannot compile all test packages | `cmd/wingmate/wingmate.go:14` | 🔵 Verified |
|
||
| 5 | P2: CLI tests call a process entry point they cannot control | `cmd/wingmate/wingmate_test.go:8` | 🔵 Verified |
|
||
| 6 | P2: One config load can read another load's YAML | `config/yaml.go:40` | 🔵 Verified |
|
||
| 7 | P1: `wmexec` retains supplementary groups when changing identity | `cmd/exec/exec.go:106` | 🔵 Verified |
|
||
| 8 | P1: A long log line can stall a service or cron job | `init/service.go:98` | 🔵 Verified |
|
||
| 9 | P1: `wmpidproxy` can signal processes other than its daemon | `cmd/pidproxy/pidproxy.go:109` | 🔵 Verified |
|
||
| 10 | P2: Legacy cron commands with arguments don't run | `task/task.go:40` | 🔵 Verified |
|
||
| 11 | P2: A YAML parse error can leak secrets into logs | `config/yaml.go:52` | 🔵 Verified |
|
||
| 12 | P2: A failing service can restart continuously without a useful exit diagnostic | `init/service.go:71` | 🔵 Verified |
|
||
| 13 | P2: Named identities crash `wmexec` instead of working or returning a clear error | `cmd/exec/ent.go:5` | 🔵 Verified |
|
||
|
||
## Findings
|
||
|
||
### 1. P1: Init mode does not enforce its PID 1 operating requirement
|
||
|
||
- **Status**: 🔴 Open
|
||
- **File**: `init/signal-pump.go:31–67`, `init/sighandler.go:21–35`
|
||
- **Kind**: Reliability and test isolation — namespace-wide shutdown is intentional for container init; the concern is accidental use outside that operating mode.
|
||
- **Summary**: Wingmate's shutdown path broadcasts TERM and potentially KILL without checking that it is running as PID 1.
|
||
- **Failure scenario**: A developer runs Wingmate as an ordinary host process and sends it TERM to exercise shutdown. The signal pump can reach unrelated processes in the same PID namespace that Wingmate has permission to signal.
|
||
- **Recommendations**:
|
||
1. **(Recommended)** Preserve init-mode broadcasts in a dedicated PID namespace. Reject init-mode startup outside PID 1, and guard the real broadcast at the signal boundary so callers cannot bypass the check. Document the dedicated namespace requirement separately from the PID 1 check.
|
||
2. Unit-test shutdown decisions with a fake signal sender and clock. Track real signal delivery in the separate [WM-001 Docker shutdown integration test](tasks/WM-001-docker-shutdown-test.md), which does not cover production enforcement.
|
||
3. Implement targeted shutdown for ordinary Linux processes as a separate mode under [WM-002](tasks/WM-002-non-init-supervisor-mode.md).
|
||
|
||
### 2. P1: A missing task command crashes the supervisor
|
||
|
||
- **Status**: 🔵 Verified
|
||
- **File**: `task/task.go:256–306`, `task/cron.go:210–253`, `config/yaml.go:48–73`
|
||
- **Summary**: YAML loading accepts tasks without a command, and the task accessors assume `UtilDepCheck` populated a nonempty command line.
|
||
- **Failure scenario**: A YAML service with a `working_dir` but no `command` passes config loading. `UtilDepCheck` leaves `cmdLine` empty, and `ServiceTask.Command()` panics when the worker indexes it. Valid legacy tasks also panic if a caller reads their command before `UtilDepCheck()`.
|
||
- **Verification note**: A config probe confirmed that `Read()` accepts the missing command, and a separate run of the built binary reproduced the panic from `init/service.go:45`. `TestServicesV0` and `TestCronV0` reproduced the initialization failure independently.
|
||
- **Recommendations**:
|
||
1. **(Recommended)** Validate command inputs before launching workers and separate command construction from helper-binary version checks.
|
||
2. Cover missing commands, valid legacy tasks, and wrapper argument construction with regression tests.
|
||
|
||
### 3. P1: A zero cron step can hang startup and exhaust memory
|
||
|
||
- **Status**: 🔴 Open
|
||
- **File**: `config/yaml.go:145–161`, `config/crontab.go:165–181`
|
||
- **Summary**: Both cron parsers accept a zero step for fields whose valid range includes zero.
|
||
- **Failure scenario**: A `*/0` minute step passes the field range check, then the expansion loop repeatedly appends zero because its counter never advances. Startup can hang and exhaust memory. This path was identified by inspection; the unbounded loop was not run.
|
||
- **Recommendations**:
|
||
1. **(Recommended)** Reject zero before expansion and share the step parser across YAML and legacy crontab.
|
||
2. Add table-driven tests for zero, valid steps, and field boundaries.
|
||
|
||
### 4. P2: A clean checkout cannot compile all test packages
|
||
|
||
- **Status**: 🔵 Verified
|
||
- **File**: `cmd/wingmate/wingmate.go:14`, `cmd/pidproxy/pidproxy.go:37`, `cmd/exec/exec.go:36` (and each command's `Makefile:1–3`)
|
||
- **Kind**: Build and test setup — the standard Go entry point depends on files generated by Make.
|
||
- **Summary**: Each command embeds an ignored `version.txt` that its Makefile creates.
|
||
- **Failure scenario**: Running `go test ./...` in a clean checkout fails to compile all three command packages with `pattern version.txt: no matching files found`.
|
||
- **Verification note**: `go test ./... -run '^$'` isolated the compile failures. After generating version files in a temporary copy, `go build ./...` and `go vet ./...` passed.
|
||
- **Recommendations**:
|
||
1. **(Recommended)** Give ordinary Go builds a default version and inject release versions at build time, preserving the version match between Wingmate and its helper binaries.
|
||
|
||
### 5. P2: CLI tests call a process entry point they cannot control
|
||
|
||
- **Status**: 🔵 Verified
|
||
- **File**: `cmd/wingmate/wingmate_test.go:8–23`, `cmd/wingmate/wingmate.go:18–36`, `config/flags.go:11–25`
|
||
- **Kind**: Test design — configuration tests enter the production process lifecycle.
|
||
- **Summary**: The tests use machine-specific paths, mutate process-wide arguments, and call `main()` directly.
|
||
- **Failure scenario**: `TestEntry_configPathEnv` points at a developer-specific `/Volumes/Source/...` path. Without that directory, `main()` logs a fatal error and exits the test process. With a valid fixture, `main()` enters the blocking supervisor.
|
||
- **Verification note**: After the version-file prerequisite was satisfied in a temporary copy, `go test ./... -timeout=15s` reached the command tests and reproduced the fatal exit on the missing config path.
|
||
- **Recommendations**:
|
||
1. **(Recommended)** Extract a startup function that takes explicit arguments, uses a fresh flag set, returns errors, and accepts a supervisor callback.
|
||
2. Use `t.TempDir()` and `t.Setenv()` to assert flag, environment, and default precedence without launching services.
|
||
|
||
### 6. P2: One config load can read another load's YAML
|
||
|
||
- **Status**: 🔵 Verified
|
||
- **File**: `config/yaml.go:27–49`, `config/config.go:84–115`
|
||
- **Summary**: The package-global Viper instance retains prior search paths between calls to `Read()`.
|
||
- **Failure scenario**: A process loads YAML from a directory defining service `first`, then changes `WINGMATE_CONFIG_PATH` to a directory defining only `second`. The second `Read()` returns `first`.
|
||
- **Verification note**: A same-process probe with two valid temporary config directories reproduced the stale service without resetting Viper between calls.
|
||
- **Recommendations**:
|
||
1. **(Recommended)** Use a fresh Viper instance for each load, read the explicitly selected file, and store resolved settings on the returned config.
|
||
2. Keep a regression test that loads two distinct directories in sequence.
|
||
|
||
### 7. P1: `wmexec` retains supplementary groups when changing identity
|
||
|
||
- **Status**: 🔵 Verified
|
||
- **File**: `cmd/exec/exec.go:106–138`
|
||
- **Kind**: Security — incomplete credential change.
|
||
- **Summary**: `wmexec` sets the requested UID and optional primary GID without replacing the supplementary group list.
|
||
- **Failure scenario**: Wingmate starts a service under a less-privileged account, but the child inherits supplementary groups that may still grant access to files or devices the target account should not be able to use.
|
||
- **Verification note**: Invoking the built binary with the review user's numeric UID and primary GID left the supplementary groups unchanged. A privileged root-to-user transition was not exercised.
|
||
- **Recommendations**:
|
||
1. **(Recommended)** Resolve the target identity and group list before changing credentials, replace the supplementary groups, and fail before executing the child if any part of the switch fails.
|
||
2. Verify the child's full group list in an isolated privileged test.
|
||
|
||
### 8. P1: A long log line can stall a service or cron job
|
||
|
||
- **Status**: 🔵 Verified
|
||
- **File**: `init/service.go:80–110`, `init/cron.go:59–75`
|
||
- **Kind**: Reliability — the output reader can block the workload it is observing.
|
||
- **Summary**: When `bufio.Scanner` encounters an oversized line, the shared reader stops draining the pipe without closing it.
|
||
- **Failure scenario**: A child continues writing a long record after the scanner stops. The pipe fills, the child blocks instead of exiting, and Wingmate can stay stuck waiting for the other output reader.
|
||
- **Verification note**: A bounded test with the real pipe reader reproduced the scanner error and a writer that remained blocked until its deadline.
|
||
- **Recommendations**:
|
||
1. **(Recommended)** Keep draining output while capping or splitting individual log records. Raising the scanner limit alone leaves the same failure at a higher threshold.
|
||
2. Cover an oversized line followed by ordinary output and verify the stream still completes.
|
||
|
||
### 9. P1: `wmpidproxy` can signal processes other than its daemon
|
||
|
||
- **Status**: 🔵 Verified
|
||
- **File**: `cmd/pidproxy/pidproxy.go:109–157`
|
||
- **Kind**: Security and reliability — a daemon-writable file determines what the proxy can signal.
|
||
- **Summary**: The proxy passes unvalidated PID-file contents to `kill` and rereads the file when handling shutdown.
|
||
- **Failure scenario**: A nonpositive value has process-group or broadcast semantics rather than identifying one daemon. Even a positive PID can redirect TERM if the file changes after the proxy has checked the original process.
|
||
- **Verification note**: A parser probe confirmed that nonpositive values are accepted. The shutdown target was traced in code; no live signals were sent to PID-file targets.
|
||
- **Recommendations**:
|
||
1. **(Recommended)** Reject values outside the valid positive PID range and bind monitoring and shutdown to the same verified process identity, rather than rereading the target from the file.
|
||
2. Cover invalid PID values and a file replacement between monitoring and shutdown.
|
||
|
||
### 10. P2: Legacy cron commands with arguments don't run
|
||
|
||
- **Status**: 🔵 Verified
|
||
- **File**: `config/crontab.go:76–110`, `cmd/wingmate/bridge.go:45–49`, `task/task.go:40–42`, `init/cron.go:32–39`
|
||
- **Kind**: Compatibility — the README promises simple commands with arguments in legacy crontabs.
|
||
- **Summary**: The legacy parser passes the whole command field through as one executable name.
|
||
- **Failure scenario**: A cron entry ending in `/bin/echo hello` makes Wingmate try to start an executable named `/bin/echo hello`, so the job never runs.
|
||
- **Verification note**: A probe followed the crontab through `config.Read()` and `convert()` and confirmed that the task exposes `/bin/echo hello` as the executable and no arguments.
|
||
- **Recommendations**:
|
||
1. **(Recommended)** Parse the documented simple-command format into an executable and arguments without introducing shell evaluation.
|
||
2. Test both executable-only entries and commands with arguments.
|
||
|
||
### 11. P2: A YAML parse error can leak secrets into logs
|
||
|
||
- **Status**: 🔵 Verified
|
||
- **File**: `config/yaml.go:48–67`
|
||
- **Kind**: Security and observability — configuration diagnostics can expose values to log readers.
|
||
- **Summary**: A task decode failure logs the entire YAML entry, including unrelated environment values.
|
||
- **Failure scenario**: An operator supplies an invalid `startsecs` alongside a valid secret in `environ`. The startup error includes the secret even though the secret had nothing to do with the decode failure.
|
||
- **Verification note**: A probe with an invalid `startsecs` captured a fake environment token in the emitted logs.
|
||
- **Recommendations**:
|
||
1. **(Recommended)** Log the task name and a sanitized field-level error without dumping task values.
|
||
2. Assert that a parse error still identifies the failing task while redacting unrelated environment values.
|
||
|
||
### 12. P2: A failing service can restart continuously without a useful exit diagnostic
|
||
|
||
- **Status**: 🔵 Verified
|
||
- **File**: `init/service.go:71–94`
|
||
- **Kind**: Performance and operations — rapid restarts consume resources and obscure why the service is failing.
|
||
- **Summary**: The restart loop sleeps after setup or start failures but discards `cmd.Wait()` results and immediately retries when a started child exits.
|
||
- **Failure scenario**: A service starts successfully and immediately exits nonzero. Wingmate repeatedly forks the service without a delay or an exit-status diagnostic.
|
||
- **Verification note**: A service-loop probe observed two launches of a failing process in about 11 ms.
|
||
- **Recommendations**:
|
||
1. **(Recommended)** Apply bounded backoff to repeated short-lived exits, interrupt the delay on shutdown, and report the child's exit reason.
|
||
2. Test repeated failures and cancellation during the delay.
|
||
|
||
### 13. P2: Named identities crash `wmexec` instead of working or returning a clear error
|
||
|
||
- **Status**: 🔵 Verified
|
||
- **File**: `cmd/exec/ent.go:1–10`, `cmd/exec/ent_lin.go:12–32`, `cmd/exec/exec.go:106–127`
|
||
- **Kind**: Compatibility — the documented account-name syntax depends on the build and the lookup result.
|
||
- **Summary**: The CGO-disabled account lookup panics, and the CGO implementation can dereference a null result when a name is missing.
|
||
- **Failure scenario**: A CGO-disabled build panics for a valid username. A CGO-enabled build can segfault for an unknown username because `getpwnam` may return null without setting `errno`.
|
||
- **Verification note**: Local CLI runs reproduced the panic for an existing named user with CGO disabled and the segmentation fault for an unknown user with CGO enabled.
|
||
- **Recommendations**:
|
||
1. **(Recommended)** Use an account lookup that works on supported builds and returns a normal error for unknown users and groups.
|
||
2. Exercise named and numeric identities in both CGO build configurations.
|
||
|
||
## Clean areas (checked, no issues found)
|
||
|
||
- Existing CLI helper and configuration tests passed `go test -race -shuffle=on -count=10 ./cmd/cli ./config`. This run did not cover the supervisor lifecycle.
|
||
- With the generated version files present, `go build ./...` passed with CGO enabled and disabled, and `go vet ./...` passed. `go mod verify` also passed. Docker was unavailable, so container packaging and real PID 1 shutdown were not verified.
|