Skip to content

ssh: check the backend and ACL of an existing keys secret scope before reusing it - #8141

Open
anton-107 wants to merge 2 commits into
mainfrom
ssh-keys-scope-check
Open

anton-107 wants to merge 2 commits into
mainfrom
ssh-keys-scope-check

Conversation

@anton-107

Copy link
Copy Markdown
Contributor

Changes

databricks ssh connect keeps the SSH keys for a session in a secret scope named <user>-<session>-ssh-tunnel-keys. Before this change, the CLI reused that scope whenever it already existed. Now, when the scope exists, CreateKeysSecretScope accepts it only if both of these hold:

  • The scope is Databricks-backed. The CLI finds the scope in the scope list, because the Secrets API has no call that returns one scope. The ACL of an Azure Key Vault-backed scope covers only access through Databricks: whoever controls the vault can read and replace the keys regardless of it.
  • The scope's ACL list has exactly one entry: MANAGE for the current user.

The backend is checked first. A scope the CLI creates looks like that, because CreateScope grants MANAGE to its creator and the CLI sets no initial_manage_principal.

  • If listing the ACLs is denied, the scope counts as not owned. Listing requires MANAGE.
  • Any other error from listing the ACLs is returned as an error.
  • A failure to list the scopes, or a scope missing from that list, is returned as an error.
  • A scope that is refused fails the connection before the CLI reads a secret or writes anything. The error names the scope and says how to delete it. In serverless mode it also suggests connecting with a different --name. On a dedicated cluster the session is the cluster ID, so that hint does not apply there.

Client key handling is unchanged. The only change outside internal/keys is that client.go passes the serverless flag to CreateKeysSecretScope. The README gets a short section on the check and how to recover.

Why

Before this change, any principal that also had access to the keys scope could read the client private key stored there, or replace the client public key that the server authorizes. The check refuses such a scope before the CLI uses it.

Behavior change for users

If a user's existing keys scope has any extra ACL entry (another user, a group, a service principal), or the user has only READ or WRITE on it, ssh connect now fails with this error (the last sentence appears only in serverless mode):

secret scope <scope> already exists and is not exclusively owned by <user> (the scope must grant MANAGE to <user> and no access to other principals). Delete the scope with databricks secrets delete-scope <scope> (this needs MANAGE permission on the scope; otherwise ask a workspace admin) and connect again once no SSH server for this session is running: a running server keeps the keys of the deleted scope and shuts down --shutdown-delay after its last client disconnects. You can instead connect with a different --name

The error says to wait for a running server because deleting the scope and connecting again right away does not work while a server for the session is still running. The CLI reuses that server, and the server still authorizes the client key it read at startup. Meanwhile the recreated scope gets a new client key pair and has no host key to pin. In the local fake workspace this reconnect fails with failed to read the SSH server host key: ... server-public-key not found.

What the check does not cover

This is a deliberate limit of the change, not an oversight. The check only shows that, right now, nobody else can read or change the scope. It does not show who created the scope or who wrote the secrets in it. Another principal could write keys, grant the user MANAGE and then remove its own entry. A scope that passes the check is used as before: the client reads the client key pair stored in it, and the server authorizes the client public key stored in it. That other principal still has no way to use such a key by itself: the tunnel runs only on serverless compute or on a dedicated single-user cluster, so another user cannot reach the session's SSH server. Requiring the scope's client key to match a key kept on the local machine would close this, but it would refuse a session's scope from a second machine or after the local key is removed, so it is left out.

Tests

  • Unit tests in experimental/ssh/internal/keys/secrets_test.go cover each ACL case: a missing scope is created; a single MANAGE entry for the user is accepted; a scope is refused when another user or a group also has access, when the user has only READ or WRITE, when only another principal has MANAGE, when the ACL list is empty, and when listing is denied; the --name hint appears only in serverless mode; any other listing error is returned; an Azure Key Vault-backed scope is refused before its ACL is listed; a scope missing from the scope list is an error. The tests assert the error text.
  • The acceptance test acceptance/ssh/connect-scope-not-owned sets up a scope with an extra ACL entry and stored keys. It checks that ssh connect fails with the error above, reports the SECRET_SCOPE_FAILED category, and sends no request after the scope list and the ACL list: no secrets/get, no secrets/put, no upload and no job submit.
  • go test ./experimental/ssh/... ./libs/testserver/... and all acceptance/ssh tests pass locally.

Not verified on a real workspace

  • Whether the ACL principal always equals the SCIM userName for both users and service principals. If it does not for some identity, that identity's own scope would be refused.
  • Whether some tiers or workspace configurations add default ACL entries to new scopes. If they do, every scope the CLI creates there would be refused on the next connect.
  • That a running server rejects the new client key after the scope is recreated. The fake workspace's sshd reads the authorized key on every connection, so it cannot show this. The fake does show the missing host key failure described above.

This pull request and its description were written by Isaac.

…e reusing it

