@starci/hfs 4.11.12 → 4.11.13
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/CHANGELOG.md +10 -0
- package/README.md +1 -1
- package/package.json +1 -1
- package/release/index.mjs +2 -2
- package/runtime/knowledge/hfs/canon-pins.yaml +6 -6
- package/runtime/scripts/api/sops/lib.mjs +25 -3
- package/runtime/scripts/api/sops/seal.mjs +4 -3
- package/runtime/scripts/hfs/secret-init.mjs +15 -0
- package/runtime/scripts/hfs/secret-sops.mjs +65 -33
- package/runtime/scripts/lib/sops-envelope.mjs +36 -11
- package/src/main.mjs +3 -3
- package/stack/age-install.mjs +10 -2
- package/stack/context.mjs +2 -2
- package/stack/remote.mjs +29 -8
- package/stack/sealed.mjs +15 -11
- package/stack/server-key.mjs +31 -7
- package/templates/app/ci-workflows/github/workflows/stack-key-restore.yml +1 -1
- package/templates/app/ci-workflows-lite/github/workflows/stack-key-restore.yml +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 4.11.13 - 2026-10-29
|
|
4
|
+
|
|
5
|
+
- Fixed: a member sealed to an environment's whole recipient set (the owner key and the deploy server key, the production standard after `server-key --execute`) opens with either identity alone. The selected-identity decrypt (`runtime/scripts/lib/sops-envelope.mjs` `selectedAgeEnvelope`) refused every envelope whose age list held more than one entry (`unsupported-age-set`), so every production read failed once the server key joined; it now admits a set that holds the selected recipient and refuses an empty entry or gap (`invalid-age-entry`) and a recipient named twice (`duplicate-age-recipient`); a dotenv envelope reads every `sops_age__list_<n>__` entry.
|
|
6
|
+
- Fixed: every seal keeps the member's full recipient set (`secret-sops.mjs` `sealRecipients`): the caller's set, else the environment's `.sops.yaml` rule, else the set the existing member is sealed to, under a private one-rule sops config when no rule of the app matches (sops refuses an unmatched file even with `--age`). `set`, `migrate`, `split` and the edit verbs on a production member keep the server recipient.
|
|
7
|
+
- Changed: one age identity lookup for every decrypt of a member, `decryptionIdentity` (`secret-init.mjs`): the environment, the app's `.claude/secret.env`, its main checkout's, the harness CLI's secret.env (`hostIdentity`), then sops' keys.txt. `defaultSops` uses it, `stack`, `release` and `db` hand their context `hostIdentity` (`stackContext`, `release/index.mjs` `contextOf`, `main.mjs`), so a stack deploy opens its members with the same identity `app secret` does; `stack/sealed.mjs` `hasAgeIdentity` reads the seam's finding instead of guessing from files.
|
|
8
|
+
- Changed: a member that cannot be opened is refused naming the member, the format it was read as, its recipients, where the identity came from and its recipient, and why: a failed selected sops run names its class (`sopsFailureClass`: no-matching-identity, mac-mismatch, unparsable-document, timeout, exit-<n>) instead of "the selected invocation was not qualified" alone.
|
|
9
|
+
- Changed: the deploy's sealed SSH members (`deploy.remote.sealed`) are read as what they are: a `.enc.yaml` member through `decrypt(file, "yaml")` and its key, a legacy `.enc` through the binary envelope. The keys are `SEALED_SSH_KEYS` (`stack/remote.mjs`): `privateKey` of `sshKey`, `knownHosts` of `knownHosts`; the `key` and `known_hosts` aliases are gone, and a member without its key is refused naming the keys it holds.
|
|
10
|
+
- Fixed: `server-key` resolves age-keygen as root, the way it calls it (`RESOLVE_AGE_KEYGEN`, `ageKeygenScript`: root's PATH, then `/usr/local/bin`, `/usr/bin`, `/bin`): on AlmaLinux 10 sudo's secure_path leaves `/usr/local/bin` out, so the deploy user's `command -v age-keygen` passed and the root script exited 127 ("age-keygen failed on the server"). The static age installer links age and age-keygen from `/usr/bin` and counts age as present only when root sees it too; `stack-key-restore.yml` (both editions) adds `/usr/local/bin` to its root shell's PATH.
|
|
11
|
+
- Changed: the bundled canon pins name hfs 4.11.13, eslint-canon-be 3.8.12, eslint-canon-fe 9.5.14 and the Grammar family 0.15.25.
|
|
12
|
+
|
|
3
13
|
## 4.11.12 - 2026-10-29
|
|
4
14
|
|
|
5
15
|
- Changed: the skeleton canon gate (`src/scaffold-template-canon-be.spec.mjs`) lints every file under `be/src/modules/platform` of both editions with the starci-be rules, no longer `platform/http` alone; both editions are green.
|
package/README.md
CHANGED
|
@@ -230,7 +230,7 @@ one key its whole text or several one `KEY=value` line each, `--from-file KEY=pa
|
|
|
230
230
|
A member is sealed to its environment's rule of the managed `.sops.yaml`; `recipients <env> [--add|--remove <age1...|owner>]`
|
|
231
231
|
rewrites that rule (`environmentRecipients`, `secret-init.mjs`), and `init` takes the owner's identity as the app's recipient.
|
|
232
232
|
Re-sealing a member whose every key the set replaces needs no age identity; adding a key to one does, and the identity is found
|
|
233
|
-
by itself (`
|
|
233
|
+
by itself (`decryptionIdentity`, the one lookup every decrypt of a member uses: secret, stack, release, db): SOPS_AGE_KEY or SOPS_AGE_KEY_FILE of the environment, else of the app's git-ignored
|
|
234
234
|
`.claude/secret.env`, else of its main checkout's when the app is a git worktree, else the `hostIdentity` the harness CLI passes
|
|
235
235
|
(its own secret.env), else the sops `keys.txt`; with none, the verb refuses before asking for a value, naming every place it
|
|
236
236
|
looked and the one line that fixes it. `audit [<env>]` names every deviation and exits 1; `migrate <env> <member> [--to
|
package/package.json
CHANGED
package/release/index.mjs
CHANGED
|
@@ -18,9 +18,9 @@ import { RELEASE_CODE, VERSION, normalizeRelease, releaseGate } from './gate.mjs
|
|
|
18
18
|
import { releasePush } from './push.mjs';
|
|
19
19
|
import { releaseUrgentPush } from './urgent.mjs';
|
|
20
20
|
|
|
21
|
-
const IO_KEYS = ['cwd', 'stdout', 'stderr', 'env', 'sops'];
|
|
21
|
+
const IO_KEYS = ['cwd', 'stdout', 'stderr', 'env', 'sops', 'hostIdentity'];
|
|
22
22
|
|
|
23
|
-
/** The stack context of one invocation: the IO of the app (cwd, writers, env, sops) over the injectable seams of `io.stackIo` (spawn, sleep, now, fetch). */
|
|
23
|
+
/** The stack context of one invocation: the IO of the app (cwd, writers, env, sops, hostIdentity) over the injectable seams of `io.stackIo` (spawn, sleep, now, fetch). */
|
|
24
24
|
export function contextOf(io = {}) {
|
|
25
25
|
const own = Object.fromEntries(IO_KEYS.filter((key) => io[key] !== undefined).map((key) => [key, io[key]]));
|
|
26
26
|
return stackContext({ ...io.stackIo, ...own });
|
|
@@ -31,35 +31,35 @@ pins:
|
|
|
31
31
|
source: packages/event-stream/package.json
|
|
32
32
|
why: 'the one server-sent-events client of every front end (fe-stack event-stream, owner:event-stream-package): the transport client layer (modules/api/sse/clients) creates one instance for the app with the bearer token source and the stream operations follow on it; it carries Last-Event-ID resume, the capped doubling backoff, the heartbeat timeout, the single 401 renewal and the useSWRSubscription adapter, so no app keeps a hand-written reader.'
|
|
33
33
|
'@starci/grammar':
|
|
34
|
-
version: 0.15.
|
|
34
|
+
version: 0.15.25
|
|
35
35
|
group: starci
|
|
36
36
|
install: registry
|
|
37
37
|
side: fe
|
|
38
38
|
source: packages/grammar/package.json
|
|
39
39
|
why: 'the grammar front ends read: the brand layer sets `--font-sans` and `--font-mono` and the grammar reads them; it carries the Input tel kind, the copyable and read-only Input, the IconButton disclosure props and count badge, ChatBubble, FillViewport, Textarea mentions and Enter-to-send, the leading PrimaryRailLayout rail, the plate-less Image, ListRow, the soft Alert, Progress steps, the floating primary IconButton, FlowGraph, the STATE-8 loading views and the bordered selectable TagGroup chips. The runtime source version wins for a @starci package.'
|
|
40
40
|
'@starci/eslint-canon-be':
|
|
41
|
-
version: 3.8.
|
|
41
|
+
version: 3.8.12
|
|
42
42
|
group: starci
|
|
43
43
|
install: registry
|
|
44
44
|
side: be
|
|
45
45
|
source: packages/eslint-canon-be/package.json
|
|
46
46
|
why: 'the back-end ESLint canon: `loadHfs(import.meta.url)` of be/eslint.config.mjs finds the app-root hfs.json (kind app) and gives every linted file the view of the be side, and the project graph is built per side; its bundled runtime copies (slots, canon-pins, failure codes, the architecture machine) put .starcistacks and .sops.yaml at the app root; `starciBeConfig({ hfs: loadHfs(import.meta.url) })` is the typed factory and the BE-CONVENTION laws are its rules.'
|
|
47
47
|
'@starci/eslint-canon-fe':
|
|
48
|
-
version: 9.5.
|
|
48
|
+
version: 9.5.14
|
|
49
49
|
group: starci
|
|
50
50
|
install: registry
|
|
51
51
|
side: fe
|
|
52
52
|
source: packages/eslint-canon-fe/package.json
|
|
53
53
|
why: 'the front-end ESLint canon: `loadHfs(import.meta.url)` of fe/eslint.config.mjs finds the app-root hfs.json (kind app) and gives every linted file the view of the fe side, and the project graph is built per side; its bundled runtime copies (slots, canon-pins, failure codes, the architecture machine) put .starcistacks and .sops.yaml at the app root; the front end has no tests (FE_NO_TESTS R97 in hfs) and no-vietnamese-in-source (R91) applies.'
|
|
54
54
|
'@starci/eslint-grammar-core':
|
|
55
|
-
version: 0.15.
|
|
55
|
+
version: 0.15.25
|
|
56
56
|
group: starci
|
|
57
57
|
install: registry
|
|
58
58
|
side: fe
|
|
59
59
|
source: packages/eslint-grammar-core/package.json
|
|
60
60
|
why: 'the StarCi Grammar component API lint, versioned with @starci/grammar; front ends compose this family package with the universal FE canon.'
|
|
61
61
|
'@starci/eslint-grammar-offset-pop':
|
|
62
|
-
version: 0.15.
|
|
62
|
+
version: 0.15.25
|
|
63
63
|
group: starci
|
|
64
64
|
install: registry
|
|
65
65
|
side: fe
|
|
@@ -106,7 +106,7 @@ pins:
|
|
|
106
106
|
source: packages/ai-router/package.json
|
|
107
107
|
why: 'the AI pool router of a back end: a NestJS module that routes OpenAI-compatible chat, stream and embeddings calls across keys, models and providers, with @starci/ai-router/testing for its specs; @starci/jest-preset compiles it as an ESM-only dependency.'
|
|
108
108
|
'@starci/hfs':
|
|
109
|
-
version: 4.11.
|
|
109
|
+
version: 4.11.13
|
|
110
110
|
group: starci
|
|
111
111
|
install: registry
|
|
112
112
|
side: both
|
|
@@ -116,7 +116,11 @@ function isolatedSopsEnv(env, inlineName = 'SOPS_AGE_KEY') {
|
|
|
116
116
|
return out;
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
-
|
|
119
|
+
/**
|
|
120
|
+
* A refusal of the selected invocation. `detail` says what failed in public words; `facts` carries only public values the caller
|
|
121
|
+
* names in its own refusal (`publicRecipient`, the selected identity's recipient; `sopsFailure`, the class of a failed sops run).
|
|
122
|
+
*/
|
|
123
|
+
const held = (reason, detail = 'the selected invocation was not qualified', facts = {}) => ({ status: null, stdout: '', stderr: '', error: Object.assign(new Error(`SOPS selected identity [${reason}]: ${detail}`), { name: 'SopsIdentityRefusal', identityRefusal: reason, ...facts }) });
|
|
120
124
|
const nativeFile = file => {
|
|
121
125
|
if (typeof file !== 'string' || !path.isAbsolute(file) || /\.(?:[cm]?js|cmd|bat|ps1|sh)$/i.test(file)) return false;
|
|
122
126
|
let fd;
|
|
@@ -175,11 +179,29 @@ const selectedAdmission = (selection, spec, invocation, env) => {
|
|
|
175
179
|
|
|
176
180
|
const decryptArgs = (file, inputType, outputType) => ['decrypt', '--input-type', inputType, '--output-type', outputType, '--filename-override', file, '--enable-local-keyservice=true', '--decryption-order', 'age'];
|
|
177
181
|
|
|
182
|
+
/**
|
|
183
|
+
* The class of a failed sops run, read from its stderr and exit; sops prints no value there, and only the class leaves. Classes:
|
|
184
|
+
* no-matching-identity (no age entry opens with the identity), mac-mismatch (the document changed after it was sealed),
|
|
185
|
+
* unparsable-document (the bytes are not the format they were read as), timeout, or exit-<n>.
|
|
186
|
+
*/
|
|
187
|
+
export function sopsFailureClass(result) {
|
|
188
|
+
if (result?.error?.code === 'ETIMEDOUT' || result?.signal === 'SIGTERM') return 'timeout';
|
|
189
|
+
const text = Buffer.isBuffer(result?.stderr) ? result.stderr.toString('utf8') : String(result?.stderr ?? '');
|
|
190
|
+
if (/MAC mismatch/iu.test(text)) return 'mac-mismatch';
|
|
191
|
+
if (/no identity matched|failed to get the data key|could not decrypt data key|0 successful groups/iu.test(text)) return 'no-matching-identity';
|
|
192
|
+
if (/unmarshal|could not parse|error loading file|invalid character|yaml:/iu.test(text)) return 'unparsable-document';
|
|
193
|
+
return `exit-${String(result?.status ?? 'none')}`;
|
|
194
|
+
}
|
|
195
|
+
|
|
178
196
|
const decryptSelected = (run, exe, file, input, spec, recipient) => {
|
|
197
|
+
const facts = { publicRecipient: recipient };
|
|
179
198
|
const envelope = selectedAgeEnvelope(decoded(input), spec.inputType, recipient);
|
|
180
|
-
if (!envelope.ok) return held(envelope.reason);
|
|
199
|
+
if (!envelope.ok) return held(envelope.reason, `the ${spec.inputType} envelope was refused for the selected recipient ${recipient}`, facts);
|
|
181
200
|
const result = run(exe, decryptArgs(file, spec.inputType, spec.outputType), input);
|
|
182
|
-
if (!captured(result))
|
|
201
|
+
if (!captured(result)) {
|
|
202
|
+
const failure = sopsFailureClass(result);
|
|
203
|
+
return held('selected-decryption-failed', `sops could not decrypt the ${spec.inputType} document with the selected recipient ${recipient} (${failure})`, { ...facts, sopsFailure: failure });
|
|
204
|
+
}
|
|
183
205
|
return { status: 0, stdout: decoded(result.stdout), stderr: '', error: null };
|
|
184
206
|
};
|
|
185
207
|
|
|
@@ -7,10 +7,11 @@ import { resolveSops, runSelectedSops } from './lib.mjs';
|
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Run `<bin> encrypt` (bin null: the sops resolveSops finds) over `plaintext` of format `inputType` (json, yaml or dotenv). Sops reads stdin only with a `--filename-override`, the path the sealed
|
|
10
|
-
* file will have: recipients are age keys (`--age`), and when none are given sops picks them from the repository's .sops.yaml for that path.
|
|
10
|
+
* file will have: recipients are age keys (`--age`), and when none are given sops picks them from the repository's .sops.yaml for that path. `config` names
|
|
11
|
+
* the sops configuration to read instead of the repository's (a rule-less member sealed to its own recipients). {status, stdout, stderr, error}.
|
|
11
12
|
*/
|
|
12
|
-
export function seal(bin, { inputType, plaintext, recipients = [], filenameOverride }, { invocation = null, env = process.env, cwd = undefined, maxBuffer = 16 * 1024 * 1024, timeout = undefined } = {}) {
|
|
13
|
-
const args = ['encrypt', '--input-type', inputType, '--output-type', inputType, '--filename-override', filenameOverride];
|
|
13
|
+
export function seal(bin, { inputType, plaintext, recipients = [], filenameOverride, config = null }, { invocation = null, env = process.env, cwd = undefined, maxBuffer = 16 * 1024 * 1024, timeout = undefined } = {}) {
|
|
14
|
+
const args = [...(config ? ['--config', config] : []), 'encrypt', '--input-type', inputType, '--output-type', inputType, '--filename-override', filenameOverride];
|
|
14
15
|
if (recipients.length) args.push('--age', recipients.join(','));
|
|
15
16
|
const selected = sopsIdentityEnv(env);
|
|
16
17
|
if (selected.error?.identityRefusal === 'inline-context-unqualified') return runSelectedSops(bin, { operation: 'seal', params: { inputType, plaintext, recipients, filenameOverride } }, { selection: selected, invocation, env, cwd, maxBuffer, timeout });
|
|
@@ -106,6 +106,21 @@ export function localAgeIdentity(repoRoot, env, tools, host = null) {
|
|
|
106
106
|
return { env: { ...env }, source: null, looked };
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
+
/**
|
|
110
|
+
* The one age identity every decrypt of a sealed member opens with (secret get, verify, materialize, set over an existing member,
|
|
111
|
+
* migrate, split, the edit verbs, updatekeys, server-key, the stack's sealed members and the CLI's custody): localAgeIdentity's
|
|
112
|
+
* order (the environment, the app's `.claude/secret.env`, its main checkout's, the `host` port), then sops' per-user keys.txt.
|
|
113
|
+
* Same shape as localAgeIdentity; `looked` names every place read, keys.txt last.
|
|
114
|
+
*/
|
|
115
|
+
export function decryptionIdentity(repoRoot, env, { tools, host = null, platform = process.platform } = {}) {
|
|
116
|
+
const local = localAgeIdentity(repoRoot, env, tools, host);
|
|
117
|
+
if (local.source !== null) return local;
|
|
118
|
+
const keys = secretRoots(env, platform).identity;
|
|
119
|
+
const looked = [...local.looked, keys];
|
|
120
|
+
if (!fs.existsSync(keys)) return { ...local, looked };
|
|
121
|
+
return { env: { ...local.env, SOPS_AGE_KEY_FILE: keys }, source: keys, looked };
|
|
122
|
+
}
|
|
123
|
+
|
|
109
124
|
/** Load host-local age selections below the explicit environment (localAgeIdentity), without copying any other credentials. */
|
|
110
125
|
export function ageIdentityEnv(repoRoot, env, tools) {
|
|
111
126
|
return localAgeIdentity(repoRoot, env, tools).env;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// secret-sops.mjs - runtime SOPS adapter and age identity selection.
|
|
2
2
|
import fs from "node:fs";
|
|
3
|
+
import os from "node:os";
|
|
3
4
|
import path from "node:path";
|
|
4
5
|
import { runProgram } from "../api/process/run-program.mjs";
|
|
5
6
|
import { resolveRealTool } from "../api/process/resolve-real-tool.mjs";
|
|
@@ -9,8 +10,8 @@ import { updateKeys as sopsUpdateKeys } from "../api/sops/update-keys.mjs";
|
|
|
9
10
|
import { isLegacyName } from "../lib/sealed-member.mjs";
|
|
10
11
|
import { invocationDir } from "../lib/roots.mjs";
|
|
11
12
|
import { envelopeOf } from "./secret-document.mjs";
|
|
12
|
-
import { configuredRecipients,
|
|
13
|
-
import { outsideRepository
|
|
13
|
+
import { configuredRecipients, decryptionIdentity, secretTools } from "./secret-init.mjs";
|
|
14
|
+
import { outsideRepository } from "./secret-files.mjs";
|
|
14
15
|
import { SecretError, publicStorage } from "./secret-errors.mjs";
|
|
15
16
|
|
|
16
17
|
const sopsInvocation = Object.freeze({ runProgram, resolveRealTool });
|
|
@@ -45,15 +46,27 @@ function recipientsOf(file) {
|
|
|
45
46
|
* The refusal of a decrypt whose selected identity is not one `file` is sealed to: names where the identity came from and the
|
|
46
47
|
* member's recipients, and the two ways out. It carries no value.
|
|
47
48
|
*/
|
|
48
|
-
function identityMismatch(repoRoot, identity, file) {
|
|
49
|
+
function identityMismatch(repoRoot, identity, file, publicRecipient) {
|
|
49
50
|
const recipients = recipientsOf(file);
|
|
51
|
+
const own = publicRecipient ? ` (recipient ${publicRecipient})` : "";
|
|
50
52
|
return new SecretError(
|
|
51
|
-
`the age identity of ${identity.source ?? "the environment"} does not open ${path.basename(file)}, ` +
|
|
52
|
-
`sealed to ${recipients.join(", ") || "another recipient"}. Fix: put
|
|
53
|
-
"or, when no one holds
|
|
53
|
+
`the age identity of ${identity.source ?? "the environment"}${own} does not open ${path.basename(file)}, ` +
|
|
54
|
+
`sealed to ${recipients.join(", ") || "another recipient"}. Fix: put one of those recipients' age secret key in ${path.join(repoRoot, ".claude", "secret.env")} as SOPS_AGE_KEY, ` +
|
|
55
|
+
"or, when no one holds any of them any more, seal the member's keys again (remove it and set them) after .sops.yaml names this identity's recipient",
|
|
54
56
|
);
|
|
55
57
|
}
|
|
56
58
|
|
|
59
|
+
/**
|
|
60
|
+
* Any other refusal of a decrypt: the member, the format it was read as, the recipients it is sealed to, where the age identity
|
|
61
|
+
* came from and (when derived) its recipient, then the refusal itself. Public facts only.
|
|
62
|
+
*/
|
|
63
|
+
function identityRefused(identity, file, format, error) {
|
|
64
|
+
const recipients = recipientsOf(file);
|
|
65
|
+
const own = error.publicRecipient ? `, recipient ${error.publicRecipient}` : "";
|
|
66
|
+
const source = identity.source ? `the age identity of ${identity.source}${own}` : `no age identity (looked in ${identity.looked.join(", ") || "the environment"})`;
|
|
67
|
+
return `${path.basename(file)} (read as ${format ?? "its own format"}, sealed to ${recipients.join(", ") || "no age recipient"}) cannot be opened with ${source}: ${error.message}`;
|
|
68
|
+
}
|
|
69
|
+
|
|
57
70
|
/**
|
|
58
71
|
* The refusal of an operation that must decrypt `file` with no age identity selected: it names the recipient the member is
|
|
59
72
|
* sealed to, every place looked, and the one line that fixes it. It carries no value.
|
|
@@ -70,8 +83,40 @@ function identityMissing(repoRoot, identity, file) {
|
|
|
70
83
|
}
|
|
71
84
|
|
|
72
85
|
/**
|
|
73
|
-
* The
|
|
74
|
-
*
|
|
86
|
+
* The recipient set a seal of `file` writes: the caller's `named` set, else the environment's .sops.yaml rule, else the full set
|
|
87
|
+
* the existing member is sealed to, so no rewrite (set, migrate, split, an edit) drops a recipient such as the deploy server's.
|
|
88
|
+
* `ruled` says whether a rule of the app's .sops.yaml matches the file. Refused, as the rule refuses, when none names one.
|
|
89
|
+
*/
|
|
90
|
+
function sealRecipients(repoRoot, file, named) {
|
|
91
|
+
try {
|
|
92
|
+
const rule = configuredRecipients(repoRoot, file);
|
|
93
|
+
return { recipients: named.length ? named : rule, ruled: true };
|
|
94
|
+
} catch (error) {
|
|
95
|
+
const existing = named.length ? named : fs.existsSync(file) ? recipientsOf(file) : [];
|
|
96
|
+
if (existing.length) return { recipients: existing, ruled: false };
|
|
97
|
+
throw error;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Runs `seal` with a private sops configuration naming only `recipients` when the app's .sops.yaml has no rule for the member
|
|
103
|
+
* (sops refuses a file no rule matches even with --age); the folder is removed after. Public keys only.
|
|
104
|
+
*/
|
|
105
|
+
function withOwnRule(ruled, recipients, seal) {
|
|
106
|
+
if (ruled) return seal(null);
|
|
107
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "starci-sops-rule-"));
|
|
108
|
+
try {
|
|
109
|
+
const config = path.join(dir, ".sops.yaml");
|
|
110
|
+
fs.writeFileSync(config, `creation_rules:\n - age: ${recipients.join(",")}\n`);
|
|
111
|
+
return seal(config);
|
|
112
|
+
} finally {
|
|
113
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* The default sops seam: the runtime's sops api, which finds the binary on this machine; the age identity is decryptionIdentity's
|
|
119
|
+
* (`host` the harness CLI's secret.env, then sops' keys.txt). `identity` says where the age identity
|
|
75
120
|
* was found (`source`, null when nowhere) and where it was looked for; `requireIdentity(file)` refuses, before any value is
|
|
76
121
|
* read, an operation that must decrypt `file` with no identity.
|
|
77
122
|
*/
|
|
@@ -83,7 +128,7 @@ export function defaultSops(
|
|
|
83
128
|
host = null,
|
|
84
129
|
) {
|
|
85
130
|
const { sops: binary } = publicStorage(() => secretTools(env, tools));
|
|
86
|
-
const local =
|
|
131
|
+
const local = decryptionIdentity(repoRoot, env, { tools, host, platform });
|
|
87
132
|
const selectedEnv = local.env;
|
|
88
133
|
const identity = { source: local.source, looked: [...local.looked] };
|
|
89
134
|
const invocation = {
|
|
@@ -109,27 +154,16 @@ export function defaultSops(
|
|
|
109
154
|
);
|
|
110
155
|
checkIdentity(value);
|
|
111
156
|
}
|
|
112
|
-
if (
|
|
113
|
-
!Object.keys(selectedEnv).some((name) => AGE_IDENTITY_NAME.test(name))
|
|
114
|
-
) {
|
|
115
|
-
const keys = secretRoots(env, platform).identity;
|
|
116
|
-
checkIdentity(keys);
|
|
117
|
-
identity.looked.push(keys);
|
|
118
|
-
if (fs.existsSync(keys)) {
|
|
119
|
-
selectedEnv.SOPS_AGE_KEY_FILE = keys;
|
|
120
|
-
identity.source = keys;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
157
|
const requireIdentity = (file) => {
|
|
124
158
|
if (identity.source === null) throw identityMissing(repoRoot, identity, file);
|
|
125
159
|
};
|
|
126
|
-
const refuse = (what, result, file) => {
|
|
160
|
+
const refuse = (what, result, file, format) => {
|
|
127
161
|
if (result.error?.identityRefusal === "identity-not-supplied" && file)
|
|
128
162
|
return identityMissing(repoRoot, identity, file);
|
|
129
163
|
if (result.error?.identityRefusal === "recipient-mismatch" && file)
|
|
130
|
-
return identityMismatch(repoRoot, identity, file);
|
|
164
|
+
return identityMismatch(repoRoot, identity, file, result.error.publicRecipient);
|
|
131
165
|
if (result.error?.identityRefusal)
|
|
132
|
-
return Object.assign(new SecretError(result.error.message), {
|
|
166
|
+
return Object.assign(new SecretError(file ? identityRefused(identity, file, format, result.error) : result.error.message), {
|
|
133
167
|
identityRefusal: result.error.identityRefusal,
|
|
134
168
|
});
|
|
135
169
|
if (result.error?.code === "SOPS_MISSING")
|
|
@@ -157,6 +191,7 @@ export function defaultSops(
|
|
|
157
191
|
`decrypt ${path.basename(file)}; is the age identity installed?`,
|
|
158
192
|
result,
|
|
159
193
|
file,
|
|
194
|
+
format,
|
|
160
195
|
);
|
|
161
196
|
if (exact) return exactMap(result.stdout);
|
|
162
197
|
const map = Object.create(null);
|
|
@@ -193,6 +228,7 @@ export function defaultSops(
|
|
|
193
228
|
`decrypt ${path.basename(file)}; is the age identity installed?`,
|
|
194
229
|
result,
|
|
195
230
|
file,
|
|
231
|
+
types[0],
|
|
196
232
|
);
|
|
197
233
|
return String(result.stdout);
|
|
198
234
|
},
|
|
@@ -207,21 +243,17 @@ export function defaultSops(
|
|
|
207
243
|
{ env: selectedEnv, cwd: repoRoot, invocation },
|
|
208
244
|
);
|
|
209
245
|
if (result.status !== 0)
|
|
210
|
-
throw refuse(`update the keys of ${path.basename(file)}; is the age identity a recipient of it?`, result, file);
|
|
246
|
+
throw refuse(`update the keys of ${path.basename(file)}; is the age identity a recipient of it?`, result, file, isLegacyName(file) ? "dotenv" : "yaml");
|
|
211
247
|
},
|
|
212
248
|
seal(request) {
|
|
213
|
-
const recipients = request.recipients
|
|
214
|
-
|
|
215
|
-
: publicStorage(() =>
|
|
216
|
-
configuredRecipients(repoRoot, request.filenameOverride),
|
|
217
|
-
);
|
|
218
|
-
// Sealing needs only public recipients, so it runs with no identity selected and may name several (an environment's
|
|
249
|
+
const { recipients, ruled } = publicStorage(() => sealRecipients(repoRoot, request.filenameOverride, request.recipients));
|
|
250
|
+
// Sealing needs only public recipients, so it runs with no identity selected and seals to the whole set (an environment's
|
|
219
251
|
// server key and the owner key both).
|
|
220
|
-
const result = sopsSeal(
|
|
252
|
+
const result = withOwnRule(ruled, recipients, (config) => sopsSeal(
|
|
221
253
|
binary,
|
|
222
|
-
{ ...request, recipients },
|
|
254
|
+
{ ...request, recipients, config },
|
|
223
255
|
{ env: withoutIdentity(selectedEnv), cwd: repoRoot, invocation },
|
|
224
|
-
);
|
|
256
|
+
));
|
|
225
257
|
if (result.status !== 0) throw refuse("seal the secret", result);
|
|
226
258
|
return result.stdout;
|
|
227
259
|
},
|
|
@@ -62,13 +62,17 @@ export function isSopsEnvelope(text) {
|
|
|
62
62
|
try { return sopsTree(parseYaml(src)); } catch { return false; }
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
/**
|
|
65
|
+
/** A refused admission, named by its reason. */
|
|
66
66
|
const refusal = (reason) => ({ ok: false, reason });
|
|
67
67
|
|
|
68
|
+
const DOTENV_AGE_FIELD = /^age__list_(0|[1-9]\d{0,2})__map_(recipient|enc)$/u;
|
|
69
|
+
|
|
68
70
|
function dotenvMetadataValue(meta, age, key, value) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
71
|
+
const field = DOTENV_AGE_FIELD.exec(key);
|
|
72
|
+
if (field) {
|
|
73
|
+
const entry = (age[Number(field[1])] ??= {});
|
|
74
|
+
entry[field[2]] = value;
|
|
75
|
+
} else if (key === 'mac_only_encrypted') {
|
|
72
76
|
if (value !== 'false') return 'partial-mac';
|
|
73
77
|
meta[key] = false;
|
|
74
78
|
} else if (key.includes('__')) return 'unsupported-key-group';
|
|
@@ -88,13 +92,14 @@ function readDotenvMetadata(text) {
|
|
|
88
92
|
pairs.set(name, line.slice(at + 1).replaceAll(String.raw`\n`, '\n'));
|
|
89
93
|
}
|
|
90
94
|
const meta = {};
|
|
91
|
-
const age =
|
|
95
|
+
const age = [];
|
|
92
96
|
for (const [name, value] of pairs) {
|
|
93
97
|
if (!name.startsWith('sops_')) continue;
|
|
94
98
|
const reason = dotenvMetadataValue(meta, age, name.slice('sops_'.length), value);
|
|
95
99
|
if (reason) return { refusal: reason };
|
|
96
100
|
}
|
|
97
|
-
|
|
101
|
+
// A gap in the list indices is an entry sops never wrote: refused as an empty entry, never skipped.
|
|
102
|
+
meta.age = Array.from(age, (entry) => entry ?? null);
|
|
98
103
|
return { meta };
|
|
99
104
|
}
|
|
100
105
|
|
|
@@ -142,15 +147,35 @@ function validateAgeMetadata(meta, text, recipient) {
|
|
|
142
147
|
const fields = new Set([...providers, 'age', 'lastmodified', 'mac', 'version', 'unencrypted_suffix', 'encrypted_suffix', 'unencrypted_regex', 'encrypted_regex', 'unencrypted_comment_regex', 'encrypted_comment_regex', 'mac_only_encrypted']);
|
|
143
148
|
if (Object.keys(meta).some(name => !fields.has(name))) return refusal('unknown-metadata');
|
|
144
149
|
if (Object.hasOwn(meta, 'mac_only_encrypted') && meta.mac_only_encrypted !== false) return refusal('partial-mac');
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
if (!
|
|
148
|
-
if (typeof entry.recipient !== 'string' || entry.recipient !== recipient) return refusal('recipient-mismatch');
|
|
149
|
-
if (!hasValidAgePayload(entry)) return refusal('invalid-age-entry');
|
|
150
|
+
const set = ageSet(meta.age);
|
|
151
|
+
if (!set.ok) return set;
|
|
152
|
+
if (!set.recipients.includes(recipient)) return refusal('recipient-mismatch');
|
|
150
153
|
if (!hasValidEnvelopeVersion(meta)) return refusal('invalid-envelope');
|
|
151
154
|
return { ok: true };
|
|
152
155
|
}
|
|
153
156
|
|
|
157
|
+
const AGE_RECIPIENT = /^age1[ac-hj-np-z02-9]+$/u;
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* The age set of an envelope: one or more entries (the owner key and an environment's server key are the standard pair), each a
|
|
161
|
+
* well-formed recipient with its wrapped data key; an empty entry or a recipient named twice is refused.
|
|
162
|
+
*/
|
|
163
|
+
function ageSet(entries) {
|
|
164
|
+
if (!Array.isArray(entries) || entries.length === 0) return refusal('unsupported-age-set');
|
|
165
|
+
const recipients = [];
|
|
166
|
+
for (const entry of entries) {
|
|
167
|
+
if (!isAgeEntry(entry) || typeof entry.recipient !== 'string' || !AGE_RECIPIENT.test(entry.recipient) || !hasValidAgePayload(entry))
|
|
168
|
+
return refusal('invalid-age-entry');
|
|
169
|
+
if (recipients.includes(entry.recipient)) return refusal('duplicate-age-recipient');
|
|
170
|
+
recipients.push(entry.recipient);
|
|
171
|
+
}
|
|
172
|
+
return { ok: true, recipients };
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Admit one flat age envelope for the native selected-identity invocation when `recipient` (the selected identity's public key) is
|
|
177
|
+
* one of its age set. Shape admission, never cryptographic proof.
|
|
178
|
+
*/
|
|
154
179
|
export function selectedAgeEnvelope(text, format, recipient) {
|
|
155
180
|
if (!['binary', 'json', 'yaml', 'dotenv'].includes(format)) return refusal('unsupported-format');
|
|
156
181
|
const parsed = readAgeMetadata(text, format);
|
package/src/main.mjs
CHANGED
|
@@ -435,8 +435,8 @@ function declaredEdition(cwd) {
|
|
|
435
435
|
* `starci app stack`: the deploy actions (prepare, doctor, render, deploy, converge, verify, rollback, prune, backup, jobs, ...) are the Swarm
|
|
436
436
|
* tooling of stack/cli.mjs; up, down and status are the full edition's test-world infrastructure.
|
|
437
437
|
*/
|
|
438
|
-
async function stackAppMain(argv, { cwd, edition, stackMain, stdout: out, stderr: err, env, sops, stackIo }) {
|
|
439
|
-
if (STACK_ACTIONS.includes(argv[0])) return deployStackMain(argv, { ...stackIo, cwd, stdout: out, stderr: err, env, ...(sops ? { sops } : {}) });
|
|
438
|
+
async function stackAppMain(argv, { cwd, edition, stackMain, stdout: out, stderr: err, env, sops, hostIdentity, stackIo }) {
|
|
439
|
+
if (STACK_ACTIONS.includes(argv[0])) return deployStackMain(argv, { ...stackIo, cwd, stdout: out, stderr: err, env, hostIdentity, ...(sops ? { sops } : {}) });
|
|
440
440
|
if ((edition ?? declaredEdition(cwd)) === 'lite') throw new Error('starci app stack up|down|status manage the local test world of the full edition; a lite app starts its local database with npm run db:start');
|
|
441
441
|
const run = stackMain ?? await installedStackMain(cwd);
|
|
442
442
|
return run(argv, { cwd, out, err });
|
|
@@ -462,7 +462,7 @@ function errorMessage(error) {
|
|
|
462
462
|
* `harness` ({ version }) is the CLI that runs this package in-process: its version is the starci-harness an app is judged and
|
|
463
463
|
* scaffolded at (runtime/scripts/hfs/canon-pins.mjs). `run` injects the database runner, `runLinter` the linter transport, `checkApp`
|
|
464
464
|
* the HFS check and `stackIo` Swarm tools; production defaults execute every check. `hostIdentity` ({ label, read }) is the
|
|
465
|
-
* harness CLI's own secret.env SOPS_AGE_KEY, which
|
|
465
|
+
* harness CLI's own secret.env SOPS_AGE_KEY, which every verb that opens a sealed member (secret, stack, release, db) reads last for the age identity (decryptionIdentity); `prompt` replaces its masked prompt.
|
|
466
466
|
*/
|
|
467
467
|
export async function main(argv, {
|
|
468
468
|
cwd: baseCwd = process.cwd(), harness, stdout = (s) => process.stdout.write(s), stderr = (s) => process.stderr.write(s), presets, prettier, lock, run, stackMain,
|
package/stack/age-install.mjs
CHANGED
|
@@ -17,10 +17,18 @@ const STATIC_INSTALL = [
|
|
|
17
17
|
`echo "${AGE_SHA256} $tmp/age.tgz" | sha256sum -c -`,
|
|
18
18
|
'tar -xzf "$tmp/age.tgz" -C "$tmp"',
|
|
19
19
|
'sudo -n install -m 0755 "$tmp/age/age" "$tmp/age/age-keygen" /usr/local/bin/',
|
|
20
|
+
// sudo's secure_path (AlmaLinux 10, RHEL) leaves /usr/local/bin out: a link in /usr/bin makes both tools visible to the deploy
|
|
21
|
+
// user and to root alike; an existing /usr/bin tool (a packaged age) is kept.
|
|
22
|
+
'for b in age age-keygen; do if [ ! -e "/usr/bin/$b" ]; then sudo -n ln -s "/usr/local/bin/$b" "/usr/bin/$b"; fi; done',
|
|
20
23
|
].join('; ');
|
|
21
24
|
|
|
22
25
|
const packageManager = (run) => run('for m in dnf yum apk apt-get; do command -v $m >/dev/null 2>&1 && echo $m && break; done').stdout.trim();
|
|
23
|
-
|
|
26
|
+
/**
|
|
27
|
+
* Both tools, as the deploy user and, where passwordless sudo exists, as root: an install the root PATH cannot see is not taken
|
|
28
|
+
* for present.
|
|
29
|
+
*/
|
|
30
|
+
const PRESENT = 'command -v age >/dev/null 2>&1 && command -v age-keygen >/dev/null 2>&1 && { [ "$(id -u)" -eq 0 ] || ! sudo -n true 2>/dev/null || sudo -n sh -c \'command -v age >/dev/null 2>&1 && command -v age-keygen >/dev/null 2>&1\'; }';
|
|
31
|
+
const present = (run) => run(PRESENT).status === 0;
|
|
24
32
|
|
|
25
33
|
/** Installs age when it is missing; reports through `report`. */
|
|
26
34
|
export function installAge(run, report) {
|
|
@@ -33,6 +41,6 @@ export function installAge(run, report) {
|
|
|
33
41
|
failure = `${manager} could not install age: ${firstLine(packaged.stderr)}`;
|
|
34
42
|
}
|
|
35
43
|
const fetched = run(STATIC_INSTALL);
|
|
36
|
-
if (fetched.status === 0 && present(run)) report.note(`installed the official static age ${AGE_VERSION} (sha256 verified) into /usr/local/bin; ${failure}`);
|
|
44
|
+
if (fetched.status === 0 && present(run)) report.note(`installed the official static age ${AGE_VERSION} (sha256 verified) into /usr/local/bin, linked from /usr/bin; ${failure}`);
|
|
37
45
|
else report.bad(`cannot install age (${failure}); the static install failed too: ${firstLine(fetched.stderr)} (needs passwordless sudo once, or install age by hand)`);
|
|
38
46
|
}
|
package/stack/context.mjs
CHANGED
|
@@ -57,7 +57,7 @@ const realSleep = (ms) => new Promise((done) => { setTimeout(done, ms); });
|
|
|
57
57
|
* stdout, stderr text writers
|
|
58
58
|
* fetch the HTTP seam of verify (url, init) -> Response
|
|
59
59
|
* pipe (source, sink) -> Promise<{ source, sink, stderr }>: one process's stdout streamed into another's stdin (realPipe)
|
|
60
|
-
* sops the secret seam (decrypt(file, format) -> map; decryptBinary(file) -> text); `io.sops`, else on first use `io.openSops()` or the app's own sops/age tools
|
|
60
|
+
* sops the secret seam (decrypt(file, format) -> map; decryptBinary(file) -> text); `io.sops`, else on first use `io.openSops()` or the app's own sops/age tools with the age identity decryptionIdentity finds (`io.hostIdentity` the harness CLI's secret.env)
|
|
61
61
|
*/
|
|
62
62
|
export function stackContext(io = {}) {
|
|
63
63
|
const cwd = io.cwd ?? process.cwd();
|
|
@@ -78,7 +78,7 @@ export function stackContext(io = {}) {
|
|
|
78
78
|
pipe: io.pipe ?? realPipe,
|
|
79
79
|
/** The secret seam: the app's own sops/age tools, created on first use so verbs that open no custody never need them. */
|
|
80
80
|
get sops() {
|
|
81
|
-
sops ??= io.openSops?.() ?? defaultSops(env, cwd);
|
|
81
|
+
sops ??= io.openSops?.() ?? defaultSops(env, cwd, io.platform ?? process.platform, undefined, io.hostIdentity ?? null);
|
|
82
82
|
return sops;
|
|
83
83
|
},
|
|
84
84
|
});
|
package/stack/remote.mjs
CHANGED
|
@@ -64,24 +64,36 @@ function sshCommandArgv(sshCmd) {
|
|
|
64
64
|
return parts;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
/**
|
|
68
|
-
|
|
67
|
+
/**
|
|
68
|
+
* The key each sealed SSH member of `deploy.remote.sealed` holds (contexts/project/stacks.md PROJECT-STACKS-5): the one owner of
|
|
69
|
+
* these names. `sshKey` names the member whose `privateKey` is the PEM private key, `knownHosts` the member whose `knownHosts` is
|
|
70
|
+
* the pinned known_hosts text.
|
|
71
|
+
*/
|
|
72
|
+
export const SEALED_SSH_KEYS = Object.freeze({ sshKey: 'privateKey', knownHosts: 'knownHosts' });
|
|
73
|
+
|
|
74
|
+
/** A legacy binary member is the file itself; a JSON object around it ({ data | <key> }, the re-sealed shape of `starci app secret rename`) is unwrapped. */
|
|
75
|
+
function unwrap(text, key) {
|
|
69
76
|
const body = lfOnly(text);
|
|
70
77
|
const trimmed = body.trim();
|
|
71
78
|
if (!trimmed.startsWith('{')) return body;
|
|
72
79
|
let parsed;
|
|
73
80
|
try { parsed = JSON.parse(trimmed); } catch { return body; }
|
|
74
|
-
for (const name of ['data',
|
|
81
|
+
for (const name of ['data', key]) if (typeof parsed[name] === 'string') return lfOnly(parsed[name]);
|
|
75
82
|
return body;
|
|
76
83
|
}
|
|
77
84
|
|
|
85
|
+
/** The sops format a sealed member is read as: a `.enc.yaml` member is YAML, a legacy `.enc` one dotenv. */
|
|
86
|
+
const memberFormat = (file) => (isLegacyName(file) ? 'dotenv' : 'yaml');
|
|
87
|
+
|
|
88
|
+
/** Opens one member through the sops seam; a failure is refused naming the member and the seam's own reason (format, recipients, identity). */
|
|
78
89
|
function openMember(slug, read) {
|
|
79
90
|
try { return read(); } catch (error) { throw refusal('STACK_REMOTE_SEALED', `cannot open the sealed member ${slug}: ${error.message}`); }
|
|
80
91
|
}
|
|
81
92
|
|
|
82
93
|
function opsAccount(ctx, config) {
|
|
83
94
|
const slug = config.remote.sealed.ops;
|
|
84
|
-
const
|
|
95
|
+
const file = memberFile(config.secretsDir, slug);
|
|
96
|
+
const map = openMember(slug, () => ctx.sops.decrypt(file, memberFormat(file)));
|
|
85
97
|
for (const name of ['VPS_HOST', 'VPS_USER']) {
|
|
86
98
|
const value = map[name];
|
|
87
99
|
if (typeof value !== 'string' || !ACCOUNT.test(value) || value.startsWith('-')) throw refusal('STACK_REMOTE_OPS', `${slug} must hold ${name} (letters, digits, . _ @ -)`);
|
|
@@ -89,8 +101,17 @@ function opsAccount(ctx, config) {
|
|
|
89
101
|
return `${map.VPS_USER}@${map.VPS_HOST}`;
|
|
90
102
|
}
|
|
91
103
|
|
|
92
|
-
|
|
93
|
-
|
|
104
|
+
/**
|
|
105
|
+
* The text a sealed SSH member holds under `key` (SEALED_SSH_KEYS): a `.enc.yaml` member is read as YAML and the key taken from
|
|
106
|
+
* its map; a legacy `.enc` member is the sops binary or JSON envelope it was sealed as.
|
|
107
|
+
*/
|
|
108
|
+
function sshMember(ctx, config, slug, key) {
|
|
109
|
+
const file = memberFile(config.secretsDir, slug);
|
|
110
|
+
if (isLegacyName(file)) return unwrap(openMember(slug, () => ctx.sops.decryptBinary(file)), key);
|
|
111
|
+
const map = openMember(slug, () => ctx.sops.decrypt(file, 'yaml'));
|
|
112
|
+
if (typeof map[key] !== 'string' || map[key] === '')
|
|
113
|
+
throw refusal('STACK_REMOTE_SEALED', `the sealed member ${slug} holds no ${key} (it holds ${Object.keys(map).join(', ') || 'no key'}): seal it with starci app secret set ${config.env ?? '<env>'} ${slug} ${key} --from-file ${key}=<file>`);
|
|
114
|
+
return lfOnly(map[key]);
|
|
94
115
|
}
|
|
95
116
|
|
|
96
117
|
const withNewline = (text) => `${text.trim()}\n`;
|
|
@@ -107,9 +128,9 @@ export function openSealedSession(ctx, config) {
|
|
|
107
128
|
const account = opsAccount(ctx, config);
|
|
108
129
|
if (config.nativeTarget && account !== `${config.nativeTarget.user}@${config.nativeTarget.host}`)
|
|
109
130
|
throw refusal('STACK_REMOTE_OPS', 'the sealed SSH account differs from the accepted native target');
|
|
110
|
-
const key =
|
|
131
|
+
const key = sshMember(ctx, config, sealed.sshKey, SEALED_SSH_KEYS.sshKey);
|
|
111
132
|
if (!key.includes('PRIVATE KEY')) throw refusal('STACK_REMOTE_KEY', `${sealed.sshKey} does not hold a PEM private key`);
|
|
112
|
-
const known =
|
|
133
|
+
const known = sshMember(ctx, config, sealed.knownHosts, SEALED_SSH_KEYS.knownHosts).trim();
|
|
113
134
|
assertStackAccount(config.nativeTarget, account, known);
|
|
114
135
|
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'stack-ssh-'));
|
|
115
136
|
const keyFile = path.join(dir, 'id');
|
package/stack/sealed.mjs
CHANGED
|
@@ -5,7 +5,6 @@ import { createHash, createHmac } from 'node:crypto';
|
|
|
5
5
|
import { memberFile } from '../runtime/scripts/lib/sealed-member.mjs';
|
|
6
6
|
import fs from 'node:fs';
|
|
7
7
|
import path from 'node:path';
|
|
8
|
-
import { secretRoots } from '../runtime/scripts/hfs/secret-files.mjs';
|
|
9
8
|
import { readMap } from '../runtime/scripts/hfs/secret-store.mjs';
|
|
10
9
|
import { refusal } from './errors.mjs';
|
|
11
10
|
|
|
@@ -52,27 +51,32 @@ function secretRuntimeName(stack, key, value, versionKey) {
|
|
|
52
51
|
return name;
|
|
53
52
|
}
|
|
54
53
|
|
|
55
|
-
const
|
|
56
|
-
const AGE_HINT = 'load the age identity into SOPS_AGE_KEY (the secret.env of the owner machine, or the CI secret) and retry';
|
|
54
|
+
const AGE_HINT = 'add SOPS_AGE_KEY to .claude/secret.env of the app or the harness secret.env of the owner machine (the CI secret in a workflow) and retry';
|
|
57
55
|
|
|
58
|
-
/**
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
56
|
+
/**
|
|
57
|
+
* True when the sops seam found an age identity (secret-init.mjs decryptionIdentity, the one lookup every decrypt uses). A seam
|
|
58
|
+
* that reports no `identity` (a spec double) decides for itself.
|
|
59
|
+
*/
|
|
60
|
+
export function hasAgeIdentity(ctx) {
|
|
61
|
+
const { identity } = ctx.sops;
|
|
62
|
+
return identity === undefined || identity.source !== null;
|
|
62
63
|
}
|
|
63
64
|
|
|
64
65
|
/** Refuses up front, before any work, when sealed custody must be opened and no age identity is reachable. */
|
|
65
66
|
export function requireAgeIdentity(ctx, config, purpose) {
|
|
66
|
-
if (!hasAgeIdentity(ctx
|
|
67
|
+
if (!hasAgeIdentity(ctx)) throw refusal('STACK_AGE_IDENTITY_MISSING', `${purpose} needs the sealed members, and no age identity is available (looked in ${ctx.sops.identity.looked.join(', ')}): ${AGE_HINT}`);
|
|
67
68
|
}
|
|
68
69
|
|
|
69
|
-
/**
|
|
70
|
+
/**
|
|
71
|
+
* Opens one sealed member (`<secretsDir>/<member>.enc.yaml`, or a legacy `.enc`) into a { KEY: value } map. A failure is refused
|
|
72
|
+
* naming the member and the seam's reason (its format, recipients and the identity tried); no value.
|
|
73
|
+
*/
|
|
70
74
|
export function openMember(ctx, config, member) {
|
|
71
75
|
try {
|
|
72
76
|
const map = readMap(memberFile(config.secretsDir, member), ctx.sops);
|
|
73
77
|
return Object.fromEntries(Object.entries(map).map(([key, value]) => [key, typeof value === 'string' && !value.includes(String.fromCodePoint(0)) ? lfText(value) : value]));
|
|
74
|
-
} catch {
|
|
75
|
-
throw refusal('STACK_SECRET_MEMBER_UNREADABLE', `the sealed member ${member} cannot be opened${hasAgeIdentity(ctx
|
|
78
|
+
} catch (error) {
|
|
79
|
+
throw refusal('STACK_SECRET_MEMBER_UNREADABLE', `the sealed member ${member} cannot be opened: ${error.message}${hasAgeIdentity(ctx) ? '' : `; ${AGE_HINT}`}`);
|
|
76
80
|
}
|
|
77
81
|
}
|
|
78
82
|
|
package/stack/server-key.mjs
CHANGED
|
@@ -42,6 +42,22 @@ const RECIPIENT = /^age1[a-z0-9]+$/u;
|
|
|
42
42
|
/** A command run as root: directly when the deploy user is root, else over passwordless sudo, the script read from stdin. */
|
|
43
43
|
const AS_ROOT = 'if [ "$(id -u)" -eq 0 ]; then sh -s; else sudo -n sh -s; fi';
|
|
44
44
|
|
|
45
|
+
/**
|
|
46
|
+
* The directories, after root's PATH, where age-keygen is looked for: sudo's secure_path (AlmaLinux 10, RHEL) leaves out
|
|
47
|
+
* /usr/local/bin, where the static installer puts it, so the presence check and every call resolve it the same way, as root.
|
|
48
|
+
*/
|
|
49
|
+
export const AGE_KEYGEN_DIRS = ['/usr/local/bin', '/usr/bin', '/bin'];
|
|
50
|
+
|
|
51
|
+
/** The shell lines that set k to age-keygen's absolute path as root sees it, or exit 127 naming it missing. Every root script holds them. */
|
|
52
|
+
export const RESOLVE_AGE_KEYGEN = [
|
|
53
|
+
'k="$(command -v age-keygen 2>/dev/null || true)"',
|
|
54
|
+
`for d in ${AGE_KEYGEN_DIRS.join(' ')}; do if [ -z "$k" ] && [ -x "$d/age-keygen" ]; then k="$d/age-keygen"; fi; done`,
|
|
55
|
+
'if [ -z "$k" ]; then echo "age-keygen is not installed" >&2; exit 127; fi',
|
|
56
|
+
].join('\n');
|
|
57
|
+
|
|
58
|
+
/** The root script that only resolves age-keygen and prints its path: the presence check, run exactly as the calls run. */
|
|
59
|
+
export const ageKeygenScript = () => ['set -eu', RESOLVE_AGE_KEYGEN, String.raw`printf '%s\n' "$k"`].join('\n');
|
|
60
|
+
|
|
45
61
|
/**
|
|
46
62
|
* The GitHub Environment secret that holds an environment's server identity. It carries the name the deploy workflows read
|
|
47
63
|
* (secrets.SOPS_AGE_KEY), scoped to the Environment <env>: for a job bound to <env> it overrides a repository secret of that name.
|
|
@@ -54,24 +70,25 @@ export function ensureIdentityScript(file) {
|
|
|
54
70
|
return [
|
|
55
71
|
'set -eu',
|
|
56
72
|
'umask 077',
|
|
73
|
+
RESOLVE_AGE_KEYGEN,
|
|
57
74
|
`f=${quoted}`,
|
|
58
75
|
'if [ -e "$f" ] || [ -L "$f" ]; then',
|
|
59
76
|
' if [ -L "$f" ] || [ ! -f "$f" ]; then echo "the identity path is not an ordinary file" >&2; exit 4; fi',
|
|
60
77
|
' echo "identity kept" >&2',
|
|
61
78
|
'else',
|
|
62
79
|
' mkdir -p "$(dirname "$f")"',
|
|
63
|
-
'
|
|
80
|
+
' "$k" -o "$f" >/dev/null 2>&1',
|
|
64
81
|
' echo "identity created" >&2',
|
|
65
82
|
'fi',
|
|
66
83
|
'chown root:root "$f"',
|
|
67
84
|
'chmod 600 "$f"',
|
|
68
|
-
'
|
|
85
|
+
'"$k" -y "$f"',
|
|
69
86
|
].join('\n');
|
|
70
87
|
}
|
|
71
88
|
|
|
72
89
|
/** The shell that prints only the public key of `file`, or exits 5 when there is none. */
|
|
73
90
|
export function publicKeyScript(file) {
|
|
74
|
-
return ['set -eu', `f=${shellQuote(file)}`, '[ -f "$f" ] || exit 5', '
|
|
91
|
+
return ['set -eu', RESOLVE_AGE_KEYGEN, `f=${shellQuote(file)}`, '[ -f "$f" ] || exit 5', '"$k" -y "$f"'].join('\n');
|
|
75
92
|
}
|
|
76
93
|
|
|
77
94
|
/** The shell that swaps the staged `<file>.next` in, keeping the old identity as `retired`, then prints only the new public key. */
|
|
@@ -79,6 +96,7 @@ export function swapIdentityScript(file, retired) {
|
|
|
79
96
|
return [
|
|
80
97
|
'set -eu',
|
|
81
98
|
'umask 077',
|
|
99
|
+
RESOLVE_AGE_KEYGEN,
|
|
82
100
|
`f=${shellQuote(file)}`,
|
|
83
101
|
`r=${shellQuote(retired)}`,
|
|
84
102
|
'n="$f.next"',
|
|
@@ -87,7 +105,7 @@ export function swapIdentityScript(file, retired) {
|
|
|
87
105
|
'mv "$f" "$r"',
|
|
88
106
|
'mv "$n" "$f"',
|
|
89
107
|
'chmod 600 "$f" "$r"',
|
|
90
|
-
'
|
|
108
|
+
'"$k" -y "$f"',
|
|
91
109
|
].join('\n');
|
|
92
110
|
}
|
|
93
111
|
|
|
@@ -112,14 +130,20 @@ function declaredRemote(repoRoot, env) {
|
|
|
112
130
|
return remote;
|
|
113
131
|
}
|
|
114
132
|
|
|
115
|
-
/**
|
|
133
|
+
/** True when root resolves age-keygen the way every server-key script does (ageKeygenScript). */
|
|
134
|
+
const hasKeygen = (run) => asRoot(run, ageKeygenScript()).status === 0;
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Ensures age-keygen on the server, checked as root exactly as it is called: stack prepare's installer owns the install (with
|
|
138
|
+
* --execute); without it the exact commands.
|
|
139
|
+
*/
|
|
116
140
|
function ensureTool(run, execute, lines) {
|
|
117
|
-
if (run
|
|
141
|
+
if (hasKeygen(run)) return true;
|
|
118
142
|
const install = `install age on the server (one of: ${Object.values(AGE_INSTALL).join('; ')})`;
|
|
119
143
|
if (!execute) { lines.push(`dry run: age-keygen is missing on the server; --execute installs it with stack prepare's installer, or ${install}`); return false; }
|
|
120
144
|
const problems = [];
|
|
121
145
|
installAge(run, { note: (text) => lines.push(text), bad: (text) => problems.push(text) });
|
|
122
|
-
if (problems.length || run
|
|
146
|
+
if (problems.length || !hasKeygen(run))
|
|
123
147
|
throw refusal('STACK_SERVER_KEY_NO_AGE', `age-keygen is not on the server and could not be installed (${problems.join('; ') || 'still missing'}): ${install}`);
|
|
124
148
|
return true;
|
|
125
149
|
}
|
|
@@ -53,6 +53,6 @@ jobs:
|
|
|
53
53
|
printf '%s\n' "$VPS_SSH_KEY" > "$dir/id"
|
|
54
54
|
printf '%s\n' "$VPS_KNOWN_HOSTS" > "$dir/known_hosts"
|
|
55
55
|
# The server writes the identity beside its target, keeps it only when its public key is the recipient, then moves it in.
|
|
56
|
-
remote="f={{serverAgeIdentity}}; r=$RECIPIENT; "'if [ "$(id -u)" -eq 0 ]; then S=; else S="sudo -n"; fi; if $S test -e "$f"; then cat >/dev/null; echo "the server already holds $f; move it aside first" >&2; exit 3; fi; $S sh -c '"'"'umask 077; f="$1"; r="$2"; d="$(dirname "$f")"; mkdir -p "$d"; t="$(mktemp "$d/.restore.XXXXXX")"; cat > "$t"; if [ "$(age-keygen -y "$t" 2>/dev/null)" != "$r" ]; then rm -f "$t"; echo "the secret is not the identity of $r (or age-keygen is missing); nothing was written" >&2; exit 6; fi; chown root:root "$t"; chmod 600 "$t"; mv "$t" "$f"; age-keygen -y "$f"'"'"' sh "$f" "$r"'
|
|
56
|
+
remote="f={{serverAgeIdentity}}; r=$RECIPIENT; "'if [ "$(id -u)" -eq 0 ]; then S=; else S="sudo -n"; fi; if $S test -e "$f"; then cat >/dev/null; echo "the server already holds $f; move it aside first" >&2; exit 3; fi; $S sh -c '"'"'PATH="$PATH:/usr/local/bin"; umask 077; f="$1"; r="$2"; d="$(dirname "$f")"; mkdir -p "$d"; t="$(mktemp "$d/.restore.XXXXXX")"; cat > "$t"; if [ "$(age-keygen -y "$t" 2>/dev/null)" != "$r" ]; then rm -f "$t"; echo "the secret is not the identity of $r (or age-keygen is missing); nothing was written" >&2; exit 6; fi; chown root:root "$t"; chmod 600 "$t"; mv "$t" "$f"; age-keygen -y "$f"'"'"' sh "$f" "$r"'
|
|
57
57
|
printf '%s\n' "$AGE_IDENTITY" | ssh -T -i "$dir/id" -o IdentitiesOnly=yes -o UserKnownHostsFile="$dir/known_hosts" \
|
|
58
58
|
-o StrictHostKeyChecking=yes -o BatchMode=yes -o ConnectTimeout=20 "$VPS_USER@$VPS_HOST" "$remote"
|
|
@@ -53,6 +53,6 @@ jobs:
|
|
|
53
53
|
printf '%s\n' "$VPS_SSH_KEY" > "$dir/id"
|
|
54
54
|
printf '%s\n' "$VPS_KNOWN_HOSTS" > "$dir/known_hosts"
|
|
55
55
|
# The server writes the identity beside its target, keeps it only when its public key is the recipient, then moves it in.
|
|
56
|
-
remote="f={{serverAgeIdentity}}; r=$RECIPIENT; "'if [ "$(id -u)" -eq 0 ]; then S=; else S="sudo -n"; fi; if $S test -e "$f"; then cat >/dev/null; echo "the server already holds $f; move it aside first" >&2; exit 3; fi; $S sh -c '"'"'umask 077; f="$1"; r="$2"; d="$(dirname "$f")"; mkdir -p "$d"; t="$(mktemp "$d/.restore.XXXXXX")"; cat > "$t"; if [ "$(age-keygen -y "$t" 2>/dev/null)" != "$r" ]; then rm -f "$t"; echo "the secret is not the identity of $r (or age-keygen is missing); nothing was written" >&2; exit 6; fi; chown root:root "$t"; chmod 600 "$t"; mv "$t" "$f"; age-keygen -y "$f"'"'"' sh "$f" "$r"'
|
|
56
|
+
remote="f={{serverAgeIdentity}}; r=$RECIPIENT; "'if [ "$(id -u)" -eq 0 ]; then S=; else S="sudo -n"; fi; if $S test -e "$f"; then cat >/dev/null; echo "the server already holds $f; move it aside first" >&2; exit 3; fi; $S sh -c '"'"'PATH="$PATH:/usr/local/bin"; umask 077; f="$1"; r="$2"; d="$(dirname "$f")"; mkdir -p "$d"; t="$(mktemp "$d/.restore.XXXXXX")"; cat > "$t"; if [ "$(age-keygen -y "$t" 2>/dev/null)" != "$r" ]; then rm -f "$t"; echo "the secret is not the identity of $r (or age-keygen is missing); nothing was written" >&2; exit 6; fi; chown root:root "$t"; chmod 600 "$t"; mv "$t" "$f"; age-keygen -y "$f"'"'"' sh "$f" "$r"'
|
|
57
57
|
printf '%s\n' "$AGE_IDENTITY" | ssh -T -i "$dir/id" -o IdentitiesOnly=yes -o UserKnownHostsFile="$dir/known_hosts" \
|
|
58
58
|
-o StrictHostKeyChecking=yes -o BatchMode=yes -o ConnectTimeout=20 "$VPS_USER@$VPS_HOST" "$remote"
|