Repository navigation
Record the profile auth docker configure selects for Docker - #7383
Conversation
849da49 to
71222b5
Compare
|
Commit: Regression test reportSelected 4 changed tests (limit=20, 0 not selected) 4 tests: regression=3 unreleased=0 coverage=1 failing=0
TestAccept/cmd/auth/docker/configure: branch ✅ | main (7f25e1e) ❌ | latest (v1.27.0) ❌main (7f25e1e): latest (v1.27.0): same output as main (7f25e1e) TestAccept/cmd/auth/docker/help: branch ✅ | main (7f25e1e) ❌ | latest (v1.27.0) ❌main (7f25e1e): latest (v1.27.0): same output as main (7f25e1e) TestAccept/cmd/auth/docker/token: branch ✅ | main (7f25e1e) ❌ | latest (v1.27.0) ❌main (7f25e1e): latest (v1.27.0): same output as main (7f25e1e) |
✅ Integration test reportCommit: 46c7f24
Top 4 slowest tests (at least 2 minutes):
|
71222b5 to
79702a7
Compare
pietern
left a comment
There was a problem hiding this comment.
This can have unintended side effects. Let's say you configure Docker assuming profile B, but profile A is earlier in the .databrickscfg for the same workspace host. What happens? Does a docker push use profile A?
I recommend using the "default profile" switcher (run databricks auth switch to see what happens) to be the tie-breaker, if it exists, and keep the error otherwise.
@pietern Yes, it will indeed have potential unintended effects. The problem originates from the credential helper protocol which can only use hostname (not profile) to pick the profile to get the auth token. And our user feedback suggested they'd prefer allowing profiles linking to the same workspace. Your suggest would only work if one of such profiles is the default profile, right? |
49a2dc9 to
4b40835
Compare
4b40835 to
68233ed
Compare
|
@pietern I'm now trying a better way to disambiguate the profile. It saves a new value in |
68233ed to
c10c14a
Compare
There was a problem hiding this comment.
LGTM modulo comments; all of them are non-blocking. Thanks @yolocs for moving it to [__settings__]!
Note: this review was done by AI (Claude).
| if err != nil { | ||
| log.Debugf(ctx, "Docker credential helper cannot resolve %s to a profile: %v", registryHost, err) | ||
| } | ||
| configured = err == nil && selected.Name == profileName |
There was a problem hiding this comment.
Can auth docker host print the profile the helper resolves to, instead of folding it into Configured? NO can now mean Docker isn't set up, it's set up for another profile, several profiles match with none recorded, or the recorded profile is gone, and the reason is only logged at debug level. Something like Credential helper profile: shared, plus a profile field in the JSON output, would make it clear which profile Docker uses.
There was a problem hiding this comment.
Done in 46c7f24. host now prints Credential helper profile: <name> and a profile JSON field, and leaves them out when the helper can't resolve a profile.
| return profile.Profile{}, fmt.Errorf("no Databricks profile found for workspace ID %s from registry host %s. Run databricks auth login --host <workspace-url> and set workspace_id for that profile", registry.WorkspaceID, registry.Host) | ||
| } | ||
|
|
||
| recorded, err := databrickscfg.GetDockerProfile(ctx, registry.Host, env.Get(ctx, "DATABRICKS_CONFIG_FILE")) |
There was a problem hiding this comment.
[nit] ProfileForRegistry takes a profiler for the profiles but reads the recorded selection from DATABRICKS_CONFIG_FILE itself. That's why the tests now need both an InMemoryProfiler and a real file. Can we pass the recorded profile in, so both come from one place? The two callers can call GetDockerProfile.
There was a problem hiding this comment.
Done in 46c7f24. Both callers now call GetDockerProfile and pass the result in, so the tests no longer need a config file.
| configFile.DeleteSection(profileName) | ||
| } | ||
|
|
||
| if settings, err := configFile.GetSection(databricksSettingsSection); err == nil { |
There was a problem hiding this comment.
[nit] Logout clears default_profile with ClearDefaultProfile after DeleteProfile. Why are the Docker entries handled inside DeleteProfile instead? Let's do both the same way: either add a ClearDockerProfiles next to ClearDefaultProfile, or move both into DeleteProfile.
There was a problem hiding this comment.
Went with ClearDockerProfiles next to ClearDefaultProfile, called from logout right after it (46c7f24). Moving both into DeleteProfile would mean removing ClearDefaultProfile, which felt out of scope here.
| } | ||
| } | ||
|
|
||
| func TestInspectRequiresDockerConfigAndProfile(t *testing.T) { |
There was a problem hiding this comment.
[nit] Why a different table? TestInspectRequiresHelperOnPath tests the same Inspect call, so installed and onPath can be fields in this table.
There was a problem hiding this comment.
Done in 46c7f24. Merged into one TestInspect table.
| return writeConfigFile(ctx, configFile) | ||
| } | ||
|
|
||
| // GetDockerProfile returns the profile recorded for the Docker registry host, or "" if none is recorded. |
There was a problem hiding this comment.
[nit] Can we wrap these comments at about 80 characters, like the rest of ops.go? Ditto profile.go:59 and configure.go:42.
auth docker configure no longer fails when several profiles match the workspace. It records the selected profile for the registry host as docker_profile.<registry-host> in the [__settings__] section of .databrickscfg, alongside default_profile, and warns when the selection switches. auth docker token uses the recorded profile and fails instead of falling back when it no longer matches. auth docker host shows the profile the helper uses and reports the helper as configured only if Docker's config selects it and it uses that profile. auth logout --delete removes entries naming the deleted profile, next to clearing default_profile. Co-authored-by: Isaac <no-reply@databricks.com>
c10c14a to
46c7f24
Compare
❌ Integration test reportCommit: d96e1fe
27 interesting tests: 21 RECOVERED, 6 KNOWN
Top 50 slowest tests (at least 2 minutes):
|
Changes
databricks auth docker configure <profile>no longer fails when several profiles match the selected workspace. It records the chosen profile for the registry in the[__settings__]section of.databrickscfg, next todefault_profile, and leaves profile sections untouched:Running it with another profile switches the selection:
databricks auth docker token(the Docker credential helper) picks the profile for a registry like this:... Select the profile for Docker with: databricks auth docker configure <profile-name>.databricks auth docker host --profile Pshows the profile the helper uses for the registry (Credential helper profile: prod, andprofilein JSON output). It reports the helper as configured only if Docker'sconfig.jsonselects it for the registry, it is onPATH, and it would useP.databricks auth logout --deleteremoves entries that name the deleted profile, the same way it clearsdefault_profile. The helper then falls back to the no-recorded-profile rules above.Why
Docker gives the credential helper only the registry host, which encodes the workspace ID, so the helper cannot tell which of several matching profiles was meant.
auth loginnow savesworkspace_idon every profile, so two logins to one workspace were enough to blockauth docker configure. Recording the choice at configure time meansdocker pushuses the profile that was configured, whatever the order in.databrickscfg, and the helper never switches identity on its own.The choice is a CLI setting rather than part of a profile's identity, so it lives in
[__settings__]likedefault_profile. Keying it by registry host keeps one entry per registry, and re-pointing a profile at another workspace cannot carry the choice with it. Being in.databrickscfg, it followsDATABRICKS_CONFIG_FILE.This replaces the "remove the duplicate profile" hint that #7363 added in v1.25.0.
Follow-up: matching compares only the workspace ID and loopback vs remote host, not the deployment's DNS zone, so a profile on another Databricks deployment with the same workspace ID also matches, whether or not it is recorded.
Tests
ProfileForRegistry(recorded profile wins; missing, other-workspace and unsupported recorded profiles fail; no entry keeps the previous rules),GetDockerProfileandSetDockerProfile(new entry, switch, no-op without a write, other registries untouched and read as unset,default_profilekept),ClearDockerProfiles(clears only entries for the given profile, no write when nothing matches or the file is missing), andInspect(Docker config,PATHand profile selection are all required, and the reported profile in each case).cmd/auth/docker/{configure,configure-errors,token,help}. Configure switches to another profile and back, withhostreporting the profile Docker uses and whether it matches, and prints the resulting.databrickscfg.auth logout --deleteof the recorded profile clears its entry. A stale entry makeshostreport not configured and the helper fail. Token errors when several profiles match and none is recorded, and uses the recorded profile over an earlier logged-in one.go test ./cmd/... ./libs/dockercredentials/... ./libs/auth/... ./libs/databrickscfg/...andgo test ./acceptance -run 'TestAccept/(cmd|air|auth)/'pass, includingair/image-push, which parses theauth docker configureoutput. Lint, deadcode, whitespace and changelog checks pass.This pull request and its description were written by Isaac.