Skip to content

fix(auth): honor custom OAuth M2M scopes without forcing all-apis - #493

Merged
vuanhphung merged 3 commits into
mainfrom
fix/m2m-custom-scopes
Oct 6, 2026
Merged

vuanhphung merged 3 commits into
mainfrom
fix/m2m-custom-scopes

Conversation

@vuanhphung

Copy link
Copy Markdown
Collaborator

Description

NewAuthenticatorWithScopes always appended all-apis, so service principals whose OAuth secret is scoped (e.g. sql only) failed with access_denied: Scopes 'all-apis' are not assigned to the client. Non-empty scopes are now requested as given; all-apis remains the default when none are passed, so NewAuthenticator is unchanged. This matches JDBC's Auth_Scope behavior (databricks/databricks-jdbc#1707).

On the kernel backend, custom M2M scopes were rejected because set_auth_m2m takes no scopes. The bundled kernel already exposes kernel_session_config_set_oauth_scopes, which applies to client-secret M2M (databricks/databricks-sql-kernel#263), so the driver now forwards the scopes through it.

Behavior change: callers passing custom scopes to NewAuthenticatorWithScopes no longer get all-apis appended.

Fixes #476.

Testing

  • go vet ./...; go test ./auth/... ./internal/config/... ./internal/backend/... .
  • CGO_ENABLED=1 go test -tags databricks_kernel ./internal/backend/kernel/ . (includes a new TestSetAuthByMode case calling the real scopes setter)
  • Not exercised against a live workspace with a sql-scoped secret.

This pull request and its description were written by Isaac.


This PR was created with GitHub MCP.

NewAuthenticatorWithScopes always appended all-apis, so service principals
with scoped secrets (e.g. sql only) failed with access_denied. Non-empty
scopes are now requested as given; all-apis remains the default when none
are passed, so NewAuthenticator is unchanged.

The kernel backend now forwards M2M scopes via set_oauth_scopes instead of
rejecting custom scopes.

Fixes #476

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>

@peco-review-bot peco-review-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verdict: 1 Nit

Looks good — a clean, least-privilege fix that honors custom OAuth M2M scopes instead of force-appending all-apis, with matching Thrift and kernel wiring. Verified the removed M2MScopesSupported has no remaining callers, the kernel header confirms set_oauth_scopes semantics (comma-separated, M2M default all-apis, applied after mode selection), and test imports stay used so there's no build break. Only a cosmetic nit: m2m.GetScopes's hostName parameter is now unused.

Other findings

  • ⚪ Nit — GetScopes no longer references its hostName parameter — it's now dead. Keeping the signature is reasonable for API compatibility (it's exported and mirrors oauth.GetScopes), so this is purely cosmetic; a _ = hostName or a doc note that the arg is retained only for signature parity would make the intent explicit. No action required.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
@vuanhphung vuanhphung added the integration-test Preview the Go integration replay suite on this PR label Oct 6, 2026
@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown

Go integration tests triggered (thrift / replay). View workflow runs.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
@github-actions github-actions Bot removed the integration-test Preview the Go integration replay suite on this PR label Oct 6, 2026
@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown

Integration test approval reset.

New commits were pushed to this PR. Label(s) integration-test were removed for security.

A maintainer must re-review and re-add a label to preview tests again. (The real gate runs in the merge queue.)

Latest commit: efa7c9d

@peco-review-bot peco-review-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ No issues identified by the review bot.

@vuanhphung vuanhphung added the integration-test Preview the Go integration replay suite on this PR label Oct 6, 2026
@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown

Go integration tests triggered (thrift / replay). View workflow runs.

@vuanhphung
vuanhphung enabled auto-merge October 6, 2026 15:27
@vuanhphung
vuanhphung added this pull request to the merge queue Oct 6, 2026
Merged via the queue into main with commit 7fa1003 Oct 6, 2026
18 checks passed
@vuanhphung
vuanhphung deleted the fix/m2m-custom-scopes branch October 6, 2026 15:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-assisted integration-test Preview the Go integration replay suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OAuth M2M fails with scoped secrets because all-apis is always requested

2 participants