Skip to content

auth: clear error for PAT profile on SPOG without workspace_id#5341

Open
simonfaltum wants to merge 3 commits into
mainfrom
simonfaltum/auth-pat-spog-no-wid-error
Open

auth: clear error for PAT profile on SPOG without workspace_id#5341
simonfaltum wants to merge 3 commits into
mainfrom
simonfaltum/auth-pat-spog-no-wid-error

Conversation

@simonfaltum
Copy link
Copy Markdown
Member

Why

Personal access tokens are workspace-scoped. When a PAT profile points at a SPOG host (account-scoped OIDC discovery) without `workspace_id`, the SDK can't add the routing identifier, the request lands on the account-plane where PATs aren't accepted, and the user sees the opaque error "Credential was not sent or was of an unsupported type for this API" from the auth endpoint. Reported in a bug bash.

Reproduced against `db-deco-test.databricks.com`:
```
[spog-pat-no-wid]
host = https://db-deco-test.databricks.com
token = dapi...

$ databricks auth describe --profile spog-pat-no-wid
Unable to authenticate: Credential was not sent or was of an unsupported type for this API. [ReqId: ...]
```

Changes

  • Before: PAT-on-SPOG without `workspace_id` failed with the opaque credentials error.
  • Now: `workspaceClientOrPrompt` detects the combination (`auth_type=pat` + SPOG discovery signal + `workspace_id` empty) before any API call and returns a message that names the profile, explains the routing constraint, and points at the fix: add `workspace_id = ` for the workspace the token was minted in.

`databricks auth describe --profile spog-pat-no-wid` now prints:
```
Unable to authenticate: profile "spog-pat-no-wid" uses PAT auth on a SPOG host but is missing workspace_id; PATs are workspace-scoped, so the request can't be routed. Edit the profile to add workspace_id = matching the workspace the token was minted in
```

Test plan

  • Reproduced against `db-deco-test.databricks.com` with a PAT profile that has no `workspace_id`; saw the opaque "Credential was not sent" error.
  • Same profile with the fix → clear, actionable error message naming the profile and pointing at the fix (verified with `auth describe` and `current-user me`).
  • Existing `spog-deco-aws` (PAT with valid `workspace_id`) still works against the same host — no regression.
  • New unit tests: `TestIsPATOnSPOGWithoutWorkspaceID`, `TestWorkspaceClientOrPromptRejectsPATOnSPOGWithoutWorkspaceID`
  • `go test ./cmd/root/...`, `./task checks`, `./task lint-q`

Personal access tokens are workspace-scoped. When a PAT profile points
at a SPOG host (account-scoped OIDC discovery) without `workspace_id`,
the SDK can't add the routing identifier; the request lands on the
account-plane where PATs aren't accepted, and the user sees the opaque
"Credential was not sent or was of an unsupported type for this API"
error from the auth endpoint.

Detect this combination (auth_type=pat, SPOG discovery signal,
workspace_id empty) up front in `workspaceClientOrPrompt` and return a
message that names the profile, explains the routing constraint, and
points at the fix: add `workspace_id = <id>` for the workspace the
token was minted in.

Co-authored-by: Isaac
@github-actions
Copy link
Copy Markdown
Contributor

Waiting for approval

Based on git history, these people are best suited to review:

  • @pietern -- recent work in cmd/root/
  • @denik -- recent work in cmd/root/

Eligible reviewers: @Divyansh-db, @chrisst, @hectorcast-db, @mihaimitrea-db, @parthban-db, @rauchy, @renaudhartert-db, @tanmay-db, @tejaskochar-db

Suggestions based on git history. See OWNERS for ownership rules.

@eng-dev-ecosystem-bot
Copy link
Copy Markdown
Collaborator

eng-dev-ecosystem-bot commented May 27, 2026

Commit: 32ce366

Run: 26513315313

GPT review pointed out the existing test seeded AuthType and DiscoveryURL
manually, so it didn't prove the detector still fires when those fields
come from the SDK during NewWorkspaceClient (the realistic flow).

Add a test that writes a .databrickscfg with only `host` and `token`
(matching the bug bash repro), points the host at an httptest server
serving SPOG-style .well-known metadata, and runs through the public
workspaceClientOrPrompt entry point. AuthType is populated by the SDK
credential probe; DiscoveryURL is populated by host metadata
resolution. The detector still catches the case.

Co-authored-by: Isaac
The Windows GitHub runner doesn't have IPv6 configured. httptest.NewServer
tried 127.0.0.1 first and fell through to "[::1]:0" on retry, then
panicked: "listen tcp6 [::1]:0: socket: The requested service provider
could not be loaded or initialized." Build the listener directly with
net.Listen("tcp4", "127.0.0.1:0") and hand it to httptest.

Co-authored-by: Isaac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants