warn when running as root/Administrator to prevent daemon.lock issues#1431
Merged
Conversation
dff8ec1 to
dec42da
Compare
…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>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…install scripts When the install script decides root is acceptable (CI, MDM, daemon upgrade), export GIT_AI_ALLOW_SUPERUSER=1 so that post-install commands (install-hooks, exchange-nonce, login) also pass the binary's superuser guard. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Instead of refusing to run as root/Administrator, emit a deprecation warning that a future version will block. This makes initial rollout less disruptive while still surfacing the issue to users. The warning is suppressed in CI, MDM, and daemon-upgrade environments. Users can also suppress it by setting GIT_AI_ALLOW_SUPERUSER=1 or adding "allow_superuser": true to ~/.git-ai/config.json. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The tests mutate process-global env vars (CI, GIT_AI_ALLOW_SUPERUSER) and must not run concurrently with other env-var-sensitive tests. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Detect container environments via the `container` env var (set by podman, systemd-nspawn, and other runtimes) and `/.dockerenv` (created by Docker in every container). This prevents the deprecation warning from firing inside containers where running as root is the norm. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
c0a2c00 to
cb72921
Compare
Clearer verbiage: running as root isn't deprecated (implies removal on a timeline), it's simply not recommended due to file ownership issues. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…rship The previous check used IsInRole(Administrator) which returns true for any user in the Administrators group — the default for most Windows users, even in non-elevated terminals. This caused false warnings during normal installs. Now checks token ownership: when UAC-elevated, the token owner is BUILTIN\Administrators (S-1-5-32-544); when non-elevated, it's the user's own SID. This matches what the Rust binary does via TokenElevation. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The Owner-based check still returns true for admin-group users in
non-elevated terminals (Owner is BUILTIN\Administrators regardless of
elevation on many Windows configurations).
Instead check for the High Mandatory Level SID (S-1-16-12288) in the
token's groups — this is only present when the process is actually
UAC-elevated ("Run as Administrator"). Non-elevated admin users have
Medium integrity (S-1-16-8192) and won't trigger the warning.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Neither the Owner-based check nor the integrity level SID approach works reliably across Windows configurations. Use the same Win32 TokenElevation API that the Rust binary uses — this is the definitive way to detect "Run as Administrator" vs normal admin-group user. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
always-admin accounts TokenElevation (class 20) returns true for users with UAC disabled or the built-in Administrator account, causing false warnings. These users always run elevated so there's no file-ownership mismatch. Switch to TokenElevationType (class 18) which returns: - Type 1 (Default): no split token, always-admin → don't warn - Type 2 (Full): explicitly elevated via "Run as Administrator" → warn - Type 3 (Limited): non-elevated terminal → don't warn Only type 2 creates the permission mismatch from issue #1287. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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