@mp-lb/forum-secrets 0.2.4 → 0.2.5
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/README.md +81 -8
- package/dist/cli.js +327 -37
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +147 -2
- package/dist/index.js +733 -29
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,150 @@
|
|
|
1
|
-
export { DecryptForumEncryptedFileInput, ForumEncryptedFilePayload, ForumEncryptedRecipient, ForumEncryptedValue, currentEncryptedFileVersion, decryptForumEncryptedFile, decryptForumEncryptedFileText, encryptedFileCipher, forumRecipientSecretPrefix, legacyEncryptedFileVersion, parseForumEncryptedFilePayload } from '@mp-lb/forum-encryption';
|
|
1
|
+
export { DecryptForumEncryptedFileInput, EncryptedEnvelopeExpectation, EncryptedEnvelopeMismatchError, ForumEncryptedFilePayload, ForumEncryptedRecipient, ForumEncryptedValue, currentEncryptedFileVersion, decryptForumEncryptedFile, decryptForumEncryptedFileText, encryptedFileCipher, forumRecipientSecretPrefix, legacyEncryptedFileVersion, parseEncryptedEnvelopeExpectation, parseForumEncryptedFilePayload } from '@mp-lb/forum-encryption';
|
|
2
|
+
import { ChildProcess } from 'node:child_process';
|
|
3
|
+
import { Writable } from 'node:stream';
|
|
2
4
|
|
|
3
5
|
declare const readRecipientSecret: (secretArg: string | null) => string;
|
|
4
6
|
|
|
5
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Forum credentials that must never reach a secret-consuming child: wrapping
|
|
9
|
+
* keys, encryption passwords and the Forum auth token.
|
|
10
|
+
*/
|
|
11
|
+
declare const credentialEnvironmentNames: readonly string[];
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Reads a credential (recipient secret or encryption password) from an
|
|
15
|
+
* already-open file descriptor such as `3<secret.txt`, `3<<<"$VAR"` or a pipe
|
|
16
|
+
* on fd 0, so it never appears in argv or shell history. Reads to EOF, removes
|
|
17
|
+
* one trailing newline and closes the descriptor. fd 1 and 2 are refused.
|
|
18
|
+
*/
|
|
19
|
+
declare const readCredentialFromFd: (fd: number, label: string) => Promise<string>;
|
|
20
|
+
|
|
21
|
+
/** Plaintext layout of a decrypted secret source. */
|
|
22
|
+
type SecretSourceFormat = "json" | "env";
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Parses decrypted secret plaintext as JSON or dotenv. Without an explicit
|
|
26
|
+
* format, plaintext starting with `{` is JSON and anything else is dotenv.
|
|
27
|
+
*/
|
|
28
|
+
declare const parseSecretSource: (plaintext: string, format?: SecretSourceFormat) => Record<string, unknown>;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Parses decrypted dotenv plaintext (`KEY=value` lines, optional `export`,
|
|
32
|
+
* `#` comments, quoted values). A malformed line or a repeated key fails, so an
|
|
33
|
+
* ambiguous source never silently picks one value. Errors cite line numbers and
|
|
34
|
+
* key names only, never values.
|
|
35
|
+
*/
|
|
36
|
+
declare const parseDotenvSecretSource: (plaintext: string) => Record<string, string>;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Parses decrypted JSON secret plaintext into a flat record. Values are
|
|
40
|
+
* returned unvalidated; selection decides which must be strings. Errors never
|
|
41
|
+
* include plaintext.
|
|
42
|
+
*/
|
|
43
|
+
declare const parseJsonSecretSource: (plaintext: string) => Record<string, unknown>;
|
|
44
|
+
|
|
45
|
+
/** One requested child variable and the source key that supplies it. */
|
|
46
|
+
type SecretSelection = {
|
|
47
|
+
output: string;
|
|
48
|
+
source: string;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Parses `NAME` (same name in source and child) or `OUTPUT=SOURCE_KEY` (rename).
|
|
53
|
+
* The output must be a portable environment variable name; the source key may
|
|
54
|
+
* be any non-empty JSON key.
|
|
55
|
+
*/
|
|
56
|
+
declare const parseSecretSelection: (spec: string) => SecretSelection;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Resolves exactly the requested variables from decrypted source values, or
|
|
60
|
+
* every value with `"all"`. Every problem is reported before anything runs:
|
|
61
|
+
* duplicate outputs, missing keys (all listed together) and unusable values.
|
|
62
|
+
* Errors name keys but never include values.
|
|
63
|
+
*/
|
|
64
|
+
declare const selectSecretVariables: (values: Record<string, unknown>, selections: SecretSelection[] | "all") => Record<string, string>;
|
|
65
|
+
|
|
66
|
+
type Environment = Record<string, string | undefined>;
|
|
67
|
+
/**
|
|
68
|
+
* Builds a child environment: the parent environment (or only a minimal set
|
|
69
|
+
* with `cleanEnv`), minus Forum credentials, plus the selected secrets.
|
|
70
|
+
*
|
|
71
|
+
* Credentials are removed by name and also by value, so a recipient secret,
|
|
72
|
+
* password or token copied into another variable is not inherited either.
|
|
73
|
+
* Selecting a secret under a credential variable name is refused.
|
|
74
|
+
*/
|
|
75
|
+
declare const buildChildEnvironment: ({ cleanEnv, credentialValues, parentEnvironment, secrets, }: {
|
|
76
|
+
cleanEnv: boolean;
|
|
77
|
+
credentialValues: readonly (string | null | undefined)[];
|
|
78
|
+
parentEnvironment: Environment;
|
|
79
|
+
secrets: Record<string, string>;
|
|
80
|
+
}) => {
|
|
81
|
+
environment: Record<string, string>;
|
|
82
|
+
removed: string[];
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
declare const redactedMarker = "[redacted]";
|
|
86
|
+
/** Values shorter than this are not redacted: they would mangle normal output. */
|
|
87
|
+
declare const minimumRedactedLength = 4;
|
|
88
|
+
/**
|
|
89
|
+
* Streaming exact-match redactor. It replaces literal occurrences of the given
|
|
90
|
+
* values, including ones split across chunks, by holding back the last
|
|
91
|
+
* (longest value − 1) characters until more text or `flush()` arrives.
|
|
92
|
+
*
|
|
93
|
+
* Best-effort only: it cannot catch transformed values (encoded, split across
|
|
94
|
+
* an idle flush, reformatted) and is no defence against a child that
|
|
95
|
+
* deliberately discloses its inputs.
|
|
96
|
+
*/
|
|
97
|
+
declare const createSecretRedactor: (values: readonly string[]) => {
|
|
98
|
+
flush: () => string;
|
|
99
|
+
push: (chunk: string) => string;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
type SignalSource = {
|
|
103
|
+
off: (signal: NodeJS.Signals, listener: () => void) => unknown;
|
|
104
|
+
on: (signal: NodeJS.Signals, listener: () => void) => unknown;
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* Relays termination signals received by this process to `child` while it
|
|
108
|
+
* runs. Listening also stops Node's default exit-on-signal, so the parent stays
|
|
109
|
+
* alive to collect the child's status and clean up. Returns a disposer.
|
|
110
|
+
*/
|
|
111
|
+
declare const forwardSignals: (child: ChildProcess, source?: SignalSource) => (() => void);
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* How a secret-consuming child's stdout/stderr reach the terminal:
|
|
115
|
+
* - `redact`: piped through a best-effort exact-match redactor (default)
|
|
116
|
+
* - `inherit`: explicit raw passthrough; the child owns the terminal
|
|
117
|
+
* - `withhold`: discarded; only the exit status is reported
|
|
118
|
+
*/
|
|
119
|
+
type SecretOutputMode = "redact" | "inherit" | "withhold";
|
|
120
|
+
declare const secretOutputModes: readonly SecretOutputMode[];
|
|
121
|
+
|
|
122
|
+
type LaunchFailure = "not_found" | "not_executable" | "spawn_failed";
|
|
123
|
+
type RunCommandWithSecretsResult = {
|
|
124
|
+
exitCode: number;
|
|
125
|
+
launchFailure: LaunchFailure | null;
|
|
126
|
+
signal: NodeJS.Signals | null;
|
|
127
|
+
};
|
|
128
|
+
/**
|
|
129
|
+
* Runs `command` (argv array, never a shell string) with an explicit
|
|
130
|
+
* environment that already contains the selected secrets. No plaintext file is
|
|
131
|
+
* written. Termination signals are forwarded to the child, and the child's exit
|
|
132
|
+
* status is returned: its own code, 128 + signal number when it was killed, or
|
|
133
|
+
* 126/127 when it could not be started.
|
|
134
|
+
*
|
|
135
|
+
* Output handling follows `output` (see {@link SecretOutputMode}); `redact`
|
|
136
|
+
* replaces exact occurrences of `redactValues`.
|
|
137
|
+
*/
|
|
138
|
+
declare const runCommandWithSecrets: ({ command, cwd, environment, output, redactValues, signalSource, stderr, stdin, stdout, }: {
|
|
139
|
+
command: readonly string[];
|
|
140
|
+
cwd?: string;
|
|
141
|
+
environment: Record<string, string>;
|
|
142
|
+
output: SecretOutputMode;
|
|
143
|
+
redactValues: readonly string[];
|
|
144
|
+
signalSource?: SignalSource;
|
|
145
|
+
stderr?: Writable;
|
|
146
|
+
stdin: "inherit" | "ignore";
|
|
147
|
+
stdout?: Writable;
|
|
148
|
+
}) => Promise<RunCommandWithSecretsResult>;
|
|
149
|
+
|
|
150
|
+
export { type LaunchFailure, type RunCommandWithSecretsResult, type SecretOutputMode, type SecretSelection, type SecretSourceFormat, type SignalSource, buildChildEnvironment, createSecretRedactor, credentialEnvironmentNames, forwardSignals, minimumRedactedLength, parseDotenvSecretSource, parseJsonSecretSource, parseSecretSelection, parseSecretSource, readCredentialFromFd, readRecipientSecret, redactedMarker, runCommandWithSecrets, secretOutputModes, selectSecretVariables };
|