@impz/client 2.0.8 → 2.2.0
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/index.d.ts +4 -0
- package/dist/index.js +25 -10
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -81,6 +81,7 @@ declare const ExecStartMessageSchema: z.ZodObject<{
|
|
|
81
81
|
broker: "broker";
|
|
82
82
|
}>>>;
|
|
83
83
|
log: z.ZodOptional<z.ZodBoolean>;
|
|
84
|
+
dropSysAdmin: z.ZodOptional<z.ZodBoolean>;
|
|
84
85
|
}, z.core.$strip>;
|
|
85
86
|
declare const ExecAttachMessageSchema: z.ZodObject<{
|
|
86
87
|
type: z.ZodLiteral<"attach">;
|
|
@@ -16594,6 +16595,7 @@ declare const impContract: {
|
|
|
16594
16595
|
brokerRefusals: z.ZodOptional<z.ZodBoolean>;
|
|
16595
16596
|
grantFilters: z.ZodOptional<z.ZodBoolean>;
|
|
16596
16597
|
readOnlyFiles: z.ZodOptional<z.ZodBoolean>;
|
|
16598
|
+
execDropSysAdmin: z.ZodOptional<z.ZodBoolean>;
|
|
16597
16599
|
}, z.core.$strip>>;
|
|
16598
16600
|
}, z.core.$strip>, import("@orpc/contract").MergedErrorMap<Record<never, never>, {
|
|
16599
16601
|
NOT_FOUND: {
|
|
@@ -20532,6 +20534,7 @@ declare const SystemInfoSchema: z.ZodObject<{
|
|
|
20532
20534
|
brokerRefusals: z.ZodOptional<z.ZodBoolean>;
|
|
20533
20535
|
grantFilters: z.ZodOptional<z.ZodBoolean>;
|
|
20534
20536
|
readOnlyFiles: z.ZodOptional<z.ZodBoolean>;
|
|
20537
|
+
execDropSysAdmin: z.ZodOptional<z.ZodBoolean>;
|
|
20535
20538
|
}, z.core.$strip>>;
|
|
20536
20539
|
}, z.core.$strip>;
|
|
20537
20540
|
type SystemInfo = z.infer<typeof SystemInfoSchema>;
|
|
@@ -20685,6 +20688,7 @@ interface ExecOptions {
|
|
|
20685
20688
|
readonly resumeFrom?: ResumeFrom;
|
|
20686
20689
|
readonly require?: readonly ExecRequirement[];
|
|
20687
20690
|
readonly log?: boolean;
|
|
20691
|
+
readonly dropSysAdmin?: boolean;
|
|
20688
20692
|
readonly signal?: Readonly<AbortSignal>;
|
|
20689
20693
|
readonly maxUnreadBytes?: number;
|
|
20690
20694
|
}
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { RPCLink } from "@orpc/client/fetch";
|
|
|
3
3
|
import * as z from "zod";
|
|
4
4
|
//#endregion
|
|
5
5
|
//#region src/check-server.ts
|
|
6
|
-
const CLIENT_VERSION = "2.0
|
|
6
|
+
const CLIENT_VERSION = "2.2.0";
|
|
7
7
|
async function checkServer(rpc) {
|
|
8
8
|
const info = await rpc.system.info();
|
|
9
9
|
return {
|
|
@@ -221,7 +221,8 @@ const ExecStartMessageSchema = z.object({
|
|
|
221
221
|
killGraceMs: z.int().min(1).max(6e4).optional(),
|
|
222
222
|
resumeFrom: ResumeFromSchema.optional(),
|
|
223
223
|
require: z.array(z.enum(EXEC_REQUIREMENTS)).optional(),
|
|
224
|
-
log: z.boolean().optional()
|
|
224
|
+
log: z.boolean().optional(),
|
|
225
|
+
dropSysAdmin: z.boolean().optional()
|
|
225
226
|
}).refine((start) => start.session === void 0 || start.tty, {
|
|
226
227
|
message: "a session needs a tty",
|
|
227
228
|
path: ["tty"]
|
|
@@ -243,6 +244,9 @@ const ExecStartMessageSchema = z.object({
|
|
|
243
244
|
}).refine((start) => start.require === void 0 || start.require.length === 0 || start.tool === void 0 && start.outer !== true, {
|
|
244
245
|
message: "a tool or an outer exec takes no require",
|
|
245
246
|
path: ["require"]
|
|
247
|
+
}).refine((start) => start.dropSysAdmin !== true || start.tool === void 0 && start.outer !== true, {
|
|
248
|
+
message: "a tool or an outer exec cannot drop CAP_SYS_ADMIN",
|
|
249
|
+
path: ["dropSysAdmin"]
|
|
246
250
|
});
|
|
247
251
|
const ExecAttachMessageSchema = z.object({
|
|
248
252
|
type: z.literal("attach"),
|
|
@@ -906,11 +910,18 @@ var ExecError = class extends Error {
|
|
|
906
910
|
}
|
|
907
911
|
};
|
|
908
912
|
//#endregion
|
|
909
|
-
//#region src/exec/check-exec-
|
|
913
|
+
//#region src/exec/check-exec-feature.ts
|
|
910
914
|
const CHECK_TIMEOUT_MS$1 = 5e3;
|
|
911
|
-
const
|
|
915
|
+
const EXEC_FEATURE_GAPS = {
|
|
916
|
+
execRequire: "this impd is older than 0.30.0 and does not check exec requirements",
|
|
917
|
+
execDropSysAdmin: "this impd cannot start a command without CAP_SYS_ADMIN"
|
|
918
|
+
};
|
|
919
|
+
const FeaturesSchema = z.object({
|
|
920
|
+
execRequire: z.boolean().optional(),
|
|
921
|
+
execDropSysAdmin: z.boolean().optional()
|
|
922
|
+
});
|
|
912
923
|
const InfoAnswerSchema = z.object({ json: z.object({ features: FeaturesSchema.optional() }) });
|
|
913
|
-
async function
|
|
924
|
+
async function checkExecFeature(feature, baseUrl, token, customFetch = fetch) {
|
|
914
925
|
let response;
|
|
915
926
|
try {
|
|
916
927
|
response = await customFetch(new Request(resolveImpdUrl(baseUrl, "/rpc/system/info").href, {
|
|
@@ -935,8 +946,8 @@ async function checkExecRequire(baseUrl, token, customFetch = fetch) {
|
|
|
935
946
|
code: null,
|
|
936
947
|
message: `impd answered system.info with ${String(response.status)}; nothing was started`
|
|
937
948
|
};
|
|
938
|
-
if (parsed.data.json.features?.
|
|
939
|
-
const detail =
|
|
949
|
+
if (parsed.data.json.features?.[feature] === true) return null;
|
|
950
|
+
const detail = EXEC_FEATURE_GAPS[feature];
|
|
940
951
|
return {
|
|
941
952
|
kind: "failed",
|
|
942
953
|
code: "PRECONDITION_FAILED",
|
|
@@ -1063,8 +1074,11 @@ function openExecSession(options) {
|
|
|
1063
1074
|
};
|
|
1064
1075
|
const sendOpen = async () => {
|
|
1065
1076
|
const start = options.start;
|
|
1066
|
-
|
|
1067
|
-
|
|
1077
|
+
const features = [];
|
|
1078
|
+
if ("argv" in start && start.require !== void 0 && start.require.length > 0) features.push("execRequire");
|
|
1079
|
+
if ("argv" in start && start.dropSysAdmin === true) features.push("execDropSysAdmin");
|
|
1080
|
+
for (const feature of features) {
|
|
1081
|
+
const refusal = await checkExecFeature(feature, options.baseUrl, options.token, options.fetch);
|
|
1068
1082
|
if (refusal !== null) {
|
|
1069
1083
|
resolveOutcome(refusal);
|
|
1070
1084
|
return;
|
|
@@ -1254,7 +1268,8 @@ function openExec(deps, name, argv, options = {}) {
|
|
|
1254
1268
|
...options.killGraceMs !== void 0 && { killGraceMs: options.killGraceMs },
|
|
1255
1269
|
...options.resumeFrom !== void 0 && { resumeFrom: options.resumeFrom },
|
|
1256
1270
|
...options.require !== void 0 && { require: options.require },
|
|
1257
|
-
...options.log === true && { log: true }
|
|
1271
|
+
...options.log === true && { log: true },
|
|
1272
|
+
...options.dropSysAdmin === true && { dropSysAdmin: true }
|
|
1258
1273
|
});
|
|
1259
1274
|
}
|
|
1260
1275
|
function openAttach(deps, name, session, options = {}) {
|