@infosupport/huddle-cli 0.0.0-experiment-160.104.1 → 0.0.0-experiment-160.106.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/init.js +6 -1
- package/dist/pipe/command.js +2 -2
- package/dist/pipe/protocol.js +34 -1
- package/dist/pipe/serve.js +2 -2
- package/package.json +1 -1
package/dist/init.js
CHANGED
|
@@ -175,7 +175,12 @@ async function runInit(opts, images) {
|
|
|
175
175
|
console.log((0, utils_1.dim)(` Mounting extensions folder: ${extFolder} -> /extensions`));
|
|
176
176
|
// The host pipe lives inside the ~/.huddle mount; create it now so the
|
|
177
177
|
// gateway sees the folder from its first start, before the agent runs.
|
|
178
|
-
|
|
178
|
+
try {
|
|
179
|
+
(0, protocol_1.ensurePrivateDir)(protocol_1.PIPE_DIR);
|
|
180
|
+
}
|
|
181
|
+
catch (err) {
|
|
182
|
+
console.log((0, utils_1.yellow)(` Host pipe folder not usable: ${err instanceof Error ? err.message : err}`));
|
|
183
|
+
}
|
|
179
184
|
// Build the container command as an argv array (runArgs → execFileSync, no
|
|
180
185
|
// shell). The folder paths below come from config and are operator-writable via
|
|
181
186
|
// the settings API, so they must never reach a shell as a string.
|
package/dist/pipe/command.js
CHANGED
|
@@ -88,13 +88,13 @@ function rotateLog() {
|
|
|
88
88
|
*/
|
|
89
89
|
async function startPipeAgent() {
|
|
90
90
|
try {
|
|
91
|
-
|
|
91
|
+
(0, protocol_1.ensurePrivateDir)(protocol_1.PIPE_DIR);
|
|
92
92
|
const old = await stopRunning();
|
|
93
93
|
rotateLog();
|
|
94
94
|
// dist/pipe/command.js -> dist/index.js: the entry of THIS install, not
|
|
95
95
|
// whatever `huddle` resolves to on PATH.
|
|
96
96
|
const entry = path_1.default.join(__dirname, '..', 'index.js');
|
|
97
|
-
const logFd = fs_1.default.openSync(LOG_PATH, 'a');
|
|
97
|
+
const logFd = fs_1.default.openSync(LOG_PATH, 'a', 0o600);
|
|
98
98
|
let pid;
|
|
99
99
|
try {
|
|
100
100
|
const child = (0, child_process_1.spawn)(process.execPath, [entry, 'pipe', 'serve'], {
|
package/dist/pipe/protocol.js
CHANGED
|
@@ -9,6 +9,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
9
9
|
};
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
11
|
exports.PipeError = exports.MAX_TOOL_TIMEOUT_MS = exports.DEFAULT_TOOL_TIMEOUT_MS = exports.MAX_OUTPUT_BYTES = exports.MAX_FOLDER_ENTRIES = exports.STALE_FILE_MS = exports.HEARTBEAT_STALE_MS = exports.HEARTBEAT_MS = exports.POLL_MS = exports.LOG_FILE = exports.HEARTBEAT_FILE = exports.PIPE_DIR = exports.PROTOCOL_VERSION = void 0;
|
|
12
|
+
exports.ensurePrivateDir = ensurePrivateDir;
|
|
12
13
|
exports.writeJsonAtomic = writeJsonAtomic;
|
|
13
14
|
exports.readHeartbeat = readHeartbeat;
|
|
14
15
|
exports.heartbeatFresh = heartbeatFresh;
|
|
@@ -44,9 +45,41 @@ exports.PipeError = PipeError;
|
|
|
44
45
|
* never reads a half-written file. Rename within one folder is atomic on every
|
|
45
46
|
* platform, including across the Docker bind mount.
|
|
46
47
|
*/
|
|
48
|
+
/**
|
|
49
|
+
* Creates the pipe folder owner-only, or makes an existing one so. Whoever can
|
|
50
|
+
* write a request into it can run the allowlisted host tools, so on POSIX it
|
|
51
|
+
* must be ours (not a symlink) and closed to everyone else, and its parent must
|
|
52
|
+
* not let anyone else swap it out. Throws when that cannot be made true. On
|
|
53
|
+
* Windows a folder under the user profile is private already.
|
|
54
|
+
*/
|
|
55
|
+
function ensurePrivateDir(dir) {
|
|
56
|
+
fs_1.default.mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
57
|
+
if (process.platform === 'win32' || typeof process.getuid !== 'function')
|
|
58
|
+
return;
|
|
59
|
+
const uid = process.getuid();
|
|
60
|
+
const st = fs_1.default.lstatSync(dir);
|
|
61
|
+
if (!st.isDirectory())
|
|
62
|
+
throw new Error(`${dir} is not a directory (a symlink is not accepted)`);
|
|
63
|
+
if (st.uid !== uid)
|
|
64
|
+
throw new Error(`${dir} belongs to uid ${st.uid}, not to you: refusing to use it as the host pipe`);
|
|
65
|
+
// The parent: ours (then closed to writes by others), or root's and either not
|
|
66
|
+
// writable by others or sticky (like /tmp), where nobody else can rename ours.
|
|
67
|
+
const parent = path_1.default.dirname(dir);
|
|
68
|
+
const ps = fs_1.default.statSync(parent);
|
|
69
|
+
const pmode = ps.mode & 0o7777;
|
|
70
|
+
if (ps.uid === uid) {
|
|
71
|
+
if (pmode & 0o022)
|
|
72
|
+
fs_1.default.chmodSync(parent, pmode & ~0o022);
|
|
73
|
+
}
|
|
74
|
+
else if (ps.uid !== 0 || ((pmode & 0o022) && !(pmode & 0o1000))) {
|
|
75
|
+
throw new Error(`${parent} can be changed by other users: refusing to serve the host pipe below it`);
|
|
76
|
+
}
|
|
77
|
+
if ((fs_1.default.statSync(dir).mode & 0o777) !== 0o700)
|
|
78
|
+
fs_1.default.chmodSync(dir, 0o700);
|
|
79
|
+
}
|
|
47
80
|
function writeJsonAtomic(file, data) {
|
|
48
81
|
const tmp = `${file}.tmp`;
|
|
49
|
-
fs_1.default.writeFileSync(tmp, JSON.stringify(data));
|
|
82
|
+
fs_1.default.writeFileSync(tmp, JSON.stringify(data), { mode: 0o600 });
|
|
50
83
|
fs_1.default.renameSync(tmp, file);
|
|
51
84
|
}
|
|
52
85
|
/** The heartbeat in `dir`, or null when there is none (or it is unreadable). */
|
package/dist/pipe/serve.js
CHANGED
|
@@ -89,7 +89,7 @@ function servePipe(opts) {
|
|
|
89
89
|
const { dir } = opts;
|
|
90
90
|
const maxEntries = opts.maxEntries ?? protocol_1.MAX_FOLDER_ENTRIES;
|
|
91
91
|
const log = opts.log ?? (() => { });
|
|
92
|
-
|
|
92
|
+
(0, protocol_1.ensurePrivateDir)(dir);
|
|
93
93
|
const startedAt = new Date().toISOString();
|
|
94
94
|
const version = (0, self_update_1.cliVersion)();
|
|
95
95
|
const inFlight = new Map();
|
|
@@ -134,7 +134,7 @@ function servePipe(opts) {
|
|
|
134
134
|
catch {
|
|
135
135
|
// The folder went away (e.g. ~/.huddle was removed); recreate and carry on.
|
|
136
136
|
try {
|
|
137
|
-
|
|
137
|
+
(0, protocol_1.ensurePrivateDir)(dir);
|
|
138
138
|
}
|
|
139
139
|
catch { /* retry next tick */ }
|
|
140
140
|
}
|
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.106.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.",
|