Skip to content
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

Detect mismatch between host defined in config and env variable #2549

Merged
merged 12 commits into from
Mar 25, 2025

Conversation

ilyakuz-db
Copy link
Contributor

@ilyakuz-db ilyakuz-db commented Mar 22, 2025

Changes

  • Adds a mismatch check when host is defined in config and as an env variable
  • https:// prefix is ignored during validation on host mismatch, both in env and profiles

Why

If I defined both DATABRICKS_TOKEN and DATABRICKS_HOST I expect this token to be used only for requests to DATABRICKS_HOST, while now we have it added to w.CurrentUser.Me requests to the hosts defined in the config

Tests

Added acceptance tests

@@ -7,19 +7,14 @@ Warning: Variable interpolation is not supported for fields that configure authe
Interpolation is not supported for the field workspace.host. Please set
the DATABRICKS_HOST environment variable if you wish to configure this field at runtime.

Error: failed during request visitor: parse "https://${var.host}": invalid character "{" in host name
Error: cannot resolve bundle auth configuration: config host mismatch: DATABRICKS_HOST is defined as [DATABRICKS_URL], but CLI configured to use ${var.host}
Copy link
Contributor Author

@ilyakuz-db ilyakuz-db Mar 22, 2025

Choose a reason for hiding this comment

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

Just in case - we have a warning displayed above that explains incorrect usage of variables in auth-related fields

@@ -1,26 +0,0 @@
package databrickscfg
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved to shared package

return u1.Host == u2.Host
}

func fixUrlIfNeeded(s string) string {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Apparently u := url.Parse('foo.com') will put foo.com in u.Path instead of u.Host so we're handling such cases explicitly

hostFromProfile := normalizeHost(match.Key("host").Value())
if hostFromProfile != "" && host != "" && hostFromProfile != host {
hostFromProfile := workspace.NormalizeHost(match.Key("host").Value())
if hostFromProfile != "" && host != "" && !workspace.MatchHost(hostFromProfile, host) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added same ignore-scheme-behavior for config-defined hosts

@@ -94,6 +95,8 @@ func configureBundle(cmd *cobra.Command, b *bundle.Bundle) (*bundle.Bundle, diag
return b, diags
}

diags = diags.Extend(bundle.Apply(ctx, b, validate.NoInterpolationInAuthConfig()))
Copy link
Contributor

Choose a reason for hiding this comment

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

You can actually convert the whole NoInterpolationInAuthConfig mutator in a usual Go function and don't use bundle.Apply here at all because this mutator does not actually mutate anything

@@ -149,3 +149,34 @@ func TestWorkspaceVerifyProfileForHost(t *testing.T) {
assert.ErrorContains(t, err, "config host mismatch")
})
}

func TestWorkspaceValidateConfigAndEnvHost(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you instead convert this to acceptance test?

@ilyakuz-db ilyakuz-db added this pull request to the merge queue Mar 25, 2025
Merged via the queue into main with commit 314766a Mar 25, 2025
9 checks passed
@ilyakuz-db ilyakuz-db deleted the env-vs-config-host-mismatch branch March 25, 2025 16:59
deco-sdk-tagging bot added a commit that referenced this pull request Mar 26, 2025
## Release v0.245.0

### Bundles
* Processing 'artifacts' section is now done in "bundle validate" (adding defaults, inferring "build", asserting required fields) ([#2526])(#2526))
* When uploading artifacts, include relative path in log message ([#2539])(#2539))
* Added support for clusters in deployment bind/unbind commands ([#2536](#2536))
* Added support for volumes in deployment bind/unbind commands ([#2527](#2527))
* Added support for dashboards in deployment bind/unbind commands ([#2516](#2516))
* Added support for registered models in deployment bind/unbind commands ([#2556](#2556))
* Added a mismatch check when host is defined in config and as an env variable ([#2549](#2549))
* New attribute on artifacts entries: `dynamic_version`. When set to true, it patches the wheel with dynamic version suffix so it is always used by Databricks environments, even if original wheel version is the same. Intended for development loop on interactive clusters. ([#2520](#2520))
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.

2 participants