@caelo-cms/provisioning 0.11.20 → 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 (170) hide show
  1. package/dist/adapter.d.ts +6 -1
  2. package/dist/adapter.d.ts.map +1 -1
  3. package/dist/admin-internal-google.d.ts +13 -1
  4. package/dist/admin-internal-google.d.ts.map +1 -1
  5. package/dist/admin-internal-google.js +47 -0
  6. package/dist/admin-internal-google.js.map +1 -1
  7. package/dist/agent/command.d.ts +1 -1
  8. package/dist/agent-db.js +133 -8
  9. package/dist/bootstrap-token.d.ts +4 -3
  10. package/dist/bootstrap-token.d.ts.map +1 -1
  11. package/dist/bootstrap-token.js.map +1 -1
  12. package/dist/cli-routing.d.ts.map +1 -1
  13. package/dist/cli-routing.js +7 -2
  14. package/dist/cli-routing.js.map +1 -1
  15. package/dist/cli.js +9 -0
  16. package/dist/cli.js.map +1 -1
  17. package/dist/converge-checkpoint.d.ts +6 -0
  18. package/dist/converge-checkpoint.d.ts.map +1 -1
  19. package/dist/converge-job-gcp.d.ts +1 -16
  20. package/dist/converge-job-gcp.d.ts.map +1 -1
  21. package/dist/converge-job-gcp.js +10 -97
  22. package/dist/converge-job-gcp.js.map +1 -1
  23. package/dist/converge-job.d.ts +7 -46
  24. package/dist/converge-job.d.ts.map +1 -1
  25. package/dist/converge-job.js +22 -57
  26. package/dist/converge-job.js.map +1 -1
  27. package/dist/dns/manual.d.ts +5 -1
  28. package/dist/dns/manual.d.ts.map +1 -1
  29. package/dist/dns/manual.js +2 -1
  30. package/dist/dns/manual.js.map +1 -1
  31. package/dist/gateway-armor.d.ts.map +1 -1
  32. package/dist/gateway-armor.js +11 -3
  33. package/dist/gateway-armor.js.map +1 -1
  34. package/dist/gcp-names.d.ts +2 -0
  35. package/dist/gcp-names.d.ts.map +1 -1
  36. package/dist/gcp-names.js +4 -0
  37. package/dist/gcp-names.js.map +1 -1
  38. package/dist/index.d.ts +3 -2
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +1 -1
  41. package/dist/index.js.map +1 -1
  42. package/dist/infra-contract.d.ts +1 -1
  43. package/dist/infra-contract.d.ts.map +1 -1
  44. package/dist/infra-contract.js +14 -1
  45. package/dist/infra-contract.js.map +1 -1
  46. package/dist/install-job-runner.d.ts.map +1 -1
  47. package/dist/install-job-runner.js +4 -3
  48. package/dist/install-job-runner.js.map +1 -1
  49. package/dist/install-job.d.ts +25 -1
  50. package/dist/install-job.d.ts.map +1 -1
  51. package/dist/install-job.js +72 -3
  52. package/dist/install-job.js.map +1 -1
  53. package/dist/job-handover-gcp.d.ts +40 -0
  54. package/dist/job-handover-gcp.d.ts.map +1 -0
  55. package/dist/job-handover-gcp.js +108 -0
  56. package/dist/job-handover-gcp.js.map +1 -0
  57. package/dist/job-handover.d.ts +141 -0
  58. package/dist/job-handover.d.ts.map +1 -0
  59. package/dist/job-handover.js +141 -0
  60. package/dist/job-handover.js.map +1 -0
  61. package/dist/operator-access.d.ts +7 -2
  62. package/dist/operator-access.d.ts.map +1 -1
  63. package/dist/operator-access.js +37 -6
  64. package/dist/operator-access.js.map +1 -1
  65. package/dist/owner-setup-token.d.ts +52 -0
  66. package/dist/owner-setup-token.d.ts.map +1 -0
  67. package/dist/owner-setup-token.js +111 -0
  68. package/dist/owner-setup-token.js.map +1 -0
  69. package/dist/project-status.d.ts +128 -0
  70. package/dist/project-status.d.ts.map +1 -0
  71. package/dist/project-status.js +303 -0
  72. package/dist/project-status.js.map +1 -0
  73. package/dist/stack-converge.d.ts.map +1 -1
  74. package/dist/stack-converge.js +9 -5
  75. package/dist/stack-converge.js.map +1 -1
  76. package/dist/state-attach.d.ts +17 -0
  77. package/dist/state-attach.d.ts.map +1 -1
  78. package/dist/state-attach.js +27 -9
  79. package/dist/state-attach.js.map +1 -1
  80. package/dist/static-security-headers.d.ts +6 -0
  81. package/dist/static-security-headers.d.ts.map +1 -1
  82. package/dist/static-security-headers.js +11 -1
  83. package/dist/static-security-headers.js.map +1 -1
  84. package/dist/upgrader-assess.d.ts +30 -3
  85. package/dist/upgrader-assess.d.ts.map +1 -1
  86. package/dist/upgrader-assess.js +77 -24
  87. package/dist/upgrader-assess.js.map +1 -1
  88. package/dist/upgrader-gcp.d.ts +4 -2
  89. package/dist/upgrader-gcp.d.ts.map +1 -1
  90. package/dist/upgrader-gcp.js +16 -3
  91. package/dist/upgrader-gcp.js.map +1 -1
  92. package/dist/upgrader-iam-preflight.d.ts +14 -3
  93. package/dist/upgrader-iam-preflight.d.ts.map +1 -1
  94. package/dist/upgrader-iam-preflight.js +40 -6
  95. package/dist/upgrader-iam-preflight.js.map +1 -1
  96. package/dist/upgrader-job.d.ts +51 -9
  97. package/dist/upgrader-job.d.ts.map +1 -1
  98. package/dist/upgrader-job.js +92 -37
  99. package/dist/upgrader-job.js.map +1 -1
  100. package/dist/upgrader-setup.d.ts +1 -1
  101. package/dist/upgrader-setup.d.ts.map +1 -1
  102. package/dist/upgrader-setup.js +5 -2
  103. package/dist/upgrader-setup.js.map +1 -1
  104. package/dist/wizards/gcp-install-job.d.ts +27 -4
  105. package/dist/wizards/gcp-install-job.d.ts.map +1 -1
  106. package/dist/wizards/gcp-install-job.js +73 -33
  107. package/dist/wizards/gcp-install-job.js.map +1 -1
  108. package/dist/wizards/gcp-pulumi.d.ts +0 -13
  109. package/dist/wizards/gcp-pulumi.d.ts.map +1 -1
  110. package/dist/wizards/gcp-pulumi.js +0 -12
  111. package/dist/wizards/gcp-pulumi.js.map +1 -1
  112. package/dist/wizards/gcp.d.ts +3 -0
  113. package/dist/wizards/gcp.d.ts.map +1 -1
  114. package/dist/wizards/gcp.js +30 -53
  115. package/dist/wizards/gcp.js.map +1 -1
  116. package/package.json +2 -2
  117. package/src/adapter.ts +6 -1
  118. package/src/admin-internal-google.ts +48 -0
  119. package/src/bootstrap-token.ts +4 -3
  120. package/src/caddy-redirects.docker.test.ts +5 -0
  121. package/src/cli-routing.test.ts +1 -1
  122. package/src/cli-routing.ts +9 -2
  123. package/src/cli.ts +9 -0
  124. package/src/converge-job-gcp.test.ts +1 -40
  125. package/src/converge-job-gcp.ts +10 -100
  126. package/src/converge-job.test.ts +9 -3
  127. package/src/converge-job.ts +33 -115
  128. package/src/dns/manual.ts +4 -1
  129. package/src/gateway-armor.ts +14 -3
  130. package/src/gateway-edge.test.ts +16 -1
  131. package/src/gcp-names.ts +4 -0
  132. package/src/gcp-url-map.test.ts +2 -0
  133. package/src/index.ts +3 -0
  134. package/src/infra-contract.test.ts +4 -3
  135. package/src/infra-contract.ts +14 -1
  136. package/src/install-job-runner.ts +4 -2
  137. package/src/install-job.ts +86 -4
  138. package/src/job-handover-gcp.test.ts +129 -0
  139. package/src/job-handover-gcp.ts +135 -0
  140. package/src/job-handover.ts +259 -0
  141. package/src/operator-access.test.ts +43 -0
  142. package/src/operator-access.ts +38 -6
  143. package/src/owner-setup-token.test.ts +195 -0
  144. package/src/owner-setup-token.ts +138 -0
  145. package/src/project-status.test.ts +571 -0
  146. package/src/project-status.ts +430 -0
  147. package/src/stack-converge.ts +12 -5
  148. package/src/state-attach.ts +46 -16
  149. package/src/static-security-headers.test.ts +16 -0
  150. package/src/static-security-headers.ts +12 -1
  151. package/src/upgrader-assess.test.ts +75 -1
  152. package/src/upgrader-assess.ts +121 -57
  153. package/src/upgrader-gcp.ts +19 -5
  154. package/src/upgrader-iam-preflight.test.ts +28 -1
  155. package/src/upgrader-iam-preflight.ts +46 -6
  156. package/src/upgrader-job.test.ts +365 -31
  157. package/src/upgrader-job.ts +177 -53
  158. package/src/upgrader-setup.test.ts +17 -0
  159. package/src/upgrader-setup.ts +5 -2
  160. package/src/url-map-redirects-access.test.ts +1 -1
  161. package/src/wizards/gcp-install-job.ts +101 -47
  162. package/src/wizards/gcp-pulumi.ts +0 -18
  163. package/src/wizards/gcp.ts +37 -67
  164. package/stacks/aws/README.md +4 -2
  165. package/stacks/aws/index.ts +4 -8
  166. package/stacks/azure/README.md +4 -2
  167. package/stacks/azure/index.ts +4 -8
  168. package/stacks/gcp/README.md +6 -3
  169. package/stacks/gcp/index.ts +7 -8
  170. package/stacks/gcp-firebase/index.ts +4 -6
