Commit 278e906
authored
Return clear error when
## Summary
Fixes #1939
When `databricks auth token --profile <m2m-profile>` is used with a
profile that has `client_id`/`client_secret` configured (M2M / service
principal auth), the command currently either:
1. **Silently returns the wrong token** — a cached U2M token for the
same host, identifying the user instead of the service principal
2. **Triggers an interactive browser login** — pushing the user into U2M
auth with no explanation
This PR adds early detection of M2M profiles and returns a clear error:
```
Error: profile "my-sp" uses M2M authentication (client_id/client_secret).
`databricks auth token` only supports U2M (user-to-machine) authentication tokens.
To authenticate as a service principal, use the Databricks SDK directly
```
### Changes
- Added `ClientID` field to `profile.Profile` struct (populated from
`.databrickscfg`)
- Added check in `loadToken` that detects M2M profiles before attempting
U2M token lookup
- After host-based profile resolution, `existingProfile` is reloaded so
the M2M guard also covers `--host` invocations that resolve to a single
M2M profile
- Works for all three profile resolution paths: `--profile` flag,
positional argument, and host-based matching
## Test plan
- [x] `M2M profile returns clear error` — explicit `--profile` targeting
M2M profile
- [x] `M2M profile detected via positional arg` — positional arg
resolves to M2M profile
- [x] `M2M profile detected via host resolution` — `--host` uniquely
matches an M2M profile
- [x] All existing `TestToken_loadToken` cases pass (no regressions)
- [x] `make checks` passes
- [x] `make lintfull` passesauth token is used with M2M profile (#4594)1 parent 79d8237 commit 278e906
File tree
4 files changed
+78
-14
lines changed- cmd/auth
- libs/databrickscfg/profile
4 files changed
+78
-14
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
205 | 205 | | |
206 | 206 | | |
207 | 207 | | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
208 | 212 | | |
209 | 213 | | |
| 214 | + | |
210 | 215 | | |
211 | 216 | | |
212 | 217 | | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
213 | 229 | | |
214 | 230 | | |
215 | 231 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
128 | 133 | | |
129 | 134 | | |
130 | 135 | | |
| |||
526 | 531 | | |
527 | 532 | | |
528 | 533 | | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
529 | 575 | | |
530 | 576 | | |
531 | 577 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
89 | 90 | | |
90 | 91 | | |
91 | 92 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
0 commit comments