Fix host based auth conflicting with DEFAULT profile (#309)

## Changes
Consider the following host based configuration:
```
bundle:
  name: job_with_file_task

workspace:
  host: https://e2-dogfood.staging.cloud.databricks.com/
```

If you have a DEFAULT profile, then this host is ignored. The solution
proposed here is to remove the profile config loader if host is
explicitly specified in the bundle config.

This does come with a cost, namely that if a `DATABRICKS_CONFIG_PROFILE`
env var will be ignored, which maybe goes against unified auth spec

The ideal solution here is probably to make a change to go-SDK to not
select DEFAULT profile if host is not empty

## Tests
<!-- How is this tested? -->
This commit is contained in:
shreyas-goenka 2023-04-05 18:12:11 +02:00 committed by GitHub
parent d7ac265536
commit 6feaed4990
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 7 deletions

View File

@ -88,17 +88,21 @@ func (w *Workspace) Client() (*databricks.WorkspaceClient, error) {
AzureLoginAppID: w.AzureLoginAppID,
}
// HACKY fix to not used host based auth when the profile is already set
profile := os.Getenv("DATABRICKS_CONFIG_PROFILE")
// If only the host is configured, we try and unambiguously match it to
// a profile in the user's databrickscfg file. Override the default loaders.
if w.Host != "" && w.Profile == "" && profile == "" {
cfg.Loaders = []config.Loader{
// Defaults.
// Load auth creds from env vars
config.ConfigAttributes,
config.ConfigFile,
// Our loader that resolves a profile from the host alone.
// This only kicks in if the above loaders don't configure auth.
databrickscfg.ResolveProfileFromHost,
}
}
return databricks.NewWorkspaceClient(&cfg)
}