@infosupport/huddle-cli 0.0.0-experiment-160.129.1 → 0.0.0-experiment-160.131.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.
@@ -18,6 +18,7 @@ exports.isAbsoluteHostPath = isAbsoluteHostPath;
18
18
  exports.hostRoots = hostRoots;
19
19
  exports.listHostFolders = listHostFolders;
20
20
  exports.fsList = fsList;
21
+ exports.fsResolve = fsResolve;
21
22
  const fs_1 = __importDefault(require("fs"));
22
23
  const os_1 = __importDefault(require("os"));
23
24
  const path_1 = __importDefault(require("path"));
@@ -155,3 +156,26 @@ async function fsList(args, max = protocol_1.MAX_FOLDER_ENTRIES) {
155
156
  throw new protocol_1.PipeError('bad_request', `not an absolute host path: ${raw}`);
156
157
  return listHostFolders(toHuddlePath(raw), max);
157
158
  }
159
+ const MAX_RESOLVE_PATHS = 64;
160
+ /**
161
+ * The `fs.resolve` op: where each path really is (links followed), or null when
162
+ * it does not exist. The portal cannot see host links, and a workspace that is a
163
+ * link into ~/.huddle would otherwise pass its lexical mount check.
164
+ */
165
+ async function fsResolve(args) {
166
+ const raw = args.paths;
167
+ if (!Array.isArray(raw) || raw.length > MAX_RESOLVE_PATHS)
168
+ throw new protocol_1.PipeError('bad_request', `paths must be an array of at most ${MAX_RESOLVE_PATHS}`);
169
+ const paths = [];
170
+ for (const p of raw) {
171
+ if (typeof p !== 'string' || p.includes('\0') || !isAbsoluteHostPath(p))
172
+ throw new protocol_1.PipeError('bad_request', 'paths must be absolute host paths');
173
+ try {
174
+ paths.push(toHuddlePath(await fs_1.default.promises.realpath(p)));
175
+ }
176
+ catch {
177
+ paths.push(null);
178
+ }
179
+ }
180
+ return { paths };
181
+ }
@@ -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
- const SPEC = `schemaVersion: "2"
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 ${IN_BOX}/install.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", "${IN_BOX}/jbr-watch.sh"]
50
+ - command: ["sh", "${V2_IN_BOX}/jbr-watch.sh"]
48
51
  `;
49
- const INSTALL = `#!/bin/sh
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 ${IN_BOX}/huddle-ca.crt /usr/local/share/ca-certificates/huddle-ca.crt
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 JBR_WATCH = `#!/bin/sh
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=${IN_BOX}/huddle-ca.crt
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 home = path_1.default.join(dir, 'files', 'home', '.huddle-ca');
96
- fs_1.default.mkdirSync(home, { recursive: true, mode: 0o700 });
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
- write(path_1.default.join(dir, 'spec.yaml'), SPEC);
100
- write(path_1.default.join(home, 'huddle-ca.crt'), caPem.endsWith('\n') ? caPem : `${caPem}\n`);
101
- write(path_1.default.join(home, 'install.sh'), INSTALL);
102
- write(path_1.default.join(home, 'jbr-watch.sh'), JBR_WATCH);
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
  }
@@ -38,6 +38,8 @@ async function dispatch(req, maxEntries) {
38
38
  };
39
39
  case 'fs.list':
40
40
  return (0, fs_list_1.fsList)(args, maxEntries);
41
+ case 'fs.resolve':
42
+ return (0, fs_list_1.fsResolve)(args);
41
43
  case 'tool.run':
42
44
  return (0, tools_1.toolRun)(args);
43
45
  case 'sbx.links':
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infosupport/huddle-cli",
3
- "version": "0.0.0-experiment-160.129.1",
3
+ "version": "0.0.0-experiment-160.131.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.",