`databricks ssh connect` keeps the tunnel's SSH keys in a secret scope with a
predictable name and reused an existing scope without looking at who can
access it. It now reuses an existing scope only when the scope is
Databricks-backed and its ACL is exactly one entry, MANAGE for the current
user, and fails before reading any key otherwise. The error says how to
recover: delete the scope and connect again once no SSH server for the session
is running, or on serverless connect with a different --name.

The checks keep other principals from reading or replacing keys while the
scope is in use. The ACL of an Azure Key Vault-backed scope would not, because
it does not cover access through the vault. The checks do not prove who
created the scope or wrote its secrets; keys in a scope that passes them are
used as before.

Co-authored-by: Isaac <no-reply@databricks.com>
@anton-107
anton-107 requested review from a team as code owners November 27, 2026 18:04
Co-authored-by: Isaac <no-reply@databricks.com>
@github-actions

Copy link
Copy Markdown
Contributor

Regression test report ✅

Commit: 903c5bebf | Workflow run

Selected 1 changed tests (limit=20, 0 not selected)

1 tests: regression=1 unreleased=0 coverage=0 failing=0
test branch main (a0805a0) latest (v1.28.0)
TestAccept/ssh/connect-scope-not-owned ✅ ❌ ❌
TestAccept/ssh/connect-scope-not-owned: branch ✅ | main (a0805a0) ❌ | latest (v1.28.0) ❌

main (a0805a0):

acceptance_test.go:1402: Diff:
        --- ssh/connect-scope-not-owned/output.txt
        +++ /tmp/TestAcceptsshconnect-scope-not-owned103995357/002/output.txt
        @@ -11,12 +11,13 @@
         
         >>> musterr [CLI] ssh connect --name scope-not-owned -- echo 'Connection successful'
         Connecting to scope-not-owned...
        -Error: failed to create secret scope: secret scope [USERNAME]-scope-not-owned-ssh-tunnel-keys already exists and is not exclusively owned by [USERNAME] (the scope must grant MANAGE to [USERNAME] and no access to other principals). Delete the scope with `databricks secrets delete-scope [USERNAME]-scope-not-owned-ssh-tunnel-keys` (this needs MANAGE permission on the scope; otherwise ask a workspace admin) and connect again once no SSH server for this session is running: a running server keeps the keys of the deleted scope and shuts down --shutdown-delay after its last client disconnects. You can instead connect with a different --name
        +Uploading binaries...
        +Error: failed to upload ssh-tunnel binaries: failed to get archive for architecture amd64: failed to download https://github.com/databricks/cli/releases/download/v[CLI_VERSION]/databricks_cli_linux_amd64.zip: Get "https://github.com/databricks/cli/releases/download/v[CLI_VERSION]/databricks_cli_linux_amd64.zip": Bad Request
         
         === Reported error category
         
         >>> jq -r select(.path == "/telemetry-ext") | .body.protoLogs[] | fromjson | .entry.databricks_cli_log.ssh_tunnel_event.error_category [OUTPUT_DIR]/out.requests.txt
        -SECRET_SCOPE_FAILED
        +BINARY_UPLOAD_FAILED
         
         === Requests made by ssh connect
         
        @@ -24,5 +21,7 @@
         {"method": "GET", "path": "/api/2.1/settings/port_fwd_serverless_enabled"}
         {"method": "GET", "path": "/api/2.0/preview/scim/v2/Me"}
         {"method": "GET", "path": "/api/2.0/secrets/list", "q": {"scope": "[USERNAME]-scope-not-owned-ssh-tunnel-keys"}}
        -{"method": "GET", "path": "/api/2.0/secrets/scopes/list"}
        -{"method": "GET", "path": "/api/2.0/secrets/acls/list", "q": {"scope": "[USERNAME]-scope-not-owned-ssh-tunnel-keys"}}
        +{"method": "GET", "path": "/api/2.0/secrets/get", "q": {"key": "client-private-key", "scope": "[USERNAME]-scope-not-owned-ssh-tunnel-keys"}}
        +{"method": "GET", "path": "/api/2.0/secrets/get", "q": {"key": "client-public-key", "scope": "[USERNAME]-scope-not-owned-ssh-tunnel-keys"}}
        +{"method": "GET", "path": "/api/2.0/preview/scim/v2/Me"}
        +{"method": "POST", "path": "/api/2.0/workspace/mkdirs", "body": {"path": "/Workspace/Users/[USERNAME]/.databricks/ssh-tunnel/[CLI_VERSION]/databricks_cli_linux_amd64"}}
        
FAIL

latest (v1.28.0):

