Repository navigation
aitools: skip auto-install when the CLI runs as root in another user's home #7828
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| * The automatic installation of Databricks AI tools no longer runs when the CLI runs as root in a home directory another user owns, as under `sudo` with `HOME` kept (the macOS default). Such a run used to leave a root-owned `~/.databricks` that broke `databricks auth login`, `databricks aitools install` and `databricks aitools auto-install disable` for the user, and could install the tools as root. ([#7828](https://github.com/databricks/cli/pull/7828)) |
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| //go:build unix | ||
|
|
||
| package autoinstall | ||
|
|
||
| import ( | ||
| "context" | ||
| "os" | ||
|
|
||
| "github.com/databricks/cli/libs/env" | ||
| "golang.org/x/sys/unix" | ||
| ) | ||
|
|
||
| // RootInUserHome reports whether the CLI runs as root in a home directory | ||
| // that another user owns, as under sudo with HOME kept (the macOS default, | ||
| // and `sudo -E` on Linux). What auto-install writes there, its state and the | ||
| // agents' files, would belong to root, and the user could no longer change | ||
| // it. A home that cannot be inspected counts as not. Only the home is | ||
| // checked: an agent directory set through an environment variable, such as | ||
| // CLAUDE_CONFIG_DIR kept by `sudo -E -H`, is out of scope. | ||
| func RootInUserHome(ctx context.Context) bool { | ||
| return rootInUserHome(ctx, os.Geteuid()) | ||
| } | ||
|
|
||
| // rootInUserHome is RootInUserHome for the effective user ID euid. | ||
| func rootInUserHome(ctx context.Context, euid int) bool { | ||
| if euid != 0 { | ||
| return false | ||
| } | ||
| home, err := env.UserHomeDir(ctx) | ||
|
anton-107 marked this conversation as resolved.
Resolved
|
||
| if err != nil { | ||
| return false | ||
| } | ||
| var st unix.Stat_t | ||
| if err := unix.Stat(home, &st); err != nil { | ||
| return false | ||
| } | ||
| return st.Uid != 0 | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| //go:build unix | ||
|
|
||
| package autoinstall | ||
|
|
||
| import ( | ||
| "os" | ||
| "path/filepath" | ||
| "testing" | ||
|
|
||
| "github.com/databricks/cli/libs/env" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| "golang.org/x/sys/unix" | ||
| ) | ||
|
|
||
| func TestRootInUserHome(t *testing.T) { | ||
| userHome := t.TempDir() | ||
| tests := []struct { | ||
| name string | ||
| euid int | ||
| home string | ||
| }{ | ||
| {name: "the user in their home", euid: os.Geteuid(), home: userHome}, | ||
| {name: "another user in the home", euid: os.Geteuid() + 1, home: userHome}, | ||
| {name: "root with a home that does not exist", euid: 0, home: filepath.Join(userHome, "missing")}, | ||
| {name: "root without a home", euid: 0, home: ""}, | ||
| } | ||
| for _, tc := range tests { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| ctx := env.WithUserHomeDir(t.Context(), tc.home) | ||
| assert.False(t, rootInUserHome(ctx, tc.euid)) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestRootInUserHomeOwnedByRoot(t *testing.T) { | ||
| var st unix.Stat_t | ||
| require.NoError(t, unix.Stat("/", &st)) | ||
| if st.Uid != 0 { | ||
| t.Skip("the root directory is not owned by root, as in a user namespace that does not map root") | ||
| } | ||
| ctx := env.WithUserHomeDir(t.Context(), "/") | ||
| assert.False(t, rootInUserHome(ctx, 0)) | ||
| } | ||
|
|
||
| func TestRootInUserHomeOwnedByAnotherUser(t *testing.T) { | ||
| if os.Geteuid() == 0 { | ||
| t.Skip("a home the test creates is owned by root") | ||
| } | ||
| ctx := env.WithUserHomeDir(t.Context(), t.TempDir()) | ||
| assert.True(t, rootInUserHome(ctx, 0)) | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| //go:build windows | ||
|
|
||
| package autoinstall | ||
|
|
||
| import "context" | ||
|
|
||
| // RootInUserHome reports whether the CLI runs as root in a home directory | ||
| // that another user owns. Windows has no root user that the CLI switches to: | ||
| // an elevated process keeps the user's own profile, so it reports false. | ||
| func RootInUserHome(context.Context) bool { | ||
| return false | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.