@infosupport/huddle-cli 0.0.0-experiment-160.129.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/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/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.",
|