-
Notifications
You must be signed in to change notification settings - Fork 229
Invalidate cached OAuth tokens when profiles change #6427
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
base: main
Are you sure you want to change the base?
Changes from all commits
75fb3af
ab374d0
c69fa5d
f20a48b
aa3b01d
091ffb1
295f961
6177888
8311aac
19dbc61
04141ee
81da84a
49fc74d
a1df656
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| * Require a new OAuth login before reusing cached credentials after the corresponding profile configuration changes. ([#6427](https://github.com/databricks/cli/pull/6427)) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
|
|
||
| >>> [CLI] auth login --host [DATABRICKS_URL] --profile fingerprint-test --scopes jobs | ||
| Profile fingerprint-test was successfully saved | ||
|
|
||
| >>> musterr [CLI] clusters list --profile fingerprint-test | ||
| Error: error getting token: cache: profile "fingerprint-test" has changed since the last login; run `databricks auth login --profile "fingerprint-test"` to sign in again |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # Ordinary workspace commands must reject a cached token after its profile changes. | ||
| sethome "./home" | ||
| export BROWSER="browser.py" | ||
| export DATABRICKS_AUTH_STORAGE=plaintext | ||
|
|
||
| # Login creates a cached token bound to the saved profile. | ||
| trace $CLI auth login --host $DATABRICKS_HOST --profile fingerprint-test --scopes jobs | ||
|
|
||
| # Simulate changing an authentication-related profile field by hand. | ||
| sed -i.bak 's/scopes = jobs/scopes = all-apis,sql/' "./home/.databrickscfg" | ||
|
|
||
| # An ordinary workspace command must reject the token bound to the old profile. | ||
| trace musterr $CLI clusters list --profile fingerprint-test |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| EnvMatrix.DATABRICKS_BUNDLE_ENGINE = ["direct"] | ||
|
|
||
| Ignore = [ | ||
| "home", | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,11 @@ | ||
| # Create the profile and a valid profile-bound token that can be refreshed. | ||
| setup_test_profile | ||
| setup_test_token_cache | ||
|
|
||
| # Replace the valid refresh token with one the fake OIDC server rejects. | ||
| jq '.tokens["test-profile"].refresh_token = "invalid-refresh-token"' \ | ||
| "./home/.databricks/token-cache.json" > "./token-cache.json" | ||
| mv "./token-cache.json" "./home/.databricks/token-cache.json" | ||
|
|
||
| # The CLI must report that the user needs to log in again. | ||
| musterr $CLI auth token --profile test-profile --force-refresh |
This file was deleted.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
|
|
||
| >>> musterr [CLI] auth token --profile test-profile | ||
| Error: cache: cached credentials for profile "test-profile" predate profile change detection; run `databricks auth login --profile "test-profile"` to sign in again |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # A token without fingerprint metadata must require a new login. | ||
| # Create the profile that the legacy cached token belongs to. | ||
| setup_test_profile | ||
|
|
||
| # Install a cache written by an older CLI that omits profile_fingerprint. | ||
| mkdir -p "./home/.databricks" | ||
| cp "./token-cache.json" "./home/.databricks/token-cache.json" | ||
|
|
||
| # The CLI must reject a cached token whose profile binding cannot be verified. | ||
| trace musterr $CLI auth token --profile test-profile |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| EnvMatrix.DATABRICKS_BUNDLE_ENGINE = ["direct"] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "version": 1, | ||
| "tokens": { | ||
| "test-profile": { | ||
| "access_token": "cached-access-token", | ||
| "token_type": "Bearer", | ||
| "refresh_token": "test-refresh-token", | ||
| "expiry": "2099-01-01T00:00:00Z" | ||
| } | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
|
|
||
| >>> [CLI] auth login --host [DATABRICKS_URL] --profile fingerprint-test --scopes jobs | ||
| Profile fingerprint-test was successfully saved | ||
|
|
||
| >>> musterr [CLI] auth token --profile fingerprint-test | ||
| Error: cache: profile "fingerprint-test" has changed since the last login; run `databricks auth login --profile "fingerprint-test"` to sign in again | ||
| Token cache unchanged |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # A cached token must be rejected without mutation after its profile changes. | ||
| sethome "./home" | ||
| export BROWSER="browser.py" | ||
| export DATABRICKS_AUTH_STORAGE=plaintext | ||
|
|
||
| # Login creates a cached token bound to the saved profile. | ||
| trace $CLI auth login --host $DATABRICKS_HOST --profile fingerprint-test --scopes jobs | ||
|
|
||
| # Keep the original cache so we can verify that rejection does not modify it. | ||
| cp "./home/.databricks/token-cache.json" "./token-cache.before.json" | ||
|
|
||
| # Simulate changing an authentication-related profile field by hand. | ||
| sed -i.bak 's/scopes = jobs/scopes = all-apis,sql/' "./home/.databrickscfg" | ||
|
|
||
| # auth token must reject the token bound to the old profile. | ||
| trace musterr $CLI auth token --profile fingerprint-test | ||
|
|
||
| # Rejecting the stale token must leave the cached credentials unchanged. | ||
| if cmp -s "./token-cache.before.json" "./home/.databricks/token-cache.json"; then | ||
| echo "Token cache unchanged" | ||
| else | ||
| echo "Token cache changed" | ||
| fi |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| EnvMatrix.DATABRICKS_BUNDLE_ENGINE = ["direct"] | ||
|
|
||
| Ignore = [ | ||
| "home", | ||
| "token-cache.before.json", | ||
| ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be a call site comment? It does not tell me much about the function itself.