@norskvideo/ctl-product-template-schema 0.1.80 → 0.1.82
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/index.d.ts +58 -0
- package/index.js +31 -2
- package/package.json +1 -1
- package/secrets/config.d.ts +3 -2
- package/secrets/config.js +6 -3
- package/secrets/providers/file.d.ts +7 -1
- package/secrets/providers/file.js +18 -2
package/index.d.ts
CHANGED
|
@@ -115,6 +115,22 @@ export declare const ProductTemplateAcceleratorSchema: z.ZodEnum<{
|
|
|
115
115
|
}>;
|
|
116
116
|
export type ProductTemplateAccelerator = z.infer<typeof ProductTemplateAcceleratorSchema>;
|
|
117
117
|
export declare const ProductTemplateRequirementsSchema: z.ZodObject<{
|
|
118
|
+
vcpus: z.ZodOptional<z.ZodObject<{
|
|
119
|
+
mode: z.ZodEnum<{
|
|
120
|
+
default: "default";
|
|
121
|
+
fixed: "fixed";
|
|
122
|
+
required: "required";
|
|
123
|
+
}>;
|
|
124
|
+
value: z.ZodOptional<z.ZodNumber>;
|
|
125
|
+
}, z.core.$strip>>;
|
|
126
|
+
pinnedCores: z.ZodOptional<z.ZodObject<{
|
|
127
|
+
mode: z.ZodEnum<{
|
|
128
|
+
default: "default";
|
|
129
|
+
fixed: "fixed";
|
|
130
|
+
required: "required";
|
|
131
|
+
}>;
|
|
132
|
+
value: z.ZodOptional<z.ZodNumber>;
|
|
133
|
+
}, z.core.$strip>>;
|
|
118
134
|
capacity: z.ZodOptional<z.ZodObject<{
|
|
119
135
|
mode: z.ZodEnum<{
|
|
120
136
|
default: "default";
|
|
@@ -184,6 +200,16 @@ export declare const ProductTemplateRequirementsSchema: z.ZodObject<{
|
|
|
184
200
|
}, z.core.$strip>>;
|
|
185
201
|
}, z.core.$strip>;
|
|
186
202
|
export type ProductTemplateRequirements = z.infer<typeof ProductTemplateRequirementsSchema>;
|
|
203
|
+
/** The vCPU dimension a manifest declares, under its name or its old one. */
|
|
204
|
+
export declare function requirementVcpus(r: ProductTemplateRequirements | undefined): {
|
|
205
|
+
mode: "default" | "fixed" | "required";
|
|
206
|
+
value?: number | undefined;
|
|
207
|
+
} | undefined;
|
|
208
|
+
/** The pinned-cores dimension a manifest declares, under its name or its old one. */
|
|
209
|
+
export declare function requirementPinnedCores(r: ProductTemplateRequirements | undefined): {
|
|
210
|
+
mode: "default" | "fixed" | "required";
|
|
211
|
+
value?: number | undefined;
|
|
212
|
+
} | undefined;
|
|
187
213
|
export declare const PRODUCT_TEMPLATE_MIGRATION_STRATEGIES: readonly ["overlap", "stopThenStart", "handover"];
|
|
188
214
|
export type MigrationStrategy = (typeof PRODUCT_TEMPLATE_MIGRATION_STRATEGIES)[number];
|
|
189
215
|
export declare const DEFAULT_MIGRATION_STRATEGY: MigrationStrategy;
|
|
@@ -302,6 +328,22 @@ export declare const ProductTemplateManifestSchema: z.ZodObject<{
|
|
|
302
328
|
}, z.core.$strip>>;
|
|
303
329
|
}, z.core.$strip>>;
|
|
304
330
|
requirements: z.ZodOptional<z.ZodObject<{
|
|
331
|
+
vcpus: z.ZodOptional<z.ZodObject<{
|
|
332
|
+
mode: z.ZodEnum<{
|
|
333
|
+
default: "default";
|
|
334
|
+
fixed: "fixed";
|
|
335
|
+
required: "required";
|
|
336
|
+
}>;
|
|
337
|
+
value: z.ZodOptional<z.ZodNumber>;
|
|
338
|
+
}, z.core.$strip>>;
|
|
339
|
+
pinnedCores: z.ZodOptional<z.ZodObject<{
|
|
340
|
+
mode: z.ZodEnum<{
|
|
341
|
+
default: "default";
|
|
342
|
+
fixed: "fixed";
|
|
343
|
+
required: "required";
|
|
344
|
+
}>;
|
|
345
|
+
value: z.ZodOptional<z.ZodNumber>;
|
|
346
|
+
}, z.core.$strip>>;
|
|
305
347
|
capacity: z.ZodOptional<z.ZodObject<{
|
|
306
348
|
mode: z.ZodEnum<{
|
|
307
349
|
default: "default";
|
|
@@ -604,6 +646,22 @@ export declare const ProductTemplateMaterialsSchema: z.ZodObject<{
|
|
|
604
646
|
}, z.core.$strip>>;
|
|
605
647
|
}, z.core.$strip>>;
|
|
606
648
|
requirements: z.ZodOptional<z.ZodObject<{
|
|
649
|
+
vcpus: z.ZodOptional<z.ZodObject<{
|
|
650
|
+
mode: z.ZodEnum<{
|
|
651
|
+
default: "default";
|
|
652
|
+
fixed: "fixed";
|
|
653
|
+
required: "required";
|
|
654
|
+
}>;
|
|
655
|
+
value: z.ZodOptional<z.ZodNumber>;
|
|
656
|
+
}, z.core.$strip>>;
|
|
657
|
+
pinnedCores: z.ZodOptional<z.ZodObject<{
|
|
658
|
+
mode: z.ZodEnum<{
|
|
659
|
+
default: "default";
|
|
660
|
+
fixed: "fixed";
|
|
661
|
+
required: "required";
|
|
662
|
+
}>;
|
|
663
|
+
value: z.ZodOptional<z.ZodNumber>;
|
|
664
|
+
}, z.core.$strip>>;
|
|
607
665
|
capacity: z.ZodOptional<z.ZodObject<{
|
|
608
666
|
mode: z.ZodEnum<{
|
|
609
667
|
default: "default";
|
package/index.js
CHANGED
|
@@ -408,11 +408,17 @@ const ProductTemplateGpuRequirementSchema = z.object({
|
|
|
408
408
|
export const ProductTemplateAcceleratorSchema = z.enum(["none", "nvidia", "quadra"]);
|
|
409
409
|
export const ProductTemplateRequirementsSchema = z
|
|
410
410
|
.object({
|
|
411
|
+
vcpus: requirementDimension(z.number().positive()).optional().meta({
|
|
412
|
+
description: "vCPUs: the runtime's share of a node's CPU, the primary placement dimension. Every runtime has one; absent, the operator's value or 1.",
|
|
413
|
+
}),
|
|
414
|
+
pinnedCores: requirementDimension(z.number().int().positive()).optional().meta({
|
|
415
|
+
description: "Whole cores pinned to the runtime (cpuset), out of its vCPUs: never more than `vcpus`.",
|
|
416
|
+
}),
|
|
411
417
|
capacity: requirementDimension(z.number().positive()).optional().meta({
|
|
412
|
-
description: "
|
|
418
|
+
description: "Deprecated: the old name for `vcpus`, still read. Give one or the other.",
|
|
413
419
|
}),
|
|
414
420
|
cores: requirementDimension(z.number().int().positive()).optional().meta({
|
|
415
|
-
description: "
|
|
421
|
+
description: "Deprecated: the old name for `pinnedCores`, still read. Give one or the other.",
|
|
416
422
|
}),
|
|
417
423
|
gpu: requirementDimension(ProductTemplateGpuRequirementSchema, (v) => v.capacity !== undefined || v.model !== undefined)
|
|
418
424
|
.optional()
|
|
@@ -440,8 +446,31 @@ export const ProductTemplateRequirementsSchema = z
|
|
|
440
446
|
st2110Nics: z.object({ count: z.number().int().positive() }).optional().meta({
|
|
441
447
|
description: "How many ST 2110 NICs an instance must claim. For a product that cannot know which NICs a host has: the operator picks them at launch (advanced.st2110Nics names a default).",
|
|
442
448
|
}),
|
|
449
|
+
})
|
|
450
|
+
.superRefine((r, ctx) => {
|
|
451
|
+
// The old names are read, but never beside the new: which would win?
|
|
452
|
+
if (r.capacity !== undefined && r.vcpus !== undefined)
|
|
453
|
+
ctx.addIssue({
|
|
454
|
+
code: "custom",
|
|
455
|
+
path: ["capacity"],
|
|
456
|
+
message: "give `vcpus` or its old name `capacity`, not both",
|
|
457
|
+
});
|
|
458
|
+
if (r.cores !== undefined && r.pinnedCores !== undefined)
|
|
459
|
+
ctx.addIssue({
|
|
460
|
+
code: "custom",
|
|
461
|
+
path: ["cores"],
|
|
462
|
+
message: "give `pinnedCores` or its old name `cores`, not both",
|
|
463
|
+
});
|
|
443
464
|
})
|
|
444
465
|
.meta({ id: "ProductTemplateRequirements", outputId: "ProductTemplateRequirements" });
|
|
466
|
+
/** The vCPU dimension a manifest declares, under its name or its old one. */
|
|
467
|
+
export function requirementVcpus(r) {
|
|
468
|
+
return r?.vcpus ?? r?.capacity;
|
|
469
|
+
}
|
|
470
|
+
/** The pinned-cores dimension a manifest declares, under its name or its old one. */
|
|
471
|
+
export function requirementPinnedCores(r) {
|
|
472
|
+
return r?.pinnedCores ?? r?.cores;
|
|
473
|
+
}
|
|
445
474
|
// How a running instance of the product may be moved between nodes
|
|
446
475
|
// (norsk-mgr/docs/internal/design/job-migration.md §6). The manifest
|
|
447
476
|
// declares the strongest promise the product keeps; a migrate request may
|
package/package.json
CHANGED
package/secrets/config.d.ts
CHANGED
|
@@ -58,8 +58,9 @@ export interface LoadSecretProvidersOptions {
|
|
|
58
58
|
path?: string;
|
|
59
59
|
/** Config text (YAML, so JSON too), as an environment variable carries it. */
|
|
60
60
|
inline?: string;
|
|
61
|
-
/** Where `file` reads when the config names no `fileDir
|
|
62
|
-
*
|
|
61
|
+
/** Where `file` reads when the config names no `fileDir`: ctl's own
|
|
62
|
+
* directory, so a file in it, or it, that group or others can reach is
|
|
63
|
+
* refused. Without either, there is no `file` provider. */
|
|
63
64
|
defaultFileDir?: string;
|
|
64
65
|
/** Where a resolve through a profile's redirect is recorded; stderr by default. */
|
|
65
66
|
log?: (line: string) => void;
|
package/secrets/config.js
CHANGED
|
@@ -81,9 +81,12 @@ export function loadSecretProviders(opts) {
|
|
|
81
81
|
}
|
|
82
82
|
return ok(providers);
|
|
83
83
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
84
|
+
// The default is ctl's own directory, so it must be private; one the config
|
|
85
|
+
// names (a mounted Secret volume, say) is the config author's call.
|
|
86
|
+
if (config.fileDir)
|
|
87
|
+
providers.file = fileSecretProvider(config.fileDir);
|
|
88
|
+
else if (opts.defaultFileDir)
|
|
89
|
+
providers.file = fileSecretProvider(opts.defaultFileDir, { requirePrivate: true });
|
|
87
90
|
if (config.k8s)
|
|
88
91
|
providers.k8s = k8sSecretProvider(config.k8s);
|
|
89
92
|
if (config.aws)
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import { type SecretProvider } from "../provider.js";
|
|
2
|
+
export interface FileSecretProviderOptions {
|
|
3
|
+
/** Refuse a file, or the directory, that group or others can reach. For a
|
|
4
|
+
* directory ctl owns (RFC 0011 §3.6); a mounted volume's own modes are
|
|
5
|
+
* usually wider, and are its operator's call. */
|
|
6
|
+
requirePrivate?: boolean;
|
|
7
|
+
}
|
|
2
8
|
/** `<dir>/<key>`, file names only. A file holding the obfuscated form is read
|
|
3
9
|
* back as its value; any other file is its own value. */
|
|
4
|
-
export declare function fileSecretProvider(dir: string): SecretProvider;
|
|
10
|
+
export declare function fileSecretProvider(dir: string, opts?: FileSecretProviderOptions): SecretProvider;
|
|
@@ -1,16 +1,32 @@
|
|
|
1
|
-
import { readFileSync } from "node:fs";
|
|
1
|
+
import { readFileSync, statSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { err, ok, tryResult } from "@norskvideo/ctl-foundation";
|
|
4
4
|
import { deobfuscate, isObfuscated } from "../obfuscation.js";
|
|
5
5
|
import { dropTrailingNewline } from "../provider.js";
|
|
6
6
|
const FILE_KEY = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
7
|
+
/** Group or other access of any kind. */
|
|
8
|
+
const NOT_OWNER_ONLY = 0o077;
|
|
9
|
+
/** An error naming the fix when `path` is reachable by more than its owner;
|
|
10
|
+
* undefined when it is not, or cannot be stat'd (the read reports that). */
|
|
11
|
+
function looseMode(path, fix) {
|
|
12
|
+
const stat = tryResult(() => statSync(path), () => "");
|
|
13
|
+
if (stat.status === "error" || (stat.value.mode & NOT_OWNER_ONLY) === 0)
|
|
14
|
+
return undefined;
|
|
15
|
+
return `${path} can be reached by group or others; a secret must be its owner's alone (${fix})`;
|
|
16
|
+
}
|
|
7
17
|
/** `<dir>/<key>`, file names only. A file holding the obfuscated form is read
|
|
8
18
|
* back as its value; any other file is its own value. */
|
|
9
|
-
export function fileSecretProvider(dir) {
|
|
19
|
+
export function fileSecretProvider(dir, opts = {}) {
|
|
10
20
|
return async (key) => {
|
|
11
21
|
if (!FILE_KEY.test(key)) {
|
|
12
22
|
return err(`'${key}' is not a secret file name (letters, digits, '.', '_', '-'; no directories)`);
|
|
13
23
|
}
|
|
24
|
+
if (opts.requirePrivate) {
|
|
25
|
+
const path = join(dir, key);
|
|
26
|
+
const loose = looseMode(dir, `chmod 700 ${dir}`) ?? looseMode(path, `chmod 600 ${path}`);
|
|
27
|
+
if (loose)
|
|
28
|
+
return err(loose);
|
|
29
|
+
}
|
|
14
30
|
const read = tryResult(() => readFileSync(join(dir, key), "utf-8"), () => `no readable secret '${key}' in ${dir}`);
|
|
15
31
|
if (read.status === "error")
|
|
16
32
|
return read;
|