Hi team! We are having trouble with service principal authentication following the introduction of scoped OAuth secrets. The M2M authenticator in databricks-sql-go unconditionally requests all-apis, but all-apis is no longer the default in the UI.
Steps to reproduce
- Create a Databricks service principal with access to a SQL warehouse.
- Generate an OAuth secret restricted to the
sql scope.
- Verify the credential directly:
curl --request POST \
--url "https://<workspace-host>/oidc/v1/token" \
--user "<client-id>:<client-secret>" \
--data-urlencode "grant_type=client_credentials" \
--data-urlencode "scope=sql"
This succeeds and returns a token with scope sql.
- Connect using the Go driver's M2M authenticator:
authenticator := m2m.NewAuthenticator(
clientID,
clientSecret,
workspaceHost,
)
connector, err := dbsql.NewConnector(
dbsql.WithServerHostname(workspaceHost),
dbsql.WithPort(443),
dbsql.WithHTTPPath(warehouseHTTPPath),
dbsql.WithAuthenticator(authenticator),
)
if err != nil {
return err
}
db := sql.OpenDB(connector)
defer db.Close()
var result int
err = db.QueryRowContext(context.Background(), "SELECT 1").Scan(&result)
The connection fails before opening the SQL session:
oauth2: "access_denied" "Scopes 'all-apis' are not assigned to the client <redacted>"
Root cause
NewAuthenticatorWithScopes calls GetScopes, which always appends all-apis:
func GetScopes(hostName string, scopes []string) []string {
if !oauth.HasScope(scopes, "all-apis") {
scopes = append(scopes, "all-apis")
}
return scopes
}
The code comments say the behavior matches the underlying kernel unconditionally requiring all-apis.
Suggested fix: Investigate whether NewAuthenticatorWithScopes can pass through nonempty caller-provided scopes.
Thank you!
Hi team! We are having trouble with service principal authentication following the introduction of scoped OAuth secrets. The M2M authenticator in
databricks-sql-gounconditionally requestsall-apis, butall-apisis no longer the default in the UI.Steps to reproduce
sqlscope.This succeeds and returns a token with scope
sql.The connection fails before opening the SQL session:
Root cause
NewAuthenticatorWithScopescallsGetScopes, which always appendsall-apis:The code comments say the behavior matches the underlying kernel unconditionally requiring
all-apis.Suggested fix: Investigate whether
NewAuthenticatorWithScopescan pass through nonempty caller-provided scopes.Thank you!