@rocket.chat/houston 0.27.0-next.3 → 2.1.9
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/LICENSE +1 -1
- package/README.md +109 -15
- package/bin/houston +62 -0
- package/data/docs/ARCHITECTURE.md +387 -0
- package/data/docs/automation.md +107 -0
- package/data/docs/e2ee.md +76 -0
- package/data/docs/eks.md +258 -0
- package/data/docs/gui.md +282 -0
- package/data/docs/guide.md +642 -0
- package/data/docs/kubernetes.md +138 -0
- package/data/docs/loadtest.md +264 -0
- package/data/docs/troubleshooting.md +203 -0
- package/data/docs/upgrading.md +84 -0
- package/data/docs/voice.md +253 -0
- package/data/iam/engineer-policy.json +11 -0
- package/data/iam/engineer-rbac.yaml +42 -0
- package/data/iam/operator-policy.json +211 -0
- package/data/loadtest/badbot.js +22 -0
- package/data/loadtest/common.js +170 -0
- package/data/loadtest/custom.js +20 -0
- package/data/loadtest/journey.js +58 -0
- package/data/loadtest/login.js +18 -0
- package/data/loadtest/messages.js +13 -0
- package/data/loadtest/mixed.js +57 -0
- package/data/loadtest/read.js +12 -0
- package/data/loadtest/webhook.js +20 -0
- package/data/monitoring/houston-logs.json +98 -0
- package/data/monitoring/k6-loadtest.json +610 -0
- package/data/monitoring/mongodb-exporter.json +3007 -0
- package/data/monitoring/node-exporter-full.json +16114 -0
- package/data/monitoring/rocketchat-metrics.json +6471 -0
- package/data/presets/airgapped.yaml +16 -0
- package/data/presets/default.yaml +9 -0
- package/data/seed/avatar-0.png +0 -0
- package/data/seed/avatar-1.png +0 -0
- package/data/seed/avatar-2.png +0 -0
- package/data/seed/avatar-3.png +0 -0
- package/data/seed/avatar-4.png +0 -0
- package/data/seed/avatar-5.png +0 -0
- package/data/seed/avatar-6.png +0 -0
- package/data/seed/avatar-7.png +0 -0
- package/data/seed/seed-metrics.csv +3 -0
- package/data/seed/seed-preview.png +0 -0
- package/data/seed/seed-report.pdf +32 -0
- package/data/seed/seed-runbook.txt +3 -0
- package/data/skill/SKILL.md +399 -0
- package/data/versions.yaml +55 -0
- package/data/voice/freeswitch/drachtio.xml +52 -0
- package/data/voice/freeswitch/public.xml +87 -0
- package/data/webui/app.css +2003 -0
- package/data/webui/index.html +678 -0
- package/data/webui/js/api.js +561 -0
- package/data/webui/js/boot.js +44 -0
- package/data/webui/js/clusters-tail.js +1377 -0
- package/data/webui/js/clusters.js +896 -0
- package/data/webui/js/create.js +276 -0
- package/data/webui/js/detail.js +507 -0
- package/data/webui/js/jobs.js +636 -0
- package/data/webui/js/logs.js +634 -0
- package/data/webui/js/main.js +14 -0
- package/data/webui/js/options.js +408 -0
- package/data/webui/js/people.js +438 -0
- package/data/webui/js/perf.js +303 -0
- package/data/webui/js/render.js +438 -0
- package/data/webui/js/shared.js +3 -0
- package/data/webui/js/state.js +583 -0
- package/data/webui/js/theme.js +123 -0
- package/data/webui/js/util.js +584 -0
- package/dist/cli/app.js +593 -0
- package/dist/cli/capabilities.js +76 -0
- package/dist/cli/cell-widths.js +495 -0
- package/dist/cli/entry.js +10 -0
- package/dist/cli/error-panel.js +492 -0
- package/dist/cli/handlers/actor.js +84 -0
- package/dist/cli/handlers/https.js +614 -0
- package/dist/cli/handlers/prompt.js +299 -0
- package/dist/cli/handlers/users.js +226 -0
- package/dist/cli/handlers.js +3694 -0
- package/dist/cli/help.js +183 -0
- package/dist/cli/index.js +15 -0
- package/dist/cli/perf.js +814 -0
- package/dist/cli/render.js +254 -0
- package/dist/cli/serve.js +858 -0
- package/dist/cli/spec-data.js +2599 -0
- package/dist/cli/spec-types.js +8 -0
- package/dist/cli/usage-error.js +520 -0
- package/dist/cli/wire.js +70 -0
- package/dist/core/audit.js +346 -0
- package/dist/core/backup-compat.js +85 -0
- package/dist/core/backup.js +1639 -0
- package/dist/core/cluster.js +1398 -0
- package/dist/core/configimport.js +345 -0
- package/dist/core/data.js +267 -0
- package/dist/core/database-of.js +82 -0
- package/dist/core/diagnose.js +159 -0
- package/dist/core/doctor.js +1518 -0
- package/dist/core/edge/acme.js +338 -0
- package/dist/core/edge/engine.js +500 -0
- package/dist/core/edge/networks.js +174 -0
- package/dist/core/edge/paths.js +107 -0
- package/dist/core/edge/routes.js +251 -0
- package/dist/core/edge/routeyml.js +195 -0
- package/dist/core/edge/runtime.js +493 -0
- package/dist/core/edge/spec.js +305 -0
- package/dist/core/edge/types.js +202 -0
- package/dist/core/eks-docs.js +135 -0
- package/dist/core/eks.js +2240 -0
- package/dist/core/envvars.js +562 -0
- package/dist/core/eventlog.js +541 -0
- package/dist/core/firstrun.js +153 -0
- package/dist/core/journal.js +694 -0
- package/dist/core/kube/ask.js +231 -0
- package/dist/core/kube/capabilities.js +269 -0
- package/dist/core/kube/certmanager.js +452 -0
- package/dist/core/kube/chart.js +413 -0
- package/dist/core/kube/cluster.js +196 -0
- package/dist/core/kube/context.js +545 -0
- package/dist/core/kube/endpoints.js +448 -0
- package/dist/core/kube/exec.js +195 -0
- package/dist/core/kube/forward.js +732 -0
- package/dist/core/kube/grafana-ingress.js +110 -0
- package/dist/core/kube/ingress.js +218 -0
- package/dist/core/kube/manifests.js +361 -0
- package/dist/core/kube/monitoring.js +768 -0
- package/dist/core/kube/names.js +237 -0
- package/dist/core/kube/namespace.js +678 -0
- package/dist/core/kube/operator.js +941 -0
- package/dist/core/kube/probe.js +202 -0
- package/dist/core/kube/reachability.js +163 -0
- package/dist/core/kube/release.js +439 -0
- package/dist/core/kube/replicaset.js +180 -0
- package/dist/core/kube/scale.js +398 -0
- package/dist/core/kube/status.js +633 -0
- package/dist/core/kube/tools.js +238 -0
- package/dist/core/kube/transfer.js +173 -0
- package/dist/core/kube/workspace.js +423 -0
- package/dist/core/lifecycle/admin.js +64 -0
- package/dist/core/lifecycle/create-docker.js +1549 -0
- package/dist/core/lifecycle/create-k8s.js +960 -0
- package/dist/core/lifecycle/destroy.js +339 -0
- package/dist/core/lifecycle/inspect.js +636 -0
- package/dist/core/lifecycle/naming.js +298 -0
- package/dist/core/lifecycle/notes.js +862 -0
- package/dist/core/lifecycle/ownership.js +313 -0
- package/dist/core/lifecycle/payload.js +401 -0
- package/dist/core/lifecycle/ports.js +388 -0
- package/dist/core/lifecycle/preconditions.js +367 -0
- package/dist/core/lifecycle/pruning.js +551 -0
- package/dist/core/lifecycle/ready.js +818 -0
- package/dist/core/lifecycle/request.js +510 -0
- package/dist/core/lifecycle/seeding.js +281 -0
- package/dist/core/lifecycle/sizing.js +392 -0
- package/dist/core/lifecycle/state.js +286 -0
- package/dist/core/lifecycle/tlsplan.js +704 -0
- package/dist/core/lifecycle/types.js +232 -0
- package/dist/core/loadtest.js +1051 -0
- package/dist/core/migrate.js +612 -0
- package/dist/core/monitor.js +494 -0
- package/dist/core/postready.js +976 -0
- package/dist/core/promote.js +804 -0
- package/dist/core/rcapi.js +1336 -0
- package/dist/core/recovery.js +75 -0
- package/dist/core/runner/engine.js +394 -0
- package/dist/core/runner/host.js +298 -0
- package/dist/core/runner/locks.js +129 -0
- package/dist/core/runner/paths.js +173 -0
- package/dist/core/runner/ports.js +172 -0
- package/dist/core/runner/queries.js +612 -0
- package/dist/core/runner/record.js +563 -0
- package/dist/core/scaleseed.js +271 -0
- package/dist/core/seed-db.js +208 -0
- package/dist/core/sessions.js +472 -0
- package/dist/core/skill.js +326 -0
- package/dist/core/sso-identities.js +172 -0
- package/dist/core/sso.js +703 -0
- package/dist/core/tls-local.js +311 -0
- package/dist/core/tls.js +878 -0
- package/dist/core/topology.js +482 -0
- package/dist/core/upgrade.js +877 -0
- package/dist/core/users.js +739 -0
- package/dist/lib/audit.js +100 -0
- package/dist/lib/close-matches.js +238 -0
- package/dist/lib/compose.js +672 -0
- package/dist/lib/config.js +1398 -0
- package/dist/lib/context.js +18 -0
- package/dist/lib/errors.js +305 -0
- package/dist/lib/events.js +208 -0
- package/dist/lib/float-text.js +126 -0
- package/dist/lib/format.js +1320 -0
- package/dist/lib/home.js +325 -0
- package/dist/lib/journal.js +122 -0
- package/dist/lib/json-text.js +733 -0
- package/dist/lib/jsonout.js +382 -0
- package/dist/lib/lock.js +516 -0
- package/dist/lib/login-name.js +202 -0
- package/dist/lib/map-limit.js +29 -0
- package/dist/lib/mkdir-parents.js +90 -0
- package/dist/lib/mongo-kernel.js +67 -0
- package/dist/lib/monitoring.js +492 -0
- package/dist/lib/platform-name.js +59 -0
- package/dist/lib/presets/common.js +390 -0
- package/dist/lib/presets/composite.js +326 -0
- package/dist/lib/presets/e2ee.js +143 -0
- package/dist/lib/presets/email.js +172 -0
- package/dist/lib/presets/guides.js +27 -0
- package/dist/lib/presets/index.js +490 -0
- package/dist/lib/presets/keycloak.js +371 -0
- package/dist/lib/presets/ldap.js +1285 -0
- package/dist/lib/presets/livechat.js +220 -0
- package/dist/lib/presets/multi-instance.js +124 -0
- package/dist/lib/presets/oidc.js +161 -0
- package/dist/lib/presets/public.js +496 -0
- package/dist/lib/presets/registry.js +64 -0
- package/dist/lib/presets/s3-minio.js +300 -0
- package/dist/lib/presets/saml.js +149 -0
- package/dist/lib/presets/scenario.js +51 -0
- package/dist/lib/presets/types.js +86 -0
- package/dist/lib/presets/voice-pbx.js +320 -0
- package/dist/lib/presets/voice.js +345 -0
- package/dist/lib/presets/webhooks.js +182 -0
- package/dist/lib/redact.js +106 -0
- package/dist/lib/seed-options.js +68 -0
- package/dist/lib/seed-profiles.js +59 -0
- package/dist/lib/targz.js +1383 -0
- package/dist/lib/teammode.js +25 -0
- package/dist/lib/tempdir.js +162 -0
- package/dist/lib/unicode-tables.js +2335 -0
- package/dist/lib/version-spec.js +357 -0
- package/dist/lib/versions.js +463 -0
- package/dist/lib/yaml-dump.js +1361 -0
- package/dist/perf/baseline.js +168 -0
- package/dist/perf/constrain.js +299 -0
- package/dist/perf/k6.js +235 -0
- package/dist/perf/mongoprof.js +171 -0
- package/dist/perf/rcmetrics.js +191 -0
- package/dist/perf/report.js +386 -0
- package/dist/perf/resources.js +236 -0
- package/dist/perf/slo.js +111 -0
- package/dist/perf/timeline.js +187 -0
- package/dist/perf/timings.js +85 -0
- package/dist/perf/verdict.js +201 -0
- package/dist/seams/aws-cli.js +126 -0
- package/dist/seams/docker-cli.js +280 -0
- package/dist/seams/exec.js +861 -0
- package/dist/seams/fs/lock.js +528 -0
- package/dist/seams/kubectl.js +83 -0
- package/dist/seams/rc-http.js +921 -0
- package/dist/seed/apply.js +190 -0
- package/dist/seed/assets.js +76 -0
- package/dist/seed/check.js +391 -0
- package/dist/seed/client.js +172 -0
- package/dist/seed/executor.js +726 -0
- package/dist/seed/history.js +281 -0
- package/dist/seed/kinds.js +91 -0
- package/dist/seed/plan.js +432 -0
- package/dist/seed/receipt.js +339 -0
- package/dist/seed/repairs.js +75 -0
- package/dist/seed/verification.js +363 -0
- package/dist/seed/wording.js +248 -0
- package/dist/web/app.js +326 -0
- package/dist/web/jobs.js +510 -0
- package/dist/web/route-deps.js +211 -0
- package/dist/web/route-table.js +213 -0
- package/dist/web/routes/backup.js +244 -0
- package/dist/web/routes/clusters.js +303 -0
- package/dist/web/routes/data.js +187 -0
- package/dist/web/routes/edge.js +82 -0
- package/dist/web/routes/index.js +63 -0
- package/dist/web/routes/jobs.js +95 -0
- package/dist/web/routes/logs.js +297 -0
- package/dist/web/routes/meta.js +191 -0
- package/dist/web/routes/people.js +151 -0
- package/dist/web/routes/perf.js +95 -0
- package/dist/web/routes/repros.js +550 -0
- package/dist/web/routes/session.js +361 -0
- package/dist/web/routes/spa.js +198 -0
- package/dist/web/security.js +475 -0
- package/dist/web/signin.js +246 -0
- package/package.json +70 -32
- package/.eslintrc +0 -94
- package/.swcrc +0 -18
- package/dist/bin.js +0 -3
- package/dist/cli.js +0 -184
- package/dist/commands/createBranch.js +0 -194
- package/dist/outputCI.js +0 -59
- package/src/bin.js +0 -4
- package/src/cli.ts +0 -25
- package/src/commands/createBranch.ts +0 -28
- package/src/outputCI.ts +0 -12
- package/src-old/logs.js +0 -323
- package/src-old/md.js +0 -191
- package/src-old/release-table.js +0 -60
- package/src-old/set-version.js +0 -614
- package/src-old/utils.js +0 -15
|
@@ -0,0 +1,704 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.tlsFromRecord = tlsFromRecord;
|
|
37
|
+
exports.recordedLocalHost = recordedLocalHost;
|
|
38
|
+
exports.nameReaches = nameReaches;
|
|
39
|
+
exports.pickChallenge = pickChallenge;
|
|
40
|
+
exports.challengeMode = challengeMode;
|
|
41
|
+
exports.resolveTls = resolveTls;
|
|
42
|
+
exports.routeKubernetesName = routeKubernetesName;
|
|
43
|
+
exports.reportWhatTheNameServes = reportWhatTheNameServes;
|
|
44
|
+
exports.publishKubernetesName = publishKubernetesName;
|
|
45
|
+
exports.refuseANameThatWillNotReach = refuseANameThatWillNotReach;
|
|
46
|
+
exports.installTheIngressMachinery = installTheIngressMachinery;
|
|
47
|
+
exports.probeTheCluster = probeTheCluster;
|
|
48
|
+
exports.kubernetesTlsPlan = kubernetesTlsPlan;
|
|
49
|
+
exports.issueDirectoryCertificate = issueDirectoryCertificate;
|
|
50
|
+
/**
|
|
51
|
+
* Everything HTTPS a workspace can be given, decided before anything is built.
|
|
52
|
+
*
|
|
53
|
+
* Tier 3. A workspace never terminates TLS -- one Traefik edge holds :80/:443 for the box and
|
|
54
|
+
* a workspace gains or loses HTTPS by a route file appearing or disappearing. So this module
|
|
55
|
+
* produces a PLAN and a name, and the create path acts on it; nothing here starts a
|
|
56
|
+
* container.
|
|
57
|
+
*/
|
|
58
|
+
const promises_1 = require("node:dns/promises");
|
|
59
|
+
const config = __importStar(require("../../lib/config"));
|
|
60
|
+
const errors_1 = require("../../lib/errors");
|
|
61
|
+
const events_1 = require("../../lib/events");
|
|
62
|
+
const format_1 = require("../../lib/format");
|
|
63
|
+
const tls_1 = require("../tls");
|
|
64
|
+
const routes_1 = require("../edge/routes");
|
|
65
|
+
const types_1 = require("../edge/types");
|
|
66
|
+
const spec_1 = require("../edge/spec");
|
|
67
|
+
const networks_1 = require("../edge/networks");
|
|
68
|
+
const engine_1 = require("../edge/engine");
|
|
69
|
+
const runtime_1 = require("../edge/runtime");
|
|
70
|
+
const certmanager_1 = require("../kube/certmanager");
|
|
71
|
+
const ingress_1 = require("../kube/ingress");
|
|
72
|
+
const cluster_1 = require("../kube/cluster");
|
|
73
|
+
const context_1 = require("../kube/context");
|
|
74
|
+
const names_1 = require("../kube/names");
|
|
75
|
+
const probe_1 = require("../kube/probe");
|
|
76
|
+
const status_1 = require("../kube/status");
|
|
77
|
+
const endpoints_1 = require("../kube/endpoints");
|
|
78
|
+
const host_1 = require("../runner/host");
|
|
79
|
+
const locks_1 = require("../runner/locks");
|
|
80
|
+
const paths = __importStar(require("../runner/paths"));
|
|
81
|
+
const record_1 = require("../runner/record");
|
|
82
|
+
const tls_local_1 = require("../tls-local");
|
|
83
|
+
const fs = __importStar(require("node:fs"));
|
|
84
|
+
const types_2 = require("./types");
|
|
85
|
+
function isTruthy(value) {
|
|
86
|
+
if (value === null || value === undefined || value === false)
|
|
87
|
+
return false;
|
|
88
|
+
if (typeof value === 'string')
|
|
89
|
+
return value !== '';
|
|
90
|
+
if (typeof value === 'number')
|
|
91
|
+
return value !== 0;
|
|
92
|
+
if (Array.isArray(value))
|
|
93
|
+
return value.length > 0;
|
|
94
|
+
if (typeof value === 'object')
|
|
95
|
+
return Object.keys(value).length > 0;
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
/** The URL's hostname, or "" when it has none. */
|
|
99
|
+
function urlHostname(value) {
|
|
100
|
+
if (!value)
|
|
101
|
+
return '';
|
|
102
|
+
try {
|
|
103
|
+
return new URL(value).hostname;
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
return '';
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function realSleep(seconds) {
|
|
110
|
+
return new Promise((resolve) => setTimeout(resolve, seconds * 1000));
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* (https, domain) an EXISTING workspace was created with, or null.
|
|
114
|
+
*
|
|
115
|
+
* Read from repro.json rather than remembered in the request, because the `up` that
|
|
116
|
+
* brings a workspace back is a different invocation -- usually a different day -- from
|
|
117
|
+
* the one that gave it a name.
|
|
118
|
+
*/
|
|
119
|
+
async function tlsFromRecord(name) {
|
|
120
|
+
if (!name || !(await paths.exists(name)))
|
|
121
|
+
return null;
|
|
122
|
+
let meta;
|
|
123
|
+
try {
|
|
124
|
+
meta = await (0, record_1.readMeta)(name);
|
|
125
|
+
}
|
|
126
|
+
catch {
|
|
127
|
+
// half-written record
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
const extra = meta.extra;
|
|
131
|
+
const mode = extra.tls;
|
|
132
|
+
if (!isTruthy(mode) || !meta.publicUrl)
|
|
133
|
+
return null;
|
|
134
|
+
if (mode === tls_1.MODE_LOCAL)
|
|
135
|
+
return [true, ''];
|
|
136
|
+
const host = meta.publicUrl.split('://').slice(-1)[0]?.split('/')[0] ?? '';
|
|
137
|
+
return host ? [false, host] : null;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* The `.localhost` name this workspace already holds a certificate for, or "".
|
|
141
|
+
*
|
|
142
|
+
* A local-CA hostname used to be re-derivable from the workspace name plus the suffix,
|
|
143
|
+
* so nothing had to remember it. Renaming the tool changed the suffix, and a later `up`
|
|
144
|
+
* would then mint a SECOND hostname for a workspace whose issued leaf, whose Traefik
|
|
145
|
+
* route and whose Rocket.Chat ROOT_URL all still say the first one.
|
|
146
|
+
*/
|
|
147
|
+
async function recordedLocalHost(name) {
|
|
148
|
+
const url = await (0, record_1.recorded)(name, 'public_url');
|
|
149
|
+
const host = urlHostname(url);
|
|
150
|
+
return host && host.endsWith('.localhost') ? host : '';
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Whether `host` resolves to the address the cluster's ingress answers on.
|
|
154
|
+
*
|
|
155
|
+
* Unresolvable is true, deliberately: a `--domain` whose DNS has not propagated yet is
|
|
156
|
+
* the normal case for a name being set up. The case this exists to catch is a name that
|
|
157
|
+
* resolves SOMEWHERE ELSE, which is a fact rather than a not-yet.
|
|
158
|
+
*/
|
|
159
|
+
async function nameReaches(host, claim) {
|
|
160
|
+
const address = claim === null ? '' : String(claim.address);
|
|
161
|
+
if (!address)
|
|
162
|
+
return false;
|
|
163
|
+
let addrs;
|
|
164
|
+
try {
|
|
165
|
+
addrs = (await (0, promises_1.lookup)(host, { all: true })).map((entry) => entry.address);
|
|
166
|
+
}
|
|
167
|
+
catch {
|
|
168
|
+
// Any resolver failure is an OS error, and every one answers the same way.
|
|
169
|
+
return true;
|
|
170
|
+
}
|
|
171
|
+
return addrs.includes(address);
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Choose the ACME challenge. Not a flag -- there is a right answer.
|
|
175
|
+
*
|
|
176
|
+
* TLS-ALPN-01 is the default and what the official compose uses. It needs Let's Encrypt
|
|
177
|
+
* to reach this host on 443, which is impossible behind NAT, behind a tunnel, or behind
|
|
178
|
+
* a proxy that terminates TLS in front of the origin.
|
|
179
|
+
*
|
|
180
|
+
* dns-01 needs none of that: the provider's API writes a TXT record and Let's Encrypt
|
|
181
|
+
* never connects here. So it is selected exactly when credentials for it exist, which is
|
|
182
|
+
* the only signal that says "the operator set this up on purpose".
|
|
183
|
+
*/
|
|
184
|
+
function pickChallenge(req, cfg, emit = events_1.nullEmit) {
|
|
185
|
+
// The escape hatch, as the edge honours it. Ignored here, `up --domain` asked for TLS-ALPN
|
|
186
|
+
// behind a tunnel or a proxy that terminates TLS, and the box's first certificate failed.
|
|
187
|
+
// A forced dns-01 still needs its credentials, below.
|
|
188
|
+
const forced = (0, types_1.forcedChallenge)(cfg);
|
|
189
|
+
if (forced === 'http' || forced === 'tlsalpn') {
|
|
190
|
+
req.acmeChallenge = forced;
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
if ((0, tls_1.dnsEnvVars)().length === 0) {
|
|
194
|
+
req.acmeChallenge = 'tlsalpn';
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
let provider = isTruthy(cfg.acme_dns_provider) ? String(cfg.acme_dns_provider) : '';
|
|
198
|
+
if (!provider) {
|
|
199
|
+
const [found, why] = (0, tls_1.inferDnsProvider)();
|
|
200
|
+
provider = found;
|
|
201
|
+
if (!provider) {
|
|
202
|
+
// Credentials are present but unreadable as a provider. Falling back to tlsalpn
|
|
203
|
+
// silently would ignore a file the user deliberately created.
|
|
204
|
+
throw new errors_1.ValidationError(`${(0, tls_1.dnsEnvPath)()} exists, so dns-01 was assumed, but the ` +
|
|
205
|
+
`provider could not be worked out: ${why}.\n` +
|
|
206
|
+
' Name it with `houston config set acme.dns_provider <name>` — ' +
|
|
207
|
+
`providers and their variables: ${tls_1.LEGO_PROVIDER_DOCS}\n` +
|
|
208
|
+
' Or delete the file to use the inbound challenge instead.');
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
const [ok, detail] = (0, tls_1.dnsCredentials)(provider);
|
|
212
|
+
if (!ok)
|
|
213
|
+
throw new errors_1.ValidationError(detail);
|
|
214
|
+
req.acmeChallenge = 'dns';
|
|
215
|
+
req.acmeDnsProvider = provider;
|
|
216
|
+
(0, events_1.info)(emit, `using the dns-01 challenge via ${provider} (${detail}) — no inbound ` +
|
|
217
|
+
'connection needed, so the workspace stays on loopback', { phase: 'tls' });
|
|
218
|
+
}
|
|
219
|
+
/** Which ACME challenge this request means, and what each one implies about the bind. */
|
|
220
|
+
function challengeMode(domain, emit, req) {
|
|
221
|
+
const cfg = config.loadConfig();
|
|
222
|
+
let mode;
|
|
223
|
+
if (domain) {
|
|
224
|
+
mode = tls_1.MODE_ACME;
|
|
225
|
+
// DOMAIN + LETSENCRYPT_EMAIL, the two the official compose asks for. The email is
|
|
226
|
+
// remembered so only the first run needs it.
|
|
227
|
+
req.acmeEmail = req.acmeEmail || (0, format_1.toText)(cfg.acme_email);
|
|
228
|
+
if (!req.acmeEmail) {
|
|
229
|
+
throw new errors_1.ValidationError("a Let's Encrypt certificate needs a contact email:\n" +
|
|
230
|
+
' houston up ... --domain ' +
|
|
231
|
+
domain +
|
|
232
|
+
' --email you@example.com\n' +
|
|
233
|
+
'It is remembered after the first use, or set it once with:\n' +
|
|
234
|
+
' houston config set acme.email you@example.com');
|
|
235
|
+
}
|
|
236
|
+
// `config.truthy`, not a truth test: a config written by an older houston holds the
|
|
237
|
+
// STRING "false", which a truth test reads as true -- so staging could never be turned
|
|
238
|
+
// back off.
|
|
239
|
+
req.acmeStaging = req.acmeStaging || config.truthy(cfg.acme_staging);
|
|
240
|
+
pickChallenge(req, cfg, emit);
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
mode = tls_1.MODE_LOCAL;
|
|
244
|
+
}
|
|
245
|
+
// The workspace stays on loopback whatever the challenge. It publishes no TLS port at
|
|
246
|
+
// all now, so there is nothing for Let's Encrypt to connect TO here -- the EDGE answers
|
|
247
|
+
// the TLS-ALPN challenge on 443, for every name it serves.
|
|
248
|
+
req.bindPublic = false;
|
|
249
|
+
return mode;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Turn the --https flags into a tls.TlsSpec, or null when --https is absent.
|
|
253
|
+
*
|
|
254
|
+
* Validates here rather than letting Traefik fail at boot: a bad combination otherwise
|
|
255
|
+
* produces a repro that comes up and serves nothing, with the reason only in `docker
|
|
256
|
+
* compose logs traefik`.
|
|
257
|
+
*/
|
|
258
|
+
/**
|
|
259
|
+
* The other workspace here that the CLUSTER serves `host` for, '' for none.
|
|
260
|
+
*
|
|
261
|
+
* A route file speaks for every name the edge serves, so `hostOwner` sees those, and `down`
|
|
262
|
+
* frees one by removing its file. A Kubernetes workspace on a cluster that owns :443 -- EKS,
|
|
263
|
+
* with no edge on this box -- has no route file: its name is served by the cluster's ingress
|
|
264
|
+
* for as long as the release is there, and `down` uninstalls it. So: a name recorded that way,
|
|
265
|
+
* by a workspace still running there. Asked of its cluster, and an unanswered ask is raised.
|
|
266
|
+
*/
|
|
267
|
+
async function clusterHostOwner(host, excluding) {
|
|
268
|
+
for (const meta of await (0, record_1.listMeta)()) {
|
|
269
|
+
const extra = meta.extra;
|
|
270
|
+
if (excluding.includes(meta.name) || extra.tls_terminates !== 'cluster')
|
|
271
|
+
continue;
|
|
272
|
+
if (isTruthy(extra.edge))
|
|
273
|
+
continue;
|
|
274
|
+
let theirs;
|
|
275
|
+
try {
|
|
276
|
+
theirs = new URL(meta.publicUrl).hostname;
|
|
277
|
+
}
|
|
278
|
+
catch {
|
|
279
|
+
continue; // an unreadable URL names no host
|
|
280
|
+
}
|
|
281
|
+
if (theirs.toLowerCase() !== host.toLowerCase())
|
|
282
|
+
continue;
|
|
283
|
+
const context = isTruthy(extra[config.EXTRA_CONTEXT])
|
|
284
|
+
? String(extra[config.EXTRA_CONTEXT])
|
|
285
|
+
: names_1.CONTEXT;
|
|
286
|
+
if (await (0, status_1.workloadExists)(meta.name, { context }))
|
|
287
|
+
return meta.name;
|
|
288
|
+
}
|
|
289
|
+
return '';
|
|
290
|
+
}
|
|
291
|
+
async function resolveTls(req, reproName, bindHost, exclude = '', emit = events_1.nullEmit) {
|
|
292
|
+
// A domain means HTTPS; requiring --https alongside it was ceremony. --https on its own
|
|
293
|
+
// selects the local-CA mode, which needs nothing else.
|
|
294
|
+
const askedLocal = req.https;
|
|
295
|
+
if (!(req.https || req.domain)) {
|
|
296
|
+
// ...unless this workspace ALREADY has an https name. `down` then `up` is the
|
|
297
|
+
// documented way to bring a workspace back ("data intact"), and it silently dropped
|
|
298
|
+
// TLS: the record went on claiming public_url while nothing served it. With --email
|
|
299
|
+
// too: skipping the record there turned a --domain workspace into a local-CA one.
|
|
300
|
+
const restored = await tlsFromRecord(exclude || reproName);
|
|
301
|
+
if (restored !== null) {
|
|
302
|
+
[req.https, req.domain] = restored;
|
|
303
|
+
(0, events_1.info)(emit, 'restoring the https name this workspace already had' +
|
|
304
|
+
(req.domain ? ` (${req.domain})` : ''), { phase: 'tls' });
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
// --email is the contact for a domain's certificate, not a mode: alone it silently chose
|
|
308
|
+
// the local CA, a name no browser on another computer opens.
|
|
309
|
+
if (req.acmeEmail && !req.domain && !askedLocal) {
|
|
310
|
+
throw new errors_1.ValidationError("--email is the Let's Encrypt contact for --domain; it needs a name. For HTTPS " +
|
|
311
|
+
'without a domain use --https (a browser on the machine running houston only).');
|
|
312
|
+
}
|
|
313
|
+
if (!(req.https || req.domain))
|
|
314
|
+
return null;
|
|
315
|
+
void bindHost;
|
|
316
|
+
// Normalized before anything else reads it: it becomes ROOT_URL, the Host() router rule
|
|
317
|
+
// and a TLS SNI name, so a scheme or trailing slash surviving this far corrupts all
|
|
318
|
+
// three at once.
|
|
319
|
+
let domain = '';
|
|
320
|
+
if (req.domain) {
|
|
321
|
+
const [normalized, fixed] = (0, tls_1.normalizeDomain)(req.domain);
|
|
322
|
+
domain = normalized;
|
|
323
|
+
if (fixed)
|
|
324
|
+
req.domain = domain; // so downstream and repro.json agree with reality
|
|
325
|
+
}
|
|
326
|
+
const mode = challengeMode(domain, emit, req);
|
|
327
|
+
// Remembered after the first use, as `serve` remembers it and as the refusal and --email's
|
|
328
|
+
// help promise: `up` read the box's address and never wrote one, so bringing an HTTPS
|
|
329
|
+
// workspace back without --email was refused.
|
|
330
|
+
if (mode === tls_1.MODE_ACME && !(0, format_1.toText)(config.loadConfig().acme_email)) {
|
|
331
|
+
await (0, locks_1.updateConfig)((cfg) => {
|
|
332
|
+
cfg.acme_email = req.acmeEmail;
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
const host = domain || (await recordedLocalHost(reproName)) || (0, tls_1.localHostFor)(reproName);
|
|
336
|
+
// Every name answers on the edge's 443. No port is allocated per workspace and no port
|
|
337
|
+
// is probed: this workspace terminates no TLS, so there is nothing to conflict with.
|
|
338
|
+
const port = 443;
|
|
339
|
+
// ONE NAME, ONE WORKSPACE. Both runtimes come through here, so this is the single place
|
|
340
|
+
// the collision can be refused.
|
|
341
|
+
let taken = (0, routes_1.hostOwner)(host, { excluding: exclude || reproName });
|
|
342
|
+
// A CLAIM WITH NO WORKSPACE BEHIND IT is released, not obeyed. A route file that outlived
|
|
343
|
+
// its record blocked every later `up --domain` with advice -- `houston down --name X` --
|
|
344
|
+
// that answered NOT_FOUND, and `prune` could not see it either: nothing could release it.
|
|
345
|
+
while (taken && !(await paths.exists(taken))) {
|
|
346
|
+
(0, routes_1.deregister)(taken);
|
|
347
|
+
// And its network: the edge stayed attached, so the vanished workspace's network could
|
|
348
|
+
// never be removed ("Resource is still in use") and outlived even `edge stop`.
|
|
349
|
+
await (0, networks_1.releaseVanished)(taken);
|
|
350
|
+
(0, events_1.info)(emit, `released ${host} from '${taken}', a workspace that no longer exists`, {
|
|
351
|
+
phase: 'tls',
|
|
352
|
+
});
|
|
353
|
+
taken = (0, routes_1.hostOwner)(host, { excluding: exclude || reproName });
|
|
354
|
+
}
|
|
355
|
+
// AND A NAME NO ROUTE FILE HOLDS. On a cluster that owns :443 itself -- EKS, with no edge
|
|
356
|
+
// on this box -- a Kubernetes workspace's name is never routed here, so the check above
|
|
357
|
+
// could not see it, and a second workspace given the same --domain was handed to the
|
|
358
|
+
// cluster's ingress beside the first.
|
|
359
|
+
const servedByCluster = taken ? '' : await clusterHostOwner(host, [reproName, exclude]);
|
|
360
|
+
if (servedByCluster) {
|
|
361
|
+
throw new errors_1.ConflictError(`${host} is already served for workspace '${servedByCluster}' by its cluster's ingress, ` +
|
|
362
|
+
'and two ingresses on one name means the controller picks one and the other never ' +
|
|
363
|
+
`answers. Use a different name, or \`houston down --name ${servedByCluster}\` first.`);
|
|
364
|
+
}
|
|
365
|
+
if (taken) {
|
|
366
|
+
throw new errors_1.ConflictError(`${host} is already served for workspace '${taken}', and the edge routes by ` +
|
|
367
|
+
'hostname -- two claims on one name means Traefik picks one and the other ' +
|
|
368
|
+
'silently never answers. Use a different name, or `houston down --name ' +
|
|
369
|
+
`${taken}\` first.`);
|
|
370
|
+
}
|
|
371
|
+
return (0, tls_1.tlsSpec)({
|
|
372
|
+
mode,
|
|
373
|
+
host,
|
|
374
|
+
port,
|
|
375
|
+
acmeEmail: req.acmeEmail,
|
|
376
|
+
acmeStaging: req.acmeStaging,
|
|
377
|
+
acmeChallenge: req.acmeChallenge,
|
|
378
|
+
acmeDnsProvider: req.acmeDnsProvider,
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Where the cluster answers plain HTTP, for an ACME name's http-01 challenge, or ''.
|
|
383
|
+
*
|
|
384
|
+
* '' for a local-CA name (no challenge), for a cluster holding this host's ports itself
|
|
385
|
+
* (the challenge reaches it directly), and -- said, not thrown -- when the cluster's :80
|
|
386
|
+
* cannot be found: the workspace still comes up, only the certificate cannot.
|
|
387
|
+
*/
|
|
388
|
+
async function challengeEndpoint(ktls, emit) {
|
|
389
|
+
if (ktls.issuer?.mode !== 'acme' || ktls.clusterOwns443)
|
|
390
|
+
return '';
|
|
391
|
+
let http;
|
|
392
|
+
try {
|
|
393
|
+
http = await (0, endpoints_1.ingressEndpoint)(String(ktls.context || ''), { port: 80 });
|
|
394
|
+
}
|
|
395
|
+
catch (error) {
|
|
396
|
+
http = null;
|
|
397
|
+
(0, events_1.warn)(emit, `could not find where cluster '${ktls.context}' answers :80: ${(0, errors_1.errorText)(error)}`, {
|
|
398
|
+
phase: 'tls',
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
if (http === null) {
|
|
402
|
+
(0, events_1.warn)(emit, `no Service in '${ktls.context}' publishes :80 to the outside, so the http-01 ` +
|
|
403
|
+
`challenge for ${ktls.host} cannot reach cert-manager and its certificate will not ` +
|
|
404
|
+
'issue. `kubectl get svc -A` — the ingress controller needs :80 as a NodePort or ' +
|
|
405
|
+
'LoadBalancer.', { phase: 'tls' });
|
|
406
|
+
return '';
|
|
407
|
+
}
|
|
408
|
+
return (0, endpoints_1.endpointString)(http);
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* Put the name in front of the cluster. BEFORE the chart, and that is not tidiness.
|
|
412
|
+
*
|
|
413
|
+
* An ACME order starts the moment cert-manager sees the Ingress -- which the chart
|
|
414
|
+
* creates during `helm install` -- and the http-01 challenge arrives on this host's :80.
|
|
415
|
+
* If the edge is not up and the route is not written by then, Let's Encrypt gets a
|
|
416
|
+
* connection refused, the order fails, and `waitForCertificate` spends its whole budget
|
|
417
|
+
* on a challenge that could never have been answered.
|
|
418
|
+
*
|
|
419
|
+
* Writing the route early is harmless in the other direction: it points at the cluster's
|
|
420
|
+
* ingress, which exists whether or not this workspace does.
|
|
421
|
+
*/
|
|
422
|
+
async function routeKubernetesName(name, ktls, { emit = events_1.nullEmit } = {}) {
|
|
423
|
+
// cert-manager's http-01 challenge comes in on this host's :80, and the edge has to hand
|
|
424
|
+
// it to the cluster rather than redirect it to HTTPS, where there is no solver.
|
|
425
|
+
const challengeTo = await challengeEndpoint(ktls, emit);
|
|
426
|
+
if (!ktls.clusterOwns443) {
|
|
427
|
+
// REBUILT FROM THE RECORD when the challenge needs :80: an edge an earlier houston
|
|
428
|
+
// wrote redirects every :80 request ahead of any route, and `ensureRunning` below
|
|
429
|
+
// recreates it only if its command changed.
|
|
430
|
+
if (challengeTo !== '')
|
|
431
|
+
await (0, spec_1.rewrite)();
|
|
432
|
+
if (challengeTo !== '' || !(await (0, engine_1.running)())) {
|
|
433
|
+
(0, events_1.info)(emit, 'starting the edge (one Traefik, :80 and :443 for every name)', { phase: 'tls' });
|
|
434
|
+
const started = await (0, runtime_1.ensureRunning)();
|
|
435
|
+
if (!started.ok) {
|
|
436
|
+
const holder = await (0, engine_1.portHolder)(443);
|
|
437
|
+
const because = holder
|
|
438
|
+
? ` — ${holder} is holding :443`
|
|
439
|
+
: started.why
|
|
440
|
+
? ` — ${started.why}`
|
|
441
|
+
: '';
|
|
442
|
+
(0, events_1.warn)(emit, `the edge did not start${because}, so ${ktls.host} will not ` +
|
|
443
|
+
'answer yet. The workspace itself is unaffected; ' +
|
|
444
|
+
(holder ? 'free the port and ' : 'once that is fixed, ') +
|
|
445
|
+
'`houston edge start`.', { phase: 'tls' });
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
if ((0, spec_1.installed)()) {
|
|
450
|
+
// THE EDGE MAY NOT BE ABLE TO REACH THE ENDPOINT YET. A kind cluster's node is a
|
|
451
|
+
// container on kind's own Docker network, so its ingress NodePort answers from the
|
|
452
|
+
// host and not from a container on the default bridge. Joining is the same mechanism
|
|
453
|
+
// `attach` uses for a workspace's network, applied to the cluster's.
|
|
454
|
+
const node = (0, endpoints_1.kindNodeContainer)(String(ktls.context || ''));
|
|
455
|
+
if (node) {
|
|
456
|
+
const net = await (0, networks_1.containerNetwork)(node);
|
|
457
|
+
if (net && (await (0, networks_1.attachNetwork)(net))) {
|
|
458
|
+
(0, events_1.info)(emit, `the edge joined the cluster's Docker network (${net}) — ` +
|
|
459
|
+
'its ingress is not reachable from the default bridge', { phase: 'tls' });
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
await (0, routes_1.register)(name, ktls.host, {
|
|
463
|
+
passthrough: (0, endpoints_1.endpointString)(ktls.endpoint),
|
|
464
|
+
passthroughHttp: challengeTo,
|
|
465
|
+
});
|
|
466
|
+
(0, events_1.info)(emit, `${ktls.host} → ${(0, endpoints_1.endpointString)(ktls.endpoint)} (${ktls.endpoint.source}), passed ` +
|
|
467
|
+
'through untouched — TLS terminates in the cluster', { phase: 'tls' });
|
|
468
|
+
}
|
|
469
|
+
else if (ktls.clusterOwns443) {
|
|
470
|
+
(0, events_1.info)(emit, `${ktls.host} is served by the cluster's own ingress, which holds ` +
|
|
471
|
+
"this host's :443 — no edge needed", { phase: 'tls' });
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
/** What the probe found, in terms the reader can act on. */
|
|
475
|
+
function reportWhatTheNameServes(certReady, emit, ktls, name, seen) {
|
|
476
|
+
if (seen.fallback && !certReady) {
|
|
477
|
+
// THE ORDINARY CASE, and it was being reported as the alarming one. An ingress
|
|
478
|
+
// controller serves its OWN default certificate for a name it has no certificate for
|
|
479
|
+
// yet -- so while cert-manager is still working through the ACME order, the cluster
|
|
480
|
+
// answers with exactly the certificate this branch used to blame on "something in
|
|
481
|
+
// front". `certReady` is false here, which says plainly that nothing was issued in
|
|
482
|
+
// time.
|
|
483
|
+
(0, events_1.warn)(emit, `${ktls.host} is answering with the ingress controller's own ` +
|
|
484
|
+
`default certificate (${seen.issuer ?? ''}) because cert-manager ` +
|
|
485
|
+
'has not issued one yet — the ACME order is usually still ' +
|
|
486
|
+
`running. The workspace is up. \`houston tls-status --name ` +
|
|
487
|
+
`${name}\` re-checks it, and \`kubectl -n houston-${name} get ` +
|
|
488
|
+
'certificate` says what cert-manager is waiting on.', { phase: 'tls' });
|
|
489
|
+
}
|
|
490
|
+
else if (seen.fallback) {
|
|
491
|
+
// The certificate IS issued and the name still answers with somebody's default one,
|
|
492
|
+
// so the cluster is not the thing terminating TLS for it.
|
|
493
|
+
(0, events_1.warn)(emit, `${ktls.host} answered with a proxy's own default certificate ` +
|
|
494
|
+
`(${seen.issuer ?? ''}), not the one in the cluster — the ` +
|
|
495
|
+
'certificate was issued, so something in front is terminating TLS ' +
|
|
496
|
+
'for this name instead of passing it through. `houston doctor` ' +
|
|
497
|
+
"names a cluster holding this host's ports.", { phase: 'tls' });
|
|
498
|
+
}
|
|
499
|
+
else if (!seen.serving) {
|
|
500
|
+
(0, events_1.warn)(emit, `nothing answered TLS for ${ktls.host} yet ` +
|
|
501
|
+
`(${seen.error ?? 'no certificate offered'}). The workspace ` +
|
|
502
|
+
`is up on its port-forward; \`houston tls-status --name ${name}\` ` +
|
|
503
|
+
're-checks the name.', { phase: 'tls' });
|
|
504
|
+
}
|
|
505
|
+
else {
|
|
506
|
+
(0, events_1.info)(emit, `https://${ktls.host} is serving the cluster's certificate (${seen.issuer ?? ''})`, {
|
|
507
|
+
phase: 'tls',
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
/**
|
|
512
|
+
* Put the name in front of the cluster, and then CHECK it rather than claim it.
|
|
513
|
+
*
|
|
514
|
+
* Two topologies, both normal, and the difference decides whether the edge is needed at
|
|
515
|
+
* all. The check at the end is the part that matters: measured on a box where the edge
|
|
516
|
+
* was bound, running, healthy, and answering every https name with its own default
|
|
517
|
+
* certificate because the cluster had taken the port underneath it.
|
|
518
|
+
*/
|
|
519
|
+
async function publishKubernetesName(name, ktls, { certReady = true, emit = events_1.nullEmit, sleep = realSleep, } = {}) {
|
|
520
|
+
if (ktls.issuer?.mode === 'acme') {
|
|
521
|
+
(0, tls_1.recordIssuance)(ktls.host, '', `${ktls.context}:workspace:${name}`);
|
|
522
|
+
const warning = (0, tls_1.budgetWarning)(ktls.host);
|
|
523
|
+
if (warning)
|
|
524
|
+
(0, events_1.warn)(emit, warning, { phase: 'tls' });
|
|
525
|
+
}
|
|
526
|
+
// ONLY for the local issuer. A Let's Encrypt certificate is checked against the SYSTEM
|
|
527
|
+
// store -- that is the whole claim being made about it -- and houston's own CA may not
|
|
528
|
+
// even exist on a box that has only ever used `--domain`.
|
|
529
|
+
const cafile = (ktls.issuer?.mode ?? 'local') !== 'acme' ? `${(0, tls_1.caDir)()}/${tls_1.CA_CRT}` : '';
|
|
530
|
+
let seen = null;
|
|
531
|
+
let fronted = '';
|
|
532
|
+
for (let attempt = 0; attempt < types_2.PUBLISH_PROOF_TRIES; attempt += 1) {
|
|
533
|
+
seen = await (0, tls_1.verify)(ktls.host, cafile ? { port: 443, cafile } : { port: 443 });
|
|
534
|
+
// WHOSE certificate, when the edge passes the name through: a CDN in front answers the
|
|
535
|
+
// name with its own valid one. Behind Cloudflare this said "serving the cluster's
|
|
536
|
+
// certificate (Google Trust Services WE1)" while the cluster had issued nothing. The
|
|
537
|
+
// origin -- the ingress the edge hands the bytes to, asked with the name -- decides; an
|
|
538
|
+
// origin this machine cannot reach leaves the name's answer standing.
|
|
539
|
+
if (!ktls.clusterOwns443 && seen.serving && !seen.fallback) {
|
|
540
|
+
const origin = await (0, tls_1.verify)(ktls.endpoint.address, {
|
|
541
|
+
port: ktls.endpoint.port,
|
|
542
|
+
sni: ktls.host,
|
|
543
|
+
...(cafile ? { cafile } : {}),
|
|
544
|
+
});
|
|
545
|
+
if (origin.serving) {
|
|
546
|
+
fronted = origin.issuer !== seen.issuer ? seen.issuer : '';
|
|
547
|
+
seen = origin;
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
if (seen.serving && !seen.fallback)
|
|
551
|
+
break;
|
|
552
|
+
if (attempt < types_2.PUBLISH_PROOF_TRIES - 1)
|
|
553
|
+
await sleep(types_2.PUBLISH_PROOF_PAUSE);
|
|
554
|
+
}
|
|
555
|
+
reportWhatTheNameServes(certReady, emit, ktls, name, seen ?? {});
|
|
556
|
+
if (fronted !== '') {
|
|
557
|
+
(0, events_1.info)(emit, `${ktls.host} itself answers with ${fronted}: something in front of this machine (a ` +
|
|
558
|
+
"CDN or proxy) terminates TLS for the name, so browsers see its certificate, not the cluster's", { phase: 'tls' });
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
/** Every reason this name cannot be served, checked before anything is installed. */
|
|
562
|
+
async function refuseANameThatWillNotReach(claim, emit, endpoint, remoteIngress, spec, tlsspec) {
|
|
563
|
+
const endpointAddress = endpoint === null ? '' : endpoint.address;
|
|
564
|
+
if (spec.mode === 'acme') {
|
|
565
|
+
(0, events_1.info)(emit, remoteIngress
|
|
566
|
+
? "the http-01 challenge goes straight to the cluster's own load " +
|
|
567
|
+
`balancer (${endpointAddress}) — this machine is not in the path`
|
|
568
|
+
: claim !== null && (claim.ports ?? []).includes(80)
|
|
569
|
+
? "the http-01 challenge will reach the cluster's ingress directly " +
|
|
570
|
+
"— it holds this host's :80"
|
|
571
|
+
: "the http-01 challenge arrives on the edge's :80 and is routed to the " +
|
|
572
|
+
"cluster's own :80, ahead of the edge's HTTPS redirect", { phase: 'tls' });
|
|
573
|
+
}
|
|
574
|
+
// WHETHER THIS HOSTNAME REACHES THE CLUSTER, not whether the cluster holds *a* host
|
|
575
|
+
// address. k3s ServiceLB claims :443 at the host's own address, so `claim` said yes --
|
|
576
|
+
// while `<name>.houston.localhost` resolves to ::1 first, klipper's DNAT is IPv4-only,
|
|
577
|
+
// and the edge is what answers there.
|
|
578
|
+
let owns = claim !== null && (claim.ports ?? []).includes(443);
|
|
579
|
+
if (owns && !(await nameReaches(tlsspec.host, claim))) {
|
|
580
|
+
(0, events_1.info)(emit, `${tlsspec.host} does not resolve to the cluster's ingress ` +
|
|
581
|
+
`(${claim === null ? '' : claim.address}), so the name is published through the edge ` +
|
|
582
|
+
'rather than straight at the cluster', { phase: 'tls' });
|
|
583
|
+
owns = false;
|
|
584
|
+
}
|
|
585
|
+
// A REMOTE INGRESS CANNOT BE FRONTED BY A LOCAL EDGE, so there is nothing here to
|
|
586
|
+
// decide. `claim` asks whether the cluster holds THIS HOST's :443, which for any
|
|
587
|
+
// managed cluster is definitionally no.
|
|
588
|
+
return owns;
|
|
589
|
+
}
|
|
590
|
+
/**
|
|
591
|
+
* cert-manager and an ingress controller, and where the cluster is receiving.
|
|
592
|
+
*
|
|
593
|
+
* ADOPT WHAT IS THERE, INSTALL WHAT IS NOT -- and this is the FIRST thing on this path
|
|
594
|
+
* that changes the cluster, which is why every refusal above it is a read.
|
|
595
|
+
*/
|
|
596
|
+
async function installTheIngressMachinery(asked, context, emit, plan, pre, req) {
|
|
597
|
+
const where = pre.distribution || plan.distribution;
|
|
598
|
+
// THE GUIDE'S TWO PREREQUISITES, in the order they depend on each other. Both are
|
|
599
|
+
// adopted when the cluster has them and installed with the guide's own command when it
|
|
600
|
+
// does not; both refuse on a cluster that is not on this machine, where CRDs and a
|
|
601
|
+
// LoadBalancer are somebody else's to create; and neither is ever removed.
|
|
602
|
+
//
|
|
603
|
+
// cert-manager first: it is what the ingress annotation will name, and an issuer
|
|
604
|
+
// created before its webhook is serving is accepted and then never reconciled.
|
|
605
|
+
await (0, certmanager_1.ensureCertManager)({ context, distribution: where, emit });
|
|
606
|
+
const ingressClass = await (0, ingress_1.ensureIngress)({
|
|
607
|
+
context,
|
|
608
|
+
distribution: where,
|
|
609
|
+
prefer: req.ingressClass,
|
|
610
|
+
emit,
|
|
611
|
+
});
|
|
612
|
+
// AFTER `ensureIngress`, because on a cluster that had none the ingress Service is
|
|
613
|
+
// something houston has just created. Read before it, this found nothing and refused
|
|
614
|
+
// for want of the thing it was about to install.
|
|
615
|
+
const endpoint = await (0, endpoints_1.ingressEndpoint)(context);
|
|
616
|
+
if (endpoint === null) {
|
|
617
|
+
throw new errors_1.PreflightError(`${asked}: cluster '${context}' has the ingress class '${ingressClass}' but ` +
|
|
618
|
+
'no Service publishing :443 that can be reached from outside it, so ' +
|
|
619
|
+
"nothing can route to this workspace's name. `kubectl get svc -A` — the " +
|
|
620
|
+
"controller's Service needs to be a LoadBalancer or a NodePort. An " +
|
|
621
|
+
'ingress exposed by a hostPort DaemonSet has none to find.');
|
|
622
|
+
}
|
|
623
|
+
const claim = await (0, endpoints_1.hostPortClaim)(context);
|
|
624
|
+
return [claim, endpoint, ingressClass];
|
|
625
|
+
}
|
|
626
|
+
/**
|
|
627
|
+
* Bring the cluster up if it is ours to, probe it, and refuse a local CA it cannot be
|
|
628
|
+
* taught to trust.
|
|
629
|
+
*
|
|
630
|
+
* THE CLUSTER HAS TO EXIST BEFORE IT CAN BE ASKED ANYTHING. This used to refuse outright
|
|
631
|
+
* when `plan.create` was set -- there was nothing to probe and houston installed no
|
|
632
|
+
* ingress controller, so `--https` on a box whose only Kubernetes was a not-yet-created
|
|
633
|
+
* kind cluster was a dead end.
|
|
634
|
+
*/
|
|
635
|
+
async function probeTheCluster(emit, plan, spec) {
|
|
636
|
+
const context = plan.create ? await (0, cluster_1.ensureKubeconfig)(plan, emit) : plan.context;
|
|
637
|
+
const pre = await (0, probe_1.preflight)(context);
|
|
638
|
+
// WHERE THE CA KEY WOULD GO. `tls-local.ts`: this key "can mint a certificate for any name
|
|
639
|
+
// the browser will trust". On this machine's own cluster that is the same trust boundary
|
|
640
|
+
// as the box. On somebody else's it is not, and there is a better answer that needs no
|
|
641
|
+
// CA at all.
|
|
642
|
+
if (spec.mode === 'local' &&
|
|
643
|
+
!(await (0, context_1.isLocalCluster)(pre.distribution || plan.distribution, context))) {
|
|
644
|
+
throw new errors_1.AuthorityGateError("--https would copy houston's CA private key into a Secret in cluster " +
|
|
645
|
+
`'${context}', which is not on this machine ` +
|
|
646
|
+
`(${pre.distribution || plan.distribution || 'unknown'}). That key can ` +
|
|
647
|
+
'mint a certificate for any name this box trusts, so it does not leave ' +
|
|
648
|
+
'here. Use --domain for a publicly-trusted certificate instead, or ' +
|
|
649
|
+
'reach the workspace on its port-forward.', { code: 'GATE_UNAPPROVED_CLUSTER' });
|
|
650
|
+
}
|
|
651
|
+
return [context, pre];
|
|
652
|
+
}
|
|
653
|
+
/**
|
|
654
|
+
* Refuse, or return what the ingress needs. Reads only; writes nothing.
|
|
655
|
+
*
|
|
656
|
+
* Every refusal here costs one probe and no state. That ordering is the point: an
|
|
657
|
+
* `up --https` that cannot work should say so in a second, not after four minutes of
|
|
658
|
+
* MongoDB and a chart install.
|
|
659
|
+
*/
|
|
660
|
+
async function kubernetesTlsPlan(req, tlsspec, plan, { emit = events_1.nullEmit } = {}) {
|
|
661
|
+
// Both modes are honoured now, and they are the same code path with a different
|
|
662
|
+
// ClusterIssuer -- which is what the official values.yaml already implies.
|
|
663
|
+
const spec = {
|
|
664
|
+
mode: tlsspec.mode === tls_1.MODE_ACME ? 'acme' : 'local',
|
|
665
|
+
acmeEmail: tlsspec.acmeEmail,
|
|
666
|
+
acmeStaging: tlsspec.acmeStaging,
|
|
667
|
+
};
|
|
668
|
+
// Which request every refusal below is about. Defined here, beside the spec it is
|
|
669
|
+
// derived from, because the first refusal comes before the cluster is even probed.
|
|
670
|
+
const asked = spec.mode === 'acme' ? '--domain' : '--https';
|
|
671
|
+
const [context, pre] = await probeTheCluster(emit, plan, spec);
|
|
672
|
+
const [claim, endpoint, ingressClass] = await installTheIngressMachinery(asked, context, emit, plan, pre, req);
|
|
673
|
+
const remoteIngress = !endpoint.local;
|
|
674
|
+
let owns = await refuseANameThatWillNotReach(claim, emit, endpoint, remoteIngress, spec, tlsspec);
|
|
675
|
+
if (!owns && remoteIngress)
|
|
676
|
+
owns = true;
|
|
677
|
+
// THE EDGE IS A DOCKER CONTAINER. Without Docker it could not start, and `ready` then
|
|
678
|
+
// waited out its whole budget on a name nothing would answer: refuse before MongoDB and
|
|
679
|
+
// the chart, naming the cause. Only here, once it is known the name needs the edge.
|
|
680
|
+
if (!owns && !(await (0, host_1.dockerAvailable)())) {
|
|
681
|
+
throw new errors_1.PreflightError(`${asked}: ${tlsspec.host} is served through houston's edge, a Traefik container, ` +
|
|
682
|
+
'and Docker is not available on this machine. Install or start Docker ' +
|
|
683
|
+
`(\`houston doctor\` checks it) and run this again, or leave out ${asked} and ` +
|
|
684
|
+
'reach the workspace on its port-forward.');
|
|
685
|
+
}
|
|
686
|
+
return (0, types_2.kubeTls)({
|
|
687
|
+
host: tlsspec.host,
|
|
688
|
+
ingressClass,
|
|
689
|
+
endpoint: { ...endpoint },
|
|
690
|
+
issuer: spec,
|
|
691
|
+
context,
|
|
692
|
+
clusterOwns443: owns,
|
|
693
|
+
});
|
|
694
|
+
}
|
|
695
|
+
/**
|
|
696
|
+
* A certificate for a preset's directory, signed by houston's own CA, the one `trust-ca`
|
|
697
|
+
* installs: for `--set tls=ldaps|starttls` on the ldap preset. The name is the service name
|
|
698
|
+
* Rocket.Chat dials on either runtime.
|
|
699
|
+
*/
|
|
700
|
+
async function issueDirectoryCertificate(host = 'openldap') {
|
|
701
|
+
const [, caCrt] = await (0, tls_local_1.ensureCa)();
|
|
702
|
+
const [crt, key] = await (0, tls_local_1.issueLeaf)(host, [host]);
|
|
703
|
+
return { crt, key, ca: fs.readFileSync(caCrt, 'utf8') };
|
|
704
|
+
}
|