acceptance_test.go:1402: Diff:
        --- ssh/connect-scope-not-owned/output.txt
        +++ /tmp/TestAcceptsshconnect-scope-not-owned3280814123/002/output.txt
        @@ -11,12 +11,17 @@
         
         >>> musterr [CLI] ssh connect --name scope-not-owned -- echo 'Connection successful'
         Connecting to scope-not-owned...
        -Error: failed to create secret scope: secret scope [USERNAME]-scope-not-owned-ssh-tunnel-keys already exists and is not exclusively owned by [USERNAME] (the scope must grant MANAGE to [USERNAME] and no access to other principals). Delete the scope with `databricks secrets delete-scope [USERNAME]-scope-not-owned-ssh-tunnel-keys` (this needs MANAGE permission on the scope; otherwise ask a workspace admin) and connect again once no SSH server for this session is running: a running server keeps the keys of the deleted scope and shuts down --shutdown-delay after its last client disconnects. You can instead connect with a different --name
        +Uploading binaries...
        +Error: failed to upload ssh-tunnel binaries: failed to get archive for architecture amd64: failed to download https://github.com/databricks/cli/releases/download/v[CLI_VERSION]/databricks_cli_[CLI_VERSION]_linux_amd64.zip: Get "https://github.com/databricks/cli/releases/download/v[CLI_VERSION]/databricks_cli_[CLI_VERSION]_linux_amd64.zip": Bad Request
         
        +Downloading it from the Python package index failed too: failed to fetch the databricks package from databricks.jfrog.io: Bad Request
        +
        +The SSH tunnel uploads the Linux build of the Databricks CLI to your workspace. Allow access to GitHub (github.com, release-assets.githubusercontent.com), or check that the HTTPS package index set by PIP_INDEX_URL, or index-url in your per-user pip config, serves the databricks package
        +
         === Reported error category
         
         >>> jq -r select(.path == "/telemetry-ext") | .body.protoLogs[] | fromjson | .entry.databricks_cli_log.ssh_tunnel_event.error_category [OUTPUT_DIR]/out.requests.txt
        -SECRET_SCOPE_FAILED
        +BINARY_UPLOAD_FAILED
         
         === Requests made by ssh connect
         
        @@ -24,5 +25,8 @@
         {"method": "GET", "path": "/api/2.1/settings/port_fwd_serverless_enabled"}
         {"method": "GET", "path": "/api/2.0/preview/scim/v2/Me"}
         {"method": "GET", "path": "/api/2.0/secrets/list", "q": {"scope": "[USERNAME]-scope-not-owned-ssh-tunnel-keys"}}
        -{"method": "GET", "path": "/api/2.0/secrets/scopes/list"}
        -{"method": "GET", "path": "/api/2.0/secrets/acls/list", "q": {"scope": "[USERNAME]-scope-not-owned-ssh-tunnel-keys"}}
        +{"method": "GET", "path": "/api/2.0/secrets/get", "q": {"key": "client-private-key", "scope": "[USERNAME]-scope-not-owned-ssh-tunnel-keys"}}
        +{"method": "GET", "path": "/api/2.0/secrets/get", "q": {"key": "client-public-key", "scope": "[USERNAME]-scope-not-owned-ssh-tunnel-keys"}}
        +{"method": "GET", "path": "/api/2.0/preview/scim/v2/Me"}
        +{"method": "GET", "path": "/api/2.0/workspace/get-status", "q": {"path": "/Workspace/Users/[USERNAME]/.databricks/ssh-tunnel/[CLI_VERSION]/databricks_cli_[CLI_VERSION]_linux_amd64/databricks", "return_export_info": "true"}}
        +{"method": "POST", "path": "/api/2.0/workspace/mkdirs", "body": {"path": "/Workspace/Users/[USERNAME]/.databricks/ssh-tunnel/[CLI_VERSION]/databricks_cli_[CLI_VERSION]_linux_amd64"}}
        
FAIL

@eng-dev-ecosystem-bot

Copy link
Copy Markdown
Collaborator

✅ Integration test report

Commit: 903c5be

Run: 46047035243

Env 💚​RECOVERED ✅​pass 🙈​skip Time
💚​ aws linux-2core-8gb 1 173 18 4:05
💚​ aws-windows-latest-4core-16gb 1 173 18 2:25
💚​ azure linux-2core-8gb 1 172 18 4:14
💚​ azure-windows-latest-4core-16gb 1 172 18 2:31
💚​ gcp linux-2core-8gb 1 173 18 4:58
💚​ gcp-windows-latest-4core-16gb 1 173 18 2:59
Test Name aws linux-2core-8gb aws-windows-latest-4core-16gb azure linux-2core-8gb azure-windows-latest-4core-16gb gcp linux-2core-8gb gcp-windows-latest-4core-16gb
💚​ TestAccept 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R
Top 6 slowest tests (at least 2 minutes):
duration env testname
3:58 gcp linux-2core-8gb TestAccept
3:54 aws linux-2core-8gb TestAccept
3:53 azure linux-2core-8gb TestAccept
2:57 gcp-windows-latest-4core-16gb TestAccept
2:29 azure-windows-latest-4core-16gb TestAccept
2:23 aws-windows-latest-4core-16gb TestAccept

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants