-
Notifications
You must be signed in to change notification settings - Fork 59
Custom scopes support in M2M authentication #1388
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
Open
Tejas-Kochar
wants to merge
4
commits into
main
Choose a base branch
from
m2m
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
+152
−3
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
github-merge-queue bot
pushed a commit
that referenced
this pull request
Jan 4, 2026
## Summary + Adds new `Scopes` and `DisableOAuthRefreshToken` fields. + Adds support for parsing lists in config files. ## Notes - Environment variable support is **not** provided for scopes because we do not think users would actually want this. It can be easily added as a follow up if there are requests for it. ## Testing - Parsing logic tested by loading profiles from a test `.databrickscfg` file. Subsequent PRs add support for custom scopes in OAuth authentication methods: - M2M: #1388 - WIF: #1389 - U2M: #1390 <!-- This PR adds support for user-provided OAuth scopes across all OAuth authentication flows (M2M, U2M, and WIF/OIDC). Users can now request fine-grained permissions instead of the default `all-apis` scope. ## Review Guide 1. **Start with `config/config.go`** - Review the new `Scopes` and `DisableOAuthRefreshToken` fields and `GetScopes()` method 2. **Review each auth flow integration**: - `config/auth_m2m.go` (one-line change) - `config/auth_u2m.go` (passes scopes to PersistentAuth, adds `persistentAuthFactory` for testability) - `config/auth_default.go` (passes scopes to OIDC token source) - `credentials/u2m/persistent_auth.go` (new options, `offline_access` handling, `GetScopes()` for test introspection) - `config/experimental/auth/oidc/tokensource.go` (accepts scopes in config) 3. **Review `config/config_attribute.go`** - adds slice type support for config file parsing 4. **Review tests** - verify scope assertions match expected behavior and look for missing test cases. #### Backwards Compatibility - All three OAuth flows continue to use `all-apis` as the default scope. - U2M continues to append `offline_access` scope by default. ## Testing #### Shared Config Layer - **`TestConfigFile_Scopes`** - Loads profiles from `.databrickscfg`; calls `cfg.EnsureResolved()`; asserts `cfg.GetScopes()` returns correctly parsed and sorted values. #### M2M Flow - **`TestM2M_Scopes`** - Sets up mock HTTP transport expecting specific `scope` values; calls `Config.Authenticate()`; asserts the token request contains expected scopes. #### U2M Flow Tests are split across two files to test different responsibilities: **`config/auth_u2m_test.go`** - Tests scope propagation from Config to PersistentAuth: - **`TestU2MCredentials_Configure_DefaultScopes`** - Uses a capturing factory that creates a real `PersistentAuth` and spies on it; calls `u2mCredentials.Configure()` with nil scopes; asserts `PersistentAuth.GetScopes()` returns `["all-apis"]`. - **`TestU2MCredentials_Configure_CustomScopes`** - Same setup; calls `Configure()` with custom scopes; asserts they are passed through correctly. **`credentials/u2m/persistent_auth_test.go`** - Tests `offline_access` handling: - **`TestU2M_ScopesAndOfflineAccess`** - Sets up mock browser capturing the authorization URL; calls `PersistentAuth.Challenge()`; asserts the `scope` query parameter contains expected scopes with `offline_access` appended (or omitted when `disableOfflineAccess` is true). ### WIF/OIDC Flow - **`TestWIF_Scopes`** - Sets up mock HTTP transport expecting specific `scope` values; calls `TokenSource.Token()`; asserts the token exchange request contains expected scopes. - **`TestGithubOIDC_Scopes`** - Sets up mock HTTP transport for GitHub and Databricks endpoints; calls `Config.Authenticate()`; asserts scopes flow correctly through to the token exchange request. --> --- NO_CHANGELOG=true --------- Co-authored-by: Renaud Hartert <renaud.hartert@databricks.com>
|
If integration tests don't run automatically, an authorized user can run them manually by following the instructions below: Trigger: Inputs:
Checks will be approved automatically on success. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
One-line change passing configured scopes instead of hard-coded value "all-apis".
You might also see changes from parent branch #1374
Testing
Test the (mocked) authentication of requests configured for M2M with various different scopes (nil, empty, single, multiple unsorted).
Custom scopes tested for both Account and Workspace level requests.
NO_CHANGELOG=true