@norskvideo/ctl-product-template-schema 0.1.80 → 0.1.81
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/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/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;
|