fix: register a web-traversable kimaki binary for CLI dispatch (#198)#200
Merged
Conversation
The kimaki CLI-channel command is shelled by the Data Machine Code CLI transport from agents/dispatch-message, which runs inside PHP-FPM as the www-data web user on WP-cron / Action Scheduler fires — not as the kimaki.service user. On a RUN_AS_ROOT install the binary resolves under /root/.kimaki/bin and the data dir under /root (mode 0700). www-data cannot traverse 0700 /root, so proc_open fails with EACCES and every scheduled dispatch dies as datamachine_code_cli_dispatch_spawn_failed, while manual-as-root runs succeed. The opencode service-user home (/home/opencode, 0750) is the same trap. Add _kimaki_path_is_web_traversable() which asserts every ancestor dir of a candidate binary carries the world-execute bit (o+x), and use it in both resolution paths: _kimaki_register_cli_channel now ignores a KIMAKI_BIN trapped under a private home, and _kimaki_find_native_binary skips executable-but-unreachable PATH entries in favor of a reachable system-prefix binary (e.g. /usr/bin/kimaki, the npm-global symlink). This is the targeted stopgap; the durable fix is migrating off RUN_AS_ROOT to the opencode service user (#93). Making the registered command web-reachable regardless of service user is a prerequisite for that migration, since /home/opencode is also non-traversable by www-data. Adds tests/cli-channel-binary-path.sh (+ CI job) covering the 0700/0750 rejection, reachable-preference, and trapped-KIMAKI_BIN fallback. Updates tests/kimaki-agent-fallback.sh fixtures (mktemp -d defaults to 0700) to simulate web-reachable installs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #198. On a
RUN_AS_ROOTinstall, the kimaki CLI-channelcommandwas registered as/root/.kimaki/bin/kimaki. That command is shelled by the Data Machine Code CLI transport fromagents/dispatch-message, which runs inside PHP-FPM as www-data on WP-cron / Action Scheduler fires — not as thekimaki.serviceuser.www-datacannot traverse0700 /root, soproc_openfails withEACCESand every scheduled dispatch dies asdatamachine_code_cli_dispatch_spawn_failed, while manual-as-root runs succeed. Theopencodeservice-user home (/home/opencode,0750) is the same trap.This patch makes the registered command web-traversable regardless of service user, by refusing any binary whose ancestor directories lack the world-execute bit (
o+x) and preferring a reachable system-prefix binary (e.g./usr/bin/kimaki, the npm-global symlink).Changes
bridges/kimaki.sh_kimaki_path_is_web_traversable()— returns success only if every ancestor dir of a candidate binary carrieso+x(resolves symlinks first viarealpath/readlink)._kimaki_register_cli_channel()now ignores aKIMAKI_BINthat is executable but trapped under a non-traversable home, falling back to PATH resolution._kimaki_find_native_binary()now skips executable-but-unreachable$PATHentries in favor of a later reachable candidate; only falls back to a trapped path (then the bare name) as a last resort.tests/cli-channel-binary-path.sh(new) + CI job — covers 0700/0750 ancestor rejection, reachable-preference on a root-style$PATH, trapped-KIMAKI_BINfallback, and a no-regression check that a reachableKIMAKI_BINis still honored.tests/kimaki-agent-fallback.sh—mktemp -ddefaults to0700; its fixtures nowchmod 0755the temp root to simulate a normally-installed, web-reachable binary (otherwise the new, correct reachability check would reject them).Verification against the live production scenario
With root's actual
$PATHordering (/root/.kimaki/binfirst), the fixed resolver now returns the reachable binary:/usr/bin/kimakiis confirmedwww-data-executable on the affected host, so this un-breaks the scheduledEC Agent Progress Pingflow (flow_id 4).Test results
Scope / relationship to the durable fix
This is the targeted stopgap. The durable fix is migrating off
RUN_AS_ROOTto theopencodeservice user (#93, live remediation scoped in #199). Because/home/opencode(0750) is also non-traversable by www-data, making the registered command web-reachable regardless of service user is a prerequisite for that migration, not a duplicate of it.Closes #198.