Skip to content

fix: block running as root/Administrator to prevent daemon.lock issues#1431

Open
svarlamov wants to merge 8 commits into
mainfrom
fix/1287-1779581297
Open

fix: block running as root/Administrator to prevent daemon.lock issues#1431
svarlamov wants to merge 8 commits into
mainfrom
fix/1287-1779581297

Conversation

@svarlamov
Copy link
Copy Markdown
Member

@svarlamov svarlamov commented May 24, 2026

Summary

Fixes #1287

  • Adds a superuser guard that detects elevated privileges (root on Unix, Administrator on Windows) and blocks git-ai commands with a clear error message explaining the issue and how to fix it
  • Automatically bypasses the guard in CI/agent sandbox environments (CI, GITHUB_ACTIONS, GITLAB_CI, JENKINS_URL, BUILDKITE, CIRCLECI, CODEBUILD_BUILD_ID, AGENT_OS, KUBERNETES_SERVICE_HOST)
  • Allows explicit opt-in via GIT_AI_ALLOW_SUPERUSER=1 env var (with a runtime warning)
  • Exempts commands that must always work: version, help, upgrade, debug, uninstall-hooks, and daemon run/status/shutdown (for self-update flows)
  • Does NOT guard the git proxy path — when invoked as git, behavior remains transparent

Root 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

  • Unit tests for is_running_as_superuser(), superuser_is_allowed(), is_superuser_expected_environment()
  • Integration tests verifying exempt commands work, env var override works, and non-root invocations aren't affected
  • Verified manually with sudo: blocked without opt-in, allowed with GIT_AI_ALLOW_SUPERUSER=1, allowed with CI=true
  • Verified upgrade and daemon run are exempt (auto-update flow)
  • Verified git proxy mode (GIT_AI=git) is not guarded
  • Full test suite passes (3032/3032, 1 pre-existing flaky test)

🤖 Generated with Claude Code


Open in Devin Review

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 4 additional findings.

Open in Devin Review

devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

svarlamov and others added 8 commits May 30, 2026 16:34
…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>
@svarlamov svarlamov force-pushed the fix/1287-1779581297 branch from dff8ec1 to dec42da Compare May 30, 2026 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows daemon startup is blocked by daemon.lock when installed as Administrator/Root

1 participant