Skip to content

Commit ff543e3

Browse files
authored
CC-7209: Deprecate and hide OpenSSH options from ssh command (cloudflare#12853)
1 parent c2b76bc commit ff543e3

3 files changed

Lines changed: 97 additions & 148 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"wrangler": minor
3+
---
4+
5+
Deprecate SSH passthrough flags in `wrangler containers ssh`
6+
7+
The `--cipher`, `--log-file`, `--escape-char`, `--config-file`, `--pkcs11`, `--identity-file`, `--mac-spec`, `--option`, and `--tag` flags are now deprecated. These flags expose OpenSSH-specific options that are tied to the current implementation. A future release will replace the underlying SSH transport, at which point these flags will be removed. They still function for now.

packages/wrangler/src/__tests__/containers/ssh.test.ts

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,7 @@ describe("containers ssh", () => {
3535
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
3636
--env-file Path to an .env file to load - can be specified multiple times - values from earlier files are overridden by values in later files [array]
3737
-h, --help Show help [boolean]
38-
-v, --version Show version number [boolean]
39-
40-
OPTIONS
41-
--cipher Sets \`ssh -c\`: Select the cipher specification for encrypting the session [string]
42-
--log-file Sets \`ssh -E\`: Append debug logs to log_file instead of standard error [string]
43-
--escape-char Sets \`ssh -e\`: Set the escape character for sessions with a pty (default: '~') [string]
44-
-F, --config-file Sets \`ssh -F\`: Specify an alternative per-user ssh configuration file [string]
45-
--pkcs11 Sets \`ssh -I\`: Specify the PKCS#11 shared library ssh should use to communicate with a PKCS#11 token providing keys for user authentication [string]
46-
-i, --identity-file Sets \`ssh -i\`: Select a file from which the identity (private key) for public key authentication is read [string]
47-
--mac-spec Sets \`ssh -m\`: A comma-separated list of MAC (message authentication code) algorithms, specified in order of preference [string]
48-
-o, --option Sets \`ssh -o\`: Set options in the format used in the ssh configuration file. May be repeated [string]
49-
--tag Sets \`ssh -P\`: Specify a tag name that may be used to select configuration in ssh_config [string]"
38+
-v, --version Show version number [boolean]"
5039
`);
5140
});
5241

