Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,10 @@ func (c *Config) resolveHostMetadata(ctx context.Context) {
c.Cloud = c.Environment().Cloud
logger.Debugf(ctx, "Resolved cloud from hostname: %q", c.Cloud)
}
if c.TokenAudience == "" && meta.WorkspaceID == "" && c.AccountID != "" {
logger.Debugf(ctx, "Setting token_audience to account_id for account host: %q", c.AccountID)
c.TokenAudience = c.AccountID
}
if c.DiscoveryURL == "" {
if meta.OIDCEndpoint == "" {
logger.Warnf(ctx, "Host metadata missing oidc_endpoint; skipping discovery URL resolution")
Expand Down
63 changes: 63 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,69 @@ func TestEnsureResolved_HostMetadata_MissingAccountIdWithPlaceholder_Warns(t *te
assert.Empty(t, cfg.DiscoveryURL)
}

func TestApplyHostMetadata_SetsTokenAudienceForAccountHost(t *testing.T) {
noopLoader := mockLoader(func(cfg *Config) error { return nil })
cfg := &Config{
Host: testHMHost,
Experimental_IsUnifiedHost: true,
Loaders: []Loader{noopLoader},
HTTPTransport: fixtures.SliceTransport{
{
Method: "GET",
Resource: "/.well-known/databricks-config",
Status: 200,
Response: `{"oidc_endpoint": "` + testHMHost + `/oidc", "account_id": "` + testHMAccountID + `", "cloud": "AWS"}`,
},
},
}
err := cfg.EnsureResolved()
require.NoError(t, err)
// No workspace_id and has account_id β†’ token audience should be set
assert.Equal(t, testHMAccountID, cfg.TokenAudience)
}

func TestApplyHostMetadata_NoTokenAudienceForWorkspaceHost(t *testing.T) {
noopLoader := mockLoader(func(cfg *Config) error { return nil })
cfg := &Config{
Host: testHMHost,
Experimental_IsUnifiedHost: true,
Loaders: []Loader{noopLoader},
HTTPTransport: fixtures.SliceTransport{
{
Method: "GET",
Resource: "/.well-known/databricks-config",
Status: 200,
Response: `{"oidc_endpoint": "` + testHMHost + `/oidc", "account_id": "` + testHMAccountID + `", "workspace_id": "` + testHMWorkspaceID + `", "cloud": "AWS"}`,
},
},
}
err := cfg.EnsureResolved()
require.NoError(t, err)
// Has workspace_id β†’ token audience should NOT be set
assert.Empty(t, cfg.TokenAudience)
}

func TestApplyHostMetadata_DoesNotOverrideExistingTokenAudience(t *testing.T) {
noopLoader := mockLoader(func(cfg *Config) error { return nil })
cfg := &Config{
Host: testHMHost,
TokenAudience: "custom-audience",
Experimental_IsUnifiedHost: true,
Loaders: []Loader{noopLoader},
HTTPTransport: fixtures.SliceTransport{
{
Method: "GET",
Resource: "/.well-known/databricks-config",
Status: 200,
Response: `{"oidc_endpoint": "` + testHMHost + `/oidc", "account_id": "` + testHMAccountID + `", "cloud": "AWS"}`,
},
},
}
err := cfg.EnsureResolved()
require.NoError(t, err)
assert.Equal(t, "custom-audience", cfg.TokenAudience)
}

func TestConfig_ResolveHostMetadata_Clouds(t *testing.T) {
tests := []struct {
name string
Expand Down
Loading