@caelo-cms/provisioning 0.11.8 → 0.11.10
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/admin-domain.d.ts +10 -1
- package/dist/admin-domain.d.ts.map +1 -1
- package/dist/admin-domain.js +13 -3
- package/dist/admin-domain.js.map +1 -1
- package/dist/adopt-existing.d.ts +6 -1
- package/dist/adopt-existing.d.ts.map +1 -1
- package/dist/adopt-existing.js +86 -0
- package/dist/adopt-existing.js.map +1 -1
- package/dist/agent/command.d.ts +20 -0
- package/dist/agent/command.d.ts.map +1 -1
- package/dist/agent/command.js +32 -9
- package/dist/agent/command.js.map +1 -1
- package/dist/agent/run.d.ts +2 -0
- package/dist/agent/run.d.ts.map +1 -1
- package/dist/agent/run.js +5 -1
- package/dist/agent/run.js.map +1 -1
- package/dist/agent-db.js +65 -3
- package/dist/aws-task-roles.d.ts +4 -2
- package/dist/aws-task-roles.d.ts.map +1 -1
- package/dist/aws-task-roles.js +4 -1
- package/dist/aws-task-roles.js.map +1 -1
- package/dist/caddy.d.ts +21 -4
- package/dist/caddy.d.ts.map +1 -1
- package/dist/caddy.js +27 -3
- package/dist/caddy.js.map +1 -1
- package/dist/cli.js +12 -3
- package/dist/cli.js.map +1 -1
- package/dist/cloudsql-tls.d.ts +63 -0
- package/dist/cloudsql-tls.d.ts.map +1 -0
- package/dist/cloudsql-tls.js +289 -0
- package/dist/cloudsql-tls.js.map +1 -0
- package/dist/compose.d.ts +29 -6
- package/dist/compose.d.ts.map +1 -1
- package/dist/compose.js +95 -23
- package/dist/compose.js.map +1 -1
- package/dist/converge-checkpoint.d.ts +1 -0
- package/dist/converge-checkpoint.d.ts.map +1 -1
- package/dist/converge-checkpoint.js +8 -1
- package/dist/converge-checkpoint.js.map +1 -1
- package/dist/converge-job-gcp.d.ts.map +1 -1
- package/dist/converge-job-gcp.js +2 -11
- package/dist/converge-job-gcp.js.map +1 -1
- package/dist/deployed-release.d.ts +4 -1
- package/dist/deployed-release.d.ts.map +1 -1
- package/dist/deployed-release.js +18 -8
- package/dist/deployed-release.js.map +1 -1
- package/dist/gcp-names.d.ts +21 -0
- package/dist/gcp-names.d.ts.map +1 -1
- package/dist/gcp-names.js +24 -0
- package/dist/gcp-names.js.map +1 -1
- package/dist/gcp-url-map.d.ts.map +1 -1
- package/dist/gcp-url-map.js +6 -2
- package/dist/gcp-url-map.js.map +1 -1
- package/dist/index.d.ts +1 -1
- 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 +24 -1
- package/dist/infra-contract.js.map +1 -1
- package/dist/install-state.d.ts +6 -0
- package/dist/install-state.d.ts.map +1 -1
- package/dist/install-state.js +17 -4
- package/dist/install-state.js.map +1 -1
- package/dist/lifecycle.d.ts.map +1 -1
- package/dist/lifecycle.js +17 -8
- package/dist/lifecycle.js.map +1 -1
- package/dist/mcp-auth-proxy-setup.d.ts +48 -0
- package/dist/mcp-auth-proxy-setup.d.ts.map +1 -0
- package/dist/mcp-auth-proxy-setup.js +280 -0
- package/dist/mcp-auth-proxy-setup.js.map +1 -0
- package/dist/release-manifest.d.ts +25 -1
- package/dist/release-manifest.d.ts.map +1 -1
- package/dist/release-manifest.js +36 -3
- package/dist/release-manifest.js.map +1 -1
- package/dist/remote-mcp.d.ts +55 -18
- package/dist/remote-mcp.d.ts.map +1 -1
- package/dist/remote-mcp.js +307 -77
- package/dist/remote-mcp.js.map +1 -1
- package/dist/runtime-secrets.d.ts +9 -0
- package/dist/runtime-secrets.d.ts.map +1 -1
- package/dist/runtime-secrets.js +21 -10
- package/dist/runtime-secrets.js.map +1 -1
- package/dist/seal-key-rotation.d.ts +7 -7
- package/dist/seal-key-rotation.d.ts.map +1 -1
- package/dist/seal-key-rotation.js +22 -22
- package/dist/seal-key-rotation.js.map +1 -1
- package/dist/self-hosted-db-tls.d.ts +37 -0
- package/dist/self-hosted-db-tls.d.ts.map +1 -0
- package/dist/self-hosted-db-tls.js +220 -0
- package/dist/self-hosted-db-tls.js.map +1 -0
- package/dist/self-hosted-release.d.ts +3 -1
- package/dist/self-hosted-release.d.ts.map +1 -1
- package/dist/self-hosted-release.js +33 -9
- package/dist/self-hosted-release.js.map +1 -1
- package/dist/self-hosted-roles.d.ts +34 -0
- package/dist/self-hosted-roles.d.ts.map +1 -1
- package/dist/self-hosted-roles.js +52 -0
- package/dist/self-hosted-roles.js.map +1 -1
- package/dist/self-hosted-start.d.ts +0 -21
- package/dist/self-hosted-start.d.ts.map +1 -1
- package/dist/self-hosted-start.js +39 -1
- package/dist/self-hosted-start.js.map +1 -1
- package/dist/self-hosted-upgrade.d.ts +15 -6
- package/dist/self-hosted-upgrade.d.ts.map +1 -1
- package/dist/self-hosted-upgrade.js +72 -23
- package/dist/self-hosted-upgrade.js.map +1 -1
- package/dist/stack-contract.d.ts +170 -25
- package/dist/stack-contract.d.ts.map +1 -1
- package/dist/stack-contract.js +314 -37
- package/dist/stack-contract.js.map +1 -1
- package/dist/stack-converge.d.ts +31 -0
- package/dist/stack-converge.d.ts.map +1 -1
- package/dist/stack-converge.js +71 -30
- package/dist/stack-converge.js.map +1 -1
- package/dist/upgrade/app-roll.d.ts +25 -4
- package/dist/upgrade/app-roll.d.ts.map +1 -1
- package/dist/upgrade/app-roll.js +63 -17
- package/dist/upgrade/app-roll.js.map +1 -1
- package/dist/upgrade/converge.d.ts.map +1 -1
- package/dist/upgrade/converge.js +99 -12
- package/dist/upgrade/converge.js.map +1 -1
- package/dist/upgrade/health.d.ts +31 -7
- package/dist/upgrade/health.d.ts.map +1 -1
- package/dist/upgrade/health.js +41 -17
- package/dist/upgrade/health.js.map +1 -1
- package/dist/upgrade/image-forms.d.ts +1 -1
- package/dist/upgrade/image-forms.d.ts.map +1 -1
- package/dist/upgrade/image-forms.js +24 -7
- package/dist/upgrade/image-forms.js.map +1 -1
- package/dist/upgrade/release-images.d.ts +12 -3
- package/dist/upgrade/release-images.d.ts.map +1 -1
- package/dist/upgrade/release-images.js +13 -4
- package/dist/upgrade/release-images.js.map +1 -1
- package/dist/upgrade/upgrade.d.ts +13 -3
- package/dist/upgrade/upgrade.d.ts.map +1 -1
- package/dist/upgrade/upgrade.js +34 -2
- package/dist/upgrade/upgrade.js.map +1 -1
- package/dist/upgrader-gcp.d.ts +12 -0
- package/dist/upgrader-gcp.d.ts.map +1 -1
- package/dist/upgrader-gcp.js +49 -1
- package/dist/upgrader-gcp.js.map +1 -1
- package/dist/upgrader-iam-preflight.d.ts.map +1 -1
- package/dist/upgrader-iam-preflight.js +6 -1
- package/dist/upgrader-iam-preflight.js.map +1 -1
- package/dist/upgrader-job.d.ts +1 -1
- package/dist/upgrader-job.d.ts.map +1 -1
- package/dist/upgrader-job.js +20 -14
- package/dist/upgrader-job.js.map +1 -1
- package/dist/upgrader-records.d.ts +1 -1
- package/dist/upgrader-records.d.ts.map +1 -1
- package/dist/upgrader-records.js +26 -7
- package/dist/upgrader-records.js.map +1 -1
- package/dist/upgrader-setup.d.ts.map +1 -1
- package/dist/upgrader-setup.js +10 -5
- package/dist/upgrader-setup.js.map +1 -1
- package/dist/wizards/gcp-cost.d.ts.map +1 -1
- package/dist/wizards/gcp-cost.js +22 -7
- package/dist/wizards/gcp-cost.js.map +1 -1
- package/dist/wizards/gcp.d.ts.map +1 -1
- package/dist/wizards/gcp.js +43 -17
- package/dist/wizards/gcp.js.map +1 -1
- package/package.json +2 -2
- package/src/admin-domain.test.ts +9 -8
- package/src/admin-domain.ts +13 -3
- package/src/admin-memory.test.ts +1 -0
- package/src/adopt-existing.test.ts +39 -0
- package/src/adopt-existing.ts +83 -1
- package/src/agent/command.test.ts +49 -1
- package/src/agent/command.ts +36 -9
- package/src/agent/run.test.ts +19 -0
- package/src/agent/run.ts +11 -2
- package/src/aws-task-roles.ts +5 -2
- package/src/caddy-redirects.docker.test.ts +2 -0
- package/src/caddy-redirects.test.ts +3 -0
- package/src/caddy-validate.test.ts +7 -1
- package/src/caddy.test.ts +39 -1
- package/src/caddy.ts +36 -4
- package/src/checkpoint-secrets.test.ts +14 -6
- package/src/cli.ts +12 -1
- package/src/cloudsql-tls.test.ts +225 -0
- package/src/cloudsql-tls.ts +352 -0
- package/src/compose.ts +125 -24
- package/src/converge-checkpoint.ts +8 -1
- package/src/converge-job-gcp.ts +2 -11
- package/src/database-tls-builders.test.ts +55 -0
- package/src/deployed-release.test.ts +104 -40
- package/src/deployed-release.ts +30 -9
- package/src/gateway-env-isolation.test.ts +10 -5
- package/src/gcp-names.ts +31 -0
- package/src/gcp-url-map.test.ts +6 -8
- package/src/gcp-url-map.ts +6 -2
- package/src/index.test.ts +7 -1
- package/src/index.ts +1 -0
- package/src/infra-contract.test.ts +5 -3
- package/src/infra-contract.ts +24 -1
- package/src/install-state.ts +26 -4
- package/src/lifecycle.ts +20 -11
- package/src/mcp-auth-proxy-setup.test.ts +305 -0
- package/src/mcp-auth-proxy-setup.ts +374 -0
- package/src/mcp-iap-stacks.test.ts +1 -1
- package/src/media-volume.test.ts +1 -1
- package/src/operator-access-stacks.test.ts +1 -1
- package/src/operator-access.test.ts +5 -4
- package/src/pool-budget-stacks.test.ts +1 -1
- package/src/release-manifest.test.ts +25 -0
- package/src/release-manifest.ts +59 -4
- package/src/remote-mcp-stack-config.test.ts +19 -9
- package/src/remote-mcp.test.ts +252 -57
- package/src/remote-mcp.ts +336 -77
- package/src/runtime-secrets.test.ts +20 -7
- package/src/runtime-secrets.ts +50 -9
- package/src/seal-key-rotation.test.ts +2 -2
- package/src/seal-key-rotation.ts +25 -25
- package/src/self-hosted-compose.test.ts +108 -5
- package/src/self-hosted-db-tls.test.ts +111 -0
- package/src/self-hosted-db-tls.ts +287 -0
- package/src/self-hosted-release-resolve.test.ts +71 -0
- package/src/self-hosted-release.ts +41 -11
- package/src/self-hosted-roles.test.ts +54 -0
- package/src/self-hosted-roles.ts +58 -0
- package/src/self-hosted-start.test.ts +34 -2
- package/src/self-hosted-start.ts +20 -2
- package/src/self-hosted-upgrade.test.ts +103 -14
- package/src/self-hosted-upgrade.ts +115 -29
- package/src/stack-contract-parity.test.ts +79 -12
- package/src/stack-contract.test.ts +169 -29
- package/src/stack-contract.ts +362 -42
- package/src/stack-converge-secrets.test.ts +26 -13
- package/src/stack-converge.test.ts +199 -26
- package/src/stack-converge.ts +92 -30
- package/src/state-store.test.ts +2 -1
- package/src/upgrade/app-roll.ts +97 -19
- package/src/upgrade/converge.ts +120 -11
- package/src/upgrade/health.test.ts +63 -25
- package/src/upgrade/health.ts +54 -22
- package/src/upgrade/image-forms.test.ts +34 -0
- package/src/upgrade/image-forms.ts +23 -8
- package/src/upgrade/release-images.test.ts +5 -1
- package/src/upgrade/release-images.ts +22 -6
- package/src/upgrade/upgrade.test.ts +353 -44
- package/src/upgrade/upgrade.ts +55 -6
- package/src/upgrader-gcp.ts +65 -3
- package/src/upgrader-iam-preflight.test.ts +19 -0
- package/src/upgrader-iam-preflight.ts +6 -0
- package/src/upgrader-job.test.ts +101 -27
- package/src/upgrader-job.ts +27 -14
- package/src/upgrader-records.test.ts +97 -12
- package/src/upgrader-records.ts +28 -11
- package/src/upgrader-setup.test.ts +2 -0
- package/src/upgrader-setup.ts +10 -4
- package/src/wizards/gcp-cost.test.ts +50 -0
- package/src/wizards/gcp-cost.ts +24 -7
- package/src/wizards/gcp.ts +55 -14
- package/stacks/aws/index.ts +32 -14
- package/stacks/azure/index.ts +57 -18
- package/stacks/gcp/index.ts +83 -23
- package/stacks/gcp-firebase/index.ts +162 -33
- package/stacks/self-hosted/README.md +2 -1
- package/stacks/self-hosted/index.ts +11 -1
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* #1338 (gateway hardening L6) — converge a Cloud SQL install to
|
|
5
|
+
* `sslmode=verify-full` through gcloud, the way `cms-provision upgrade`
|
|
6
|
+
* converges everything else (stack-converge.ts; it never runs Pulumi).
|
|
7
|
+
*
|
|
8
|
+
* Verify-full checks the server certificate's chain AND that it names the
|
|
9
|
+
* host the client dialled. On Cloud SQL that needs three things the stacks
|
|
10
|
+
* declare for a new install (stacks/gcp, stacks/gcp-firebase) and this
|
|
11
|
+
* module brings an existing one to:
|
|
12
|
+
*
|
|
13
|
+
* 1. The shared server CA (`GOOGLE_MANAGED_CAS_CA`): "The SAN field
|
|
14
|
+
* contains the hostname (DNS name of the instance) for all types of
|
|
15
|
+
* instances", while the default per-instance CA names one "only for
|
|
16
|
+
* instances enabled with Private Service Connect"
|
|
17
|
+
* (docs.cloud.google.com/sql/docs/postgres/authorize-ssl). An instance
|
|
18
|
+
* may move from per-instance to shared, not back. After the move the
|
|
19
|
+
* instance needs a server certificate from the new CA: "create a new
|
|
20
|
+
* server certificate with `gcloud sql ssl server-certs create`", then
|
|
21
|
+
* "complete the rotation with `gcloud sql ssl server-certs rotate`"
|
|
22
|
+
* (docs.cloud.google.com/sql/docs/postgres/manage-ssl-instance). The
|
|
23
|
+
* rotation restarts nothing a client keeps: open connections drop and
|
|
24
|
+
* reconnect; every client already uses TLS (`sslmode=require` before).
|
|
25
|
+
* `sslMode=ENCRYPTED_ONLY` refuses plaintext from then on.
|
|
26
|
+
* 2. Resolution of the instance's DNS name (`dnsNames`, the
|
|
27
|
+
* PRIVATE_SERVICES_ACCESS entry, `….sql-psa.goog`) inside the VPC:
|
|
28
|
+
* "create the DNS record in a private DNS zone in the corresponding
|
|
29
|
+
* Virtual Private Cloud (VPC) network"
|
|
30
|
+
* (docs.cloud.google.com/sql/docs/postgres/configure-ssl-instance).
|
|
31
|
+
* 3. The services dialling that name. They read it from their own
|
|
32
|
+
* `*_DATABASE_URL`, and so does every job the upgrade derives from the
|
|
33
|
+
* admin's (migrations, upgrader, operator access): {@link
|
|
34
|
+
* moveServicesToDnsHost} switches the host of the live URLs first,
|
|
35
|
+
* keeping their current `sslmode`, so the old image keeps working until
|
|
36
|
+
* the roll sets verify-full with the image that carries the CA bundle.
|
|
37
|
+
*
|
|
38
|
+
* The CA the clients trust is Google's published shared-CA bundle, shipped
|
|
39
|
+
* in every image (shared database-tls.ts `CLOUD_SQL_CA_BUNDLE`): it covers
|
|
40
|
+
* the root and every regional CA, so a server-certificate rotation needs no
|
|
41
|
+
* change on the client side.
|
|
42
|
+
*
|
|
43
|
+
* Every step reads before it writes and is a no-op when already in shape,
|
|
44
|
+
* so a re-run after a failure picks up where the last one stopped.
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
import { isIpLiteral } from "@caelo-cms/shared";
|
|
48
|
+
import { type GcloudRunner, realSleep, runWithRetry, type Sleep } from "./gcloud-retry.js";
|
|
49
|
+
import type { HttpFetch } from "./runtime-secrets.js";
|
|
50
|
+
import {
|
|
51
|
+
CLOUD_SQL_SERVER_CA_MODE,
|
|
52
|
+
CLOUD_SQL_SSL_MODE,
|
|
53
|
+
cloudSqlDnsZoneName,
|
|
54
|
+
cloudSqlPrivateDnsName,
|
|
55
|
+
} from "./stack-contract.js";
|
|
56
|
+
import type { LiveEnvValue } from "./stack-converge.js";
|
|
57
|
+
|
|
58
|
+
/** The install's Cloud SQL instance. */
|
|
59
|
+
export interface CloudSqlTlsTarget {
|
|
60
|
+
readonly projectId: string;
|
|
61
|
+
readonly env: string;
|
|
62
|
+
readonly sqlInstance: string;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface CloudSqlTlsDeps {
|
|
66
|
+
readonly run: GcloudRunner;
|
|
67
|
+
readonly http?: HttpFetch;
|
|
68
|
+
readonly sleep?: Sleep;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export type CloudSqlTlsResult =
|
|
72
|
+
| { readonly ok: true; readonly host: string; readonly done: string[] }
|
|
73
|
+
| { readonly ok: false; readonly error: string; readonly done: string[] };
|
|
74
|
+
|
|
75
|
+
/** The parts of `gcloud sql instances describe --format=json` this reads. */
|
|
76
|
+
interface InstanceDescription {
|
|
77
|
+
readonly settings?: {
|
|
78
|
+
readonly ipConfiguration?: {
|
|
79
|
+
readonly serverCaMode?: string;
|
|
80
|
+
readonly sslMode?: string;
|
|
81
|
+
readonly privateNetwork?: string;
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
readonly ipAddresses?: readonly { readonly type?: string; readonly ipAddress?: string }[];
|
|
85
|
+
readonly dnsNames?: readonly { readonly name?: string; readonly connectionType?: string }[];
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const NOT_FOUND = /NOT_FOUND|not found|does not exist|404/i;
|
|
89
|
+
const SQL_ADMIN = "https://sqladmin.googleapis.com/v1";
|
|
90
|
+
|
|
91
|
+
async function describeInstance(
|
|
92
|
+
t: CloudSqlTlsTarget,
|
|
93
|
+
run: GcloudRunner,
|
|
94
|
+
): Promise<{ ok: true; d: InstanceDescription } | { ok: false; error: string }> {
|
|
95
|
+
const r = await run([
|
|
96
|
+
"sql",
|
|
97
|
+
"instances",
|
|
98
|
+
"describe",
|
|
99
|
+
t.sqlInstance,
|
|
100
|
+
`--project=${t.projectId}`,
|
|
101
|
+
"--format=json",
|
|
102
|
+
]);
|
|
103
|
+
if (!r.ok) return { ok: false, error: `describe ${t.sqlInstance}: ${r.stderr.trim()}` };
|
|
104
|
+
try {
|
|
105
|
+
return { ok: true, d: JSON.parse(r.stdout) as InstanceDescription };
|
|
106
|
+
} catch {
|
|
107
|
+
return { ok: false, error: `describe ${t.sqlInstance}: gcloud printed no JSON` };
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** The instance's server certificates and which one is active (Cloud SQL Admin API). */
|
|
112
|
+
async function listServerCertificates(
|
|
113
|
+
t: CloudSqlTlsTarget,
|
|
114
|
+
run: GcloudRunner,
|
|
115
|
+
http: HttpFetch,
|
|
116
|
+
): Promise<
|
|
117
|
+
{ ok: true; activeVersion: string | null; fingerprints: string[] } | { ok: false; error: string }
|
|
118
|
+
> {
|
|
119
|
+
const token = await run(["auth", "print-access-token"]);
|
|
120
|
+
const bearer = token.ok ? token.stdout.trim() : "";
|
|
121
|
+
if (!bearer)
|
|
122
|
+
return { ok: false, error: `gcloud auth print-access-token: ${token.stderr.trim()}` };
|
|
123
|
+
const res = await http(
|
|
124
|
+
`${SQL_ADMIN}/projects/${encodeURIComponent(t.projectId)}/instances/${encodeURIComponent(t.sqlInstance)}/listServerCertificates`,
|
|
125
|
+
{ method: "GET", headers: { Authorization: `Bearer ${bearer}` } },
|
|
126
|
+
);
|
|
127
|
+
const text = await res.text();
|
|
128
|
+
if (!res.ok) {
|
|
129
|
+
return {
|
|
130
|
+
ok: false,
|
|
131
|
+
error: `list server certificates: HTTP ${res.status} ${text.slice(0, 300)}`,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
const body = JSON.parse(text) as {
|
|
135
|
+
activeVersion?: string;
|
|
136
|
+
serverCerts?: { sha1Fingerprint?: string }[];
|
|
137
|
+
};
|
|
138
|
+
return {
|
|
139
|
+
ok: true,
|
|
140
|
+
activeVersion: body.activeVersion ?? null,
|
|
141
|
+
fingerprints: (body.serverCerts ?? []).map((c) => c.sha1Fingerprint ?? "").filter(Boolean),
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Bring the instance to verify-full: shared CA with an active server
|
|
147
|
+
* certificate from it, encrypted connections only, its DNS name resolving
|
|
148
|
+
* in the VPC. Returns the host every client must dial.
|
|
149
|
+
*/
|
|
150
|
+
export async function ensureCloudSqlVerifyFull(
|
|
151
|
+
t: CloudSqlTlsTarget,
|
|
152
|
+
deps: CloudSqlTlsDeps,
|
|
153
|
+
): Promise<CloudSqlTlsResult> {
|
|
154
|
+
const sleep = deps.sleep ?? realSleep;
|
|
155
|
+
const run = (args: string[]) => runWithRetry(deps.run, sleep, args);
|
|
156
|
+
const http = deps.http ?? (fetch as unknown as HttpFetch);
|
|
157
|
+
const done: string[] = [];
|
|
158
|
+
const fail = (error: string): CloudSqlTlsResult => ({ ok: false, error, done });
|
|
159
|
+
const project = `--project=${t.projectId}`;
|
|
160
|
+
|
|
161
|
+
let described = await describeInstance(t, run);
|
|
162
|
+
if (!described.ok) return fail(described.error);
|
|
163
|
+
const ip = described.d.settings?.ipConfiguration;
|
|
164
|
+
const patch: string[] = [];
|
|
165
|
+
if (ip?.serverCaMode !== CLOUD_SQL_SERVER_CA_MODE) {
|
|
166
|
+
patch.push(`--server-ca-mode=${CLOUD_SQL_SERVER_CA_MODE}`);
|
|
167
|
+
}
|
|
168
|
+
if (ip?.sslMode !== CLOUD_SQL_SSL_MODE) patch.push(`--ssl-mode=${CLOUD_SQL_SSL_MODE}`);
|
|
169
|
+
if (patch.length > 0) {
|
|
170
|
+
const r = await run(["sql", "instances", "patch", t.sqlInstance, project, ...patch, "--quiet"]);
|
|
171
|
+
if (!r.ok) return fail(`patch ${t.sqlInstance} (${patch.join(" ")}): ${r.stderr.trim()}`);
|
|
172
|
+
done.push(`Cloud SQL ${t.sqlInstance}: ${patch.join(" ")}`);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// The active server certificate must come from the shared CA. Before the
|
|
176
|
+
// move there is none in the list the shared CA keeps; after an
|
|
177
|
+
// interrupted run there may be an upcoming one that was never rotated in.
|
|
178
|
+
const certs = await listServerCertificates(t, run, http);
|
|
179
|
+
if (!certs.ok) return fail(certs.error);
|
|
180
|
+
const activeShared =
|
|
181
|
+
certs.activeVersion !== null && certs.fingerprints.includes(certs.activeVersion);
|
|
182
|
+
if (!activeShared) {
|
|
183
|
+
const upcoming = certs.fingerprints.filter((f) => f !== certs.activeVersion);
|
|
184
|
+
if (upcoming.length === 0) {
|
|
185
|
+
const c = await run([
|
|
186
|
+
"sql",
|
|
187
|
+
"ssl",
|
|
188
|
+
"server-certs",
|
|
189
|
+
"create",
|
|
190
|
+
`--instance=${t.sqlInstance}`,
|
|
191
|
+
project,
|
|
192
|
+
]);
|
|
193
|
+
if (!c.ok) return fail(`create a server certificate: ${c.stderr.trim()}`);
|
|
194
|
+
done.push(`Cloud SQL ${t.sqlInstance}: server certificate from the shared CA created`);
|
|
195
|
+
}
|
|
196
|
+
const rot = await run([
|
|
197
|
+
"sql",
|
|
198
|
+
"ssl",
|
|
199
|
+
"server-certs",
|
|
200
|
+
"rotate",
|
|
201
|
+
`--instance=${t.sqlInstance}`,
|
|
202
|
+
project,
|
|
203
|
+
"--quiet",
|
|
204
|
+
]);
|
|
205
|
+
if (!rot.ok) return fail(`rotate to the shared-CA server certificate: ${rot.stderr.trim()}`);
|
|
206
|
+
done.push(`Cloud SQL ${t.sqlInstance}: rotated onto the shared-CA server certificate`);
|
|
207
|
+
described = await describeInstance(t, run);
|
|
208
|
+
if (!described.ok) return fail(described.error);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const host = cloudSqlPrivateDnsName(described.d.dnsNames);
|
|
212
|
+
if (!host) {
|
|
213
|
+
return fail(
|
|
214
|
+
`${t.sqlInstance} reports no PRIVATE_SERVICES_ACCESS DNS name (dnsNames) although it uses the shared CA; verify-full needs it. Check the instance's private IP configuration and re-run.`,
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
const privateIp = described.d.ipAddresses?.find((a) => a.type === "PRIVATE")?.ipAddress;
|
|
218
|
+
if (!privateIp) return fail(`${t.sqlInstance} has no private IP address`);
|
|
219
|
+
const network = ip?.privateNetwork?.split("/").pop();
|
|
220
|
+
if (!network) return fail(`${t.sqlInstance} names no private network`);
|
|
221
|
+
|
|
222
|
+
const zone = cloudSqlDnsZoneName(t.env);
|
|
223
|
+
const fqdn = `${host}.`;
|
|
224
|
+
const z = await run(["dns", "managed-zones", "describe", zone, project, "--format=json"]);
|
|
225
|
+
if (z.ok) {
|
|
226
|
+
const existing = (JSON.parse(z.stdout) as { dnsName?: string }).dnsName?.toLowerCase();
|
|
227
|
+
if (existing !== fqdn) {
|
|
228
|
+
return fail(
|
|
229
|
+
`the private DNS zone ${zone} serves ${existing ?? "(no name)"}, not the instance's DNS name ${fqdn}. If the instance was replaced, delete the zone (gcloud dns managed-zones delete ${zone} ${project}) after removing its records, then re-run.`,
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
} else if (NOT_FOUND.test(z.stderr)) {
|
|
233
|
+
const c = await run([
|
|
234
|
+
"dns",
|
|
235
|
+
"managed-zones",
|
|
236
|
+
"create",
|
|
237
|
+
zone,
|
|
238
|
+
project,
|
|
239
|
+
`--dns-name=${fqdn}`,
|
|
240
|
+
"--visibility=private",
|
|
241
|
+
`--networks=${network}`,
|
|
242
|
+
`--description=Caelo ${t.env}: the Cloud SQL instance's DNS name inside the VPC (#1338)`,
|
|
243
|
+
]);
|
|
244
|
+
if (!c.ok) return fail(`create the private DNS zone ${zone}: ${c.stderr.trim()}`);
|
|
245
|
+
done.push(`private DNS zone ${zone} (${fqdn}) on network ${network}`);
|
|
246
|
+
} else {
|
|
247
|
+
return fail(`describe the private DNS zone ${zone}: ${z.stderr.trim()}`);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const rec = ["dns", "record-sets"];
|
|
251
|
+
const where = [fqdn, `--zone=${zone}`, "--type=A", project];
|
|
252
|
+
const a = await run([...rec, "describe", ...where, "--format=json"]);
|
|
253
|
+
if (a.ok) {
|
|
254
|
+
const rrdatas = (JSON.parse(a.stdout) as { rrdatas?: string[] }).rrdatas ?? [];
|
|
255
|
+
if (rrdatas.length !== 1 || rrdatas[0] !== privateIp) {
|
|
256
|
+
const u = await run([...rec, "update", ...where, "--ttl=300", `--rrdatas=${privateIp}`]);
|
|
257
|
+
if (!u.ok) return fail(`update the A record of ${fqdn}: ${u.stderr.trim()}`);
|
|
258
|
+
done.push(`DNS ${fqdn} A ${rrdatas.join(",") || "(none)"} → ${privateIp}`);
|
|
259
|
+
}
|
|
260
|
+
} else if (NOT_FOUND.test(a.stderr)) {
|
|
261
|
+
const c = await run([...rec, "create", ...where, "--ttl=300", `--rrdatas=${privateIp}`]);
|
|
262
|
+
if (!c.ok) return fail(`create the A record of ${fqdn}: ${c.stderr.trim()}`);
|
|
263
|
+
done.push(`DNS ${fqdn} A ${privateIp}`);
|
|
264
|
+
} else {
|
|
265
|
+
return fail(`describe the A record of ${fqdn}: ${a.stderr.trim()}`);
|
|
266
|
+
}
|
|
267
|
+
return { ok: true, host, done };
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/** The plain values of `names` in a service's live env (secret refs and unset vars skipped). */
|
|
271
|
+
export function liveDatabaseUrls(
|
|
272
|
+
liveEnv: ReadonlyMap<string, LiveEnvValue>,
|
|
273
|
+
names: readonly string[],
|
|
274
|
+
): Record<string, string> {
|
|
275
|
+
const out: Record<string, string> = {};
|
|
276
|
+
for (const name of names) {
|
|
277
|
+
const v = liveEnv.get(name);
|
|
278
|
+
if (v?.kind === "value" && v.value) out[name] = v.value;
|
|
279
|
+
}
|
|
280
|
+
return out;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/** Whether a database URL dials an IP literal (an unparsable one does not). */
|
|
284
|
+
export function dialsIpAddress(url: string): boolean {
|
|
285
|
+
try {
|
|
286
|
+
return isIpLiteral(new URL(url).hostname);
|
|
287
|
+
} catch {
|
|
288
|
+
return false;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* `url` with its host replaced by `host`, everything else kept — or null
|
|
294
|
+
* when it already dials a host name (nothing to move).
|
|
295
|
+
*/
|
|
296
|
+
export function urlOnDnsHost(url: string, host: string): string | null {
|
|
297
|
+
const parsed = new URL(url);
|
|
298
|
+
if (!isIpLiteral(parsed.hostname)) return null;
|
|
299
|
+
parsed.hostname = host;
|
|
300
|
+
return parsed.toString();
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Switch the live database URLs of `services` from the instance's IP to
|
|
305
|
+
* `host`, keeping their `sslmode` (the running image may not carry the CA
|
|
306
|
+
* bundle yet; the roll sets verify-full with the image that does). Every
|
|
307
|
+
* reader of the database host — the rolls, the migration job, the upgrader
|
|
308
|
+
* and operator-access jobs — takes it from these URLs, so after this they
|
|
309
|
+
* all dial the name the server's certificate carries.
|
|
310
|
+
*
|
|
311
|
+
* @param liveUrls the plain URL values each service carries now
|
|
312
|
+
*/
|
|
313
|
+
export async function moveServicesToDnsHost(
|
|
314
|
+
target: { readonly projectId: string; readonly region: string },
|
|
315
|
+
services: readonly {
|
|
316
|
+
readonly serviceName: string;
|
|
317
|
+
readonly liveUrls: Readonly<Record<string, string>>;
|
|
318
|
+
}[],
|
|
319
|
+
host: string,
|
|
320
|
+
deps: CloudSqlTlsDeps,
|
|
321
|
+
): Promise<{ ok: true; done: string[] } | { ok: false; error: string; done: string[] }> {
|
|
322
|
+
const sleep = deps.sleep ?? realSleep;
|
|
323
|
+
const done: string[] = [];
|
|
324
|
+
for (const s of services) {
|
|
325
|
+
const moved = Object.entries(s.liveUrls)
|
|
326
|
+
.map(([name, url]) => [name, urlOnDnsHost(url, host)] as const)
|
|
327
|
+
.filter((e): e is readonly [string, string] => e[1] !== null);
|
|
328
|
+
if (moved.length === 0) continue;
|
|
329
|
+
const r = await runWithRetry(deps.run, sleep, [
|
|
330
|
+
"run",
|
|
331
|
+
"services",
|
|
332
|
+
"update",
|
|
333
|
+
s.serviceName,
|
|
334
|
+
"--region",
|
|
335
|
+
target.region,
|
|
336
|
+
`--project=${target.projectId}`,
|
|
337
|
+
// ^|^ — the values carry `&` and `=`; a custom delimiter keeps gcloud
|
|
338
|
+
// from splitting them.
|
|
339
|
+
`--update-env-vars=^|^${moved.map(([n, u]) => `${n}=${u}`).join("|")}`,
|
|
340
|
+
"--quiet",
|
|
341
|
+
]);
|
|
342
|
+
if (!r.ok) {
|
|
343
|
+
return {
|
|
344
|
+
ok: false,
|
|
345
|
+
error: `move ${s.serviceName} onto the database's DNS name: ${r.stderr.trim()}`,
|
|
346
|
+
done,
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
done.push(`${s.serviceName}: ${moved.map(([n]) => n).join(", ")} → ${host}`);
|
|
350
|
+
}
|
|
351
|
+
return { ok: true, done };
|
|
352
|
+
}
|
package/src/compose.ts
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* P14 — production docker-compose.yml generator.
|
|
5
5
|
*
|
|
6
|
-
* Emits the production stack: Postgres + Caddy + the
|
|
7
|
-
* (admin, gateway). Idempotent: same
|
|
8
|
-
* byte-identical output. The CLI's `init` / `up` / `upgrade` sub-commands
|
|
6
|
+
* Emits the production stack: Postgres + Caddy + the Caelo services
|
|
7
|
+
* (admin, gateway and — #1328 — the MCP-Auth-Proxy). Idempotent: same
|
|
8
|
+
* input → byte-identical output. The CLI's `init` / `up` / `upgrade` sub-commands
|
|
9
9
|
* write this to `.caelo/docker-compose.yml`.
|
|
10
10
|
*
|
|
11
11
|
* #696 — the admin and gateway run the PREBUILT, cosign-verified release
|
|
@@ -27,23 +27,37 @@
|
|
|
27
27
|
* every fresh `docker compose up` fail.
|
|
28
28
|
*/
|
|
29
29
|
|
|
30
|
-
import { CADDY_REDIRECTS_FILE } from "@caelo-cms/shared";
|
|
30
|
+
import { CADDY_REDIRECTS_FILE, SELF_HOSTED_CA_FILE, verifyFullQuery } from "@caelo-cms/shared";
|
|
31
31
|
import { caddyRedirectReloadCommand } from "./caddy-redirects.js";
|
|
32
32
|
import { DEFAULT_MAX_CONNECTIONS, stackPoolBudget } from "./pool-budget-stack.js";
|
|
33
|
+
import {
|
|
34
|
+
SELF_HOSTED_DB_HOST,
|
|
35
|
+
SELF_HOSTED_TLS_DIR,
|
|
36
|
+
SELF_HOSTED_TLS_FILES,
|
|
37
|
+
} from "./self-hosted-db-tls.js";
|
|
33
38
|
import {
|
|
34
39
|
ADMIN_MEMORY_DEFAULT,
|
|
35
40
|
GATEWAY_TRUSTED_PROXY_HOPS,
|
|
41
|
+
MCP_AUTH_PROXY_TRUSTED_PROXY_HOPS,
|
|
36
42
|
memoryQuantityMiB,
|
|
37
43
|
publicSiteUrl,
|
|
44
|
+
REMOTE_MCP_MODE,
|
|
45
|
+
REMOTE_MCP_MODE_ENV,
|
|
38
46
|
TRUSTED_PROXY_HOPS_ENV,
|
|
39
47
|
} from "./stack-contract.js";
|
|
40
48
|
import { ghcrRepository, isImageDigest, type ReleaseService } from "./upgrade/release-images.js";
|
|
41
49
|
|
|
42
|
-
/** The
|
|
50
|
+
/** The release images, each `ghcr.io/caelo-cms/<svc>@sha256:…`. */
|
|
43
51
|
export interface ReleaseImages {
|
|
44
52
|
readonly mode: "release";
|
|
45
53
|
readonly admin: string;
|
|
46
54
|
readonly gateway: string;
|
|
55
|
+
/**
|
|
56
|
+
* #1328 — the MCP-Auth-Proxy. Absent only for a release recorded before
|
|
57
|
+
* the proxy shipped (a rollback target in release.json): its Compose file
|
|
58
|
+
* then has no proxy service, exactly as that release ran.
|
|
59
|
+
*/
|
|
60
|
+
readonly "mcp-auth-proxy"?: string;
|
|
47
61
|
}
|
|
48
62
|
|
|
49
63
|
/**
|
|
@@ -102,11 +116,20 @@ export const MEDIA_ROOT = "/data/media";
|
|
|
102
116
|
/** The gateway's HTTP port inside the Compose network. */
|
|
103
117
|
export const COMPOSE_GATEWAY_PORT = 8090;
|
|
104
118
|
|
|
119
|
+
/** #1328 — the MCP-Auth-Proxy's HTTP port inside the Compose network. */
|
|
120
|
+
export const COMPOSE_MCP_AUTH_PROXY_PORT = 8095;
|
|
121
|
+
|
|
122
|
+
/** #1328 — the Compose service name of the MCP-Auth-Proxy. */
|
|
123
|
+
export const COMPOSE_MCP_AUTH_PROXY_SERVICE = "caelo-mcp-auth-proxy";
|
|
124
|
+
|
|
105
125
|
/**
|
|
106
|
-
* The Compose services that
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
126
|
+
* The Compose services that touch the databases — what `backup` and
|
|
127
|
+
* `restore` stop while they read or rewrite them. Workers run inside the
|
|
128
|
+
* admin (CLAUDE.md §11.B Tier 5); there is no orchestrator or runner
|
|
129
|
+
* service. The MCP-Auth-Proxy (#1328) is deliberately not here: it holds no
|
|
130
|
+
* database login, so it keeps running, and a release from before it has no
|
|
131
|
+
* such service for `up` to start. Its health is checked wherever the
|
|
132
|
+
* install starts (self-hosted-start.ts) or rolls (self-hosted-upgrade.ts).
|
|
110
133
|
*/
|
|
111
134
|
export const COMPOSE_APP_SERVICES = ["caelo-admin", "caelo-gateway"] as const;
|
|
112
135
|
|
|
@@ -117,6 +140,7 @@ export const COMPOSE_APP_SERVICES = ["caelo-admin", "caelo-gateway"] as const;
|
|
|
117
140
|
*/
|
|
118
141
|
export const COMPOSE_ADMIN_UPSTREAM = `caelo-admin:${COMPOSE_ADMIN_PORT}`;
|
|
119
142
|
export const COMPOSE_GATEWAY_UPSTREAM = `caelo-gateway:${COMPOSE_GATEWAY_PORT}`;
|
|
143
|
+
export const COMPOSE_MCP_AUTH_PROXY_UPSTREAM = `${COMPOSE_MCP_AUTH_PROXY_SERVICE}:${COMPOSE_MCP_AUTH_PROXY_PORT}`;
|
|
120
144
|
|
|
121
145
|
/**
|
|
122
146
|
* The Caddy image, pinned to the release the generated Caddyfile is
|
|
@@ -213,6 +237,15 @@ export interface ComposeSpec {
|
|
|
213
237
|
* the gateway never gets it.
|
|
214
238
|
*/
|
|
215
239
|
readonly internalSecret: string;
|
|
240
|
+
/**
|
|
241
|
+
* #1338 — SHA-256 (hex) of the database server certificate the Postgres
|
|
242
|
+
* service mounts (`.caelo/postgres-tls/server.crt`). It is part of the
|
|
243
|
+
* service's environment so a renewed certificate changes the service's
|
|
244
|
+
* definition and `docker compose up -d` recreates Postgres: a bind-mounted
|
|
245
|
+
* file whose content changes does not, and Postgres would keep serving
|
|
246
|
+
* the old certificate until verify-full clients refuse it.
|
|
247
|
+
*/
|
|
248
|
+
readonly dbTlsServerCertSha256: string;
|
|
216
249
|
readonly anthropicApiKey?: string;
|
|
217
250
|
readonly resendApiKey?: string;
|
|
218
251
|
readonly diskSize: string;
|
|
@@ -223,7 +256,7 @@ export interface ComposeSpec {
|
|
|
223
256
|
* busy host never OOM-kills the admin at the limit.
|
|
224
257
|
*/
|
|
225
258
|
readonly adminMemory?: string;
|
|
226
|
-
/** Which
|
|
259
|
+
/** Which Caelo images run (see {@link ComposeImages}). */
|
|
227
260
|
readonly images: ComposeImages;
|
|
228
261
|
/**
|
|
229
262
|
* The host ports Caddy listens on (`80` / `443` for a public install —
|
|
@@ -274,6 +307,11 @@ export function generateDockerCompose(spec: ComposeSpec): string {
|
|
|
274
307
|
if (spec.internalSecret.length < 32) {
|
|
275
308
|
throw new Error("internalSecret is shorter than 32 characters (.caelo/internal-secret.json)");
|
|
276
309
|
}
|
|
310
|
+
if (!/^[0-9a-f]{64}$/.test(spec.dbTlsServerCertSha256)) {
|
|
311
|
+
throw new Error(
|
|
312
|
+
"dbTlsServerCertSha256 is not a SHA-256 hex digest of .caelo/postgres-tls/server.crt",
|
|
313
|
+
);
|
|
314
|
+
}
|
|
277
315
|
return `# SPDX-License-Identifier: MPL-2.0
|
|
278
316
|
# Generated by cms-provision — do not edit; re-run \`bunx cms-provision up\`.
|
|
279
317
|
# Domain: ${spec.domain}
|
|
@@ -281,10 +319,16 @@ export function generateDockerCompose(spec: ComposeSpec): string {
|
|
|
281
319
|
name: ${spec.project}
|
|
282
320
|
|
|
283
321
|
services:
|
|
284
|
-
|
|
322
|
+
${SELF_HOSTED_DB_HOST}:
|
|
285
323
|
image: postgres:16-alpine
|
|
286
|
-
#
|
|
287
|
-
|
|
324
|
+
# #1338 — TLS with the install's own certificate for the host name
|
|
325
|
+
# \`${SELF_HOSTED_DB_HOST}\` (self-hosted-db-tls.ts); every client connects with
|
|
326
|
+
# verify-full. Postgres refuses a key file it does not own, and a bind
|
|
327
|
+
# mount keeps the host's owner, so the entrypoint copies the pair to a
|
|
328
|
+
# container-local path owned by postgres first.
|
|
329
|
+
entrypoint: ${POSTGRES_TLS_ENTRYPOINT}
|
|
330
|
+
# The pool budget (COMPOSE_POOL_BUDGET) is computed from max_connections.
|
|
331
|
+
command: ["postgres", "-c", "max_connections=${DEFAULT_MAX_CONNECTIONS["self-hosted"]}", "-c", "ssl=on", "-c", "ssl_cert_file=${POSTGRES_TLS_RUNTIME_DIR}/server.crt", "-c", "ssl_key_file=${POSTGRES_TLS_RUNTIME_DIR}/server.key", "-c", "ssl_min_protocol_version=TLSv1.2"]
|
|
288
332
|
restart: unless-stopped
|
|
289
333
|
environment:
|
|
290
334
|
POSTGRES_PASSWORD: "${escapeYaml(spec.postgresPassword)}"
|
|
@@ -292,9 +336,13 @@ services:
|
|
|
292
336
|
POSTGRES_DB: caelo
|
|
293
337
|
ADMIN_ROLE_PASSWORD: "${escapeYaml(spec.rolePasswords.admin)}"
|
|
294
338
|
PUBLIC_ROLE_PASSWORD: "${escapeYaml(spec.rolePasswords.public)}"
|
|
339
|
+
# Recreates Postgres when its certificate is renewed (see the spec).
|
|
340
|
+
CAELO_DB_TLS_SERVER_CERT_SHA256: "${spec.dbTlsServerCertSha256}"
|
|
295
341
|
${postgresAgent(spec.agent)} volumes:
|
|
296
342
|
- caelo-pg:/var/lib/postgresql/data
|
|
297
343
|
- ./bootstrap.sh:/docker-entrypoint-initdb.d/00_bootstrap.sh:ro
|
|
344
|
+
- ./${SELF_HOSTED_TLS_DIR}/${SELF_HOSTED_TLS_FILES.serverCert}:${POSTGRES_TLS_MOUNT_DIR}/server.crt:ro
|
|
345
|
+
- ./${SELF_HOSTED_TLS_DIR}/${SELF_HOSTED_TLS_FILES.serverKey}:${POSTGRES_TLS_MOUNT_DIR}/server.key:ro
|
|
298
346
|
healthcheck:
|
|
299
347
|
test: ["CMD-SHELL", "pg_isready -U caelo"]
|
|
300
348
|
interval: 10s
|
|
@@ -317,7 +365,7 @@ ${postgresAgent(spec.agent)} volumes:
|
|
|
317
365
|
${adminService(spec, adminMemoryMiB, env)}
|
|
318
366
|
|
|
319
367
|
${gatewayService(spec)}
|
|
320
|
-
|
|
368
|
+
${mcpAuthProxyService(spec.images)}
|
|
321
369
|
volumes:
|
|
322
370
|
caelo-pg:
|
|
323
371
|
caelo-caddy-data:
|
|
@@ -369,10 +417,11 @@ function serviceRuntime(
|
|
|
369
417
|
...volumes(["../..:/app", ...mounts]),
|
|
370
418
|
].join("\n");
|
|
371
419
|
}
|
|
372
|
-
const
|
|
420
|
+
const ref = images[service] ?? "";
|
|
421
|
+
const digest = ghcrImageDigest(service, ref);
|
|
373
422
|
if (!digest) {
|
|
374
423
|
throw new Error(
|
|
375
|
-
`${service} image ${JSON.stringify(
|
|
424
|
+
`${service} image ${JSON.stringify(ref)} is not ${ghcrRepository(service)}@sha256:<digest>`,
|
|
376
425
|
);
|
|
377
426
|
}
|
|
378
427
|
// The image's own CMD starts the service; no source is mounted.
|
|
@@ -398,6 +447,7 @@ ${serviceRuntime(
|
|
|
398
447
|
`./${BOOTSTRAP_DIR}:/app/.caelo`,
|
|
399
448
|
`./output:${SITE_OUTPUT_ROOT}`,
|
|
400
449
|
`./${MEDIA_DIR}:${MEDIA_ROOT}`,
|
|
450
|
+
DATABASE_CA_MOUNT,
|
|
401
451
|
],
|
|
402
452
|
)}
|
|
403
453
|
restart: unless-stopped
|
|
@@ -422,7 +472,7 @@ ${env("RESEND_API_KEY", spec.resendApiKey)}`;
|
|
|
422
472
|
|
|
423
473
|
function gatewayService(spec: ComposeSpec): string {
|
|
424
474
|
return ` caelo-gateway:
|
|
425
|
-
${serviceRuntime(spec.images, "gateway", "bun run apps/api-gateway/src/server.ts")}
|
|
475
|
+
${serviceRuntime(spec.images, "gateway", "bun run apps/api-gateway/src/server.ts", [DATABASE_CA_MOUNT])}
|
|
426
476
|
restart: unless-stopped
|
|
427
477
|
depends_on:
|
|
428
478
|
postgres: { condition: service_healthy }
|
|
@@ -434,19 +484,70 @@ ${serviceRuntime(spec.images, "gateway", "bun run apps/api-gateway/src/server.ts
|
|
|
434
484
|
# Caddy is the one proxy in front (client-ip.ts in the gateway).
|
|
435
485
|
${TRUSTED_PROXY_HOPS_ENV}: "${GATEWAY_TRUSTED_PROXY_HOPS["self-hosted"]}"
|
|
436
486
|
${poolEnvLines("gateway")}
|
|
437
|
-
# #806 — no remote MCP here: it rides Google IAP, which this install
|
|
438
|
-
# does not have. CAELO_ADMIN_URL / CAELO_MCP_PUBLIC_URL /
|
|
439
|
-
# CAELO_OPERATOR_OAUTH_CLIENT_FILE stay unset, so the gateway's /api/mcp/*
|
|
440
|
-
# answers 503 remote_mcp_not_configured and Settings → MCP says
|
|
441
|
-
# "not available on this install".
|
|
442
487
|
NODE_ENV: production`;
|
|
443
488
|
}
|
|
444
489
|
|
|
445
|
-
/**
|
|
490
|
+
/**
|
|
491
|
+
* #1328 — the MCP-Auth-Proxy: remote MCP's sign-in broker, its own
|
|
492
|
+
* container so it never shares a process with visitor handlers. Remote MCP
|
|
493
|
+
* needs the admin behind Google IAP, which a Compose install does not have,
|
|
494
|
+
* so it runs with `CAELO_REMOTE_MCP=unavailable` and answers every request
|
|
495
|
+
* but its health check with one fixed 404 (E14 a of #763: the service
|
|
496
|
+
* exists on every provider, its attack surface one branch). Caddy serves it
|
|
497
|
+
* on its own host (`mcp.<domain>`, caddy.ts), never on the site's origin.
|
|
498
|
+
*
|
|
499
|
+
* It gets no database URL, no secret and no mount: there is nothing it
|
|
500
|
+
* could read. The container is locked down on top — read-only root
|
|
501
|
+
* filesystem, every capability dropped, no privilege escalation — because
|
|
502
|
+
* it is the Caelo service that holds operators' Google tokens wherever
|
|
503
|
+
* remote MCP runs. Empty for a release recorded before the proxy shipped
|
|
504
|
+
* ({@link ReleaseImages}).
|
|
505
|
+
*/
|
|
506
|
+
function mcpAuthProxyService(images: ComposeImages): string {
|
|
507
|
+
if (images.mode === "release" && images["mcp-auth-proxy"] === undefined) return "";
|
|
508
|
+
return `
|
|
509
|
+
${COMPOSE_MCP_AUTH_PROXY_SERVICE}:
|
|
510
|
+
${serviceRuntime(images, "mcp-auth-proxy", "bun run apps/mcp-auth-proxy/src/server.ts")}
|
|
511
|
+
restart: unless-stopped
|
|
512
|
+
read_only: true
|
|
513
|
+
tmpfs: ["/tmp"]
|
|
514
|
+
cap_drop: ["ALL"]
|
|
515
|
+
security_opt: ["no-new-privileges:true"]
|
|
516
|
+
environment:
|
|
517
|
+
CAELO_PROVIDER: "self-hosted"
|
|
518
|
+
${REMOTE_MCP_MODE_ENV}: "${REMOTE_MCP_MODE["self-hosted"]}"
|
|
519
|
+
MCP_AUTH_PROXY_PORT: "${COMPOSE_MCP_AUTH_PROXY_PORT}"
|
|
520
|
+
# Caddy is the one proxy in front (@caelo-cms/shared client-address.ts).
|
|
521
|
+
${TRUSTED_PROXY_HOPS_ENV}: "${MCP_AUTH_PROXY_TRUSTED_PROXY_HOPS["self-hosted"]}"
|
|
522
|
+
NODE_ENV: production
|
|
523
|
+
`;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
/**
|
|
527
|
+
* A compose-network database URL, password URL-encoded and YAML-escaped.
|
|
528
|
+
* #1338 — verify-full against the install's own CA (self-hosted-db-tls.ts),
|
|
529
|
+
* mounted at shared `SELF_HOSTED_CA_FILE` ({@link DATABASE_CA_MOUNT}).
|
|
530
|
+
*/
|
|
446
531
|
function dbUrl(role: string, password: string, database: string): string {
|
|
447
|
-
return escapeYaml(
|
|
532
|
+
return escapeYaml(
|
|
533
|
+
`postgres://${role}:${encodeURIComponent(password)}@${SELF_HOSTED_DB_HOST}:5432/${database}?${verifyFullQuery(SELF_HOSTED_CA_FILE)}`,
|
|
534
|
+
);
|
|
448
535
|
}
|
|
449
536
|
|
|
537
|
+
/** Where the server certificate + key are bind-mounted into Postgres (host-owned). */
|
|
538
|
+
const POSTGRES_TLS_MOUNT_DIR = "/caelo-tls";
|
|
539
|
+
/** Where the entrypoint copies them, owned by postgres (Postgres refuses others' keys). */
|
|
540
|
+
const POSTGRES_TLS_RUNTIME_DIR = "/var/lib/postgresql/caelo-tls";
|
|
541
|
+
/** The Postgres entrypoint: copy the TLS pair into place, then the image's own entrypoint. */
|
|
542
|
+
const POSTGRES_TLS_ENTRYPOINT = JSON.stringify([
|
|
543
|
+
"/bin/sh",
|
|
544
|
+
"-c",
|
|
545
|
+
`install -d -o postgres -g postgres -m 0700 ${POSTGRES_TLS_RUNTIME_DIR} && install -o postgres -g postgres -m 0644 ${POSTGRES_TLS_MOUNT_DIR}/server.crt ${POSTGRES_TLS_RUNTIME_DIR}/server.crt && install -o postgres -g postgres -m 0600 ${POSTGRES_TLS_MOUNT_DIR}/server.key ${POSTGRES_TLS_RUNTIME_DIR}/server.key && exec docker-entrypoint.sh "$$@"`,
|
|
546
|
+
"--",
|
|
547
|
+
]);
|
|
548
|
+
/** The install's database CA, read-only, where every verify-full URL names it. */
|
|
549
|
+
const DATABASE_CA_MOUNT = `./${SELF_HOSTED_TLS_DIR}/${SELF_HOSTED_TLS_FILES.caCert}:${SELF_HOSTED_CA_FILE}:ro`;
|
|
550
|
+
|
|
450
551
|
function escapeYaml(s: string): string {
|
|
451
552
|
// Conservative escape for double-quoted YAML strings.
|
|
452
553
|
return s.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
|
@@ -44,7 +44,14 @@ export const ConvergeCheckpointSchema = InstallJobStatusSchema.extend({
|
|
|
44
44
|
backupId: z.string().min(1),
|
|
45
45
|
})
|
|
46
46
|
.optional(),
|
|
47
|
-
priorRevisions: z
|
|
47
|
+
priorRevisions: z
|
|
48
|
+
.object({
|
|
49
|
+
admin: z.string().min(1),
|
|
50
|
+
gateway: z.string().min(1),
|
|
51
|
+
// #1328 — absent in a checkpoint an older release wrote.
|
|
52
|
+
"mcp-auth-proxy": z.string().min(1).optional(),
|
|
53
|
+
})
|
|
54
|
+
.optional(),
|
|
48
55
|
});
|
|
49
56
|
/**
|
|
50
57
|
* The ops-bucket prefix of the converge job's own files — outside the
|
package/src/converge-job-gcp.ts
CHANGED
|
@@ -42,7 +42,7 @@ import {
|
|
|
42
42
|
} from "./install-state.js";
|
|
43
43
|
import { runMigrationsViaCloudRunJob } from "./migration-runner.js";
|
|
44
44
|
import { installIapAllowlist } from "./operator-access.js";
|
|
45
|
-
import { fetchVerifiedReleaseManifest } from "./release-manifest.js";
|
|
45
|
+
import { fetchVerifiedReleaseManifest, manifestServiceImages } from "./release-manifest.js";
|
|
46
46
|
import type { HttpFetch } from "./runtime-secrets.js";
|
|
47
47
|
import { publicSiteUrl, STAGING_HOST_ENV } from "./stack-contract.js";
|
|
48
48
|
import { attachInstall } from "./state-attach.js";
|
|
@@ -314,16 +314,7 @@ export function gcpConvergeDeps(
|
|
|
314
314
|
sleep: realSleep,
|
|
315
315
|
reporter,
|
|
316
316
|
// The signed manifest's digests — never a registry tag lookup.
|
|
317
|
-
resolveImages: async () => (
|
|
318
|
-
ok: true,
|
|
319
|
-
images: {
|
|
320
|
-
admin: { digest: m.digests.admin, imageRef: releaseImageRef("admin", m.digests.admin) },
|
|
321
|
-
gateway: {
|
|
322
|
-
digest: m.digests.gateway,
|
|
323
|
-
imageRef: releaseImageRef("gateway", m.digests.gateway),
|
|
324
|
-
},
|
|
325
|
-
},
|
|
326
|
-
}),
|
|
317
|
+
resolveImages: async () => manifestServiceImages(m),
|
|
327
318
|
verifyImages: verifyCosignAll,
|
|
328
319
|
migrate: (imageRef) =>
|
|
329
320
|
runMigrationsViaCloudRunJob(
|