@caelo-cms/provisioning 0.11.21 → 0.12.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.
Files changed (135) hide show
  1. package/dist/adapter.d.ts +6 -1
  2. package/dist/adapter.d.ts.map +1 -1
  3. package/dist/agent-db.js +133 -8
  4. package/dist/bootstrap-token.d.ts +4 -3
  5. package/dist/bootstrap-token.d.ts.map +1 -1
  6. package/dist/bootstrap-token.js.map +1 -1
  7. package/dist/cli-routing.d.ts.map +1 -1
  8. package/dist/cli-routing.js +5 -0
  9. package/dist/cli-routing.js.map +1 -1
  10. package/dist/cli.js +4 -0
  11. package/dist/cli.js.map +1 -1
  12. package/dist/converge-job-gcp.d.ts +1 -16
  13. package/dist/converge-job-gcp.d.ts.map +1 -1
  14. package/dist/converge-job-gcp.js +10 -97
  15. package/dist/converge-job-gcp.js.map +1 -1
  16. package/dist/converge-job.d.ts +7 -46
  17. package/dist/converge-job.d.ts.map +1 -1
  18. package/dist/converge-job.js +22 -57
  19. package/dist/converge-job.js.map +1 -1
  20. package/dist/gateway-armor.d.ts.map +1 -1
  21. package/dist/gateway-armor.js +11 -3
  22. package/dist/gateway-armor.js.map +1 -1
  23. package/dist/gcp-names.d.ts +2 -0
  24. package/dist/gcp-names.d.ts.map +1 -1
  25. package/dist/gcp-names.js +4 -0
  26. package/dist/gcp-names.js.map +1 -1
  27. package/dist/index.d.ts +3 -2
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +1 -1
  30. package/dist/index.js.map +1 -1
  31. package/dist/infra-contract.d.ts +1 -1
  32. package/dist/infra-contract.d.ts.map +1 -1
  33. package/dist/infra-contract.js +14 -1
  34. package/dist/infra-contract.js.map +1 -1
  35. package/dist/job-handover-gcp.d.ts +40 -0
  36. package/dist/job-handover-gcp.d.ts.map +1 -0
  37. package/dist/job-handover-gcp.js +108 -0
  38. package/dist/job-handover-gcp.js.map +1 -0
  39. package/dist/job-handover.d.ts +141 -0
  40. package/dist/job-handover.d.ts.map +1 -0
  41. package/dist/job-handover.js +141 -0
  42. package/dist/job-handover.js.map +1 -0
  43. package/dist/owner-setup-token.d.ts +52 -0
  44. package/dist/owner-setup-token.d.ts.map +1 -0
  45. package/dist/owner-setup-token.js +111 -0
  46. package/dist/owner-setup-token.js.map +1 -0
  47. package/dist/project-status.d.ts +33 -0
  48. package/dist/project-status.d.ts.map +1 -1
  49. package/dist/project-status.js +116 -26
  50. package/dist/project-status.js.map +1 -1
  51. package/dist/stack-converge.d.ts.map +1 -1
  52. package/dist/stack-converge.js +9 -5
  53. package/dist/stack-converge.js.map +1 -1
  54. package/dist/static-security-headers.d.ts +6 -0
  55. package/dist/static-security-headers.d.ts.map +1 -1
  56. package/dist/static-security-headers.js +11 -1
  57. package/dist/static-security-headers.js.map +1 -1
  58. package/dist/upgrader-assess.d.ts +30 -3
  59. package/dist/upgrader-assess.d.ts.map +1 -1
  60. package/dist/upgrader-assess.js +77 -24
  61. package/dist/upgrader-assess.js.map +1 -1
  62. package/dist/upgrader-gcp.d.ts +4 -2
  63. package/dist/upgrader-gcp.d.ts.map +1 -1
  64. package/dist/upgrader-gcp.js +16 -3
  65. package/dist/upgrader-gcp.js.map +1 -1
  66. package/dist/upgrader-iam-preflight.d.ts +14 -3
  67. package/dist/upgrader-iam-preflight.d.ts.map +1 -1
  68. package/dist/upgrader-iam-preflight.js +40 -6
  69. package/dist/upgrader-iam-preflight.js.map +1 -1
  70. package/dist/upgrader-job.d.ts +51 -9
  71. package/dist/upgrader-job.d.ts.map +1 -1
  72. package/dist/upgrader-job.js +92 -37
  73. package/dist/upgrader-job.js.map +1 -1
  74. package/dist/upgrader-setup.d.ts +1 -1
  75. package/dist/upgrader-setup.d.ts.map +1 -1
  76. package/dist/upgrader-setup.js +5 -2
  77. package/dist/upgrader-setup.js.map +1 -1
  78. package/dist/wizards/gcp-install-job.d.ts.map +1 -1
  79. package/dist/wizards/gcp-install-job.js +11 -1
  80. package/dist/wizards/gcp-install-job.js.map +1 -1
  81. package/dist/wizards/gcp-pulumi.d.ts +0 -13
  82. package/dist/wizards/gcp-pulumi.d.ts.map +1 -1
  83. package/dist/wizards/gcp-pulumi.js +0 -12
  84. package/dist/wizards/gcp-pulumi.js.map +1 -1
  85. package/dist/wizards/gcp.d.ts.map +1 -1
  86. package/dist/wizards/gcp.js +21 -50
  87. package/dist/wizards/gcp.js.map +1 -1
  88. package/package.json +2 -2
  89. package/src/adapter.ts +6 -1
  90. package/src/bootstrap-token.ts +4 -3
  91. package/src/caddy-redirects.docker.test.ts +5 -0
  92. package/src/cli-routing.test.ts +1 -1
  93. package/src/cli-routing.ts +6 -0
  94. package/src/cli.ts +4 -0
  95. package/src/converge-job-gcp.test.ts +1 -40
  96. package/src/converge-job-gcp.ts +10 -100
  97. package/src/converge-job.test.ts +9 -3
  98. package/src/converge-job.ts +33 -115
  99. package/src/gateway-armor.ts +14 -3
  100. package/src/gateway-edge.test.ts +16 -1
  101. package/src/gcp-names.ts +4 -0
  102. package/src/gcp-url-map.test.ts +2 -0
  103. package/src/index.ts +3 -0
  104. package/src/infra-contract.test.ts +4 -3
  105. package/src/infra-contract.ts +14 -1
  106. package/src/job-handover-gcp.test.ts +129 -0
  107. package/src/job-handover-gcp.ts +135 -0
  108. package/src/job-handover.ts +259 -0
  109. package/src/owner-setup-token.test.ts +195 -0
  110. package/src/owner-setup-token.ts +138 -0
  111. package/src/project-status.test.ts +112 -3
  112. package/src/project-status.ts +141 -17
  113. package/src/stack-converge.ts +12 -5
  114. package/src/static-security-headers.test.ts +16 -0
  115. package/src/static-security-headers.ts +12 -1
  116. package/src/upgrader-assess.test.ts +75 -1
  117. package/src/upgrader-assess.ts +121 -57
  118. package/src/upgrader-gcp.ts +19 -5
  119. package/src/upgrader-iam-preflight.test.ts +28 -1
  120. package/src/upgrader-iam-preflight.ts +46 -6
  121. package/src/upgrader-job.test.ts +365 -31
  122. package/src/upgrader-job.ts +177 -53
  123. package/src/upgrader-setup.test.ts +17 -0
  124. package/src/upgrader-setup.ts +5 -2
  125. package/src/url-map-redirects-access.test.ts +1 -1
  126. package/src/wizards/gcp-install-job.ts +10 -1
  127. package/src/wizards/gcp-pulumi.ts +0 -18
  128. package/src/wizards/gcp.ts +24 -61
  129. package/stacks/aws/README.md +4 -2
  130. package/stacks/aws/index.ts +4 -8
  131. package/stacks/azure/README.md +4 -2
  132. package/stacks/azure/index.ts +4 -8
  133. package/stacks/gcp/README.md +6 -3
  134. package/stacks/gcp/index.ts +7 -8
  135. package/stacks/gcp-firebase/index.ts +4 -6
