Skip to content

aitools: skip auto-install when the CLI runs as root in another user's home - #7828

Merged
anton-107 merged 3 commits into
mainfrom
aitools-auto-install-skip-root-in-user-home
Nov 20, 2026
Merged

anton-107 merged 3 commits into
mainfrom
aitools-auto-install-skip-root-in-user-home

Conversation

@anton-107

Copy link
Copy Markdown
Contributor

Changes

The automatic installation of Databricks AI tools now skips a run where the CLI is root in a home directory that another user owns.

  • libs/aitools/autoinstall: new RootInUserHome(ctx). On Unix it returns true when the effective UID is 0 and the home directory (from env.UserHomeDir) belongs to a non-root UID. If the home can't be stat'ed, it returns false. On Windows it always returns false, because an elevated process keeps the user's own profile.
  • Decide gets a new input, RootInUserHome, and a new reason, root_in_user_home. The check runs right after the development-build check and before anything that reads the state. The reason is not due, so it doesn't settle the version.
  • cmd/aitools: the auto-install hook passes RootInUserHome into Decide and adds the new reason to the state-free skips. Such a run returns before it takes the lock, reads or writes the state, looks up the gate, installs anything or sends telemetry.
 Decide(in)
   skipped command / on runtime / cache disabled / development build
+  root in a user's home        -> root_in_user_home (no lock, no state, no telemetry)
   retries exhausted / already ran / CI / opt-out / gate / holdout / run

Why

sudo databricks ... keeps HOME pointing at the invoking user's home by default on macOS, and on Linux with sudo -E. The auto-install hook then ran as root in that home. It created a root-owned ~/.databricks (the state and lock files) and could install the agent skills as root. After that, databricks auth login, databricks aitools install and databricks aitools auto-install disable failed for the user, because they could no longer write to that directory.

Skipping the run without touching state leaves the home as it was, so the user's next normal run installs as usual. Root in its own home (for example sudo -H, or a root login) still installs as before.

Tests

  • TestRootInUserHome (Unix): returns false for a non-root UID, for root in a root-owned home, for a home that doesn't exist and for an empty home. TestRootInUserHomeOwnedByAnotherUser returns true for root in a directory the test user owns. It is skipped when the tests themselves run as root.
  • TestDecide: the new reason, and its precedence over the persisted state and over CI.
  • TestReasonDue: the new reason is not due.
  • TestAutoInstallSkipsRootInAUserHome: with the check forced on, the hook creates no ~/.databricks, installs no skills, does no gate lookup and buffers no telemetry. With the check off, the same setup installs and records the state.

…s home

## Changes

The automatic installation of Databricks AI tools now skips a run where the CLI is root in a home directory that another user owns.

- `libs/aitools/autoinstall`: new `RootInUserHome(ctx)`. On Unix it returns true when the effective UID is 0 and the home directory (from `env.UserHomeDir`) belongs to a non-root UID. If the home can't be stat'ed, it returns false. On Windows it always returns false, because an elevated process keeps the user's own profile.
- `Decide` gets a new input, `RootInUserHome`, and a new reason, `root_in_user_home`. The check runs right after the development-build check and before anything that reads the state. The reason is not due, so it doesn't settle the version.
- `cmd/aitools`: the auto-install hook passes `RootInUserHome` into `Decide` and adds the new reason to the state-free skips. Such a run returns before it takes the lock, reads or writes the state, looks up the gate, installs anything or sends telemetry.

```diff
 Decide(in)
   skipped command / on runtime / cache disabled / development build
+  root in a user's home        -> root_in_user_home (no lock, no state, no telemetry)
   retries exhausted / already ran / CI / opt-out / gate / holdout / run
```

## Why

`sudo databricks ...` keeps `HOME` pointing at the invoking user's home by default on macOS, and on Linux with `sudo -E`. The auto-install hook then ran as root in that home. It created a root-owned `~/.databricks` (the state and lock files) and could install the agent skills as root. After that, `databricks auth login`, `databricks aitools install` and `databricks aitools auto-install disable` failed for the user, because they could no longer write to that directory.

Skipping the run without touching state leaves the home as it was, so the user's next normal run installs as usual. Root in its own home (for example `sudo -H`, or a root login) still installs as before.

## Tests

- `TestRootInUserHome` (Unix): returns false for a non-root UID, for root in a root-owned home, for a home that doesn't exist and for an empty home. `TestRootInUserHomeOwnedByAnotherUser` returns true for root in a directory the test user owns. It is skipped when the tests themselves run as root.
- `TestDecide`: the new reason, and its precedence over the persisted state and over CI.
- `TestReasonDue`: the new reason is not due.
- `TestAutoInstallSkipsRootInAUserHome`: with the check forced on, the hook creates no `~/.databricks`, installs no skills, does no gate lookup and buffers no telemetry. With the check off, the same setup installs and records the state.

Co-authored-by: Isaac <no-reply@databricks.com>
@anton-107
anton-107 requested review from a team and lennartkats-db as code owners November 19, 2026 20:37
@github-actions github-actions Bot added the aitools AI tools (databricks aitools) related changes label Nov 19, 2026
Co-authored-by: Isaac <no-reply@databricks.com>

@simonfaltum simonfaltum left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🤖 Automated review from simonfaltum's review agent (pr-review skill) at a06d719. Each finding was verified against the code; simonfaltum may follow up.

No blocking issues found, approving. 5 non-blocking comment(s) and 1 question(s) below.

This PR skips the automatic AI tools install when the CLI runs as root in a home directory another user owns. It does so with a new not-due root_in_user_home reason that returns before any lock, state, gate lookup or telemetry. The core logic is correct and the placement in Decide is right; tests pass and CI is green. One gap: agent config dirs set through env vars like CLAUDE_CONFIG_DIR bypass the HOME check under sudo -E -H. The other comments are test and debug-log nits, plus a non-blocking scope question about other root-owned writers under sudo.

Questions

  1. Under sudo with HOME kept, other code that runs on every command still creates root-owned directories in the user's home. Examples: libs/cache, used by the version-check notice and host metadata under os.UserCacheDir(), and the agent hint throttle markers. They don't break ~/.databricks, but the user's later runs of that version fall back to a no-op cache. Should RootInUserHome become a shared helper that these writers also check, or is this PR meant to cover auto-install only, with the rest left for a follow-up? (non-blocking)

Comments outside the changed lines

  • [nit] cmd/aitools/autoinstall_run.go:117: State-free skips return without a log line because "these are most runs", but root_in_user_home is rare. A user who always runs the CLI under sudo and wonders why the tools never install sees nothing with --debug. Log auto-install: skipped: root_in_user_home at debug level for this reason, for example by checking it before the silent stateFreeSkips return.

Comment thread libs/aitools/autoinstall/home_unix.go Resolved
Comment thread libs/aitools/autoinstall/decide_test.go Resolved
Comment thread cmd/aitools/autoinstall_run_test.go Resolved
Log the root_in_user_home skip at debug level, note in the doc comment that
agent directories set through environment variables are out of scope, skip
the root-owned home test where / is not owned by UID 0, make the Decide
precedence case start from a state that skips on its own, and turn the test
closure into a named helper.

Co-authored-by: Isaac <no-reply@databricks.com>
@anton-107
anton-107 added this pull request to the merge queue Nov 20, 2026
Merged via the queue into main with commit 831e20d Nov 20, 2026
24 checks passed
@anton-107
anton-107 deleted the aitools-auto-install-skip-root-in-user-home branch November 20, 2026 00:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

aitools AI tools (databricks aitools) related changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants