Repository navigation
Apply the not-an-agent header guard to the remaining CLI SDK clients #8144
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
simonfaltum
wants to merge
8
commits into
skills/noagentsdk-the-sdk-agent-header-follows-databricks
Choose a base branch
from
skills/noagentsdk2-apply-the-agent-header-guard-to-the-rema
base: skills/noagentsdk-the-sdk-agent-header-follows-databricks
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.
+438
−14
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6532d94
libs/agent: apply the not-an-agent header guard to the remaining SDK …
simonfaltum 95232b1
Merge base tip into the not-an-agent header branch
simonfaltum 4089a20
acceptance: keep the api not-an-agent request path intact on Windows
simonfaltum bc58ccc
Merge base tip into the not-an-agent SDK header branch
simonfaltum 8283226
cmd: apply the not-an-agent header before host metadata resolves
simonfaltum b0d95ed
cmd/labs: answer the not-an-agent cluster call without a listener
simonfaltum 15161a7
Apply the not-an-agent header guard to the aitools telemetry upload c…
simonfaltum 496696c
Reword the guard-before-resolve comments
simonfaltum 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 @@ | ||
| Cloud = false |
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,39 @@ | ||
|
|
||
| === With the variable set, the request has no agent token | ||
|
|
||
| >>> DATABRICKS_NOT_AN_AGENT=1 CLAUDECODE=1 [CLI] api get /api/2.0/clusters/list | ||
| { | ||
| "headers": { | ||
| "Authorization": [ | ||
| "Bearer [DATABRICKS_TOKEN]" | ||
| ], | ||
| "User-Agent": [ | ||
| "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/api_get cmd-exec-id/[UUID][0] interactive/none auth/pat" | ||
| ], | ||
| "X-Databricks-Workspace-Id": [ | ||
| "[WORKSPACE_ID]" | ||
| ] | ||
| }, | ||
| "method": "GET", | ||
| "path": "/api/2.0/clusters/list" | ||
| } | ||
|
|
||
| === With the variable unset, the request carries the agent token | ||
|
|
||
| >>> CLAUDECODE=1 [CLI] api get /api/2.0/clusters/list | ||
| Databricks skills are not installed. To work with Databricks reliably, first run: databricks aitools install | ||
| { | ||
| "headers": { | ||
| "Authorization": [ | ||
| "Bearer [DATABRICKS_TOKEN]" | ||
| ], | ||
| "User-Agent": [ | ||
| "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/api_get cmd-exec-id/[UUID][1] interactive/none aitools-agent/none auth/pat agent/claude-code" | ||
| ], | ||
| "X-Databricks-Workspace-Id": [ | ||
| "[WORKSPACE_ID]" | ||
| ] | ||
| }, | ||
| "method": "GET", | ||
| "path": "/api/2.0/clusters/list" | ||
| } |
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,9 @@ | ||
| # The api command builds its own SDK client, so DATABRICKS_NOT_AN_AGENT must drop the agent token from its User-Agent. | ||
| title "With the variable set, the request has no agent token" | ||
| # MSYS_NO_PATHCONV stops Git Bash on Windows from rewriting the leading slash of the API path. | ||
| MSYS_NO_PATHCONV=1 trace DATABRICKS_NOT_AN_AGENT=1 CLAUDECODE=1 $CLI api get /api/2.0/clusters/list > /dev/null | ||
| print_requests.py --get //api/2.0/clusters/list | contains.py '!agent/claude-code' | ||
|
|
||
| title "With the variable unset, the request carries the agent token" | ||
| MSYS_NO_PATHCONV=1 trace CLAUDECODE=1 $CLI api get /api/2.0/clusters/list > /dev/null | ||
| print_requests.py --get //api/2.0/clusters/list | contains.py 'agent/claude-code' |
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 @@ | ||
| Cloud = false |
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,26 @@ | ||
|
|
||
| === With the variable set, the verification request has no agent token | ||
|
|
||
| >>> DATABRICKS_NOT_AN_AGENT=1 CLAUDECODE=1 [CLI] auth describe | ||
| { | ||
| "headers": { | ||
| "User-Agent": [ | ||
| "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/auth_describe cmd-exec-id/[UUID][0] interactive/none auth/pat" | ||
| ] | ||
| }, | ||
| "method": "GET", | ||
| "path": "/api/2.0/preview/scim/v2/Me" | ||
| } | ||
|
|
||
| === With the variable unset, the verification request carries the agent token | ||
|
|
||
| >>> CLAUDECODE=1 [CLI] auth describe | ||
| { | ||
| "headers": { | ||
| "User-Agent": [ | ||
| "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/auth_describe cmd-exec-id/[UUID][1] interactive/none aitools-agent/none auth/pat agent/claude-code" | ||
| ] | ||
| }, | ||
| "method": "GET", | ||
| "path": "/api/2.0/preview/scim/v2/Me" | ||
| } |
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,8 @@ | ||
| # auth describe verifies the workspace credentials with its own SDK client, so the variable must reach it too. | ||
| title "With the variable set, the verification request has no agent token" | ||
| trace DATABRICKS_NOT_AN_AGENT=1 CLAUDECODE=1 $CLI auth describe > /dev/null | ||
| print_requests.py --get //api/2.0/preview/scim/v2/Me | contains.py '!agent/claude-code' | ||
|
|
||
| title "With the variable unset, the verification request carries the agent token" | ||
| trace CLAUDECODE=1 $CLI auth describe > /dev/null | ||
| print_requests.py --get //api/2.0/preview/scim/v2/Me | contains.py 'agent/claude-code' |
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,11 @@ | ||
| RecordRequests = true | ||
| IncludeRequestHeaders = ["User-Agent"] | ||
|
|
||
| # Normalize OS-dependent and CI-only User-Agent segments so the recorded requests are stable everywhere. | ||
| [[Repls]] | ||
| Old = '(linux|darwin|windows)' | ||
| New = '[OS]' | ||
|
|
||
| [[Repls]] | ||
| Old = " cicd/[A-Za-z0-9.-]+" | ||
| New = "" |
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
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 fix: the MCP commands' telemetry upload still sends the agent token under
DATABRICKS_NOT_AN_AGENT.setUploadConfig(cmd/aitools/mcp_telemetry.go:33) builds a separate config withmcp.BoundUploadConfigand hands it totelemetry.SetUploadConfig. The guard here and inboundClientwraps only the command's own client, so the upload config'sHTTPTransportstays nil.newAPIClientinlibs/telemetry/logger.gobuilds its client withconfig.HTTPClientConfigFromConfig, and that function's visitor addsagent/<name>.I reproduced it with a scratch test in
cmd/aitools. WithCLAUDECODE=1,DATABRICKS_NOT_AN_AGENT=1and a PAT profile, I calledsetUploadConfig(...)and thentelemetry.Send(ctx, cfg, nil)against an httptest server. The server recordedPOST /telemetry-extwithUser-Agent: cli/... auth/pat agent/claude-code.Uploaduses the samenewAPIClient, soaitools mcp add,serve,loginandremoveall send it whenever telemetry is on.Fix: add one
agent.ApplyNotAnAgentHeader(ctx, cfg)on the upload config, either insetUploadConfigright afterBoundUploadConfigor insideBoundUploadConfig, which already takesctx. Then add a set/unset User-Agent check on the/telemetry-extrequest, like the other checks in this PR.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.
Done in 15161a7: setUploadConfig now applies agent.ApplyNotAnAgentHeader to the upload config right after BoundUploadConfig, so the /telemetry-ext request leaves out the agent token under DATABRICKS_NOT_AN_AGENT. Added TestSetUploadConfigNotAnAgentUserAgent, which sends a telemetry request to an httptest server and checks the User-Agent has agent/claude-code with the variable unset and no agent/ token with it set.