-
Notifications
You must be signed in to change notification settings - Fork 231
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
Open
mihaimitrea-db
wants to merge
14
commits into
main
Choose a base branch
from
auth-profile-fingerprint
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
Changes from 3 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
75fb3af
auth: invalidate cached tokens when profiles change
mihaimitrea-db ab374d0
acceptance: fix profile fingerprint fixtures
mihaimitrea-db c69fa5d
changelog: update profile fingerprint entry
mihaimitrea-db f20a48b
auth: compute fingerprints from loaded profiles
mihaimitrea-db aa3b01d
acceptance: document profile fingerprint test flows
mihaimitrea-db 091ffb1
acceptance: keep refresh fault local to test
mihaimitrea-db 295f961
auth: fingerprint resolved profile config
mihaimitrea-db 6177888
acceptance: isolate invalid refresh token test
mihaimitrea-db 8311aac
auth: reject tokens for missing profiles
mihaimitrea-db 19dbc61
auth: normalize scopes in profile fingerprints
mihaimitrea-db 04141ee
auth: simplify profile fingerprint tests
mihaimitrea-db 81da84a
auth: normalize hosts in profile fingerprints
mihaimitrea-db 49fc74d
auth: simplify profile fingerprint tests
mihaimitrea-db a1df656
acceptance: clarify stale account logout flow
mihaimitrea-db File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| 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)) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| #!/usr/bin/env python3 | ||
|
|
||
| import hashlib | ||
| import sys | ||
|
|
||
|
|
||
| def append_uvarint(data, value): | ||
| while value >= 0x80: | ||
| data.append((value & 0x7F) | 0x80) | ||
| value >>= 7 | ||
| data.append(value) | ||
|
|
||
|
|
||
| values = dict(argument.split("=", maxsplit=1) for argument in sys.argv[1:]) | ||
| serialized = bytearray() | ||
| for key in sorted(values): | ||
| value = values[key] | ||
| append_uvarint(serialized, len(key.encode())) | ||
| serialized.extend(key.encode()) | ||
| append_uvarint(serialized, len(value.encode())) | ||
| serialized.extend(value.encode()) | ||
|
|
||
| print(hashlib.sha256(serialized).hexdigest()) |
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
2 changes: 2 additions & 0 deletions
2
acceptance/cmd/auth/token/legacy-profile-fingerprint/out.test.toml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
acceptance/cmd/auth/token/legacy-profile-fingerprint/output.txt
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
| 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 |
10 changes: 10 additions & 0 deletions
10
acceptance/cmd/auth/token/legacy-profile-fingerprint/script
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # A token without fingerprint metadata must require a new login. | ||
| setup_test_profile | ||
| setup_test_token_cache | ||
|
|
||
| # Tokens created before profile fingerprinting require one new interactive login. | ||
| jq 'del(.tokens["test-profile"].profile_fingerprint)' \ | ||
| "./home/.databricks/token-cache.json" > "./token-cache.json" | ||
| mv "./token-cache.json" "./home/.databricks/token-cache.json" | ||
|
|
||
| trace musterr $CLI auth token --profile test-profile |
3 changes: 3 additions & 0 deletions
3
acceptance/cmd/auth/token/legacy-profile-fingerprint/test.toml
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Ignore = [ | ||
| "home", | ||
| ] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
| 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 |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # A cached token must be rejected without mutation after its profile changes. | ||
| sethome "./home" | ||
| export BROWSER="browser.py" | ||
| export DATABRICKS_AUTH_STORAGE=plaintext | ||
|
|
||
| trace $CLI auth login --host $DATABRICKS_HOST --profile fingerprint-test --scopes jobs | ||
|
|
||
| cp "./home/.databricks/token-cache.json" "./token-cache.before.json" | ||
|
|
||
| # Editing any parsed profile value must block cached-token reuse. | ||
| sed -i.bak 's/scopes = jobs/scopes = all-apis,sql/' "./home/.databrickscfg" | ||
| trace musterr $CLI auth token --profile fingerprint-test | ||
|
|
||
| if cmp -s "./token-cache.before.json" "./home/.databricks/token-cache.json"; then | ||
| echo "Token cache unchanged" | ||
| else | ||
| echo "Token cache changed" | ||
| fi |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| Ignore = [ | ||
| "home", | ||
| "token-cache.before.json", | ||
| ] |
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
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.