-
Notifications
You must be signed in to change notification settings - Fork 984
feat: containers ssh
command
#10582
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
flakey5
wants to merge
9
commits into
main
Choose a base branch
from
flakey5/cc-4634
base: main
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.
Open
feat: containers ssh
command
#10582
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c46017e
feat: `containers ssh` command
flakey5 0de27ab
fixup! feat: `containers ssh` command
flakey5 9d389a5
Apply suggestions from code review
flakey5 14b9c57
code review
flakey5 f94b347
Apply suggestions from code review
flakey5 3cbf1fc
code review
flakey5 0c72eaa
code review
flakey5 22f6eff
fix lock file
emily-shen d23e144
fix tests
flakey5 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
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,6 @@ | ||
--- | ||
"@cloudflare/containers-shared": minor | ||
"wrangler": patch | ||
--- | ||
|
||
Add `containers ssh` command |
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
13 changes: 13 additions & 0 deletions
13
packages/containers-shared/src/client/models/SSHPublicKeyItemV3.ts
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,13 @@ | ||
/* istanbul ignore file */ | ||
/* tslint:disable */ | ||
/* eslint-disable */ | ||
|
||
import type { SSHPublicKey } from "./SSHPublicKey"; | ||
|
||
/** | ||
* An SSH public key attached to a specific application or account. | ||
*/ | ||
export type SSHPublicKeyItemV3 = { | ||
name: string; | ||
public_key: SSHPublicKey; | ||
}; |
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
11 changes: 11 additions & 0 deletions
11
packages/containers-shared/src/client/models/WranglerSSHConfig.ts
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 @@ | ||
/* istanbul ignore file */ | ||
/* tslint:disable */ | ||
/* eslint-disable */ | ||
|
||
/** | ||
* Configuration properties for SSH'ing into a container with Wrangler | ||
*/ | ||
export type WranglerSSHConfig = { | ||
enabled: boolean; | ||
port?: number; | ||
}; |
8 changes: 8 additions & 0 deletions
8
packages/containers-shared/src/client/models/WranglerSSHResponse.ts
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 @@ | ||
/* istanbul ignore file */ | ||
/* tslint:disable */ | ||
/* eslint-disable */ | ||
|
||
export type WranglerSSHResponse = { | ||
url: string; | ||
token: string; | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { spawn } from "node:child_process"; | ||
import { createServer } from "node:net"; | ||
import { WebSocket } from "undici"; | ||
import type { WranglerSSHResponse } from "./client"; | ||
import type { Server } from "node:net"; | ||
|
||
export function verifySshInstalled(sshPath: string): Promise<undefined> { | ||
return new Promise<undefined>((resolve, reject) => { | ||
const child = spawn(sshPath, ["-V"], { | ||
detached: true, | ||
}); | ||
|
||
let errorHandled = false; | ||
child.on("close", (code) => { | ||
if (code === 0) { | ||
resolve(undefined); | ||
} else if (!errorHandled) { | ||
errorHandled = true; | ||
reject(new Error(`ssh exited with status code: ${code}`)); | ||
} | ||
}); | ||
|
||
child.on("error", (err) => { | ||
if (!errorHandled) { | ||
errorHandled = true; | ||
reject(new Error(`verifying ssh installation failed: ${err.message}`)); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
/** | ||
* Creates a local TCP proxy that wraps data sent in a websocket binary | ||
* websocket message | ||
*/ | ||
export function createSshTcpProxy(sshResponse: WranglerSSHResponse): Server { | ||
let hasConnection = false; | ||
const proxy = createServer((inbound) => { | ||
if (hasConnection) { | ||
inbound.end(); | ||
return; | ||
} | ||
|
||
hasConnection = true; | ||
|
||
const ws = new WebSocket(sshResponse.url, { | ||
headers: { | ||
authorization: `Bearer ${sshResponse.token}`, | ||
"user-agent": "wrangler", | ||
}, | ||
}); | ||
|
||
ws.addEventListener("error", (err) => { | ||
console.error("Web socket error:", err.error); | ||
inbound.end(); | ||
proxy.close(); | ||
}); | ||
|
||
ws.addEventListener("open", () => { | ||
inbound.on("data", (data) => { | ||
ws.send(data); | ||
}); | ||
|
||
inbound.on("close", () => { | ||
ws.close(); | ||
proxy.close(); | ||
}); | ||
|
||
ws.addEventListener("message", async ({ data }) => { | ||
const arrayBuffer = await data.arrayBuffer(); | ||
const arr = new Uint8Array(arrayBuffer); | ||
|
||
inbound.write(arr); | ||
}); | ||
|
||
ws.addEventListener("close", () => { | ||
inbound.end(); | ||
proxy.close(); | ||
}); | ||
}); | ||
}); | ||
|
||
return proxy; | ||
} |
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.
Is this really needed?
If not, can this be removed from all the added files?
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.
this is all auto-generated code that's being copy-pasted over, we should remove these ignores but i can do that in a separate PR - its not really on @flakey5 :')