Validate Databricks CLI token scopes against SDK configuration#689
Open
tejaskochar-db wants to merge 4 commits intomainfrom
Open
Validate Databricks CLI token scopes against SDK configuration#689tejaskochar-db wants to merge 4 commits intomainfrom
tejaskochar-db wants to merge 4 commits intomainfrom
Conversation
Detects when a cached Databricks CLI token was issued with different OAuth scopes than what the SDK configuration requires. Surfaces an actionable error telling the user how to re-authenticate instead of silently making requests with the wrong scopes. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.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. |
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
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
Detects when a cached Databricks CLI token was issued with different OAuth scopes than what the SDK configuration requires, and surfaces an actionable error telling the user how to re-authenticate instead of silently making requests with the wrong scopes.
Mirrors Python SDK PR: databricks/databricks-sdk-py#1286
Why
The
databricks auth tokenCLI command does not accept scopes — it returns whatever token was cached from the lastdatabricks auth login. If a user configures specific scopes in the SDK (e.g.scopes=["sql"], either directly in code or loaded from a CLI profile), but their cached token was issued with different scopes (e.g.all-apis), every API request silently uses the wrong scopes. This is confusing to debug because authentication succeeds — it just grants the wrong permissions.This is especially likely now that the CLI writes scopes into profiles, meaning users who switch between different scope configurations will hit this without realizing it.
What changed
Behavioral changes
Scope mismatch error — When scopes are explicitly set in the SDK config and the cached CLI token's JWT
scopeclaim doesn't match, aDatabricksExceptionis raised with a message like:Credential chain fallthrough — When
authTypeis not explicitly set to"databricks-cli"(i.e. we're being tried as part of the default credential chain), a scope mismatch logs a warning and returnsnullso other providers get a chance. WhenauthType="databricks-cli"is explicitly set, the error propagates immediately.offline_accessis ignored during comparison — This scope controls refresh token issuance, not API permissions. Its presence or absence on either side does not trigger a mismatch.Validation is skipped when scopes are not configured —
getScopes()defaults to["all-apis"]when nothing is set, which would cause false-positive mismatches. Validation only runs when scopes are explicitly set.Internal changes
DatabricksCliCredentialsProvider.validateTokenScopes()— Decodes the JWTscopeclaim (handling both space-delimited strings and JSON arrays), filters outoffline_access, and compares against configured scopes using strict set equality.DatabricksCliCredentialsProvider.getJwtClaims()— Decodes JWT payload usingBase64.getUrlDecoder()(URL-safe base64 per RFC 7519).DatabricksConfig.isScopesExplicitlySet()— Returns true when the rawscopesfield is non-null and non-empty, covering both programmatic configuration and config file loading via reflection.How is this tested?
offline_accessfiltering (both directions), scope claim as list, non-JWT tokens (skip), no scope claim (skip), and error message format with re-auth command.isScopesExplicitlySet()flag behavior.🤖 Generated with Claude Code