@mp-lb/arcnet 0.3.2 → 0.5.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/README.md +7 -53
- package/dist/arcnetConfig.d.ts +55 -0
- package/dist/arcnetConfig.d.ts.map +1 -0
- package/dist/arcnetConfig.js +53 -0
- package/dist/arcnetConfig.js.map +1 -0
- package/dist/ciOutputs.d.ts.map +1 -1
- package/dist/ciOutputs.js +26 -0
- package/dist/ciOutputs.js.map +1 -1
- package/dist/compileArcnet.d.ts +78 -0
- package/dist/compileArcnet.d.ts.map +1 -0
- package/dist/compileArcnet.js +60 -0
- package/dist/compileArcnet.js.map +1 -0
- package/dist/createCli.d.ts.map +1 -1
- package/dist/createCli.js +17 -4
- package/dist/createCli.js.map +1 -1
- package/dist/environment/grantDomainOwner.d.ts.map +1 -1
- package/dist/environment/grantDomainOwner.js.map +1 -1
- package/dist/resolveEnvironment.d.ts +21 -0
- package/dist/resolveEnvironment.d.ts.map +1 -0
- package/dist/resolveEnvironment.js +37 -0
- package/dist/resolveEnvironment.js.map +1 -0
- package/dist/runTerraform.d.ts.map +1 -1
- package/dist/runTerraform.js +57 -10
- package/dist/runTerraform.js.map +1 -1
- package/dist/runVercel.d.ts.map +1 -1
- package/dist/runVercel.js +16 -3
- package/dist/runVercel.js.map +1 -1
- package/dist/secrets/config.d.ts +16 -6
- package/dist/secrets/config.d.ts.map +1 -1
- package/dist/secrets/config.js +59 -6
- package/dist/secrets/config.js.map +1 -1
- package/dist/secrets/createSecretsCommands.d.ts.map +1 -1
- package/dist/secrets/createSecretsCommands.js +12 -10
- package/dist/secrets/createSecretsCommands.js.map +1 -1
- package/dist/secrets/loadSecrets.d.ts.map +1 -1
- package/dist/secrets/loadSecrets.js +2 -2
- package/dist/secrets/loadSecrets.js.map +1 -1
- package/dist/secrets/provisionSource.d.ts +12 -2
- package/dist/secrets/provisionSource.d.ts.map +1 -1
- package/dist/secrets/provisionSource.js +42 -7
- package/dist/secrets/provisionSource.js.map +1 -1
- package/dist/secrets/readRemoteSource.js +1 -1
- package/dist/secrets/readRemoteSource.js.map +1 -1
- package/dist/secrets/syncSecrets.d.ts +7 -0
- package/dist/secrets/syncSecrets.d.ts.map +1 -1
- package/dist/secrets/syncSecrets.js +36 -2
- package/dist/secrets/syncSecrets.js.map +1 -1
- package/dist/secrets/withDeploymentSecrets.d.ts.map +1 -1
- package/dist/secrets/withDeploymentSecrets.js +11 -5
- package/dist/secrets/withDeploymentSecrets.js.map +1 -1
- package/dist/secrets/writeSecretsWorkflow.d.ts.map +1 -1
- package/dist/secrets/writeSecretsWorkflow.js +5 -4
- package/dist/secrets/writeSecretsWorkflow.js.map +1 -1
- package/dist/setup.d.ts.map +1 -1
- package/dist/setup.js +12 -0
- package/dist/setup.js.map +1 -1
- package/dist/setupArcnet.d.ts +2 -0
- package/dist/setupArcnet.d.ts.map +1 -0
- package/dist/setupArcnet.js +63 -0
- package/dist/setupArcnet.js.map +1 -0
- package/docs/public/commands.md +6 -4
- package/docs/public/llms-full.txt +13 -57
- package/environments/mp-lb.yaml +76 -0
- package/package.json +3 -2
- package/src/arcnetConfig.ts +68 -0
- package/src/ciOutputs.ts +36 -0
- package/src/compileArcnet.ts +82 -0
- package/src/createCli.ts +45 -11
- package/src/environment/grantDomainOwner.ts +16 -3
- package/src/resolveEnvironment.ts +50 -0
- package/src/runTerraform.ts +75 -10
- package/src/runVercel.ts +29 -3
- package/src/secrets/config.ts +69 -8
- package/src/secrets/createSecretsCommands.ts +30 -38
- package/src/secrets/loadSecrets.ts +12 -4
- package/src/secrets/provisionSource.ts +69 -16
- package/src/secrets/readRemoteSource.ts +1 -1
- package/src/secrets/syncSecrets.ts +52 -6
- package/src/secrets/withDeploymentSecrets.ts +18 -8
- package/src/secrets/writeSecretsWorkflow.ts +7 -5
- package/src/setup.ts +19 -0
- package/src/setupArcnet.ts +96 -0
package/src/secrets/config.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { readFileSync } from "node:fs";
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { parse } from "yaml";
|
|
2
4
|
import { z } from "zod";
|
|
3
5
|
import { safeTargetPath } from "../safeTargetPath.js";
|
|
4
6
|
|
|
@@ -24,9 +26,12 @@ export const sourceSchema = z
|
|
|
24
26
|
snapshot: z
|
|
25
27
|
.object({
|
|
26
28
|
file: z.string(),
|
|
27
|
-
fileId: z.string().min(1),
|
|
28
|
-
revision: z.number().int().nonnegative(),
|
|
29
|
-
sha256: z
|
|
29
|
+
fileId: z.string().min(1).optional(),
|
|
30
|
+
revision: z.number().int().nonnegative().optional(),
|
|
31
|
+
sha256: z
|
|
32
|
+
.string()
|
|
33
|
+
.regex(/^[a-f0-9]{64}$/)
|
|
34
|
+
.optional(),
|
|
30
35
|
})
|
|
31
36
|
.strict()
|
|
32
37
|
.optional(),
|
|
@@ -75,14 +80,70 @@ export const secretsConfigSchema = z
|
|
|
75
80
|
export type SecretsConfig = z.infer<typeof secretsConfigSchema>;
|
|
76
81
|
export type SecretSource = z.infer<typeof sourceSchema>;
|
|
77
82
|
|
|
83
|
+
export const simpleSourceSchema = z
|
|
84
|
+
.object({
|
|
85
|
+
key: envName,
|
|
86
|
+
store: sourceSchema.shape.store,
|
|
87
|
+
path: sourceSchema.shape.path,
|
|
88
|
+
token: envName.optional(),
|
|
89
|
+
})
|
|
90
|
+
.strict();
|
|
91
|
+
|
|
92
|
+
export const snapshotPathForKey = (key: string) =>
|
|
93
|
+
`.arcnet/secrets/${key}.json.enc`;
|
|
94
|
+
export const sourceNameForKey = (key: string) =>
|
|
95
|
+
`source-${key.toLowerCase().replaceAll("_", "-")}`;
|
|
96
|
+
|
|
97
|
+
const expandSimpleSources = (sources: unknown) =>
|
|
98
|
+
z
|
|
99
|
+
.array(simpleSourceSchema)
|
|
100
|
+
.min(1)
|
|
101
|
+
.parse(sources)
|
|
102
|
+
.map((source) => ({
|
|
103
|
+
name: sourceNameForKey(source.key),
|
|
104
|
+
store: source.store,
|
|
105
|
+
path: source.path,
|
|
106
|
+
keyEnv: source.key,
|
|
107
|
+
tokenEnv: source.token,
|
|
108
|
+
snapshot: { file: snapshotPathForKey(source.key) },
|
|
109
|
+
}));
|
|
110
|
+
|
|
111
|
+
export const resolveSecretsConfigPath = (root: string, file?: string) =>
|
|
112
|
+
file ??
|
|
113
|
+
(existsSync(join(root, ".arcnet/arcnet.yaml"))
|
|
114
|
+
? ".arcnet/arcnet.yaml"
|
|
115
|
+
: ".arcnet/secrets.json");
|
|
116
|
+
|
|
117
|
+
export const hasSecretsConfig = (root: string) => {
|
|
118
|
+
const modern = join(root, ".arcnet/arcnet.yaml");
|
|
119
|
+
if (existsSync(modern))
|
|
120
|
+
return Boolean(parse(readFileSync(modern, "utf8"))?.secrets);
|
|
121
|
+
return existsSync(join(root, ".arcnet/secrets.json"));
|
|
122
|
+
};
|
|
123
|
+
|
|
78
124
|
export const readSecretsConfig = (
|
|
79
125
|
root: string,
|
|
80
|
-
file =
|
|
126
|
+
file = resolveSecretsConfigPath(root),
|
|
81
127
|
): SecretsConfig => {
|
|
82
128
|
try {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
129
|
+
if (file === ".arcnet/arcnet.yaml") {
|
|
130
|
+
const config = parse(readFileSync(safeTargetPath(root, file), "utf8"));
|
|
131
|
+
const sources = expandSimpleSources(config.secrets?.sources);
|
|
132
|
+
return secretsConfigSchema.parse({
|
|
133
|
+
version: 1,
|
|
134
|
+
repository: config.repository,
|
|
135
|
+
sources,
|
|
136
|
+
consumers: config.secrets?.consumers,
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const config = JSON.parse(readFileSync(safeTargetPath(root, file), "utf8"));
|
|
141
|
+
if (Array.isArray(config.sources) && config.sources[0]?.key)
|
|
142
|
+
return secretsConfigSchema.parse({
|
|
143
|
+
...config,
|
|
144
|
+
sources: expandSimpleSources(config.sources),
|
|
145
|
+
});
|
|
146
|
+
return secretsConfigSchema.parse(config);
|
|
86
147
|
} catch {
|
|
87
148
|
throw new Error(
|
|
88
149
|
"Missing or invalid secrets configuration (values omitted).",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Command } from "commander";
|
|
2
2
|
import { realpathSync } from "node:fs";
|
|
3
|
-
import { readSecretsConfig } from "./config.js";
|
|
3
|
+
import { readSecretsConfig, resolveSecretsConfigPath } from "./config.js";
|
|
4
4
|
import { loadSecrets } from "./loadSecrets.js";
|
|
5
5
|
import { provisionSource, type ProvisionOptions } from "./provisionSource.js";
|
|
6
6
|
import { runWithSecrets } from "./runWithSecrets.js";
|
|
@@ -30,11 +30,7 @@ export const createSecretsCommands = (
|
|
|
30
30
|
run: "Run a command with selected keys only; withhold child output.",
|
|
31
31
|
}[action],
|
|
32
32
|
)
|
|
33
|
-
.option(
|
|
34
|
-
"--config <file>",
|
|
35
|
-
"Secrets source configuration",
|
|
36
|
-
".arcnet/secrets.json",
|
|
37
|
-
)
|
|
33
|
+
.option("--config <file>", "Secrets source configuration")
|
|
38
34
|
.option("--consumer <name>", "Named mapping in the secrets configuration")
|
|
39
35
|
.option(
|
|
40
36
|
"--live",
|
|
@@ -49,14 +45,19 @@ export const createSecretsCommands = (
|
|
|
49
45
|
command.argument("<command...>", "Executable and arguments after --");
|
|
50
46
|
command.action(async (...args: unknown[]) => {
|
|
51
47
|
const options = command.opts<{
|
|
52
|
-
config
|
|
48
|
+
config?: string;
|
|
53
49
|
consumer?: string;
|
|
54
50
|
live?: boolean;
|
|
55
51
|
password?: boolean;
|
|
56
52
|
}>();
|
|
57
53
|
|
|
58
54
|
const root = realpathSync(cli.opts().root);
|
|
59
|
-
|
|
55
|
+
|
|
56
|
+
const config = readSecretsConfig(
|
|
57
|
+
root,
|
|
58
|
+
resolveSecretsConfigPath(root, options.config),
|
|
59
|
+
);
|
|
60
|
+
|
|
60
61
|
if (
|
|
61
62
|
process.env.GITHUB_ACTIONS === "true" &&
|
|
62
63
|
(process.env.GITHUB_REPOSITORY !== config.repository ||
|
|
@@ -66,12 +67,16 @@ export const createSecretsCommands = (
|
|
|
66
67
|
"Secrets commands in CI require the configured repository main branch.",
|
|
67
68
|
);
|
|
68
69
|
if (options.password && process.env.GITHUB_ACTIONS === "true")
|
|
69
|
-
throw new Error(
|
|
70
|
+
throw new Error(
|
|
71
|
+
"Password decryption is local-only; CI must use file keys.",
|
|
72
|
+
);
|
|
70
73
|
if (action !== "check" && !options.consumer)
|
|
71
74
|
throw new Error("Choose --consumer to explicitly select output keys.");
|
|
75
|
+
|
|
72
76
|
const password = options.password
|
|
73
77
|
? await promptPassword(Boolean(cli.opts().noninteractive))
|
|
74
78
|
: undefined;
|
|
79
|
+
|
|
75
80
|
const values = await loadSecrets(
|
|
76
81
|
config,
|
|
77
82
|
root,
|
|
@@ -131,25 +136,19 @@ export const createSecretsCommands = (
|
|
|
131
136
|
? "Attach an existing Forum file and provision its CI key."
|
|
132
137
|
: "Create a Forum secrets file, prompt for your password and provision its CI key.",
|
|
133
138
|
)
|
|
134
|
-
.
|
|
135
|
-
"--
|
|
136
|
-
"
|
|
139
|
+
.option(
|
|
140
|
+
"--key <name>",
|
|
141
|
+
"GitHub decryption secret for arcnet.yaml sources",
|
|
137
142
|
)
|
|
143
|
+
.option("--name <name>", "Legacy source name")
|
|
138
144
|
.requiredOption("--store <workspace/store>", "Forum store")
|
|
139
145
|
.requiredOption("--path <path>", "Encrypted file path in Forum")
|
|
140
|
-
.
|
|
141
|
-
"--key-env <name>",
|
|
142
|
-
"GitHub repository secret / environment variable for this file's key",
|
|
143
|
-
)
|
|
146
|
+
.option("--key-env <name>", "Legacy GitHub repository secret")
|
|
144
147
|
.requiredOption(
|
|
145
148
|
"--repository <owner/repo>",
|
|
146
149
|
"GitHub repository receiving the key",
|
|
147
150
|
)
|
|
148
|
-
.option(
|
|
149
|
-
"--config <file>",
|
|
150
|
-
"Secrets source configuration",
|
|
151
|
-
".arcnet/secrets.json",
|
|
152
|
-
);
|
|
151
|
+
.option("--config <file>", "Secrets source configuration");
|
|
153
152
|
|
|
154
153
|
if (mode === "add")
|
|
155
154
|
command.option(
|
|
@@ -170,7 +169,10 @@ export const createSecretsCommands = (
|
|
|
170
169
|
noninteractive: cli.opts().noninteractive,
|
|
171
170
|
},
|
|
172
171
|
realpathSync(cli.opts().root),
|
|
173
|
-
|
|
172
|
+
resolveSecretsConfigPath(
|
|
173
|
+
realpathSync(cli.opts().root),
|
|
174
|
+
command.opts().config,
|
|
175
|
+
),
|
|
174
176
|
),
|
|
175
177
|
),
|
|
176
178
|
);
|
|
@@ -181,25 +183,15 @@ export const createSecretsCommands = (
|
|
|
181
183
|
.description(
|
|
182
184
|
"Refresh encrypted snapshots from Forum and regenerate validation CI; no decryption.",
|
|
183
185
|
)
|
|
184
|
-
.option(
|
|
185
|
-
|
|
186
|
-
"Secrets source configuration",
|
|
187
|
-
".arcnet/secrets.json",
|
|
188
|
-
)
|
|
189
|
-
.action((options: { config: string }) => {
|
|
186
|
+
.option("--config <file>", "Secrets source configuration")
|
|
187
|
+
.action((options: { config?: string }) => {
|
|
190
188
|
const root = realpathSync(cli.opts().root);
|
|
191
189
|
|
|
192
|
-
const
|
|
193
|
-
readSecretsConfig(root, options.config),
|
|
194
|
-
root,
|
|
195
|
-
options.config,
|
|
196
|
-
);
|
|
190
|
+
const file = resolveSecretsConfigPath(root, options.config);
|
|
197
191
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
options.config,
|
|
202
|
-
);
|
|
192
|
+
const result = syncSecrets(readSecretsConfig(root, file), root, file);
|
|
193
|
+
|
|
194
|
+
writeSecretsWorkflow(readSecretsConfig(root, file), root, file);
|
|
203
195
|
|
|
204
196
|
output(result);
|
|
205
197
|
});
|
|
@@ -30,20 +30,27 @@ export const loadSecrets = async (
|
|
|
30
30
|
|
|
31
31
|
if (
|
|
32
32
|
!live &&
|
|
33
|
-
source.snapshot &&
|
|
33
|
+
source.snapshot?.sha256 &&
|
|
34
34
|
createHash("sha256").update(text).digest("hex") !==
|
|
35
35
|
source.snapshot.sha256
|
|
36
36
|
)
|
|
37
37
|
throw new Error("Snapshot integrity mismatch");
|
|
38
38
|
|
|
39
39
|
let plaintext: string;
|
|
40
|
+
|
|
40
41
|
if (password) {
|
|
41
42
|
const temporary = mkdtempSync(join(tmpdir(), "arcnet-decrypt-"));
|
|
43
|
+
|
|
42
44
|
try {
|
|
43
45
|
const file = join(temporary, "source.json.enc");
|
|
44
46
|
writeFileSync(file, text, { mode: 0o600 });
|
|
45
|
-
plaintext = secretCommand(
|
|
46
|
-
|
|
47
|
+
plaintext = secretCommand(
|
|
48
|
+
"fm",
|
|
49
|
+
["decrypt", "--file", file],
|
|
50
|
+
root,
|
|
51
|
+
undefined,
|
|
52
|
+
{ ...environment, DOCTRINE_ENCRYPTION_PASSWORD: password },
|
|
53
|
+
);
|
|
47
54
|
} finally {
|
|
48
55
|
rmSync(temporary, { recursive: true, force: true });
|
|
49
56
|
}
|
|
@@ -53,6 +60,7 @@ export const loadSecrets = async (
|
|
|
53
60
|
recipientSecret: key!,
|
|
54
61
|
});
|
|
55
62
|
}
|
|
63
|
+
|
|
56
64
|
const decoded: unknown = JSON.parse(plaintext);
|
|
57
65
|
|
|
58
66
|
if (!decoded || Array.isArray(decoded) || typeof decoded !== "object")
|
|
@@ -60,7 +68,7 @@ export const loadSecrets = async (
|
|
|
60
68
|
values = { ...values, ...decoded };
|
|
61
69
|
} catch {
|
|
62
70
|
throw new Error(
|
|
63
|
-
`Source ${source.name} failed to load or decrypt; check its key and
|
|
71
|
+
`Source ${source.name} failed to load or decrypt; check its key and encrypted file (values omitted).`,
|
|
64
72
|
);
|
|
65
73
|
}
|
|
66
74
|
}
|
|
@@ -8,11 +8,15 @@ import {
|
|
|
8
8
|
} from "node:fs";
|
|
9
9
|
import { tmpdir } from "node:os";
|
|
10
10
|
import { join } from "node:path";
|
|
11
|
+
import { parseDocument } from "yaml";
|
|
11
12
|
import { safeTargetPath } from "../safeTargetPath.js";
|
|
12
13
|
import {
|
|
14
|
+
hasSecretsConfig,
|
|
13
15
|
readSecretsConfig,
|
|
14
16
|
secretsConfigSchema,
|
|
15
17
|
sourceSchema,
|
|
18
|
+
snapshotPathForKey,
|
|
19
|
+
sourceNameForKey,
|
|
16
20
|
} from "./config.js";
|
|
17
21
|
import { promptPassword } from "./promptPassword.js";
|
|
18
22
|
import { secretCommand } from "./secretCommand.js";
|
|
@@ -22,10 +26,11 @@ import { writeSecretsWorkflow } from "./writeSecretsWorkflow.js";
|
|
|
22
26
|
import { assertNewSource } from "./assertNewSource.js";
|
|
23
27
|
|
|
24
28
|
export interface ProvisionOptions {
|
|
25
|
-
|
|
29
|
+
key?: string;
|
|
30
|
+
name?: string;
|
|
26
31
|
store: string;
|
|
27
32
|
path: string;
|
|
28
|
-
keyEnv
|
|
33
|
+
keyEnv?: string;
|
|
29
34
|
repository: string;
|
|
30
35
|
existingKey?: boolean;
|
|
31
36
|
input?: string;
|
|
@@ -38,32 +43,47 @@ export const provisionSource = async (
|
|
|
38
43
|
root: string,
|
|
39
44
|
configFile: string,
|
|
40
45
|
) => {
|
|
41
|
-
if (
|
|
46
|
+
if (![".arcnet/secrets.json", ".arcnet/arcnet.yaml"].includes(configFile))
|
|
42
47
|
throw new Error(
|
|
43
|
-
"Provisioning uses
|
|
48
|
+
"Provisioning uses an ArcNet configuration under .arcnet/.",
|
|
44
49
|
);
|
|
45
50
|
if (process.env.GITHUB_ACTIONS === "true")
|
|
46
51
|
throw new Error(
|
|
47
52
|
"Provision secrets from an authorized local terminal, not CI.",
|
|
48
53
|
);
|
|
49
54
|
|
|
55
|
+
const modern = configFile === ".arcnet/arcnet.yaml";
|
|
56
|
+
const configPath = safeTargetPath(root, configFile);
|
|
57
|
+
|
|
58
|
+
const simple =
|
|
59
|
+
modern ||
|
|
60
|
+
Boolean(options.key) ||
|
|
61
|
+
(existsSync(configPath) &&
|
|
62
|
+
Boolean(JSON.parse(readFileSync(configPath, "utf8")).sources?.[0]?.key));
|
|
63
|
+
|
|
64
|
+
const key = simple ? options.key : options.keyEnv;
|
|
65
|
+
if (!key || (!simple && !options.name))
|
|
66
|
+
throw new Error(
|
|
67
|
+
simple ? "Provide --key." : "Provide --name and --key-env.",
|
|
68
|
+
);
|
|
69
|
+
|
|
50
70
|
const source = sourceSchema.parse({
|
|
51
|
-
name: options.name,
|
|
71
|
+
name: simple ? sourceNameForKey(key) : options.name,
|
|
52
72
|
store: options.store,
|
|
53
73
|
path: options.path.startsWith("/") ? options.path : `/${options.path}`,
|
|
54
|
-
keyEnv:
|
|
74
|
+
keyEnv: key,
|
|
75
|
+
...(simple ? { snapshot: { file: snapshotPathForKey(key) } } : {}),
|
|
55
76
|
});
|
|
56
77
|
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
};
|
|
78
|
+
const config =
|
|
79
|
+
existsSync(configPath) && hasSecretsConfig(root)
|
|
80
|
+
? readSecretsConfig(root, configFile)
|
|
81
|
+
: {
|
|
82
|
+
version: 1 as const,
|
|
83
|
+
repository: options.repository,
|
|
84
|
+
sources: [],
|
|
85
|
+
consumers: {},
|
|
86
|
+
};
|
|
67
87
|
|
|
68
88
|
if (config.repository !== options.repository)
|
|
69
89
|
throw new Error("Repository differs from secrets configuration.");
|
|
@@ -226,6 +246,39 @@ export const provisionSource = async (
|
|
|
226
246
|
}
|
|
227
247
|
|
|
228
248
|
const result = syncSecrets(next, root, configFile);
|
|
249
|
+
|
|
250
|
+
if (simple) {
|
|
251
|
+
const simpleSources = next.sources.map((entry) => ({
|
|
252
|
+
key: entry.keyEnv,
|
|
253
|
+
store: entry.store,
|
|
254
|
+
path: entry.path,
|
|
255
|
+
...(entry.tokenEnv ? { token: entry.tokenEnv } : {}),
|
|
256
|
+
}));
|
|
257
|
+
|
|
258
|
+
if (!modern) {
|
|
259
|
+
writeFileSync(
|
|
260
|
+
configPath,
|
|
261
|
+
JSON.stringify(
|
|
262
|
+
{
|
|
263
|
+
version: 1,
|
|
264
|
+
repository: next.repository,
|
|
265
|
+
sources: simpleSources,
|
|
266
|
+
consumers: next.consumers,
|
|
267
|
+
},
|
|
268
|
+
null,
|
|
269
|
+
2,
|
|
270
|
+
) + "\n",
|
|
271
|
+
);
|
|
272
|
+
} else {
|
|
273
|
+
const document = parseDocument(readFileSync(configPath, "utf8"));
|
|
274
|
+
if (document.errors.length) throw new Error("Invalid arcnet.yaml.");
|
|
275
|
+
document.setIn(["secrets", "sources"], simpleSources);
|
|
276
|
+
if (!document.hasIn(["secrets", "consumers"]))
|
|
277
|
+
document.setIn(["secrets", "consumers"], next.consumers);
|
|
278
|
+
writeFileSync(configPath, document.toString());
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
229
282
|
writeSecretsWorkflow(readSecretsConfig(root, configFile), root, configFile);
|
|
230
283
|
return {
|
|
231
284
|
...result,
|
|
@@ -61,7 +61,7 @@ export const readRemoteSource = (
|
|
|
61
61
|
before.id !== after.id ||
|
|
62
62
|
before.revisionNumber !== after.revisionNumber ||
|
|
63
63
|
after.path !== source.path ||
|
|
64
|
-
(source.snapshot && after.id !== source.snapshot.fileId)
|
|
64
|
+
(source.snapshot?.fileId && after.id !== source.snapshot.fileId)
|
|
65
65
|
)
|
|
66
66
|
throw new Error("Source changed");
|
|
67
67
|
return { text, fileId: after.id, revision: after.revisionNumber };
|
|
@@ -1,16 +1,57 @@
|
|
|
1
1
|
import { parseForumEncryptedFilePayload } from "@mp-lb/forum-secrets";
|
|
2
2
|
import { createHash } from "node:crypto";
|
|
3
|
-
import { mkdirSync, renameSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { mkdirSync, renameSync, writeFileSync, readFileSync } from "node:fs";
|
|
4
4
|
import { dirname } from "node:path";
|
|
5
5
|
import { safeTargetPath } from "../safeTargetPath.js";
|
|
6
6
|
import type { SecretsConfig } from "./config.js";
|
|
7
7
|
import { readRemoteSource } from "./readRemoteSource.js";
|
|
8
|
+
import { parseDocument } from "yaml";
|
|
9
|
+
import { snapshotPathForKey } from "./config.js";
|
|
8
10
|
|
|
9
11
|
export const syncSecrets = (
|
|
10
12
|
config: SecretsConfig,
|
|
11
13
|
root: string,
|
|
12
14
|
file: string,
|
|
13
15
|
) => {
|
|
16
|
+
if (
|
|
17
|
+
file === ".arcnet/arcnet.yaml" ||
|
|
18
|
+
config.sources.every(
|
|
19
|
+
(source) =>
|
|
20
|
+
source.snapshot?.file === snapshotPathForKey(source.keyEnv) &&
|
|
21
|
+
!source.snapshot.sha256,
|
|
22
|
+
)
|
|
23
|
+
) {
|
|
24
|
+
const sources = config.sources.map((source) => {
|
|
25
|
+
const remote = readRemoteSource(source, root);
|
|
26
|
+
|
|
27
|
+
try {
|
|
28
|
+
parseForumEncryptedFilePayload(remote.text);
|
|
29
|
+
} catch {
|
|
30
|
+
throw new Error(
|
|
31
|
+
`Source ${source.keyEnv} is not a supported encrypted file.`,
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const target = safeTargetPath(root, snapshotPathForKey(source.keyEnv));
|
|
36
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
37
|
+
|
|
38
|
+
const temporary = safeTargetPath(
|
|
39
|
+
root,
|
|
40
|
+
`${snapshotPathForKey(source.keyEnv)}.tmp`,
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
writeFileSync(temporary, remote.text, { mode: 0o600 });
|
|
44
|
+
renameSync(temporary, target);
|
|
45
|
+
return { key: source.keyEnv, revision: remote.revision };
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
operation: "secrets.sync",
|
|
50
|
+
sources,
|
|
51
|
+
message: "Review and commit the encrypted snapshots.",
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
14
55
|
const sources = config.sources.map((source) => {
|
|
15
56
|
const remote = readRemoteSource(source, root);
|
|
16
57
|
|
|
@@ -41,11 +82,16 @@ export const syncSecrets = (
|
|
|
41
82
|
const target = safeTargetPath(root, file);
|
|
42
83
|
mkdirSync(dirname(target), { recursive: true });
|
|
43
84
|
const temporary = safeTargetPath(root, `${file}.tmp`);
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
85
|
+
let content = JSON.stringify({ ...config, sources }, null, 2) + "\n";
|
|
86
|
+
|
|
87
|
+
if (file === ".arcnet/arcnet.yaml") {
|
|
88
|
+
const document = parseDocument(readFileSync(target, "utf8"));
|
|
89
|
+
if (document.errors.length) throw new Error("Invalid arcnet.yaml.");
|
|
90
|
+
document.set("secrets", { sources, consumers: config.consumers });
|
|
91
|
+
content = document.toString();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
writeFileSync(temporary, content, { mode: 0o600 });
|
|
49
95
|
|
|
50
96
|
renameSync(temporary, target);
|
|
51
97
|
return {
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { parse } from "yaml";
|
|
4
|
-
import { readSecretsConfig } from "./config.js";
|
|
4
|
+
import { hasSecretsConfig, readSecretsConfig } from "./config.js";
|
|
5
5
|
import { loadSecrets } from "./loadSecrets.js";
|
|
6
6
|
import { selectSecrets } from "./selectSecrets.js";
|
|
7
7
|
import { promptPassword } from "./promptPassword.js";
|
|
8
|
+
import { hasArcnetConfig, readArcnetConfig } from "../arcnetConfig.js";
|
|
9
|
+
import { compileTerraform } from "../compileArcnet.js";
|
|
8
10
|
|
|
9
11
|
export const withDeploymentSecrets = async <T>(
|
|
10
12
|
root: string,
|
|
@@ -13,7 +15,7 @@ export const withDeploymentSecrets = async <T>(
|
|
|
13
15
|
usePassword = false,
|
|
14
16
|
noninteractive = false,
|
|
15
17
|
): Promise<T> => {
|
|
16
|
-
if (!
|
|
18
|
+
if (!hasSecretsConfig(root)) return action();
|
|
17
19
|
const config = readSecretsConfig(root);
|
|
18
20
|
if (
|
|
19
21
|
process.env.GITHUB_ACTIONS === "true" &&
|
|
@@ -24,15 +26,23 @@ export const withDeploymentSecrets = async <T>(
|
|
|
24
26
|
"Secrets commands in CI require the configured repository main branch.",
|
|
25
27
|
);
|
|
26
28
|
if (usePassword && process.env.GITHUB_ACTIONS === "true")
|
|
27
|
-
throw new Error(
|
|
28
|
-
|
|
29
|
+
throw new Error(
|
|
30
|
+
"Password decryption is local-only; CI must use file keys.",
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
const password = usePassword
|
|
34
|
+
? await promptPassword(noninteractive)
|
|
35
|
+
: undefined;
|
|
36
|
+
|
|
29
37
|
const pool = await loadSecrets(config, root, process.env, false, password);
|
|
30
38
|
const selected = selectSecrets(pool, config, "deploy");
|
|
31
39
|
|
|
32
40
|
if (mode !== "vercel") {
|
|
33
|
-
const manifest =
|
|
34
|
-
|
|
35
|
-
|
|
41
|
+
const manifest = hasArcnetConfig(root)
|
|
42
|
+
? { deploy: compileTerraform(readArcnetConfig(root)).deployment }
|
|
43
|
+
: (parse(readFileSync(join(root, "zap.yaml"), "utf8")) as {
|
|
44
|
+
deploy?: { services?: Record<string, { env?: string[] }> };
|
|
45
|
+
});
|
|
36
46
|
|
|
37
47
|
const keys = Object.values(manifest.deploy?.services ?? {})
|
|
38
48
|
.flatMap((service) => service.env ?? [])
|
|
@@ -15,16 +15,18 @@ export const writeSecretsWorkflow = (
|
|
|
15
15
|
".github/workflows/validate-arcnet-secrets.yaml",
|
|
16
16
|
);
|
|
17
17
|
|
|
18
|
-
const marker =
|
|
19
|
-
"# Generated by arcnet secrets; configure sources in .arcnet/secrets.json.\n";
|
|
18
|
+
const marker = `# Generated by arcnet secrets; configure sources in ${configFile}.\n`;
|
|
20
19
|
|
|
21
|
-
if (
|
|
20
|
+
if (
|
|
21
|
+
existsSync(path) &&
|
|
22
|
+
!readFileSync(path, "utf8").startsWith("# Generated by arcnet secrets;")
|
|
23
|
+
)
|
|
22
24
|
throw new Error(
|
|
23
25
|
"Existing validate-arcnet-secrets.yaml is not ArcNet-managed; move it before continuing.",
|
|
24
26
|
);
|
|
25
|
-
if (
|
|
27
|
+
if (![".arcnet/secrets.json", ".arcnet/arcnet.yaml"].includes(configFile))
|
|
26
28
|
throw new Error(
|
|
27
|
-
"Generated CI requires
|
|
29
|
+
"Generated CI requires an ArcNet configuration under .arcnet/.",
|
|
28
30
|
);
|
|
29
31
|
mkdirSync(dirname(path), { recursive: true });
|
|
30
32
|
|
package/src/setup.ts
CHANGED
|
@@ -19,6 +19,8 @@ import { resolveRepository } from "./resolveRepository.js";
|
|
|
19
19
|
import { safeTargetPath } from "./safeTargetPath.js";
|
|
20
20
|
import { selectNetwork } from "./selectNetwork.js";
|
|
21
21
|
import { setupVercel } from "./setupVercel.js";
|
|
22
|
+
import { hasArcnetConfig, readArcnetConfig } from "./arcnetConfig.js";
|
|
23
|
+
import { setupArcnet } from "./setupArcnet.js";
|
|
22
24
|
|
|
23
25
|
const home = packageRoot;
|
|
24
26
|
|
|
@@ -28,6 +30,23 @@ const json = (value: unknown) => JSON.stringify(value, null, 2) + "\n";
|
|
|
28
30
|
export const setup = (args: string[], root = process.cwd()) => {
|
|
29
31
|
const { slug, options, dry } = parseSetupInput(args);
|
|
30
32
|
root = realpathSync(root);
|
|
33
|
+
|
|
34
|
+
if (hasArcnetConfig(root)) {
|
|
35
|
+
if (
|
|
36
|
+
Object.entries(options).some(
|
|
37
|
+
([key, value]) => key.startsWith("seen-") && value,
|
|
38
|
+
) ||
|
|
39
|
+
options.services ||
|
|
40
|
+
options.vercel
|
|
41
|
+
)
|
|
42
|
+
fail(
|
|
43
|
+
"arcnet.yaml owns service selection; do not pass legacy setup flags.",
|
|
44
|
+
);
|
|
45
|
+
const config = readArcnetConfig(root);
|
|
46
|
+
if (config.project !== slug) fail("Slug must match arcnet.yaml project.");
|
|
47
|
+
return setupArcnet(root, dry);
|
|
48
|
+
}
|
|
49
|
+
|
|
31
50
|
const safe = (name: string) => safeTargetPath(root, name);
|
|
32
51
|
|
|
33
52
|
if (!options.services) {
|