@infosupport/huddle-cli 0.0.0-experiment-160.128.1 → 0.0.0-experiment-160.130.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/pipe/sbx-kit.js +52 -18
- package/dist/runtime.js +38 -19
- package/package.json +1 -1
package/dist/pipe/sbx-kit.js
CHANGED
|
@@ -10,6 +10,9 @@
|
|
|
10
10
|
// credential proxy needs (a tool trusting only the Huddle CA breaks there);
|
|
11
11
|
// - the CA in the keystore of a JetBrains backend (the JBR does not read the
|
|
12
12
|
// system store), also for a backend Toolbox installs later.
|
|
13
|
+
// sbx only combines kits of one format, so the kit comes in the agent's: v2
|
|
14
|
+
// (spec.yaml plus files/) for sbx before 0.51, v3 (a descriptor sbx builds into
|
|
15
|
+
// an image) from 0.51 on, where the built-in agents are v3 kits.
|
|
13
16
|
// The op writes the kit to ~/.huddle/sbx/kits/huddle-ca and returns its host path.
|
|
14
17
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
15
18
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
@@ -26,10 +29,10 @@ exports.SBX_KITS_DIR = path_1.default.join(config_1.CONFIG_DIR, 'sbx', 'kits');
|
|
|
26
29
|
exports.KIT_NAME = 'huddle-ca';
|
|
27
30
|
const PEM_RE = /^-----BEGIN CERTIFICATE-----\r?\n[A-Za-z0-9+/=\r\n]+-----END CERTIFICATE-----\r?\n?$/;
|
|
28
31
|
const MAX_PEM = 16 * 1024;
|
|
29
|
-
// In the sandbox, files/home/ is /home/agent/.
|
|
30
|
-
const IN_BOX = '/home/agent/.huddle-ca';
|
|
31
32
|
const BUNDLE = '/etc/ssl/certs/ca-certificates.crt';
|
|
32
|
-
|
|
33
|
+
// v2: in the sandbox, files/home/ is /home/agent/.
|
|
34
|
+
const V2_IN_BOX = '/home/agent/.huddle-ca';
|
|
35
|
+
const V2_SPEC = `schemaVersion: "2"
|
|
33
36
|
kind: mixin
|
|
34
37
|
name: ${exports.KIT_NAME}
|
|
35
38
|
description: Trust the Huddle CA, so Huddle can inspect this sandbox's TLS
|
|
@@ -40,17 +43,40 @@ environment:
|
|
|
40
43
|
REQUESTS_CA_BUNDLE: ${BUNDLE}
|
|
41
44
|
setup:
|
|
42
45
|
install:
|
|
43
|
-
- command: "sh ${
|
|
46
|
+
- command: "sh ${V2_IN_BOX}/install.sh"
|
|
44
47
|
user: "0"
|
|
45
48
|
# startup takes the command as argv, install as one string (sbx's schema).
|
|
46
49
|
startup:
|
|
47
|
-
- command: ["sh", "${
|
|
50
|
+
- command: ["sh", "${V2_IN_BOX}/jbr-watch.sh"]
|
|
48
51
|
`;
|
|
49
|
-
|
|
52
|
+
// v3: the kit is an image layer over the agent's filesystem, so it stays out of
|
|
53
|
+
// /home/agent (a layer that has that folder would take over its owner).
|
|
54
|
+
const V3_IN_BOX = '/usr/local/share/huddle-ca';
|
|
55
|
+
// Install hooks only see the variables they name.
|
|
56
|
+
const V3_SPEC = `# syntax=docker/sandbox-kit:3
|
|
57
|
+
schemaVersion: "3"
|
|
58
|
+
kind: mixin
|
|
59
|
+
displayName: Huddle CA
|
|
60
|
+
description: Trust the Huddle CA, so Huddle can inspect this sandbox's TLS
|
|
61
|
+
build: |
|
|
62
|
+
FROM scratch
|
|
63
|
+
COPY share/ ${V3_IN_BOX}/
|
|
64
|
+
ENV NODE_EXTRA_CA_CERTS=${BUNDLE} SSL_CERT_FILE=${BUNDLE} REQUESTS_CA_BUNDLE=${BUNDLE}
|
|
65
|
+
capabilities:
|
|
66
|
+
- type: com.docker.sandbox/lifecycle@1
|
|
67
|
+
config:
|
|
68
|
+
install:
|
|
69
|
+
- command: "sh ${V3_IN_BOX}/install.sh"
|
|
70
|
+
user: "0"
|
|
71
|
+
env: [PROXY_CA_CERT_B64]
|
|
72
|
+
startup:
|
|
73
|
+
- command: ["sh", "${V3_IN_BOX}/jbr-watch.sh"]
|
|
74
|
+
`;
|
|
75
|
+
const install = (inBox) => `#!/bin/sh
|
|
50
76
|
# Generated by Huddle. Runs as root when the sandbox is created.
|
|
51
77
|
set -e
|
|
52
78
|
mkdir -p /usr/local/share/ca-certificates
|
|
53
|
-
install -m 0644 ${
|
|
79
|
+
install -m 0644 ${inBox}/huddle-ca.crt /usr/local/share/ca-certificates/huddle-ca.crt
|
|
54
80
|
# sbx's own proxy CA into the same store, so the bundle the variables point at
|
|
55
81
|
# trusts both (sbx's credential proxy signs with that one).
|
|
56
82
|
if [ -n "\${PROXY_CA_CERT_B64:-}" ]; then
|
|
@@ -65,10 +91,10 @@ echo "[huddle] CA installed"
|
|
|
65
91
|
// keystore. Toolbox installs it under ~/.cache/JetBrains/RemoteDev/dist on the
|
|
66
92
|
// first connect, so this keeps watching (in the background) and imports the CA
|
|
67
93
|
// into every backend it finds, once.
|
|
68
|
-
const
|
|
94
|
+
const jbrWatch = (inBox) => `#!/bin/sh
|
|
69
95
|
# Generated by Huddle. Runs as the agent user on every sandbox start.
|
|
70
96
|
CA=/usr/local/share/ca-certificates/huddle-ca.crt
|
|
71
|
-
[ -f "$CA" ] || CA=${
|
|
97
|
+
[ -f "$CA" ] || CA=${inBox}/huddle-ca.crt
|
|
72
98
|
import_all() {
|
|
73
99
|
for d in "$HOME"/.cache/JetBrains/RemoteDev/dist/*/; do
|
|
74
100
|
kt="$d/jbr/bin/keytool"; ks="$d/jbr/lib/security/cacerts"
|
|
@@ -82,27 +108,35 @@ import_all
|
|
|
82
108
|
( while sleep 30; do import_all; done ) >/dev/null 2>&1 </dev/null &
|
|
83
109
|
exit 0
|
|
84
110
|
`;
|
|
85
|
-
/** The `sbx.kit` op: `{ caPem }` → `{ dir }`, the kit's folder as a host path. */
|
|
111
|
+
/** The `sbx.kit` op: `{ caPem, format? }` → `{ dir, format }`, the kit's folder as a host path. */
|
|
86
112
|
function sbxKit(args, root = exports.SBX_KITS_DIR, platform = process.platform) {
|
|
87
|
-
const { caPem } = args;
|
|
113
|
+
const { caPem, format = 2 } = args;
|
|
88
114
|
if (typeof caPem !== 'string' || caPem.length > MAX_PEM || !PEM_RE.test(caPem)) {
|
|
89
115
|
throw new protocol_1.PipeError('bad_request', 'caPem must be one PEM certificate');
|
|
90
116
|
}
|
|
117
|
+
if (format !== 2 && format !== 3)
|
|
118
|
+
throw new protocol_1.PipeError('bad_request', 'format must be 2 or 3');
|
|
91
119
|
const dir = path_1.default.join(root, exports.KIT_NAME);
|
|
92
120
|
try {
|
|
93
121
|
(0, protocol_1.ensurePrivateDir)(root);
|
|
122
|
+
// Rewritten whole: a kit left in the other format would confuse sbx.
|
|
123
|
+
fs_1.default.rmSync(dir, { recursive: true, force: true });
|
|
94
124
|
(0, protocol_1.ensurePrivateDir)(dir);
|
|
95
|
-
const
|
|
96
|
-
|
|
125
|
+
const inBox = format === 3 ? V3_IN_BOX : V2_IN_BOX;
|
|
126
|
+
const files = format === 3 ? path_1.default.join(dir, 'share') : path_1.default.join(dir, 'files', 'home', '.huddle-ca');
|
|
127
|
+
fs_1.default.mkdirSync(files, { recursive: true, mode: 0o700 });
|
|
97
128
|
// \n only: these are read inside the Linux sandbox, also when written on Windows.
|
|
98
129
|
const write = (file, text) => fs_1.default.writeFileSync(file, text.replace(/\r\n/g, '\n'), { mode: 0o644 });
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
130
|
+
if (format === 3)
|
|
131
|
+
write(path_1.default.join(dir, `${exports.KIT_NAME}.yaml`), V3_SPEC);
|
|
132
|
+
else
|
|
133
|
+
write(path_1.default.join(dir, 'spec.yaml'), V2_SPEC);
|
|
134
|
+
write(path_1.default.join(files, 'huddle-ca.crt'), caPem.endsWith('\n') ? caPem : `${caPem}\n`);
|
|
135
|
+
write(path_1.default.join(files, 'install.sh'), install(inBox));
|
|
136
|
+
write(path_1.default.join(files, 'jbr-watch.sh'), jbrWatch(inBox));
|
|
103
137
|
}
|
|
104
138
|
catch (err) {
|
|
105
139
|
throw new protocol_1.PipeError('internal', `could not write the sbx kit: ${err.message ?? err}`);
|
|
106
140
|
}
|
|
107
|
-
return { dir: (0, fs_list_1.toHuddlePath)(dir, platform) };
|
|
141
|
+
return { dir: (0, fs_list_1.toHuddlePath)(dir, platform), format };
|
|
108
142
|
}
|
package/dist/runtime.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseDockerContextSocket = parseDockerContextSocket;
|
|
4
4
|
exports.isRancherDesktopSocket = isRancherDesktopSocket;
|
|
5
|
+
exports.dockerMountSocket = dockerMountSocket;
|
|
5
6
|
exports.parseRuntimeName = parseRuntimeName;
|
|
6
7
|
exports.resolveRuntime = resolveRuntime;
|
|
7
8
|
const child_process_1 = require("child_process");
|
|
@@ -41,9 +42,6 @@ function podmanSocketPath() {
|
|
|
41
42
|
}
|
|
42
43
|
return '/run/podman/podman.sock';
|
|
43
44
|
}
|
|
44
|
-
function dockerSocketPath() {
|
|
45
|
-
return process.platform === 'win32' ? '//var/run/docker.sock' : '/var/run/docker.sock';
|
|
46
|
-
}
|
|
47
45
|
/**
|
|
48
46
|
* Extracts the unix socket path from the JSON of `docker context inspect`. The
|
|
49
47
|
* active context determines which engine the `docker` command talks to; Rancher
|
|
@@ -51,6 +49,11 @@ function dockerSocketPath() {
|
|
|
51
49
|
* `Endpoints.docker.Host` points to `unix:///<home>/.rd/docker.sock` instead of
|
|
52
50
|
* the default `/var/run/docker.sock`.
|
|
53
51
|
*
|
|
52
|
+
* The result is only used to DETECT the engine (see buildRuntime), never as a
|
|
53
|
+
* bind-mount source: a context socket is the path the CLI uses to reach the
|
|
54
|
+
* daemon, which for VM-based engines is a host-side forwarder that the daemon
|
|
55
|
+
* itself cannot mount.
|
|
56
|
+
*
|
|
54
57
|
* Pure function so we can test the parsing in isolation. Returns `null` for
|
|
55
58
|
* non-parsable input or a non-unix endpoint (npipe:// on Windows,
|
|
56
59
|
* tcp:// / ssh:// remote), because those cannot be bind-mounted as a file path.
|
|
@@ -72,10 +75,10 @@ function parseDockerContextSocket(json) {
|
|
|
72
75
|
const path = host.slice('unix://'.length);
|
|
73
76
|
if (!path.startsWith('/'))
|
|
74
77
|
return null;
|
|
75
|
-
// The
|
|
76
|
-
//
|
|
77
|
-
//
|
|
78
|
-
//
|
|
78
|
+
// The `Host` from `docker context inspect` is attacker-influenceable (whoever
|
|
79
|
+
// can create/activate a docker context controls the value). The path is only
|
|
80
|
+
// used for detection now, but keep it as defense in depth should it ever reach
|
|
81
|
+
// a shell command again: restrict it to characters that occur in a real
|
|
79
82
|
// socket path: allow spaces (legal in e.g. macOS `/Users/First Last/.rd/...`)
|
|
80
83
|
// but never the metacharacters that stay dangerous inside double quotes
|
|
81
84
|
// ($, backtick, ", \) or the command separators (;, |, &, (), newline).
|
|
@@ -94,6 +97,28 @@ function dockerContextSocket() {
|
|
|
94
97
|
return undefined;
|
|
95
98
|
return parseDockerContextSocket(json) ?? undefined;
|
|
96
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* Determines the docker socket to bind-mount (as seen by the engine) and
|
|
102
|
+
* whether the engine runs in a VM, given the active context's socket.
|
|
103
|
+
*
|
|
104
|
+
* Rancher Desktop (dockerd/moby mode) looks like an ordinary Docker engine, but
|
|
105
|
+
* its context points to `~/.rd/docker.sock`. That is a host-side forwarder into
|
|
106
|
+
* the Lima VM that only the CLI can use: bind-mount sources are resolved by
|
|
107
|
+
* dockerd INSIDE the VM, where that file is not a usable socket (dockerd then
|
|
108
|
+
* tries to mkdir it: "operation not supported"). Inside the VM dockerd listens
|
|
109
|
+
* on the standard /var/run/docker.sock, so we always mount that — the same
|
|
110
|
+
* engine-side reasoning as for /tmp/dc-sockets in init.ts.
|
|
111
|
+
*
|
|
112
|
+
* Pure function so we can test it without a daemon.
|
|
113
|
+
*/
|
|
114
|
+
function dockerMountSocket(contextSocket, platform) {
|
|
115
|
+
return {
|
|
116
|
+
socketPath: platform === 'win32' ? '//var/run/docker.sock' : '/var/run/docker.sock',
|
|
117
|
+
// Docker Desktop (macOS/Windows) and Rancher Desktop (every OS, Lima/WSL)
|
|
118
|
+
// run in a VM; native Docker on Linux does not.
|
|
119
|
+
isRemote: isRancherDesktopSocket(contextSocket) || platform !== 'linux',
|
|
120
|
+
};
|
|
121
|
+
}
|
|
97
122
|
function podmanIsRemote() {
|
|
98
123
|
// On macOS/Windows Podman always runs in a `podman machine` VM; on Linux too
|
|
99
124
|
// the client can point at a remote socket. `ServiceIsRemote` is the
|
|
@@ -110,21 +135,15 @@ function buildRuntime(name) {
|
|
|
110
135
|
securityOpts: ['label=disable'],
|
|
111
136
|
};
|
|
112
137
|
}
|
|
113
|
-
//
|
|
114
|
-
//
|
|
115
|
-
//
|
|
116
|
-
|
|
117
|
-
// Docker, Docker Desktop). Rancher Desktop runs the engine in a VM (Lima/WSL)
|
|
118
|
-
// on EVERY platform, so it is always 'remote'.
|
|
119
|
-
const contextSocket = dockerContextSocket();
|
|
120
|
-
const isRancher = isRancherDesktopSocket(contextSocket);
|
|
138
|
+
// The active docker context only tells us WHICH engine this is (Rancher
|
|
139
|
+
// Desktop or not); the mount source is always the engine-side socket. See
|
|
140
|
+
// dockerMountSocket().
|
|
141
|
+
const { socketPath, isRemote } = dockerMountSocket(dockerContextSocket(), process.platform);
|
|
121
142
|
return {
|
|
122
143
|
name,
|
|
123
|
-
socketPath
|
|
144
|
+
socketPath,
|
|
124
145
|
defaultNetwork: 'bridge',
|
|
125
|
-
|
|
126
|
-
// Docker on Linux does not.
|
|
127
|
-
isRemote: isRancher || process.platform !== 'linux',
|
|
146
|
+
isRemote,
|
|
128
147
|
securityOpts: [],
|
|
129
148
|
};
|
|
130
149
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@infosupport/huddle-cli",
|
|
3
|
-
"version": "0.0.0-experiment-160.
|
|
3
|
+
"version": "0.0.0-experiment-160.130.1",
|
|
4
4
|
"description": "Huddle CLI — start devcontainers and manage firewall rules",
|
|
5
5
|
"license": "GPL-3.0-or-later",
|
|
6
6
|
"author": "Info Support B.V.",
|