@@ -0,0 +1,138 @@
1
+ // SPDX-License-Identifier: MPL-2.0
2
+
3
+ /**
4
+ * The Owner setup token of a GCP install (#1476): mint it, keep it in Secret
5
+ * Manager for the admin, and store the link that carries it.
6
+ *
7
+ * The token is minted here and not in the Pulumi program, which runs on every
8
+ * `pulumi up` and would hand out a new one each time; and at the end of the
9
+ * install, so its 24 hours start when the link is shown, not hours earlier
10
+ * while the install waits for DNS. This also keeps it out of Pulumi's state.
11
+ *
12
+ * The secret and the admin's read access on it are made here, through
13
+ * gcloud, rather than declared in the stacks. Only an install still waiting
14
+ * for its Owner needs them, so an install that has one gets no new resource,
15
+ * no new binding and no infrastructure-contract step: its admin never reads
16
+ * this secret (packages/admin-core/src/security/owner-bootstrap-secret.ts).
17
+ *
18
+ * The admin reads the newest version whenever `/setup` opens, so a new token
19
+ * works without a new revision.
20
+ */
21
+
22
+ import {
23
+ OWNER_BOOTSTRAP_TOKEN_SECRET,
24
+ type OwnerBootstrapToken,
25
+ ownerSetupLink,
26
+ parseOwnerBootstrapToken,
27
+ } from "@caelo-cms/shared";
28
+ import { generateBootstrapToken } from "./bootstrap-token.js";
29
+ import type { GcloudRunner } from "./gcloud-retry.js";
30
+ import { GCP_STACK_ENV, runServiceAccountEmail } from "./gcp-names.js";
31
+ import { storeInstallSecretValue, storeSetupLink } from "./install-job.js";
32
+
33
+ /** A token with less time left than this is replaced: nobody should get a link about to die. */
34
+ const MIN_REMAINING_MS = 60 * 60 * 1000;
35
+
36
+ /**
37
+ * The token stored in `projectId`, or null when there is none or it is not
38
+ * one (a new one replaces it).
39
+ *
40
+ * @throws when it can't be read for any other reason, with what the account needs
41
+ */
42
+ export async function readOwnerBootstrapToken(
43
+ run: GcloudRunner,
44
+ projectId: string,
45
+ ): Promise<OwnerBootstrapToken | null> {
46
+ const r = await run([
47
+ "secrets",
48
+ "versions",
49
+ "access",
50
+ "latest",
51
+ `--secret=${OWNER_BOOTSTRAP_TOKEN_SECRET}`,
52
+ `--project=${projectId}`,
53
+ ]);
54
+ if (r.ok) return parseOwnerBootstrapToken(r.stdout.trim());
55
+ if (/NOT_FOUND|not found|DISABLED|DESTROYED|FAILED_PRECONDITION/i.test(r.stderr)) return null;
56
+ throw new Error(
57
+ `Could not read the Owner setup token (secret ${OWNER_BOOTSTRAP_TOKEN_SECRET} in ${projectId}): ${r.stderr.trim()}. Your gcloud account needs secretmanager.versions.access on the project (e.g. roles/secretmanager.secretAccessor or project Owner).`,
58
+ );
59
+ }
60
+
61
+ /** A working link, and whether its token is new. */
62
+ export interface OwnerSetupIssued {
63
+ readonly link: string;
64
+ readonly expiresAt: string;
65
+ readonly minted: boolean;
66
+ }
67
+
68
+ /**
69
+ * Make sure the install has a working Owner setup link: keep a stored token
70
+ * with time left (a link already handed out stays good), otherwise mint one
71
+ * and store it; let the admin's service account read it; store the link.
72
+ * Safe to repeat. Runs as the installer or as the operator's gcloud account.
73
+ *
74
+ * @param adminUrl the admin's bare origin, as the Owner opens it
75
+ * @param now the current time in ms, for tests
76
+ */
77
+ export async function issueOwnerSetup(
78
+ run: GcloudRunner,
79
+ target: { readonly projectId: string; readonly region: string },
80
+ adminUrl: string,
81
+ now: number = Date.now(),
82
+ ): Promise<({ ok: true } & OwnerSetupIssued) | { ok: false; error: string }> {
83
+ let stored: OwnerBootstrapToken | null;
84
+ try {
85
+ stored = await readOwnerBootstrapToken(run, target.projectId);
86
+ } catch (e) {
87
+ return { ok: false, error: e instanceof Error ? e.message : String(e) };
88
+ }
89
+ const kept =
90
+ stored !== null && Date.parse(stored.expiresAt) - now > MIN_REMAINING_MS ? stored : null;
91
+ const current = kept ?? generateBootstrapToken();
92
+ if (!kept) {
93
+ const written = await storeInstallSecretValue(
94
+ run,
95
+ target,
96
+ OWNER_BOOTSTRAP_TOKEN_SECRET,
97
+ JSON.stringify(current),
98
+ );
99
+ if (!written.ok) return written;
100
+ }
101
+ // Also for a kept token: an interrupted run may have stored it and stopped
102
+ // before this grant.
103
+ const granted = await run([
104
+ "secrets",
105
+ "add-iam-policy-binding",
106
+ OWNER_BOOTSTRAP_TOKEN_SECRET,
107
+ `--project=${target.projectId}`,
108
+ `--member=serviceAccount:${runServiceAccountEmail(target.projectId, GCP_STACK_ENV)}`,
109
+ "--role=roles/secretmanager.secretAccessor",
110
+ "--condition=None",
111
+ "--quiet",
112
+ "--format=none",
113
+ ]);
114
+ if (!granted.ok) {
115
+ return {
116
+ ok: false,
117
+ error: `let the admin read ${OWNER_BOOTSTRAP_TOKEN_SECRET}: ${granted.stderr.trim()}`,
118
+ };
119
+ }
120
+ const link = ownerSetupLink(adminUrl, current.token);
121
+ const linked = await storeSetupLink(run, target, link);
122
+ if (!linked.ok) return linked;
123
+ // Two secrets, no transaction: a run at the same time may have written its
124
+ // own token in between, and then this link is not the one the admin accepts.
125
+ let latest: OwnerBootstrapToken | null;
126
+ try {
127
+ latest = await readOwnerBootstrapToken(run, target.projectId);
128
+ } catch (e) {
129
+ return { ok: false, error: e instanceof Error ? e.message : String(e) };
130
+ }
131
+ if (latest?.token !== current.token) {
132
+ return {
133
+ ok: false,
134
+ error: `another run changed the Owner setup token at the same time (secret ${OWNER_BOOTSTRAP_TOKEN_SECRET}). Run this command again.`,
135
+ };
136
+ }
137
+ return { ok: true, link, expiresAt: current.expiresAt, minted: kept === null };
138
+ }