@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.
- package/dist/adapter.d.ts +6 -1
- package/dist/adapter.d.ts.map +1 -1
- package/dist/admin-internal-google.d.ts +13 -1
- package/dist/admin-internal-google.d.ts.map +1 -1
- package/dist/admin-internal-google.js +47 -0
- package/dist/admin-internal-google.js.map +1 -1
- package/dist/agent/command.d.ts +1 -1
- package/dist/agent-db.js +133 -8
- package/dist/bootstrap-token.d.ts +4 -3
- package/dist/bootstrap-token.d.ts.map +1 -1
- package/dist/bootstrap-token.js.map +1 -1
- package/dist/cli-routing.d.ts.map +1 -1
- package/dist/cli-routing.js +7 -2
- package/dist/cli-routing.js.map +1 -1
- package/dist/cli.js +9 -0
- package/dist/cli.js.map +1 -1
- package/dist/converge-checkpoint.d.ts +6 -0
- package/dist/converge-checkpoint.d.ts.map +1 -1
- package/dist/converge-job-gcp.d.ts +1 -16
- package/dist/converge-job-gcp.d.ts.map +1 -1
- package/dist/converge-job-gcp.js +10 -97
- package/dist/converge-job-gcp.js.map +1 -1
- package/dist/converge-job.d.ts +7 -46
- package/dist/converge-job.d.ts.map +1 -1
- package/dist/converge-job.js +22 -57
- package/dist/converge-job.js.map +1 -1
- package/dist/dns/manual.d.ts +5 -1
- package/dist/dns/manual.d.ts.map +1 -1
- package/dist/dns/manual.js +2 -1
- package/dist/dns/manual.js.map +1 -1
- package/dist/gateway-armor.d.ts.map +1 -1
- package/dist/gateway-armor.js +11 -3
- package/dist/gateway-armor.js.map +1 -1
- package/dist/gcp-names.d.ts +2 -0
- package/dist/gcp-names.d.ts.map +1 -1
- package/dist/gcp-names.js +4 -0
- package/dist/gcp-names.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.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 +14 -1
- package/dist/infra-contract.js.map +1 -1
- package/dist/install-job-runner.d.ts.map +1 -1
- package/dist/install-job-runner.js +4 -3
- package/dist/install-job-runner.js.map +1 -1
- package/dist/install-job.d.ts +25 -1
- package/dist/install-job.d.ts.map +1 -1
- package/dist/install-job.js +72 -3
- package/dist/install-job.js.map +1 -1
- package/dist/job-handover-gcp.d.ts +40 -0
- package/dist/job-handover-gcp.d.ts.map +1 -0
- package/dist/job-handover-gcp.js +108 -0
- package/dist/job-handover-gcp.js.map +1 -0
- package/dist/job-handover.d.ts +141 -0
- package/dist/job-handover.d.ts.map +1 -0
- package/dist/job-handover.js +141 -0
- package/dist/job-handover.js.map +1 -0
- package/dist/operator-access.d.ts +7 -2
- package/dist/operator-access.d.ts.map +1 -1
- package/dist/operator-access.js +37 -6
- package/dist/operator-access.js.map +1 -1
- package/dist/owner-setup-token.d.ts +52 -0
- package/dist/owner-setup-token.d.ts.map +1 -0
- package/dist/owner-setup-token.js +111 -0
- package/dist/owner-setup-token.js.map +1 -0
- package/dist/project-status.d.ts +128 -0
- package/dist/project-status.d.ts.map +1 -0
- package/dist/project-status.js +303 -0
- package/dist/project-status.js.map +1 -0
- package/dist/stack-converge.d.ts.map +1 -1
- package/dist/stack-converge.js +9 -5
- package/dist/stack-converge.js.map +1 -1
- package/dist/state-attach.d.ts +17 -0
- package/dist/state-attach.d.ts.map +1 -1
- package/dist/state-attach.js +27 -9
- package/dist/state-attach.js.map +1 -1
- package/dist/static-security-headers.d.ts +6 -0
- package/dist/static-security-headers.d.ts.map +1 -1
- package/dist/static-security-headers.js +11 -1
- package/dist/static-security-headers.js.map +1 -1
- package/dist/upgrader-assess.d.ts +30 -3
- package/dist/upgrader-assess.d.ts.map +1 -1
- package/dist/upgrader-assess.js +77 -24
- package/dist/upgrader-assess.js.map +1 -1
- package/dist/upgrader-gcp.d.ts +4 -2
- package/dist/upgrader-gcp.d.ts.map +1 -1
- package/dist/upgrader-gcp.js +16 -3
- package/dist/upgrader-gcp.js.map +1 -1
- package/dist/upgrader-iam-preflight.d.ts +14 -3
- package/dist/upgrader-iam-preflight.d.ts.map +1 -1
- package/dist/upgrader-iam-preflight.js +40 -6
- package/dist/upgrader-iam-preflight.js.map +1 -1
- package/dist/upgrader-job.d.ts +51 -9
- package/dist/upgrader-job.d.ts.map +1 -1
- package/dist/upgrader-job.js +92 -37
- package/dist/upgrader-job.js.map +1 -1
- package/dist/upgrader-setup.d.ts +1 -1
- package/dist/upgrader-setup.d.ts.map +1 -1
- package/dist/upgrader-setup.js +5 -2
- package/dist/upgrader-setup.js.map +1 -1
- package/dist/wizards/gcp-install-job.d.ts +27 -4
- package/dist/wizards/gcp-install-job.d.ts.map +1 -1
- package/dist/wizards/gcp-install-job.js +73 -33
- package/dist/wizards/gcp-install-job.js.map +1 -1
- package/dist/wizards/gcp-pulumi.d.ts +0 -13
- package/dist/wizards/gcp-pulumi.d.ts.map +1 -1
- package/dist/wizards/gcp-pulumi.js +0 -12
- package/dist/wizards/gcp-pulumi.js.map +1 -1
- package/dist/wizards/gcp.d.ts +3 -0
- package/dist/wizards/gcp.d.ts.map +1 -1
- package/dist/wizards/gcp.js +30 -53
- package/dist/wizards/gcp.js.map +1 -1
- package/package.json +2 -2
- package/src/adapter.ts +6 -1
- package/src/admin-internal-google.ts +48 -0
- package/src/bootstrap-token.ts +4 -3
- package/src/caddy-redirects.docker.test.ts +5 -0
- package/src/cli-routing.test.ts +1 -1
- package/src/cli-routing.ts +9 -2
- package/src/cli.ts +9 -0
- package/src/converge-job-gcp.test.ts +1 -40
- package/src/converge-job-gcp.ts +10 -100
- package/src/converge-job.test.ts +9 -3
- package/src/converge-job.ts +33 -115
- package/src/dns/manual.ts +4 -1
- package/src/gateway-armor.ts +14 -3
- package/src/gateway-edge.test.ts +16 -1
- package/src/gcp-names.ts +4 -0
- package/src/gcp-url-map.test.ts +2 -0
- package/src/index.ts +3 -0
- package/src/infra-contract.test.ts +4 -3
- package/src/infra-contract.ts +14 -1
- package/src/install-job-runner.ts +4 -2
- package/src/install-job.ts +86 -4
- package/src/job-handover-gcp.test.ts +129 -0
- package/src/job-handover-gcp.ts +135 -0
- package/src/job-handover.ts +259 -0
- package/src/operator-access.test.ts +43 -0
- package/src/operator-access.ts +38 -6
- package/src/owner-setup-token.test.ts +195 -0
- package/src/owner-setup-token.ts +138 -0
- package/src/project-status.test.ts +571 -0
- package/src/project-status.ts +430 -0
- package/src/stack-converge.ts +12 -5
- package/src/state-attach.ts +46 -16
- package/src/static-security-headers.test.ts +16 -0
- package/src/static-security-headers.ts +12 -1
- package/src/upgrader-assess.test.ts +75 -1
- package/src/upgrader-assess.ts +121 -57
- package/src/upgrader-gcp.ts +19 -5
- package/src/upgrader-iam-preflight.test.ts +28 -1
- package/src/upgrader-iam-preflight.ts +46 -6
- package/src/upgrader-job.test.ts +365 -31
- package/src/upgrader-job.ts +177 -53
- package/src/upgrader-setup.test.ts +17 -0
- package/src/upgrader-setup.ts +5 -2
- package/src/url-map-redirects-access.test.ts +1 -1
- package/src/wizards/gcp-install-job.ts +101 -47
- package/src/wizards/gcp-pulumi.ts +0 -18
- package/src/wizards/gcp.ts +37 -67
- package/stacks/aws/README.md +4 -2
- package/stacks/aws/index.ts +4 -8
- package/stacks/azure/README.md +4 -2
- package/stacks/azure/index.ts +4 -8
- package/stacks/gcp/README.md +6 -3
- package/stacks/gcp/index.ts +7 -8
- 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
|
+
}
|