@caelo-cms/provisioning 0.12.3 → 0.12.5-rc.1
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/dist/agent-db.js +9 -3
- package/dist/cli-routing.d.ts.map +1 -1
- package/dist/cli-routing.js +6 -5
- package/dist/cli-routing.js.map +1 -1
- package/dist/cli.js +18 -1
- package/dist/cli.js.map +1 -1
- package/dist/gcp-names.d.ts +51 -0
- package/dist/gcp-names.d.ts.map +1 -1
- package/dist/gcp-names.js +75 -0
- package/dist/gcp-names.js.map +1 -1
- package/dist/infra-contract.d.ts +1 -1
- package/dist/infra-contract.d.ts.map +1 -1
- package/dist/infra-contract.js +42 -1
- package/dist/infra-contract.js.map +1 -1
- package/dist/install-state.d.ts +8 -0
- package/dist/install-state.d.ts.map +1 -1
- package/dist/install-state.js +12 -0
- package/dist/install-state.js.map +1 -1
- package/dist/install-version.d.ts +110 -0
- package/dist/install-version.d.ts.map +1 -0
- package/dist/install-version.js +162 -0
- package/dist/install-version.js.map +1 -0
- package/dist/lifecycle.d.ts +6 -1
- package/dist/lifecycle.d.ts.map +1 -1
- package/dist/lifecycle.js +46 -1
- package/dist/lifecycle.js.map +1 -1
- package/dist/release-candidate.d.ts +67 -0
- package/dist/release-candidate.d.ts.map +1 -0
- package/dist/release-candidate.js +138 -0
- package/dist/release-candidate.js.map +1 -0
- package/dist/reporting-job-setup.d.ts +102 -0
- package/dist/reporting-job-setup.d.ts.map +1 -0
- package/dist/reporting-job-setup.js +347 -0
- package/dist/reporting-job-setup.js.map +1 -0
- package/dist/self-hosted-upgrade.d.ts.map +1 -1
- package/dist/self-hosted-upgrade.js +18 -3
- package/dist/self-hosted-upgrade.js.map +1 -1
- package/dist/stack-contract.d.ts +30 -5
- package/dist/stack-contract.d.ts.map +1 -1
- package/dist/stack-contract.js +74 -10
- package/dist/stack-contract.js.map +1 -1
- package/dist/upgrade/admin-image-jobs.d.ts +13 -5
- package/dist/upgrade/admin-image-jobs.d.ts.map +1 -1
- package/dist/upgrade/admin-image-jobs.js +22 -2
- package/dist/upgrade/admin-image-jobs.js.map +1 -1
- package/dist/upgrade/converge.d.ts.map +1 -1
- package/dist/upgrade/converge.js +99 -9
- package/dist/upgrade/converge.js.map +1 -1
- package/dist/upgrade/release-images.d.ts +6 -2
- package/dist/upgrade/release-images.d.ts.map +1 -1
- package/dist/upgrade/release-images.js +5 -5
- package/dist/upgrade/release-images.js.map +1 -1
- package/dist/upgrader-iam-preflight.d.ts.map +1 -1
- package/dist/upgrader-iam-preflight.js +19 -1
- package/dist/upgrader-iam-preflight.js.map +1 -1
- package/dist/upgrader-setup.d.ts.map +1 -1
- package/dist/upgrader-setup.js +16 -1
- package/dist/upgrader-setup.js.map +1 -1
- package/dist/wizard.d.ts +7 -0
- package/dist/wizard.d.ts.map +1 -1
- package/dist/wizard.js +20 -5
- package/dist/wizard.js.map +1 -1
- package/dist/wizards/gcp-cost.d.ts +7 -11
- package/dist/wizards/gcp-cost.d.ts.map +1 -1
- package/dist/wizards/gcp-cost.js +47 -36
- package/dist/wizards/gcp-cost.js.map +1 -1
- package/dist/wizards/gcp-firebase.d.ts +4 -0
- package/dist/wizards/gcp-firebase.d.ts.map +1 -1
- package/dist/wizards/gcp-firebase.js +2 -0
- package/dist/wizards/gcp-firebase.js.map +1 -1
- package/dist/wizards/gcp-install-job.d.ts +10 -0
- package/dist/wizards/gcp-install-job.d.ts.map +1 -1
- package/dist/wizards/gcp-install-job.js +41 -10
- package/dist/wizards/gcp-install-job.js.map +1 -1
- package/dist/wizards/gcp.d.ts +7 -0
- package/dist/wizards/gcp.d.ts.map +1 -1
- package/dist/wizards/gcp.js +191 -9
- package/dist/wizards/gcp.js.map +1 -1
- package/package.json +2 -2
- package/src/cli-routing.test.ts +1 -1
- package/src/cli-routing.ts +6 -5
- package/src/cli.ts +18 -1
- package/src/cpu-idle.test.ts +7 -2
- package/src/gcp-names.ts +87 -0
- package/src/infra-contract.test.ts +6 -3
- package/src/infra-contract.ts +42 -1
- package/src/install-state.ts +12 -0
- package/src/install-version.test.ts +366 -0
- package/src/install-version.ts +205 -0
- package/src/lifecycle.ts +65 -3
- package/src/release-candidate.test.ts +191 -0
- package/src/release-candidate.ts +172 -0
- package/src/reporting-job-setup.test.ts +392 -0
- package/src/reporting-job-setup.ts +431 -0
- package/src/self-hosted-upgrade.ts +18 -3
- package/src/stack-contract.test.ts +24 -0
- package/src/stack-contract.ts +87 -9
- package/src/stack-converge-secrets.test.ts +2 -0
- package/src/stack-converge.test.ts +3 -3
- package/src/upgrade/admin-image-jobs.ts +35 -6
- package/src/upgrade/converge.ts +137 -8
- package/src/upgrade/release-images.test.ts +2 -2
- package/src/upgrade/release-images.ts +6 -4
- package/src/upgrade/upgrade.test.ts +165 -4
- package/src/upgrader-iam-preflight.test.ts +58 -0
- package/src/upgrader-iam-preflight.ts +21 -0
- package/src/upgrader-job.test.ts +3 -0
- package/src/upgrader-setup.test.ts +6 -0
- package/src/upgrader-setup.ts +18 -0
- package/src/wizard.ts +30 -5
- package/src/wizards/gcp-cost.test.ts +11 -13
- package/src/wizards/gcp-cost.ts +49 -36
- package/src/wizards/gcp-firebase.ts +6 -0
- package/src/wizards/gcp-install-job.ts +46 -12
- package/src/wizards/gcp.ts +250 -7
- package/stacks/aws/index.ts +10 -0
- package/stacks/azure/index.ts +10 -0
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* #1359 — a reporting job's setup (reporting-job-setup.ts) against a fake
|
|
5
|
+
* gcloud. The load-bearing assertions are the trust boundary: the
|
|
6
|
+
* quality-audit runner's service account may sign its own IAP credential,
|
|
7
|
+
* pass the admin's IAP, write logs, read the staged build and the
|
|
8
|
+
* Lighthouse results, and start the Lighthouse job — no secret, no
|
|
9
|
+
* database, no other IAM or run right, no VPC — and the admin may run the
|
|
10
|
+
* runner with overrides and read its executions, nothing else.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { describe, expect, it } from "bun:test";
|
|
14
|
+
import { existsSync } from "node:fs";
|
|
15
|
+
import { join } from "node:path";
|
|
16
|
+
import type { GcloudResult } from "./gcloud.js";
|
|
17
|
+
import {
|
|
18
|
+
auditRunnerJobSpec,
|
|
19
|
+
buildCarrierJobSpec,
|
|
20
|
+
ensureAuditRunnerJob,
|
|
21
|
+
ensureBuildCarrierJob,
|
|
22
|
+
ensureImportCrawlJob,
|
|
23
|
+
importCrawlJobSpec,
|
|
24
|
+
REPORTING_JOB_FORBIDDEN_ROLES,
|
|
25
|
+
REPORTING_JOB_SCRIPT,
|
|
26
|
+
type ReportingJobTarget,
|
|
27
|
+
} from "./reporting-job-setup.js";
|
|
28
|
+
|
|
29
|
+
const ok = (stdout = ""): GcloudResult => ({ ok: true, stdout, stderr: "", exitCode: 0 });
|
|
30
|
+
const fail = (stderr: string): GcloudResult => ({ ok: false, stdout: "", stderr, exitCode: 1 });
|
|
31
|
+
|
|
32
|
+
const RUNNER_SA = "caelo-production-audit-run@acme.iam.gserviceaccount.com";
|
|
33
|
+
const RUNNER = `serviceAccount:${RUNNER_SA}`;
|
|
34
|
+
const ADMIN_SA = "serviceAccount:caelo-production-run-sa@acme.iam.gserviceaccount.com";
|
|
35
|
+
const ADMIN_IMAGE = `europe-west1-docker.pkg.dev/caelo-website/caelo-cms-images/admin@sha256:${"a".repeat(64)}`;
|
|
36
|
+
|
|
37
|
+
const TARGET: ReportingJobTarget = {
|
|
38
|
+
provider: "gcp",
|
|
39
|
+
projectId: "acme",
|
|
40
|
+
region: "europe-west1",
|
|
41
|
+
env: "production",
|
|
42
|
+
adminImageRef: ADMIN_IMAGE,
|
|
43
|
+
resource: { kind: "backend-services", service: "caelo-production-admin-backend-1a2b" },
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
function fakeGcloud(overrides: [RegExp, GcloudResult][] = []) {
|
|
47
|
+
const calls: string[][] = [];
|
|
48
|
+
const rules: [RegExp, GcloudResult][] = [
|
|
49
|
+
...overrides,
|
|
50
|
+
[/^iam service-accounts describe/, fail("NOT_FOUND")],
|
|
51
|
+
];
|
|
52
|
+
const run = async (args: string[]) => {
|
|
53
|
+
calls.push(args);
|
|
54
|
+
const line = args.join(" ");
|
|
55
|
+
return rules.find(([re]) => re.test(line))?.[1] ?? ok("");
|
|
56
|
+
};
|
|
57
|
+
return { run, calls };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const flag = (args: string[], name: string) =>
|
|
61
|
+
args.find((a) => a.startsWith(`--${name}=`))?.slice(name.length + 3);
|
|
62
|
+
|
|
63
|
+
/** Every IAM grant the setup made, as {where, member, role}. */
|
|
64
|
+
function grants(calls: string[][]) {
|
|
65
|
+
return calls
|
|
66
|
+
.filter((c) => c.includes("add-iam-policy-binding"))
|
|
67
|
+
.map((c) => ({
|
|
68
|
+
where: c.slice(0, c.indexOf("add-iam-policy-binding") + 2).join(" "),
|
|
69
|
+
member: flag(c, "member"),
|
|
70
|
+
role: flag(c, "role") as string,
|
|
71
|
+
}));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const deployOf = (calls: string[][]) =>
|
|
75
|
+
calls.find((c) => c[0] === "run" && c[1] === "jobs" && c[2] === "deploy") as string[];
|
|
76
|
+
|
|
77
|
+
describe("ensureAuditRunnerJob (#1359)", () => {
|
|
78
|
+
it("creates the runner's own account and grants it exactly its line", async () => {
|
|
79
|
+
const { run, calls } = fakeGcloud();
|
|
80
|
+
const r = await ensureAuditRunnerJob(TARGET, { run, sleep: async () => {} });
|
|
81
|
+
expect(r.ok).toBe(true);
|
|
82
|
+
expect(
|
|
83
|
+
calls.some((c) =>
|
|
84
|
+
c.join(" ").startsWith("iam service-accounts create caelo-production-audit-run "),
|
|
85
|
+
),
|
|
86
|
+
).toBe(true);
|
|
87
|
+
const mine = grants(calls).filter((g) => g.member === RUNNER);
|
|
88
|
+
expect(mine.map((g) => [g.where, g.role])).toEqual([
|
|
89
|
+
// Signs its own IAP credential, nobody else's.
|
|
90
|
+
[
|
|
91
|
+
`iam service-accounts add-iam-policy-binding ${RUNNER_SA}`,
|
|
92
|
+
"roles/iam.serviceAccountTokenCreator",
|
|
93
|
+
],
|
|
94
|
+
["projects add-iam-policy-binding acme", "roles/logging.logWriter"],
|
|
95
|
+
[
|
|
96
|
+
"iap web add-iam-policy-binding --resource-type=backend-services",
|
|
97
|
+
"roles/iap.httpsResourceAccessor",
|
|
98
|
+
],
|
|
99
|
+
[
|
|
100
|
+
"storage buckets add-iam-policy-binding gs://acme-caelo-production-staging",
|
|
101
|
+
"roles/storage.objectViewer",
|
|
102
|
+
],
|
|
103
|
+
[
|
|
104
|
+
"storage buckets add-iam-policy-binding gs://acme-caelo-production-audit-results",
|
|
105
|
+
"roles/storage.objectViewer",
|
|
106
|
+
],
|
|
107
|
+
// Run rights only on the Lighthouse job it starts.
|
|
108
|
+
[
|
|
109
|
+
"run jobs add-iam-policy-binding caelo-production-audit",
|
|
110
|
+
"roles/run.jobsExecutorWithOverrides",
|
|
111
|
+
],
|
|
112
|
+
["run jobs add-iam-policy-binding caelo-production-audit", "roles/run.viewer"],
|
|
113
|
+
]);
|
|
114
|
+
for (const g of mine) {
|
|
115
|
+
for (const forbidden of REPORTING_JOB_FORBIDDEN_ROLES) {
|
|
116
|
+
expect(g.role.startsWith(forbidden)).toBe(false);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it("passes IAP on the admin's own resource, the Cloud Run service on gcp-firebase", async () => {
|
|
122
|
+
const { run, calls } = fakeGcloud();
|
|
123
|
+
await ensureAuditRunnerJob(
|
|
124
|
+
{
|
|
125
|
+
...TARGET,
|
|
126
|
+
provider: "gcp-firebase",
|
|
127
|
+
resource: {
|
|
128
|
+
kind: "cloud-run",
|
|
129
|
+
service: "caelo-production-admin-x",
|
|
130
|
+
region: "europe-west1",
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
{ run, sleep: async () => {} },
|
|
134
|
+
);
|
|
135
|
+
const iap = calls.find((c) => c.slice(0, 3).join(" ") === "iap web add-iam-policy-binding");
|
|
136
|
+
expect(iap).toContain("--resource-type=cloud-run");
|
|
137
|
+
expect(iap).toContain("--service=caelo-production-admin-x");
|
|
138
|
+
expect(iap).toContain("--region=europe-west1");
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it("gives the admin run-with-overrides and view on the runner, nothing else", async () => {
|
|
142
|
+
const { run, calls } = fakeGcloud();
|
|
143
|
+
await ensureAuditRunnerJob(TARGET, { run, sleep: async () => {} });
|
|
144
|
+
expect(
|
|
145
|
+
grants(calls)
|
|
146
|
+
.filter((g) => g.member === ADMIN_SA)
|
|
147
|
+
.map((g) => [g.where, g.role]),
|
|
148
|
+
).toEqual([
|
|
149
|
+
[
|
|
150
|
+
"run jobs add-iam-policy-binding caelo-production-audit-run",
|
|
151
|
+
"roles/run.jobsExecutorWithOverrides",
|
|
152
|
+
],
|
|
153
|
+
["run jobs add-iam-policy-binding caelo-production-audit-run", "roles/run.viewer"],
|
|
154
|
+
]);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it("deploys the admin image as its own SA: no secret, no database, no VPC, no Cloud Run retry", async () => {
|
|
158
|
+
const { run, calls } = fakeGcloud();
|
|
159
|
+
await ensureAuditRunnerJob(TARGET, { run, sleep: async () => {} });
|
|
160
|
+
const deploy = deployOf(calls);
|
|
161
|
+
expect(deploy.slice(0, 4)).toEqual(["run", "jobs", "deploy", "caelo-production-audit-run"]);
|
|
162
|
+
expect(flag(deploy, "image")).toBe(ADMIN_IMAGE);
|
|
163
|
+
expect(flag(deploy, "service-account")).toBe(RUNNER_SA);
|
|
164
|
+
expect(flag(deploy, "command")).toBe("bun");
|
|
165
|
+
expect(flag(deploy, "args")).toBe(`--bun,${REPORTING_JOB_SCRIPT}`);
|
|
166
|
+
// A dead attempt is restarted by the tick's backstop with a new token.
|
|
167
|
+
expect(flag(deploy, "max-retries")).toBe("0");
|
|
168
|
+
expect(flag(deploy, "task-timeout")).toBe("3600s");
|
|
169
|
+
const env = flag(deploy, "set-env-vars") ?? "";
|
|
170
|
+
expect(env.split(",").sort()).toEqual(
|
|
171
|
+
[
|
|
172
|
+
"CAELO_PROVIDER=gcp",
|
|
173
|
+
"CAELO_STAGING_BUCKET=acme-caelo-production-staging",
|
|
174
|
+
"CAELO_AUDIT_JOB=projects/acme/locations/europe-west1/jobs/caelo-production-audit",
|
|
175
|
+
"CAELO_AUDIT_RESULTS_BUCKET=acme-caelo-production-audit-results",
|
|
176
|
+
].sort(),
|
|
177
|
+
);
|
|
178
|
+
expect(env).not.toMatch(/DATABASE|PASSWORD|SECRET|KEK/);
|
|
179
|
+
for (const a of deploy) {
|
|
180
|
+
expect(a).not.toMatch(/^--(set|update)-secrets|^--(vpc-connector|network|subnet|vpc-egress)/);
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it("points the job at an entry point the admin image ships", () => {
|
|
185
|
+
// The image copies the repo's packages/ to /app/packages (apps/admin/Dockerfile).
|
|
186
|
+
const repoRoot = join(import.meta.dir, "..", "..", "..");
|
|
187
|
+
expect(REPORTING_JOB_SCRIPT.startsWith("/app/packages/")).toBe(true);
|
|
188
|
+
expect(existsSync(join(repoRoot, REPORTING_JOB_SCRIPT.slice("/app/".length)))).toBe(true);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it("refuses an image not pinned by digest, before any change", async () => {
|
|
192
|
+
const { run, calls } = fakeGcloud();
|
|
193
|
+
const r = await ensureAuditRunnerJob(
|
|
194
|
+
{ ...TARGET, adminImageRef: "ghcr.io/caelo-cms/admin:latest" },
|
|
195
|
+
{ run, sleep: async () => {} },
|
|
196
|
+
);
|
|
197
|
+
expect(r.ok).toBe(false);
|
|
198
|
+
expect(calls).toEqual([]);
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
it("stops at the first failed grant and says which", async () => {
|
|
202
|
+
const { run, calls } = fakeGcloud([
|
|
203
|
+
[
|
|
204
|
+
/^iap web add-iam-policy-binding/,
|
|
205
|
+
fail("PERMISSION_DENIED: iap.webServiceVersions.setIamPolicy"),
|
|
206
|
+
],
|
|
207
|
+
]);
|
|
208
|
+
const r = await ensureAuditRunnerJob(TARGET, { run, sleep: async () => {} });
|
|
209
|
+
expect(r.ok).toBe(false);
|
|
210
|
+
if (r.ok) return;
|
|
211
|
+
expect(r.error).toContain("pass the admin's IAP");
|
|
212
|
+
expect(deployOf(calls)).toBeUndefined();
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it("keeps an existing account (describe succeeds) and does not create it twice", async () => {
|
|
216
|
+
const { run, calls } = fakeGcloud([[/^iam service-accounts describe/, ok(`${RUNNER_SA}\n`)]]);
|
|
217
|
+
const r = await ensureAuditRunnerJob(TARGET, { run, sleep: async () => {} });
|
|
218
|
+
expect(r.ok).toBe(true);
|
|
219
|
+
expect(calls.some((c) => c.slice(0, 3).join(" ") === "iam service-accounts create")).toBe(
|
|
220
|
+
false,
|
|
221
|
+
);
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it("names the staging slot, the results and the Lighthouse job of the install it is for", () => {
|
|
225
|
+
const spec = auditRunnerJobSpec({ ...TARGET, provider: "gcp-firebase" });
|
|
226
|
+
expect(spec.env).toContain("CAELO_PROVIDER=gcp-firebase");
|
|
227
|
+
expect(spec.readBuckets.map((b) => b.bucket)).toEqual([
|
|
228
|
+
"acme-caelo-production-staging",
|
|
229
|
+
"acme-caelo-production-audit-results",
|
|
230
|
+
]);
|
|
231
|
+
expect(spec.runJobs.map((j) => j.job)).toEqual(["caelo-production-audit"]);
|
|
232
|
+
});
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
describe("ensureImportCrawlJob (#1360)", () => {
|
|
236
|
+
const CRAWLER_SA = "caelo-production-import@acme.iam.gserviceaccount.com";
|
|
237
|
+
const CRAWLER = `serviceAccount:${CRAWLER_SA}`;
|
|
238
|
+
|
|
239
|
+
it("grants the crawler the shared line and nothing else: no bucket, no other job", async () => {
|
|
240
|
+
const { run, calls } = fakeGcloud();
|
|
241
|
+
const r = await ensureImportCrawlJob(TARGET, { run, sleep: async () => {} });
|
|
242
|
+
expect(r.ok).toBe(true);
|
|
243
|
+
if (r.ok) expect(r.serviceAccount).toBe(CRAWLER_SA);
|
|
244
|
+
expect(
|
|
245
|
+
calls.some((c) =>
|
|
246
|
+
c.join(" ").startsWith("iam service-accounts create caelo-production-import "),
|
|
247
|
+
),
|
|
248
|
+
).toBe(true);
|
|
249
|
+
const mine = grants(calls).filter((g) => g.member === CRAWLER);
|
|
250
|
+
expect(mine.map((g) => [g.where, g.role])).toEqual([
|
|
251
|
+
// Signs its own IAP credential, nobody else's.
|
|
252
|
+
[
|
|
253
|
+
`iam service-accounts add-iam-policy-binding ${CRAWLER_SA}`,
|
|
254
|
+
"roles/iam.serviceAccountTokenCreator",
|
|
255
|
+
],
|
|
256
|
+
["projects add-iam-policy-binding acme", "roles/logging.logWriter"],
|
|
257
|
+
[
|
|
258
|
+
"iap web add-iam-policy-binding --resource-type=backend-services",
|
|
259
|
+
"roles/iap.httpsResourceAccessor",
|
|
260
|
+
],
|
|
261
|
+
]);
|
|
262
|
+
for (const g of mine) {
|
|
263
|
+
for (const forbidden of REPORTING_JOB_FORBIDDEN_ROLES) {
|
|
264
|
+
expect(g.role.startsWith(forbidden)).toBe(false);
|
|
265
|
+
}
|
|
266
|
+
// It reads third-party pages: no run right anywhere, no storage at all.
|
|
267
|
+
expect(g.role.startsWith("roles/run.")).toBe(false);
|
|
268
|
+
expect(g.role.startsWith("roles/storage.")).toBe(false);
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
it("gives the admin run-with-overrides and view on the crawler, nothing else", async () => {
|
|
273
|
+
const { run, calls } = fakeGcloud();
|
|
274
|
+
await ensureImportCrawlJob(TARGET, { run, sleep: async () => {} });
|
|
275
|
+
expect(
|
|
276
|
+
grants(calls)
|
|
277
|
+
.filter((g) => g.member === ADMIN_SA)
|
|
278
|
+
.map((g) => [g.where, g.role]),
|
|
279
|
+
).toEqual([
|
|
280
|
+
[
|
|
281
|
+
"run jobs add-iam-policy-binding caelo-production-import",
|
|
282
|
+
"roles/run.jobsExecutorWithOverrides",
|
|
283
|
+
],
|
|
284
|
+
["run jobs add-iam-policy-binding caelo-production-import", "roles/run.viewer"],
|
|
285
|
+
]);
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
it("deploys the admin image as its own SA: no secret, no database, no VPC, no bucket, no Cloud Run retry", async () => {
|
|
289
|
+
const { run, calls } = fakeGcloud();
|
|
290
|
+
await ensureImportCrawlJob(TARGET, { run, sleep: async () => {} });
|
|
291
|
+
const deploy = deployOf(calls);
|
|
292
|
+
expect(deploy.slice(0, 4)).toEqual(["run", "jobs", "deploy", "caelo-production-import"]);
|
|
293
|
+
expect(flag(deploy, "image")).toBe(ADMIN_IMAGE);
|
|
294
|
+
expect(flag(deploy, "service-account")).toBe(CRAWLER_SA);
|
|
295
|
+
expect(flag(deploy, "args")).toBe(`--bun,${REPORTING_JOB_SCRIPT}`);
|
|
296
|
+
expect(flag(deploy, "max-retries")).toBe("0");
|
|
297
|
+
// admin-core JOB_TIMING.site_import.maxRunSeconds.
|
|
298
|
+
expect(flag(deploy, "task-timeout")).toBe("21600s");
|
|
299
|
+
expect(flag(deploy, "set-env-vars")).toBe("CAELO_PROVIDER=gcp");
|
|
300
|
+
for (const a of deploy) {
|
|
301
|
+
expect(a).not.toMatch(/^--(set|update)-secrets|^--(vpc-connector|network|subnet|vpc-egress)/);
|
|
302
|
+
}
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
it("asks for no bucket and no job of its own", () => {
|
|
306
|
+
const spec = importCrawlJobSpec({ provider: "gcp-firebase", env: "production" });
|
|
307
|
+
expect(spec.env).toEqual(["CAELO_PROVIDER=gcp-firebase"]);
|
|
308
|
+
expect(spec.readBuckets).toEqual([]);
|
|
309
|
+
expect(spec.runJobs).toEqual([]);
|
|
310
|
+
});
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
describe("ensureBuildCarrierJob (#1574)", () => {
|
|
314
|
+
const CARRIER_SA = "caelo-production-build@acme.iam.gserviceaccount.com";
|
|
315
|
+
const CARRIER = `serviceAccount:${CARRIER_SA}`;
|
|
316
|
+
|
|
317
|
+
it("grants the carrier exactly token creator on itself, IAP access and log writing", async () => {
|
|
318
|
+
const { run, calls } = fakeGcloud();
|
|
319
|
+
const r = await ensureBuildCarrierJob(TARGET, { run, sleep: async () => {} });
|
|
320
|
+
expect(r.ok).toBe(true);
|
|
321
|
+
if (r.ok) expect(r.serviceAccount).toBe(CARRIER_SA);
|
|
322
|
+
expect(
|
|
323
|
+
calls.some((c) =>
|
|
324
|
+
c.join(" ").startsWith("iam service-accounts create caelo-production-build "),
|
|
325
|
+
),
|
|
326
|
+
).toBe(true);
|
|
327
|
+
const mine = grants(calls).filter((g) => g.member === CARRIER);
|
|
328
|
+
expect(mine.map((g) => [g.where, g.role])).toEqual([
|
|
329
|
+
// Signs its own IAP credential, nobody else's.
|
|
330
|
+
[
|
|
331
|
+
`iam service-accounts add-iam-policy-binding ${CARRIER_SA}`,
|
|
332
|
+
"roles/iam.serviceAccountTokenCreator",
|
|
333
|
+
],
|
|
334
|
+
["projects add-iam-policy-binding acme", "roles/logging.logWriter"],
|
|
335
|
+
[
|
|
336
|
+
"iap web add-iam-policy-binding --resource-type=backend-services",
|
|
337
|
+
"roles/iap.httpsResourceAccessor",
|
|
338
|
+
],
|
|
339
|
+
]);
|
|
340
|
+
for (const g of mine) {
|
|
341
|
+
for (const forbidden of REPORTING_JOB_FORBIDDEN_ROLES) {
|
|
342
|
+
expect(g.role.startsWith(forbidden)).toBe(false);
|
|
343
|
+
}
|
|
344
|
+
// The build stays the admin's: no run right, no bucket, no secret, no database.
|
|
345
|
+
expect(g.role.startsWith("roles/run.")).toBe(false);
|
|
346
|
+
expect(g.role.startsWith("roles/storage.")).toBe(false);
|
|
347
|
+
expect(g.role.startsWith("roles/secretmanager.")).toBe(false);
|
|
348
|
+
expect(g.role.startsWith("roles/cloudsql.")).toBe(false);
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
it("gives the admin run-with-overrides and view on the carrier, nothing else", async () => {
|
|
353
|
+
const { run, calls } = fakeGcloud();
|
|
354
|
+
await ensureBuildCarrierJob(TARGET, { run, sleep: async () => {} });
|
|
355
|
+
expect(
|
|
356
|
+
grants(calls)
|
|
357
|
+
.filter((g) => g.member === ADMIN_SA)
|
|
358
|
+
.map((g) => [g.where, g.role]),
|
|
359
|
+
).toEqual([
|
|
360
|
+
[
|
|
361
|
+
"run jobs add-iam-policy-binding caelo-production-build",
|
|
362
|
+
"roles/run.jobsExecutorWithOverrides",
|
|
363
|
+
],
|
|
364
|
+
["run jobs add-iam-policy-binding caelo-production-build", "roles/run.viewer"],
|
|
365
|
+
]);
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
it("deploys the admin image as its own SA on the smallest machine, outliving the admin's request limit", async () => {
|
|
369
|
+
const { run, calls } = fakeGcloud();
|
|
370
|
+
await ensureBuildCarrierJob(TARGET, { run, sleep: async () => {} });
|
|
371
|
+
const deploy = deployOf(calls);
|
|
372
|
+
expect(deploy.slice(0, 4)).toEqual(["run", "jobs", "deploy", "caelo-production-build"]);
|
|
373
|
+
expect(flag(deploy, "image")).toBe(ADMIN_IMAGE);
|
|
374
|
+
expect(flag(deploy, "service-account")).toBe(CARRIER_SA);
|
|
375
|
+
expect(flag(deploy, "args")).toBe(`--bun,${REPORTING_JOB_SCRIPT}`);
|
|
376
|
+
expect(flag(deploy, "max-retries")).toBe("0");
|
|
377
|
+
// admin-core JOB_TIMING.build.maxRunSeconds: the request limit plus room.
|
|
378
|
+
expect(flag(deploy, "task-timeout")).toBe("3900s");
|
|
379
|
+
expect(flag(deploy, "memory")).toBe("512Mi");
|
|
380
|
+
expect(flag(deploy, "set-env-vars")).toBe("CAELO_PROVIDER=gcp");
|
|
381
|
+
for (const a of deploy) {
|
|
382
|
+
expect(a).not.toMatch(/^--(set|update)-secrets|^--(vpc-connector|network|subnet|vpc-egress)/);
|
|
383
|
+
}
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
it("asks for no bucket and no job of its own", () => {
|
|
387
|
+
const spec = buildCarrierJobSpec({ provider: "gcp-firebase", env: "production" });
|
|
388
|
+
expect(spec.env).toEqual(["CAELO_PROVIDER=gcp-firebase"]);
|
|
389
|
+
expect(spec.readBuckets).toEqual([]);
|
|
390
|
+
expect(spec.runJobs).toEqual([]);
|
|
391
|
+
});
|
|
392
|
+
});
|