fix: block running as root/Administrator to prevent daemon.lock issues#1431
Open
svarlamov wants to merge 8 commits into
Open
fix: block running as root/Administrator to prevent daemon.lock issues#1431svarlamov wants to merge 8 commits into
svarlamov wants to merge 8 commits into
Conversation
…n.lock issues When git-ai is installed or run as root/Administrator, it creates files (daemon.lock, sockets, config) owned by root that become inaccessible to the normal user account. This causes persistent "daemon startup blocked: lock held" errors that require manual cleanup. This adds a superuser guard that detects elevated privileges and refuses to run with a clear error message explaining how to fix the issue. The guard is automatically bypassed in CI/agent sandbox environments (detected via CI, GITHUB_ACTIONS, GITLAB_CI, etc. env vars) and can be explicitly overridden with GIT_AI_ALLOW_SUPERUSER=1 (with a warning). Exempt commands that must always work: version, help, upgrade, debug, uninstall-hooks, and daemon run/status/shutdown (for self-update flows). The git proxy path is not guarded to remain transparent. Fixes #1287 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…n declarations Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ed import Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… paths Address Devin review feedback: the opt-in and CI environment tests were using `version` (an exempt command), so they never exercised the actual superuser guard logic. Changed to use `status` and verify the warning message (opt-in) or absence of blocking (CI). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Block installation as root/Administrator at the install script level, before any files are created. This prevents the root cause of #1287 at the earliest possible point. Auto-allows in: - CI environments (CI, GITHUB_ACTIONS, GITLAB_CI, etc.) - MDM deployments (INSTALL_USER set by JAMF detection) - Daemon-triggered self-updates (GIT_AI_RELEASE_TAG or GIT_AI_RESTART_DAEMON_AFTER_INSTALL set by upgrade command) Override with: GIT_AI_ALLOW_SUPERUSER=1 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…oot-guard bypass Replace GIT_AI_RELEASE_TAG (user-facing version pinning var) with a private GIT_AI_DAEMON_UPGRADE env var that is only set internally by the upgrade command during daemon self-updates. This prevents users from inadvertently bypassing the root/sudo guard by setting GIT_AI_RELEASE_TAG for manual version pinning. Also adds allow_superuser config flag to ~/.git-ai/config.json as an alternative to the GIT_AI_ALLOW_SUPERUSER env var. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The install scripts invoke git-ai subcommands (install-hooks, exchange-nonce) as child processes that inherit the env var. Without this check, those post-install commands would be blocked by the superuser guard during daemon self-upgrades running as root. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
dff8ec1 to
dec42da
Compare
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 #1287
git-aicommands with a clear error message explaining the issue and how to fix itGIT_AI_ALLOW_SUPERUSER=1env var (with a runtime warning)git, behavior remains transparentRoot Cause
Installing git-ai as root/Administrator creates daemon.lock and other files owned by root. When the normal user account subsequently runs git-ai, it cannot acquire the lock, causing persistent "daemon startup blocked: lock held" errors. The fix prevents this footgun at the source.
Test plan
is_running_as_superuser(),superuser_is_allowed(),is_superuser_expected_environment()sudo: blocked without opt-in, allowed withGIT_AI_ALLOW_SUPERUSER=1, allowed withCI=trueupgradeanddaemon runare exempt (auto-update flow)GIT_AI=git) is not guarded🤖 Generated with Claude Code