@@ -65,12 +54,12 @@ describe("containers ssh", () => {
6554
setWranglerConfig({});
6655
msw.use(
6756
http.get(`*/instances/:instanceId/ssh`, async () => {
68-
return new HttpResponse(
69-
`{"success": false, "errors": [{"code": 1000, "message": "something happened"}]}`,
57+
return HttpResponse.json(
7058
{
71-
type: "applicaton/json",
72-
status: 500,
73-
}
59+
success: false,
60+
errors: [{ code: 1000, message: "something happened" }],
61+
},
62+
{ status: 500 }
7463
);
7564
})
7665
);
@@ -95,12 +84,9 @@ describe("containers ssh", () => {
9584
setWranglerConfig({});
9685
msw.use(
9786
http.get(`*/instances/:instanceId/ssh`, async () => {
98-
return new HttpResponse(
99-
`{"success": true, "result": {"url": "${wsUrl}", "token": "${sshJwt}"}}`,
100-
{
101-
type: "applicaton/json",
102-
status: 200,
103-
}
87+
return HttpResponse.json(
88+
{ success: true, result: { url: wsUrl, token: sshJwt } },
89+
{ status: 200 }
10490
);
10591
})
10692
);

packages/wrangler/src/containers/ssh.ts

Lines changed: 81 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -12,78 +12,90 @@ import {
1212
import { createCommand } from "../core/create-command";
1313
import { logger } from "../logger";
1414
import { containersScope } from "./index";
15-
import type {
16-
CommonYargsArgv,
17-
StrictYargsOptionsToInterface,
18-
} from "../yargs-types";
15+
import type { HandlerArgs, NamedArgDefinitions } from "../core/types";
1916
import type { WranglerSSHResponse } from "@cloudflare/containers-shared";
2017
import type { Config } from "@cloudflare/workers-utils";
2118
import type { Server } from "node:net";
2219

23-
export function sshYargs(args: CommonYargsArgv) {
24-
return (
25-
args
26-
.positional("ID", {
27-
describe: "ID of the container instance",
28-
type: "string",
29-
demandOption: true,
30-
})
31-
// Following are SSH flags that should be directly passed in
32-
.option("cipher", {
33-
describe:
34-
"Sets `ssh -c`: Select the cipher specification for encrypting the session",
35-
type: "string",
36-
})
37-
.option("log-file", {
38-
describe:
39-
"Sets `ssh -E`: Append debug logs to log_file instead of standard error",
40-
type: "string",
41-
})
42-
.option("escape-char", {
43-
describe:
44-
"Sets `ssh -e`: Set the escape character for sessions with a pty (default: ‘~’)",
45-
type: "string",
46-
})
47-
.option("config-file", {
48-
alias: "F",
49-
describe:
50-
"Sets `ssh -F`: Specify an alternative per-user ssh configuration file",
51-
type: "string",
52-
})
53-
.option("pkcs11", {
54-
describe:
55-
"Sets `ssh -I`: Specify the PKCS#11 shared library ssh should use to communicate with a PKCS#11 token providing keys for user authentication",
56-
type: "string",
57-
})
58-
.option("identity-file", {
59-
alias: "i",
60-
describe:
61-
"Sets `ssh -i`: Select a file from which the identity (private key) for public key authentication is read",
62-
type: "string",
63-
})
64-
.option("mac-spec", {
65-
describe:
66-
"Sets `ssh -m`: A comma-separated list of MAC (message authentication code) algorithms, specified in order of preference",
67-
type: "string",
68-
})
69-
.option("option", {
70-
alias: "o",
71-
describe:
72-
"Sets `ssh -o`: Set options in the format used in the ssh configuration file. May be repeated",
73-
type: "string",
74-
})
75-
.option("tag", {
76-
describe:
77-
"Sets `ssh -P`: Specify a tag name that may be used to select configuration in ssh_config",
78-
type: "string",
79-
})
80-
);
81-
}
20+
// Deprecated SSH flags are hidden because a future SSH implementation
21+
// will not use OpenSSH, at which point these options will not work.
22+
const sshArgDefs = {
23+
ID: {
24+
describe: "ID of the container instance",
25+
type: "string",
26+
demandOption: true,
27+
},
28+
cipher: {
29+
describe:
30+
"Sets `ssh -c`: Select the cipher specification for encrypting the session",
31+
type: "string",
32+
hidden: true,
33+
deprecated: true,
34+
},
35+
"log-file": {
36+
describe:
37+
"Sets `ssh -E`: Append debug logs to log_file instead of standard error",
38+
type: "string",
39+
hidden: true,
40+
deprecated: true,
41+
},
42+
"escape-char": {
43+
describe:
44+
"Sets `ssh -e`: Set the escape character for sessions with a pty (default: '~')",
45+
type: "string",
46+
hidden: true,
47+
deprecated: true,
48+
},
49+
"config-file": {
50+
alias: "F",
51+
describe:
52+
"Sets `ssh -F`: Specify an alternative per-user ssh configuration file",
53+
type: "string",
54+
hidden: true,
55+
deprecated: true,
56+
},
57+
pkcs11: {
58+
describe:
59+
"Sets `ssh -I`: Specify the PKCS#11 shared library ssh should use to communicate with a PKCS#11 token providing keys for user authentication",
60+
type: "string",
61+
hidden: true,
62+
deprecated: true,
63+
},
64+
"identity-file": {
65+
alias: "i",
66+
describe:
67+
"Sets `ssh -i`: Select a file from which the identity (private key) for public key authentication is read",
68+
type: "string",
69+
hidden: true,
70+
deprecated: true,
71+
},
72+
"mac-spec": {
73+
describe:
74+
"Sets `ssh -m`: A comma-separated list of MAC (message authentication code) algorithms, specified in order of preference",
75+
type: "string",
76+
hidden: true,
77+
deprecated: true,
78+
},
79+
option: {
80+
alias: "o",
81+
describe:
82+
"Sets `ssh -o`: Set options in the format used in the ssh configuration file. May be repeated",
83+
type: "string",
84+
hidden: true,
85+
deprecated: true,
86+
},
87+
tag: {
88+
describe:
89+
"Sets `ssh -P`: Specify a tag name that may be used to select configuration in ssh_config",
90+
type: "string",
91+
hidden: true,
92+
deprecated: true,
93+
},
94+
} as const satisfies NamedArgDefinitions;
8295

83-
export async function sshCommand(
84-
sshArgs: StrictYargsOptionsToInterface<typeof sshYargs>,
85-
_config: Config
86-
) {
96+
type SshArgs = HandlerArgs<typeof sshArgDefs>;
97+
98+
async function sshCommand(sshArgs: SshArgs, _config: Config) {
8799
if (sshArgs.ID.length !== 64) {
88100
throw new UserError(`Expected an instance ID but got ${sshArgs.ID}`);
89101
}
@@ -261,9 +273,7 @@ export function createSshTcpProxy(sshResponse: WranglerSSHResponse): Server {
261273
return proxy;
262274
}
263275

264-
function buildSshArgs(
265-
sshArgs: StrictYargsOptionsToInterface<typeof sshYargs>
266-
): string[] {
276+
function buildSshArgs(sshArgs: SshArgs): string[] {
267277
const flags = [
268278
// Never use a control socket.
269279
"-o",
@@ -334,61 +344,7 @@ export const containersSshCommand = createCommand({
334344
owner: "Product: Cloudchamber",
335345
hidden: true,
336346
},
337-
args: {
338-
ID: {
339-
describe: "ID of the container instance",
340-
type: "string",
341-
demandOption: true,
342-
},
343-
cipher: {
344-
describe:
345-
"Sets `ssh -c`: Select the cipher specification for encrypting the session",
346-
type: "string",
347-
},
348-
"log-file": {
349-
describe:
350-
"Sets `ssh -E`: Append debug logs to log_file instead of standard error",
351-
type: "string",
352-
},
353-
"escape-char": {
354-
describe:
355-
"Sets `ssh -e`: Set the escape character for sessions with a pty (default: '~')",
356-
type: "string",
357-
},
358-
"config-file": {
359-
alias: "F",
360-
describe:
361-
"Sets `ssh -F`: Specify an alternative per-user ssh configuration file",
362-
type: "string",
363-
},
364-
pkcs11: {
365-
describe:
366-
"Sets `ssh -I`: Specify the PKCS#11 shared library ssh should use to communicate with a PKCS#11 token providing keys for user authentication",
367-
type: "string",
368-
},
369-
"identity-file": {
370-
alias: "i",
371-
describe:
372-
"Sets `ssh -i`: Select a file from which the identity (private key) for public key authentication is read",
373-
type: "string",
374-
},
375-
"mac-spec": {
376-
describe:
377-
"Sets `ssh -m`: A comma-separated list of MAC (message authentication code) algorithms, specified in order of preference",
378-
type: "string",
379-
},
380-
option: {
381-
alias: "o",
382-
describe:
383-
"Sets `ssh -o`: Set options in the format used in the ssh configuration file. May be repeated",
384-
type: "string",
385-
},
386-
tag: {
387-
describe:
388-
"Sets `ssh -P`: Specify a tag name that may be used to select configuration in ssh_config",
389-
type: "string",
390-
},
391-
},
347+
args: sshArgDefs,
392348
positionalArgs: ["ID"],
393349
async handler(args, { config }) {
394350
await fillOpenAPIConfiguration(config, containersScope);

0 commit comments

Comments
 (0)