@@ -16,7 +16,7 @@
16
16
  import { mkdtempSync } from "node:fs";
17
17
  import { tmpdir } from "node:os";
18
18
  import { join } from "node:path";
19
- import { isIpLiteral } from "@caelo-cms/shared";
19
+ import { CAELO_VERSION, isIpLiteral } from "@caelo-cms/shared";
20
20
  import {
21
21
  ensureCloudSqlVerifyFull,
22
22
  liveDatabaseUrls,
@@ -25,8 +25,9 @@ import {
25
25
  import { findSqlInstance } from "./gateway-credentials.js";
26
26
  import { gcloud } from "./gcloud.js";
27
27
  import { type GcloudRunner, realSleep } from "./gcloud-retry.js";
28
- import { GCP_STACK_ENV } from "./gcp-names.js";
28
+ import { GCP_STACK_ENV, upgraderJobName } from "./gcp-names.js";
29
29
  import type { InstallMetadata } from "./install-state.js";
30
+ import { jobExecutionNameError, selfHandoverDeps } from "./job-handover-gcp.js";
30
31
  import { readAdminConfig, runMigrationsViaCloudRunJob } from "./migration-runner.js";
31
32
  import { fetchVerifiedReleaseManifest } from "./release-manifest.js";
32
33
  import type { HttpFetch } from "./runtime-secrets.js";
@@ -44,7 +45,7 @@ import { createIapHealthProbe } from "./upgrade/health.js";
44
45
  import { createReleaseImageForms } from "./upgrade/image-forms.js";
45
46
  import { httpsLoadBalancerGet } from "./upgrade/load-balancer-get.js";
46
47
  import { type IamTester, restIamTester } from "./upgrader-iam-preflight.js";
47
- import type { UpdateQueue, UpgraderJobDeps } from "./upgrader-job.js";
48
+ import type { UpgraderJobDeps, UpgraderQueue } from "./upgrader-job.js";
48
49
  import type { JobLog } from "./upgrader-reporter.js";
49
50
  import { UPGRADER_TASK_TIMEOUT_MINUTES } from "./upgrader-setup.js";
50
51
 
@@ -55,6 +56,11 @@ export interface UpgraderPlacement {
55
56
  readonly execution: string | null;
56
57
  }
57
58
 
59
+ /** Why `CLOUD_RUN_EXECUTION` cannot name a run of the upgrader job, or null when it can. */
60
+ export function upgraderExecutionNameError(execution: string | null): string | null {
61
+ return jobExecutionNameError(upgraderJobName(GCP_STACK_ENV), execution);
62
+ }
63
+
58
64
  /**
59
65
  * The Cloud SQL private IP the admin connects to — the job connects there
60
66
  * too (as its own IAM database user). Read from the deployed admin service.
@@ -182,7 +188,7 @@ export function gcloudIamTester(run: GcloudRunner, http: HttpFetch): IamTester {
182
188
  /** Every dependency of {@link runUpgraderJob} except the database and the log. */
183
189
  export function gcpUpgraderDeps(
184
190
  placement: UpgraderPlacement,
185
- queue: UpdateQueue,
191
+ queue: UpgraderQueue,
186
192
  log: JobLog,
187
193
  ): UpgraderJobDeps {
188
194
  const run: GcloudRunner = gcloud;
@@ -199,7 +205,15 @@ export function gcpUpgraderDeps(
199
205
  projectId: placement.projectId,
200
206
  region: placement.region,
201
207
  env: GCP_STACK_ENV,
202
- execution: placement.execution,
208
+ // #1029 — stage 1 moves this job onto the target's image, with the
209
+ // rights on itself it has always had for that (upgrader-setup.ts).
210
+ ...selfHandoverDeps(run, {
211
+ job: upgraderJobName(GCP_STACK_ENV),
212
+ projectId: placement.projectId,
213
+ region: placement.region,
214
+ execution: placement.execution,
215
+ }),
216
+ ownVersion: CAELO_VERSION,
203
217
  // #818 — the IAM self-check asks as the job's own account (gcloud's
204
218
  // token from the metadata server), so it sees exactly the job's grants.
205
219
  iam: gcloudIamTester(run, http),
@@ -21,6 +21,7 @@ import {
21
21
  testIamCall,
22
22
  UPGRADER_PREFLIGHT_VOICE,
23
23
  upgraderAccessChecks,
24
+ upgraderHandoverChecks,
24
25
  } from "./upgrader-iam-preflight.js";
25
26
  import {
26
27
  UPGRADER_FORBIDDEN_ROLES,
@@ -117,6 +118,32 @@ function tester(grants: Map<string, Set<string>>, asked: string[] = []): IamTest
117
118
  };
118
119
  }
119
120
 
121
+ describe("upgraderHandoverChecks (#1029)", () => {
122
+ const all = upgraderHandoverChecks(TARGET);
123
+
124
+ it("needs nothing setup does not already grant: the hand-over widens no right", async () => {
125
+ expect((await runIamPreflight(all, tester(setupGrants()))).kind).toBe("ok");
126
+ for (const p of all.flatMap((c) => c.permissions)) {
127
+ if (p === "iam.serviceAccounts.actAs") continue;
128
+ expect(UPGRADER_RUN_ROLE.permissions).toContain(p);
129
+ }
130
+ });
131
+
132
+ it("asks about the job's own job and own account, and is part of the full list", () => {
133
+ expect(all.map((c) => resourceName(c.resource))).toEqual([
134
+ "projects/acme/locations/europe-west1/jobs/caelo-production-upgrader",
135
+ "projects/acme",
136
+ "projects/acme/serviceAccounts/caelo-production-upgrader@acme.iam.gserviceaccount.com",
137
+ ]);
138
+ const full = new Set(upgraderAccessChecks(TARGET).flatMap((c) => c.permissions));
139
+ for (const p of all.flatMap((c) => c.permissions)) expect(full.has(p)).toBe(true);
140
+ });
141
+
142
+ it("never asks for overrides: an execution of the job runs what setup deployed", () => {
143
+ expect(all.flatMap((c) => c.permissions)).not.toContain("run.jobs.runWithOverrides");
144
+ });
145
+ });
146
+
120
147
  describe("upgraderAccessChecks", () => {
121
148
  it("asks only for what upgrader-setup.ts grants: a fresh setup passes the self-check", async () => {
122
149
  const r = await runIamPreflight(upgraderAccessChecks(TARGET), tester(setupGrants()));
@@ -190,7 +217,7 @@ describe("upgraderAccessChecks", () => {
190
217
  "run.jobs.create", // the migration job
191
218
  "run.jobs.run",
192
219
  "run.executions.get", // execute --wait, the lock lease
193
- "run.jobs.update", // the self-update
220
+ "run.jobs.update", // the hand-over, the audit and capture jobs
194
221
  "cloudsql.backupRuns.create", // the backup
195
222
  "iam.serviceAccounts.actAs",
196
223
  "iam.serviceAccounts.signJwt", // the IAP health check
@@ -123,12 +123,52 @@ export type PreflightOutcome<C extends AccessCheck = AccessCheck> =
123
123
  /** The object the `install/` probes name. It is never written: every probe fails its precondition. */
124
124
  export const PREFLIGHT_PROBE_OBJECT = ".caelo-iam-preflight";
125
125
 
126
+ const UPGRADER_MOVE_NEED = "move the upgrader itself onto the release it installs";
127
+ const UPGRADER_MOVE_PERMISSIONS = ["run.jobs.get", "run.jobs.update"];
128
+
129
+ /**
130
+ * What stage 1 of an upgrader run needs (#1029): the upgrader job's own
131
+ * rights on itself. The rest of {@link upgraderAccessChecks} is the target
132
+ * release's list, asked in its own code. The state lock's bucket grants
133
+ * are not here: a lock that cannot be taken stops the hand-over anyway.
134
+ */
135
+ export function upgraderHandoverChecks(target: {
136
+ readonly projectId: string;
137
+ readonly region: string;
138
+ readonly env: string;
139
+ }): AccessCheck[] {
140
+ const { projectId, region, env } = target;
141
+ return [
142
+ {
143
+ need: UPGRADER_MOVE_NEED,
144
+ resource: { kind: "run-job", projectId, region, name: upgraderJobName(env) },
145
+ permissions: UPGRADER_MOVE_PERMISSIONS,
146
+ },
147
+ {
148
+ // On the project, like the app-roll's own check of these two: that is
149
+ // where caeloUpgraderRun is bound.
150
+ need: "start the upgrader on that release, and see which image a run executes and whether it ended",
151
+ resource: { kind: "project", projectId },
152
+ permissions: ["run.jobs.run", "run.executions.get"],
153
+ },
154
+ {
155
+ need: "keep the upgrader job running as its own service account after it moves onto a release",
156
+ resource: {
157
+ kind: "service-account",
158
+ projectId,
159
+ email: upgraderServiceAccountEmail(projectId, env),
160
+ },
161
+ permissions: ["iam.serviceAccounts.actAs"],
162
+ },
163
+ ];
164
+ }
165
+
126
166
  /**
127
167
  * Every permission an upgrader run needs after its decision, grouped by
128
168
  * what it is for (upgrade/app-roll.ts, migration-runner.ts, backup.ts,
129
- * health.ts, state-store.ts, the self-update in upgrader-job.ts). Keep in
130
- * step with the grants in upgrader-setup.ts: a permission listed here that
131
- * setup does not grant stops every update.
169
+ * health.ts, state-store.ts). Keep in step with the grants in
170
+ * upgrader-setup.ts: a permission listed here that setup does not grant
171
+ * stops every update.
132
172
  */
133
173
  export function upgraderAccessChecks(target: {
134
174
  readonly projectId: string;
@@ -212,7 +252,7 @@ export function upgraderAccessChecks(target: {
212
252
  permissions: ["iam.serviceAccounts.actAs"],
213
253
  },
214
254
  {
215
- need: "keep the upgrader job running as its own service account after it updates itself",
255
+ need: "keep the upgrader job running as its own service account after it moves onto a release",
216
256
  resource: sa(upgraderServiceAccountEmail(projectId, env)),
217
257
  permissions: ["iam.serviceAccounts.actAs"],
218
258
  },
@@ -222,9 +262,9 @@ export function upgraderAccessChecks(target: {
222
262
  permissions: ["iam.serviceAccounts.signJwt"],
223
263
  },
224
264
  {
225
- need: "move the upgrader itself onto the new release",
265
+ need: UPGRADER_MOVE_NEED,
226
266
  resource: { kind: "run-job", projectId, region, name: upgraderJobName(env) },
227
- permissions: ["run.jobs.get", "run.jobs.update"],
267
+ permissions: UPGRADER_MOVE_PERMISSIONS,
228
268
  },
229
269
  {
230
270
  need: "list the install's ops bucket (every write there lists it first)",