|
| 1 | +## SSH Tunnel for Databricks |
| 2 | + |
| 3 | +The SSH tunnel lets customers connect any IDE to Databricks compute to run and debug all code - including non-Spark/ML - with environment parity, and simple setup. |
| 4 | + |
| 5 | +## Compute Requirements |
| 6 | +- Dedicated (single user) access mode if you want to use Remote Development tools in IDEs |
| 7 | +- Dedicated or standard access mode for terminal SSH connections |
| 8 | + |
| 9 | +## Usage |
| 10 | +A. With local ssh config setup: |
| 11 | +```shell |
| 12 | +databricks ssh setup --name=hello --cluster=id # one time only |
| 13 | +ssh hello # use system SSH client to create a session |
| 14 | +``` |
| 15 | +B. Spawn an ssh session directly: |
| 16 | +```shell |
| 17 | +databricks ssh connect --cluster=id |
| 18 | +``` |
| 19 | + |
| 20 | +## Development |
| 21 | +```shell |
| 22 | +make build snapshot-release |
| 23 | +./cli ssh connect --cluster=<id> --releases-dir=./dist --debug # or modify ssh config accordingly |
| 24 | +``` |
| 25 | + |
| 26 | +## Design |
| 27 | + |
| 28 | +High level: |
| 29 | +```mermaid |
| 30 | +--- |
| 31 | +config: |
| 32 | + theme: redux |
| 33 | + layout: dagre |
| 34 | +--- |
| 35 | +flowchart TD |
| 36 | + n1(["Client A"]) |
| 37 | + subgraph s1["Control Plane"] |
| 38 | + n3["Jobs API"] |
| 39 | + n2["Driver Proxy API"] |
| 40 | + n11["Workspace API"] |
| 41 | + end |
| 42 | + subgraph s3["Spark User A or root"] |
| 43 | + n4["SSH Server A"] |
| 44 | + end |
| 45 | + subgraph s4["Spark User B or root"] |
| 46 | + n6["SSH Server B"] |
| 47 | + end |
| 48 | + subgraph s2["Cluster"] |
| 49 | + s3 |
| 50 | + s4 |
| 51 | + n12["Workspace Filesystem"] |
| 52 | + end |
| 53 | + n1 -. "1 - start an ssh server job" .-> n3 |
| 54 | + n3 -. "2 - start ssh server" .-> n4 |
| 55 | + n4 <-. "3 - save the ssh server port number" .-> n12 |
| 56 | + n1 <-. "4 - get ssh server port number" .-> n11 |
| 57 | + n1 <-. "6 - websocket connection" .-> n2 |
| 58 | + n2 <-. "7 - websocket connection" .-> n4 |
| 59 | + n6 <-.-> n12 |
| 60 | + style s2 stroke:#757575 |
| 61 | + style s1 stroke:#757575 |
| 62 | + style s4 stroke-dasharray: 5 5 |
| 63 | + style n6 stroke-dasharray: 5 5 |
| 64 | +``` |
| 65 | + |
| 66 | +Connection flow: |
| 67 | +```mermaid |
| 68 | +--- |
| 69 | +config: |
| 70 | + theme: base |
| 71 | +--- |
| 72 | +sequenceDiagram |
| 73 | + autonumber |
| 74 | + participant P1 as databricks ssh connect |
| 75 | + participant P2 as ssh client |
| 76 | + participant P3 as databricks ssh connect --proxy |
| 77 | + participant P4 as wsfs |
| 78 | + participant P6 as databricks ssh server |
| 79 | + participant P7 as sshd |
| 80 | + Note over P1,P6: Try to get a port and a remote user name of an existing server<br/> ($v is databricks CLI version, $cluster is supplied by the user) |
| 81 | + activate P1 |
| 82 | + P1 ->> P4: GET ~/.ssh/$v/$cluster/metadata.json |
| 83 | + P4 -->> P1: {port: xxxx} or error |
| 84 | + P1 ->> P6: GET /driver-proxy-api/$cluster/$port/metadata |
| 85 | + P6 -->> P1: {user: spark-xxxx} or {user: root} or error |
| 86 | + Note over P1,P6: Start the new server in the case of an error |
| 87 | + opt |
| 88 | + P1 -->> P1: generate<br/>key pair |
| 89 | + P1 -->> P4: PUT ~/.ssh/$v/bin/databricks, unless it's already there |
| 90 | + P1 ->> P4: PUT ~/.ssh/$v/$cluster/start-server-with-pub-key.ipynb |
| 91 | + P1 ->> P6: jobs/runs/submit start-server-with-pub-key.ipynb $cluster |
| 92 | + activate P6 |
| 93 | + P6 ->> P6: start self-kill-timeout<br/>generate server key pair<br/>create custom sshd config<br/>listen for /ssh and /metadata on a free port |
| 94 | + P6 ->> P4: PUT ~/.ssh/$v/$cluster/metadata.json<br/>{port: xxxx} |
| 95 | + loop unil successful or timed out |
| 96 | + P1 -> P6: Get port and remote user name of the server (sequence 1 - 4 above) |
| 97 | + end |
| 98 | + end |
| 99 | + Note over P1,P7: We know the port and the user, spawn "ssh" |
| 100 | + P1 ->> P2: ssh -l $user -i $key<br/> -o ProxyCommand="databricks ssh connect --proxy $cluster $user $port" |
| 101 | + activate P2 |
| 102 | + P2 ->> P3: exec ProxyCommand |
| 103 | + activate P3 |
| 104 | + P3 ->> P6: wss:/dirver-proxy-api/$cluster/$port/ssh |
| 105 | + P6 ->> P6: stop self-kill-timeout |
| 106 | + P6 ->> P7: /usr/sbin/sshd -i -f config |
| 107 | + activate P7 |
| 108 | + P2 -> P7: pubkey auth |
| 109 | + loop until the connection is closed<br/>by ssh client, sshd, or driver-proxy |
| 110 | + P2 -> P7: stdin and stdout |
| 111 | + P1 -> P2: stdin, stdout, and stderr |
| 112 | + deactivate P7 |
| 113 | + deactivate P3 |
| 114 | + deactivate P2 |
| 115 | + deactivate P1 |
| 116 | + end |
| 117 | + break when the last ws connection drops |
| 118 | + P6 ->> P6: start self-kill-timeout |
| 119 | + P6 ->> P4: DELETE ~/.ssh/$v/$cluster/metadata.json |
| 120 | + deactivate P6 |
| 121 | + end |
| 122 | +``` |
0 commit comments