Commit 30f637f
authored
auth: handle account-only profiles cleanly for workspace and describe commands (#5340)
## Why
Two related bugs in a bug bash, both rooted in profiles created with
\`databricks auth login --skip-workspace\` (no \`workspace_id\`, or the
legacy \`workspace_id = none\` sentinel):
1. **Workspace commands** (e.g. \`databricks clusters list --profile
<account-only>\`) failed with the opaque backend error \"Credential was
not sent or was of an unsupported type for this API\" — the SDK
forwarded the literal sentinel as a routing identifier, or sent an
unrouted request to the account-plane.
2. **\`databricks auth describe --profile <account-only>\`** printed the
false-negative \`Unable to authenticate: Unable to load OAuth Config\`
on a perfectly valid profile — describe calls \`w.CurrentUser.Me()\`
after MustAnyClient, which hits the workspace plane without a
workspace_id and the backend rejects the call.
Reproduced both against \`db-deco-test.databricks.com\` with a real
\`--skip-workspace\` profile.
## Changes
- \`workspaceClientOrPrompt\` detects an account-only profile
(\`account_id\` set + \`workspace_id\` empty or the legacy \"none\"
sentinel + an explicit \`Profile\`) before any API call and returns a
typed \`ErrAccountOnlyProfile\` with an actionable message naming the
profile.
- \`MustAnyClient\` (used by \`auth describe\` and similar) recognizes
\`ErrAccountOnlyProfile\` and falls through to the account client, so
account-only profiles describe cleanly via the account plane.
- Workspace commands (\`MustWorkspaceClient\` directly) keep getting the
actionable error — they need a workspace.
After the fix on the same \`db-deco-test\` profile:
\`\`\`
$ databricks auth describe --profile bug2-test
Host: https://db-deco-test.databricks.com
Account ID: 968367da-...
Authenticated with: databricks-cli
✓ host: https://db-deco-test.databricks.com (from .databrickscfg)
✓ account_id: 968367da-... (from .databrickscfg)
✓ workspace_id: none (from .databrickscfg)
✓ profile: bug2-test (from --profile flag)
✓ auth_type: databricks-cli
...
$ databricks clusters list --profile bug2-test
Error: profile \"bug2-test\" has no workspace_id set (account-only);
this command requires a workspace.
Edit the profile to set workspace_id to a real ID, or pass --profile
with a workspace-scoped profile
\`\`\`
The env-var-only path (no \`Profile\` set) is intentionally left alone —
unified hosts can serve workspace APIs from the account host with just
\`DATABRICKS_HOST\` + \`DATABRICKS_ACCOUNT_ID\` + a token, and we don't
want to reject those.
## Test plan
- [x] Reproduced both bugs against \`db-deco-test.databricks.com\` with
a real \`--skip-workspace\`-created profile.
- [x] After the fix: \`auth describe --profile bug2-test\` succeeds and
shows account info; \`clusters list --profile bug2-test\` gives the
actionable error.
- [x] Existing valid SPOG workspace profile (with \`workspace_id\`)
still works against the same host — no regression.
- [x] New unit tests:
\`TestWorkspaceClientOrPromptRejectsAccountOnlyProfile\` (both shapes),
\`TestMustAnyClientFallsThroughOnAccountOnlyProfile\`.
- [x] \`go test ./cmd/root/...\`, \`./task checks\`, \`./task lint-q\`.1 parent 5e6847b commit 30f637f
2 files changed
Lines changed: 102 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
55 | 74 | | |
56 | 75 | | |
57 | 76 | | |
| |||
127 | 146 | | |
128 | 147 | | |
129 | 148 | | |
130 | | - | |
131 | | - | |
132 | | - | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
133 | 154 | | |
134 | 155 | | |
135 | 156 | | |
| |||
190 | 211 | | |
191 | 212 | | |
192 | 213 | | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
193 | 227 | | |
194 | 228 | | |
195 | 229 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
454 | 454 | | |
455 | 455 | | |
456 | 456 | | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
457 | 522 | | |
458 | 523 | | |
459 | 524 | | |
| |||
0 commit comments