@rocket.chat/houston 0.27.0-next.3 → 2.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (293) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +108 -15
  3. package/bin/houston +62 -0
  4. package/data/docs/ARCHITECTURE.md +387 -0
  5. package/data/docs/automation.md +107 -0
  6. package/data/docs/e2ee.md +76 -0
  7. package/data/docs/eks.md +258 -0
  8. package/data/docs/gui.md +282 -0
  9. package/data/docs/guide.md +669 -0
  10. package/data/docs/kubernetes.md +138 -0
  11. package/data/docs/troubleshooting.md +193 -0
  12. package/data/docs/upgrading.md +84 -0
  13. package/data/docs/voice.md +253 -0
  14. package/data/iam/engineer-policy.json +11 -0
  15. package/data/iam/engineer-rbac.yaml +42 -0
  16. package/data/iam/operator-policy.json +211 -0
  17. package/data/loadtest/badbot.js +22 -0
  18. package/data/loadtest/common.js +168 -0
  19. package/data/loadtest/custom.js +20 -0
  20. package/data/loadtest/journey.js +58 -0
  21. package/data/loadtest/login.js +18 -0
  22. package/data/loadtest/messages.js +13 -0
  23. package/data/loadtest/mixed.js +39 -0
  24. package/data/loadtest/read.js +12 -0
  25. package/data/loadtest/webhook.js +20 -0
  26. package/data/monitoring/houston-logs.json +98 -0
  27. package/data/monitoring/k6-loadtest.json +610 -0
  28. package/data/monitoring/mongodb-exporter.json +3007 -0
  29. package/data/monitoring/node-exporter-full.json +16114 -0
  30. package/data/monitoring/rocketchat-metrics.json +6471 -0
  31. package/data/presets/airgapped.yaml +16 -0
  32. package/data/presets/default.yaml +9 -0
  33. package/data/seed/avatar-0.png +0 -0
  34. package/data/seed/avatar-1.png +0 -0
  35. package/data/seed/avatar-2.png +0 -0
  36. package/data/seed/avatar-3.png +0 -0
  37. package/data/seed/avatar-4.png +0 -0
  38. package/data/seed/avatar-5.png +0 -0
  39. package/data/seed/avatar-6.png +0 -0
  40. package/data/seed/avatar-7.png +0 -0
  41. package/data/seed/seed-metrics.csv +3 -0
  42. package/data/seed/seed-preview.png +0 -0
  43. package/data/seed/seed-report.pdf +32 -0
  44. package/data/seed/seed-runbook.txt +3 -0
  45. package/data/skill/SKILL.md +399 -0
  46. package/data/versions.yaml +55 -0
  47. package/data/voice/freeswitch/drachtio.xml +52 -0
  48. package/data/voice/freeswitch/public.xml +87 -0
  49. package/data/webui/app.css +2003 -0
  50. package/data/webui/index.html +678 -0
  51. package/data/webui/js/api.js +561 -0
  52. package/data/webui/js/boot.js +44 -0
  53. package/data/webui/js/clusters-tail.js +1377 -0
  54. package/data/webui/js/clusters.js +896 -0
  55. package/data/webui/js/create.js +276 -0
  56. package/data/webui/js/detail.js +507 -0
  57. package/data/webui/js/jobs.js +636 -0
  58. package/data/webui/js/logs.js +634 -0
  59. package/data/webui/js/main.js +14 -0
  60. package/data/webui/js/options.js +408 -0
  61. package/data/webui/js/people.js +438 -0
  62. package/data/webui/js/perf.js +303 -0
  63. package/data/webui/js/render.js +438 -0
  64. package/data/webui/js/shared.js +3 -0
  65. package/data/webui/js/state.js +583 -0
  66. package/data/webui/js/theme.js +123 -0
  67. package/data/webui/js/util.js +584 -0
  68. package/dist/cli/app.js +593 -0
  69. package/dist/cli/capabilities.js +76 -0
  70. package/dist/cli/cell-widths.js +495 -0
  71. package/dist/cli/entry.js +10 -0
  72. package/dist/cli/error-panel.js +492 -0
  73. package/dist/cli/handlers/actor.js +84 -0
  74. package/dist/cli/handlers/https.js +614 -0
  75. package/dist/cli/handlers/prompt.js +299 -0
  76. package/dist/cli/handlers/users.js +226 -0
  77. package/dist/cli/handlers.js +3678 -0
  78. package/dist/cli/help.js +183 -0
  79. package/dist/cli/index.js +15 -0
  80. package/dist/cli/perf.js +810 -0
  81. package/dist/cli/render.js +254 -0
  82. package/dist/cli/serve.js +858 -0
  83. package/dist/cli/spec-data.js +2593 -0
  84. package/dist/cli/spec-types.js +8 -0
  85. package/dist/cli/usage-error.js +520 -0
  86. package/dist/cli/wire.js +70 -0
  87. package/dist/core/audit.js +346 -0
  88. package/dist/core/backup-compat.js +85 -0
  89. package/dist/core/backup.js +1639 -0
  90. package/dist/core/cluster.js +1398 -0
  91. package/dist/core/configimport.js +344 -0
  92. package/dist/core/data.js +267 -0
  93. package/dist/core/database-of.js +82 -0
  94. package/dist/core/diagnose.js +159 -0
  95. package/dist/core/doctor.js +1518 -0
  96. package/dist/core/edge/acme.js +338 -0
  97. package/dist/core/edge/engine.js +500 -0
  98. package/dist/core/edge/networks.js +174 -0
  99. package/dist/core/edge/paths.js +107 -0
  100. package/dist/core/edge/routes.js +251 -0
  101. package/dist/core/edge/routeyml.js +195 -0
  102. package/dist/core/edge/runtime.js +493 -0
  103. package/dist/core/edge/spec.js +305 -0
  104. package/dist/core/edge/types.js +202 -0
  105. package/dist/core/eks-docs.js +135 -0
  106. package/dist/core/eks.js +2240 -0
  107. package/dist/core/envvars.js +562 -0
  108. package/dist/core/eventlog.js +541 -0
  109. package/dist/core/firstrun.js +153 -0
  110. package/dist/core/journal.js +691 -0
  111. package/dist/core/kube/ask.js +231 -0
  112. package/dist/core/kube/capabilities.js +269 -0
  113. package/dist/core/kube/certmanager.js +452 -0
  114. package/dist/core/kube/chart.js +413 -0
  115. package/dist/core/kube/cluster.js +196 -0
  116. package/dist/core/kube/context.js +545 -0
  117. package/dist/core/kube/endpoints.js +448 -0
  118. package/dist/core/kube/exec.js +195 -0
  119. package/dist/core/kube/forward.js +732 -0
  120. package/dist/core/kube/grafana-ingress.js +110 -0
  121. package/dist/core/kube/ingress.js +218 -0
  122. package/dist/core/kube/manifests.js +361 -0
  123. package/dist/core/kube/monitoring.js +768 -0
  124. package/dist/core/kube/names.js +237 -0
  125. package/dist/core/kube/namespace.js +678 -0
  126. package/dist/core/kube/operator.js +941 -0
  127. package/dist/core/kube/probe.js +202 -0
  128. package/dist/core/kube/reachability.js +163 -0
  129. package/dist/core/kube/release.js +439 -0
  130. package/dist/core/kube/replicaset.js +180 -0
  131. package/dist/core/kube/scale.js +398 -0
  132. package/dist/core/kube/status.js +633 -0
  133. package/dist/core/kube/tools.js +238 -0
  134. package/dist/core/kube/transfer.js +173 -0
  135. package/dist/core/kube/workspace.js +423 -0
  136. package/dist/core/lifecycle/admin.js +64 -0
  137. package/dist/core/lifecycle/create-docker.js +1533 -0
  138. package/dist/core/lifecycle/create-k8s.js +939 -0
  139. package/dist/core/lifecycle/destroy.js +339 -0
  140. package/dist/core/lifecycle/inspect.js +635 -0
  141. package/dist/core/lifecycle/naming.js +298 -0
  142. package/dist/core/lifecycle/notes.js +726 -0
  143. package/dist/core/lifecycle/ownership.js +313 -0
  144. package/dist/core/lifecycle/payload.js +401 -0
  145. package/dist/core/lifecycle/ports.js +388 -0
  146. package/dist/core/lifecycle/preconditions.js +367 -0
  147. package/dist/core/lifecycle/pruning.js +551 -0
  148. package/dist/core/lifecycle/ready.js +753 -0
  149. package/dist/core/lifecycle/request.js +525 -0
  150. package/dist/core/lifecycle/seeding.js +281 -0
  151. package/dist/core/lifecycle/sizing.js +392 -0
  152. package/dist/core/lifecycle/state.js +286 -0
  153. package/dist/core/lifecycle/tlsplan.js +704 -0
  154. package/dist/core/lifecycle/types.js +232 -0
  155. package/dist/core/loadtest.js +995 -0
  156. package/dist/core/migrate.js +612 -0
  157. package/dist/core/monitor.js +494 -0
  158. package/dist/core/postready.js +969 -0
  159. package/dist/core/promote.js +804 -0
  160. package/dist/core/rcapi.js +1285 -0
  161. package/dist/core/recovery.js +75 -0
  162. package/dist/core/runner/engine.js +394 -0
  163. package/dist/core/runner/host.js +298 -0
  164. package/dist/core/runner/locks.js +129 -0
  165. package/dist/core/runner/paths.js +173 -0
  166. package/dist/core/runner/ports.js +172 -0
  167. package/dist/core/runner/queries.js +612 -0
  168. package/dist/core/runner/record.js +563 -0
  169. package/dist/core/scaleseed.js +271 -0
  170. package/dist/core/seed-db.js +208 -0
  171. package/dist/core/sessions.js +472 -0
  172. package/dist/core/skill.js +326 -0
  173. package/dist/core/sso-identities.js +172 -0
  174. package/dist/core/sso.js +703 -0
  175. package/dist/core/tls-local.js +311 -0
  176. package/dist/core/tls.js +878 -0
  177. package/dist/core/topology.js +482 -0
  178. package/dist/core/upgrade.js +868 -0
  179. package/dist/core/users.js +739 -0
  180. package/dist/lib/audit.js +100 -0
  181. package/dist/lib/close-matches.js +238 -0
  182. package/dist/lib/compose.js +672 -0
  183. package/dist/lib/config.js +1398 -0
  184. package/dist/lib/context.js +18 -0
  185. package/dist/lib/errors.js +305 -0
  186. package/dist/lib/events.js +208 -0
  187. package/dist/lib/float-text.js +126 -0
  188. package/dist/lib/format.js +1320 -0
  189. package/dist/lib/home.js +325 -0
  190. package/dist/lib/journal.js +122 -0
  191. package/dist/lib/json-text.js +733 -0
  192. package/dist/lib/jsonout.js +382 -0
  193. package/dist/lib/lock.js +516 -0
  194. package/dist/lib/login-name.js +202 -0
  195. package/dist/lib/map-limit.js +29 -0
  196. package/dist/lib/mkdir-parents.js +90 -0
  197. package/dist/lib/mongo-kernel.js +67 -0
  198. package/dist/lib/monitoring.js +492 -0
  199. package/dist/lib/platform-name.js +59 -0
  200. package/dist/lib/presets/common.js +390 -0
  201. package/dist/lib/presets/composite.js +326 -0
  202. package/dist/lib/presets/e2ee.js +143 -0
  203. package/dist/lib/presets/email.js +172 -0
  204. package/dist/lib/presets/guides.js +27 -0
  205. package/dist/lib/presets/index.js +490 -0
  206. package/dist/lib/presets/keycloak.js +369 -0
  207. package/dist/lib/presets/ldap.js +1285 -0
  208. package/dist/lib/presets/livechat.js +220 -0
  209. package/dist/lib/presets/multi-instance.js +124 -0
  210. package/dist/lib/presets/oidc.js +161 -0
  211. package/dist/lib/presets/public.js +496 -0
  212. package/dist/lib/presets/registry.js +64 -0
  213. package/dist/lib/presets/s3-minio.js +300 -0
  214. package/dist/lib/presets/saml.js +149 -0
  215. package/dist/lib/presets/scenario.js +51 -0
  216. package/dist/lib/presets/types.js +86 -0
  217. package/dist/lib/presets/voice-pbx.js +320 -0
  218. package/dist/lib/presets/voice.js +345 -0
  219. package/dist/lib/presets/webhooks.js +182 -0
  220. package/dist/lib/redact.js +106 -0
  221. package/dist/lib/seed-options.js +68 -0
  222. package/dist/lib/seed-profiles.js +59 -0
  223. package/dist/lib/targz.js +1383 -0
  224. package/dist/lib/teammode.js +25 -0
  225. package/dist/lib/tempdir.js +162 -0
  226. package/dist/lib/unicode-tables.js +2335 -0
  227. package/dist/lib/version-spec.js +357 -0
  228. package/dist/lib/versions.js +463 -0
  229. package/dist/lib/yaml-dump.js +1361 -0
  230. package/dist/perf/baseline.js +168 -0
  231. package/dist/perf/constrain.js +296 -0
  232. package/dist/perf/k6.js +235 -0
  233. package/dist/perf/mongoprof.js +171 -0
  234. package/dist/perf/rcmetrics.js +178 -0
  235. package/dist/perf/report.js +386 -0
  236. package/dist/perf/resources.js +224 -0
  237. package/dist/perf/slo.js +111 -0
  238. package/dist/perf/timeline.js +187 -0
  239. package/dist/perf/timings.js +85 -0
  240. package/dist/perf/verdict.js +201 -0
  241. package/dist/seams/aws-cli.js +126 -0
  242. package/dist/seams/docker-cli.js +280 -0
  243. package/dist/seams/exec.js +861 -0
  244. package/dist/seams/fs/lock.js +528 -0
  245. package/dist/seams/kubectl.js +83 -0
  246. package/dist/seams/rc-http.js +921 -0
  247. package/dist/seed/apply.js +190 -0
  248. package/dist/seed/assets.js +76 -0
  249. package/dist/seed/check.js +391 -0
  250. package/dist/seed/client.js +172 -0
  251. package/dist/seed/executor.js +726 -0
  252. package/dist/seed/history.js +281 -0
  253. package/dist/seed/kinds.js +91 -0
  254. package/dist/seed/plan.js +432 -0
  255. package/dist/seed/receipt.js +339 -0
  256. package/dist/seed/repairs.js +75 -0
  257. package/dist/seed/verification.js +363 -0
  258. package/dist/seed/wording.js +248 -0
  259. package/dist/web/app.js +326 -0
  260. package/dist/web/jobs.js +510 -0
  261. package/dist/web/route-deps.js +211 -0
  262. package/dist/web/route-table.js +213 -0
  263. package/dist/web/routes/backup.js +244 -0
  264. package/dist/web/routes/clusters.js +303 -0
  265. package/dist/web/routes/data.js +187 -0
  266. package/dist/web/routes/edge.js +82 -0
  267. package/dist/web/routes/index.js +63 -0
  268. package/dist/web/routes/jobs.js +95 -0
  269. package/dist/web/routes/logs.js +297 -0
  270. package/dist/web/routes/meta.js +191 -0
  271. package/dist/web/routes/people.js +151 -0
  272. package/dist/web/routes/perf.js +95 -0
  273. package/dist/web/routes/repros.js +550 -0
  274. package/dist/web/routes/session.js +361 -0
  275. package/dist/web/routes/spa.js +198 -0
  276. package/dist/web/security.js +475 -0
  277. package/dist/web/signin.js +246 -0
  278. package/package.json +67 -32
  279. package/.eslintrc +0 -94
  280. package/.swcrc +0 -18
  281. package/dist/bin.js +0 -3
  282. package/dist/cli.js +0 -184
  283. package/dist/commands/createBranch.js +0 -194
  284. package/dist/outputCI.js +0 -59
  285. package/src/bin.js +0 -4
  286. package/src/cli.ts +0 -25
  287. package/src/commands/createBranch.ts +0 -28
  288. package/src/outputCI.ts +0 -12
  289. package/src-old/logs.js +0 -323
  290. package/src-old/md.js +0 -191
  291. package/src-old/release-table.js +0 -60
  292. package/src-old/set-version.js +0 -614
  293. package/src-old/utils.js +0 -15
@@ -0,0 +1,452 @@
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.CERT_MANAGER_INTERVAL = exports.CERT_MANAGER_DEPLOYMENTS = exports.ACME_ISSUER_STAGING = exports.ACME_ISSUER = exports.ACME_STAGING = exports.ACME_PRODUCTION = exports.CERT_WAIT_INTERVAL = exports.CERT_WAIT_TRIES = exports.ISSUER_WAIT_INTERVAL = exports.CA_ISSUER_SECRET = exports.CA_ISSUER = exports.CERT_MANAGER_MANIFEST = exports.CERT_MANAGER_VERSION = void 0;
37
+ exports.certManagerInstalled = certManagerInstalled;
38
+ exports.issuerName = issuerName;
39
+ exports.issuerDirectory = issuerDirectory;
40
+ exports.certManagerInstallHint = certManagerInstallHint;
41
+ exports.ensureCertManager = ensureCertManager;
42
+ exports.caIssuerManifest = caIssuerManifest;
43
+ exports.ensureCaIssuer = ensureCaIssuer;
44
+ exports.acmeIssuerManifest = acmeIssuerManifest;
45
+ exports.ensureAcmeIssuer = ensureAcmeIssuer;
46
+ exports.ensureIssuer = ensureIssuer;
47
+ exports.waitForCertificate = waitForCertificate;
48
+ exports.tlsSecretFor = tlsSecretFor;
49
+ /**
50
+ * cert-manager and the issuers a workspace's ingress names.
51
+ *
52
+ * Installed only into a cluster houston may write to, and only after every read-only refusal
53
+ * has passed -- an install left behind by a refusal is the defect this ordering was measured
54
+ * against.
55
+ */
56
+ const fs = __importStar(require("node:fs"));
57
+ const YAML = __importStar(require("yaml"));
58
+ const errors_1 = require("../../lib/errors");
59
+ const events_1 = require("../../lib/events");
60
+ const tls_local_1 = require("../tls-local");
61
+ const ask_1 = require("./ask");
62
+ const context_1 = require("./context");
63
+ const exec_1 = require("./exec");
64
+ const monitoring_1 = require("./monitoring");
65
+ const names_1 = require("./names");
66
+ const release_1 = require("./release");
67
+ const realSleep = (seconds) => new Promise((resolve) => setTimeout(resolve, seconds * 1000));
68
+ /**
69
+ * Whether cert-manager can issue in this cluster.
70
+ *
71
+ * Keyed on the CRD rather than on a Deployment name or a helm release: the release can be
72
+ * named anything, and `installCRDs` versus `crds.enabled` differ by cert-manager version --
73
+ * but nothing can issue a Certificate without the CRD, and its absence is exactly the
74
+ * failure that reads as "no matches for kind ClusterIssuer".
75
+ */
76
+ async function certManagerInstalled(context) {
77
+ const res = await exec_1.kube.run(['kubectl', '--context', context, 'get', 'crd', 'certificates.cert-manager.io', '-o', 'name'], { own: (0, names_1.isOurs)(context) });
78
+ return res.returncode === 0 && res.stdout.includes('certificates.cert-manager.io');
79
+ }
80
+ /**
81
+ * The pinned cert-manager release, and the command a person runs to get it. The OFFICIAL
82
+ * Rocket.Chat guide installs cert-manager with kubectl, not helm, and lists it as a
83
+ * PREREQUISITE -- so houston requires it and names this, rather than installing it into a
84
+ * cluster it does not own.
85
+ *
86
+ * Following the guide here is not deference, it deletes work: verified against the real
87
+ * v1.21.1 manifest, it contains no `startupapicheck` and no Job of any kind, so nothing can
88
+ * fail a post-install hook, and it carries the six CRDs directly, so the
89
+ * `crds.enabled`-versus-`installCRDs` trap has nowhere to happen.
90
+ */
91
+ exports.CERT_MANAGER_VERSION = 'v1.21.1';
92
+ exports.CERT_MANAGER_MANIFEST = `https://github.com/cert-manager/cert-manager/releases/download/${exports.CERT_MANAGER_VERSION}/cert-manager.yaml`;
93
+ /**
94
+ * houston's own issuer, and the Secret holding the CA that backs it. A ClusterIssuer reads
95
+ * its Secret from the cluster-resource namespace, which for a default cert-manager install
96
+ * is its own.
97
+ */
98
+ exports.CA_ISSUER = 'houston-ca';
99
+ exports.CA_ISSUER_SECRET = 'houston-ca';
100
+ exports.ISSUER_WAIT_INTERVAL = 2.0;
101
+ /**
102
+ * How long to wait for cert-manager to issue. 45 x 2 s was too tight for a FIRST issuance on
103
+ * a cold cluster: the ACME account has to be registered, the order placed, the http-01
104
+ * challenge served and validated by Let's Encrypt from outside, and on a first workspace all
105
+ * of that starts only once the image pull has finished.
106
+ *
107
+ * OBSERVED through the GUI on a fresh EKS cluster -- the wait expired, the ingress answered
108
+ * with its own default certificate, and the certificate arrived about a minute later. The
109
+ * cost of waiting longer is bounded and only paid with `--domain`; the cost of giving up
110
+ * early is a create that ends by reporting a failure that is not one.
111
+ */
112
+ exports.CERT_WAIT_TRIES = 90;
113
+ exports.CERT_WAIT_INTERVAL = 2.0;
114
+ /**
115
+ * The ACME directories, and two ISSUER NAMES rather than one with a flag. Switching staging
116
+ * on and off must not reuse an account registered against the other directory:
117
+ * `privateKeySecretRef` holds the ACME account key, and pointing a production order at a
118
+ * staging account fails in a way that names neither.
119
+ */
120
+ exports.ACME_PRODUCTION = 'https://acme-v02.api.letsencrypt.org/directory';
121
+ exports.ACME_STAGING = 'https://acme-staging-v02.api.letsencrypt.org/directory';
122
+ exports.ACME_ISSUER = 'houston-acme';
123
+ exports.ACME_ISSUER_STAGING = 'houston-acme-staging';
124
+ function issuerName(spec) {
125
+ if (spec.mode !== 'acme')
126
+ return exports.CA_ISSUER;
127
+ return spec.acmeStaging === true ? exports.ACME_ISSUER_STAGING : exports.ACME_ISSUER;
128
+ }
129
+ function issuerDirectory(spec) {
130
+ return spec.acmeStaging === true ? exports.ACME_STAGING : exports.ACME_PRODUCTION;
131
+ }
132
+ /**
133
+ * The three Deployments the official manifest creates. Waited for by name, because the
134
+ * manifest has no hooks and `kubectl apply` returns the moment the objects are accepted --
135
+ * and a ClusterIssuer created before the webhook is serving is accepted and then never
136
+ * reconciled.
137
+ */
138
+ exports.CERT_MANAGER_DEPLOYMENTS = [
139
+ 'cert-manager',
140
+ 'cert-manager-webhook',
141
+ 'cert-manager-cainjector',
142
+ ];
143
+ exports.CERT_MANAGER_INTERVAL = 3.0;
144
+ /** What to run to satisfy the prerequisite, quoted from the official guide. */
145
+ function certManagerInstallHint() {
146
+ return `kubectl apply -f ${exports.CERT_MANAGER_MANIFEST}`;
147
+ }
148
+ /** Wait for cert-manager's deployments and CRDs after applying its manifest. */
149
+ async function waitForCertManager(context, emit, sleep) {
150
+ // THE WEBHOOK, not just the apply. `kubectl apply` returns as soon as the objects are
151
+ // accepted, and a ClusterIssuer created before the webhook is serving is accepted and then
152
+ // never reconciled -- no `.status` at all, so no Certificate ever issues and nothing says
153
+ // why.
154
+ for (const name of exports.CERT_MANAGER_DEPLOYMENTS) {
155
+ await exec_1.kube.run([
156
+ 'kubectl',
157
+ '--context',
158
+ context,
159
+ '-n',
160
+ monitoring_1.CERT_MANAGER_NAMESPACE,
161
+ 'rollout',
162
+ 'status',
163
+ `deployment/${name}`,
164
+ '--timeout=180s',
165
+ ], { timeout: names_1.INSTALL_TIMEOUT, own: (0, names_1.isOurs)(context) });
166
+ }
167
+ // And the CRD, which is what "can this cluster issue a Certificate" actually means.
168
+ let crds = false;
169
+ for (let attempt = 0; attempt < names_1.tuning.CERT_MANAGER_TRIES; attempt += 1) {
170
+ if (await certManagerInstalled(context)) {
171
+ crds = true;
172
+ break;
173
+ }
174
+ if (attempt < names_1.tuning.CERT_MANAGER_TRIES - 1)
175
+ await sleep(exports.CERT_MANAGER_INTERVAL);
176
+ }
177
+ if (!crds) {
178
+ throw new errors_1.CreateFailedError(`cert-manager was applied to '${context}' but its CRDs never appeared, so nothing can ` +
179
+ `issue a Certificate there. \`kubectl -n ${monitoring_1.CERT_MANAGER_NAMESPACE} get pods\` and ` +
180
+ '`kubectl get crd | grep cert-manager`.');
181
+ }
182
+ await waitForTheWebhook(context, sleep);
183
+ (0, events_1.info)(emit, 'cert-manager: installed and answering', { phase: 'tls' });
184
+ }
185
+ /**
186
+ * ANSWERING, which a Ready webhook pod is not yet: prove it with the object that is next.
187
+ *
188
+ * The webhook pod rolls out Ready as soon as it serves, but the API server calls it with the
189
+ * CA bundle cainjector copies into its webhook configurations, and on a fresh install that
190
+ * copy lands some seconds LATER. Until it does, every create of a cert-manager object fails
191
+ * with `failed calling webhook "webhook.cert-manager.io" ... x509: certificate signed by
192
+ * unknown authority`. MEASURED on a k3s playground: the apply straight after "installed and
193
+ * answering" failed that way (exit 7), in both implementations, including a run that met
194
+ * cert-manager's images already cached; an install that pulled its images had simply been
195
+ * slow enough to miss the window.
196
+ *
197
+ * So the wait asks the webhook itself: a server-side dry-run of the ClusterIssuer that
198
+ * `ensureCaIssuer` creates next goes through the same admission call and persists nothing.
199
+ *
200
+ * Bounded, but by its OWN bound, `tuning.CERT_MANAGER_WEBHOOK_TRIES` (60 x 3 s = 180 s, the
201
+ * rollout waits' `--timeout=180s`), not the CRD wait's 60 s. cainjector injects the bundle
202
+ * only once it holds its leader lease, and cert-manager's two Leases,
203
+ * `kube-system/cert-manager-cainjector-leader-election` and
204
+ * `kube-system/cert-manager-controller`, are created at run time, are not in the manifest,
205
+ * and OUTLIVE `kubectl delete -f` of it. A new candidate that finds a lease it does not hold
206
+ * waits a full lease duration (60 s) from when it first sees it, plus its retry period,
207
+ * however long ago the old holder died. MEASURED on a k3s playground after a
208
+ * fresh apply of the pinned v1.21.1 manifest on a cluster that had had cert-manager: the
209
+ * three Deployments rolled out at +12 s, cainjector logged "Attempting to acquire leader
210
+ * lease" at 05:51:48 and "Successfully acquired lease" at 05:53:07, and the webhook first
211
+ * accepted this dry-run at +89 s. At 60 s the wait refused every such cluster, in the
212
+ * previous implementation as here (the third run, exit 7); the first run's first install
213
+ * passed only because its cluster had never had cert-manager.
214
+ */
215
+ async function waitForTheWebhook(context, sleep) {
216
+ let res;
217
+ for (let attempt = 0; attempt < names_1.tuning.CERT_MANAGER_WEBHOOK_TRIES; attempt += 1) {
218
+ res = await exec_1.kube.run(['kubectl', '--context', context, 'apply', '--dry-run=server', '-f', '-'], { input: caClusterIssuerManifest(), own: (0, names_1.isOurs)(context) });
219
+ if (res.returncode === 0)
220
+ return;
221
+ if (attempt < names_1.tuning.CERT_MANAGER_WEBHOOK_TRIES - 1)
222
+ await sleep(exports.CERT_MANAGER_INTERVAL);
223
+ }
224
+ throw new errors_1.CreateFailedError(`cert-manager's webhook in '${context}' never accepted an object, so nothing can ` +
225
+ `create an issuer or a Certificate there: ${(0, ask_1.why)(res)}` +
226
+ `. \`kubectl --context ${context} -n ${monitoring_1.CERT_MANAGER_NAMESPACE} logs ` +
227
+ `deploy/cert-manager-webhook\`, and \`kubectl --context ${context} get ` +
228
+ 'validatingwebhookconfiguration cert-manager-webhook -o yaml` for its caBundle.');
229
+ }
230
+ /**
231
+ * Adopt cert-manager if the cluster has it, install it if not.
232
+ *
233
+ * Installed exactly as the guide installs it -- by kubectl, not helm -- and that choice is
234
+ * load-bearing rather than stylistic: the static manifest contains no `startupapicheck` and
235
+ * no Job at all, so nothing can fail a post-install hook.
236
+ *
237
+ * Only on a cluster that is on this machine, UNLESS INVITED. Six CRDs and an admission
238
+ * webhook are a change to what a cluster IS, for every workload in it -- not something to do
239
+ * to somebody else's ON THE WAY TO BOOTING A REPRO. That last clause is the whole of the
240
+ * rule, and locality was standing in for it: what makes an implicit install wrong is that
241
+ * nobody asked, not where the cluster is.
242
+ *
243
+ * Never removed. `kubectl delete -f` takes the CRDs, and removing the CRDs garbage-collects
244
+ * every Certificate and Issuer in the cluster -- the user's included.
245
+ */
246
+ async function ensureCertManager({ context, distribution = '', invited = false, emit = events_1.nullEmit, sleep = realSleep, }) {
247
+ if (await certManagerInstalled(context)) {
248
+ (0, events_1.info)(emit, 'cert-manager: already in this cluster', { phase: 'tls' });
249
+ return;
250
+ }
251
+ if (!invited &&
252
+ !(await (0, context_1.isLocalCluster)(distribution || (await (0, context_1.distributionOf)(context)), context))) {
253
+ throw new errors_1.PreflightError(`cluster '${context}' has no cert-manager, and it is not on this machine, so houston ` +
254
+ 'will not install one: six CRDs and an admission webhook change what that cluster ' +
255
+ 'is, for every workload in it. The official Rocket.Chat guide installs it as a ' +
256
+ `prerequisite:\n ${certManagerInstallHint()}\n houston adopts it as soon as it ` +
257
+ 'is there.');
258
+ }
259
+ (0, events_1.info)(emit, `no cert-manager in '${context}' — installing ${exports.CERT_MANAGER_VERSION} (once per ` +
260
+ "cluster, the guide's own command)", { phase: 'tls', pct: 10 });
261
+ const res = await exec_1.kube.run(['kubectl', '--context', context, 'apply', '-f', exports.CERT_MANAGER_MANIFEST], { timeout: names_1.INSTALL_TIMEOUT, own: (0, names_1.isOurs)(context) });
262
+ if (res.returncode !== 0) {
263
+ throw new errors_1.CreateFailedError(`could not install cert-manager into '${context}': ${(0, ask_1.why)(res)} — it is one command ` +
264
+ `if you would rather run it yourself: ${certManagerInstallHint()}`);
265
+ }
266
+ await waitForCertManager(context, emit, sleep);
267
+ }
268
+ /**
269
+ * The CA Secret and the ClusterIssuer that signs from it.
270
+ *
271
+ * `stringData`, so Kubernetes does the base64 -- the PEM never has to be re-encoded
272
+ * correctly here.
273
+ *
274
+ * A `ca` issuer rather than an `acme` one is what makes `--https` and `--domain` the same
275
+ * values.yaml with one field different.
276
+ */
277
+ function caIssuerManifest(certPem, keyPem) {
278
+ const indent = (pem) => pem
279
+ .trim()
280
+ .split('\n')
281
+ .map((line) => ` ${line}`)
282
+ .join('\n');
283
+ return (`---\napiVersion: v1\nkind: Secret\nmetadata:\n` +
284
+ ` name: ${exports.CA_ISSUER_SECRET}\n namespace: ${monitoring_1.CERT_MANAGER_NAMESPACE}\n` +
285
+ ` labels:\n ${names_1.OWNER_LABEL_KEY}: ${names_1.OWNER_LABEL_VALUE}\n` +
286
+ `type: kubernetes.io/tls\nstringData:\n` +
287
+ ` tls.crt: |\n${indent(certPem)}\n` +
288
+ ` tls.key: |\n${indent(keyPem)}\n` +
289
+ caClusterIssuerManifest());
290
+ }
291
+ /**
292
+ * The ClusterIssuer half of `caIssuerManifest`, on its own: it carries no key, so
293
+ * `waitForTheWebhook` can dry-run it before anything is created.
294
+ */
295
+ function caClusterIssuerManifest() {
296
+ return (`---\napiVersion: cert-manager.io/v1\nkind: ClusterIssuer\nmetadata:\n` +
297
+ ` name: ${exports.CA_ISSUER}\n` +
298
+ ` labels:\n ${names_1.OWNER_LABEL_KEY}: ${names_1.OWNER_LABEL_VALUE}\n` +
299
+ `spec:\n ca:\n secretName: ${exports.CA_ISSUER_SECRET}\n`);
300
+ }
301
+ /** Whether an issuer answer carries a Ready=True condition, and what it said. */
302
+ function readyCondition(doc) {
303
+ const status = doc.status;
304
+ const conditions = status !== null && typeof status === 'object'
305
+ ? (status.conditions ?? [])
306
+ : [];
307
+ for (const condition of conditions) {
308
+ if (condition.type === 'Ready' && String(condition.status) === 'True') {
309
+ return String(condition.message ?? '');
310
+ }
311
+ }
312
+ return null;
313
+ }
314
+ /**
315
+ * Put houston's CA in the cluster as a `ca` ClusterIssuer, and wait for it.
316
+ *
317
+ * THE WAIT IS THE POINT: a ClusterIssuer created before cert-manager is ready is ACCEPTED
318
+ * and then never reconciled -- no `.status` at all, so no Certificate ever issues and
319
+ * nothing says why. Waiting for `Ready=True` here means a workspace either has a working
320
+ * issuer or a refusal, and never the silent third thing.
321
+ */
322
+ async function ensureCaIssuer({ context, emit = events_1.nullEmit, sleep = realSleep, }) {
323
+ const [keyPath, crtPath] = await (0, tls_local_1.ensureCa)();
324
+ (0, events_1.info)(emit, `issuer ${exports.CA_ISSUER} from houston's own CA (once per cluster)`, { phase: 'tls' });
325
+ await (0, release_1.apply)(caIssuerManifest(fs.readFileSync(crtPath, 'utf8'), fs.readFileSync(keyPath, 'utf8')), { namespace: monitoring_1.CERT_MANAGER_NAMESPACE, context });
326
+ for (let attempt = 0; attempt < names_1.tuning.ISSUER_WAIT_TRIES; attempt += 1) {
327
+ const seen = await (0, ask_1.askObject)('clusterissuer', exports.CA_ISSUER, { context });
328
+ if ((0, ask_1.present)(seen)) {
329
+ const message = readyCondition(seen.doc);
330
+ if (message !== null) {
331
+ (0, events_1.info)(emit, `issuer ${exports.CA_ISSUER} ready — ${message || 'signing CA verified'}`, {
332
+ phase: 'tls',
333
+ });
334
+ return;
335
+ }
336
+ }
337
+ if (attempt < names_1.tuning.ISSUER_WAIT_TRIES - 1)
338
+ await sleep(exports.ISSUER_WAIT_INTERVAL);
339
+ }
340
+ throw new errors_1.PreflightError(`the ClusterIssuer ${exports.CA_ISSUER} did not become ready in cluster '${context}'. ` +
341
+ 'cert-manager accepts an issuer it is not yet able to reconcile and then says ' +
342
+ 'nothing, so a workspace built on it would never get a certificate. `kubectl ' +
343
+ `describe clusterissuer ${exports.CA_ISSUER}\`, then try again.`);
344
+ }
345
+ /**
346
+ * The official guide's own ClusterIssuer, with houston's name on it.
347
+ *
348
+ * `ingressClassName` rather than the guide's `class`, which is the deprecated spelling of
349
+ * the same field -- cert-manager 1.21 accepts both, and naming the current field is what
350
+ * stops this being a deprecation warning later.
351
+ *
352
+ * http01, and NOT tls-alpn, because cert-manager does not implement tls-alpn at all. That is
353
+ * worth stating where the choice is made: the Compose path defaults to TLS-ALPN and this one
354
+ * cannot.
355
+ *
356
+ * BUILT AS A DOCUMENT, NOT A STRING. This was string interpolation, and `acmeEmail` is
357
+ * caller-supplied -- so an address carrying newlines added its own keys to `spec.acme` and
358
+ * the result was valid YAML cert-manager accepts. A ClusterIssuer is CLUSTER-SCOPED and
359
+ * shared by every workspace on the box, so `skipTLSVerify: true` injected here would apply
360
+ * to all of them.
361
+ */
362
+ function acmeIssuerManifest(spec, { ingressClass }) {
363
+ const doc = {
364
+ apiVersion: 'cert-manager.io/v1',
365
+ kind: 'ClusterIssuer',
366
+ metadata: { name: issuerName(spec), labels: { [names_1.OWNER_LABEL_KEY]: names_1.OWNER_LABEL_VALUE } },
367
+ spec: {
368
+ acme: {
369
+ server: issuerDirectory(spec),
370
+ email: spec.acmeEmail ?? '',
371
+ privateKeySecretRef: { name: `${issuerName(spec)}-account-key` },
372
+ solvers: [{ http01: { ingress: { ingressClassName: ingressClass } } }],
373
+ },
374
+ },
375
+ };
376
+ // `---` and key order preserved: the document is written into the workspace directory for
377
+ // a human to read, and reordering it would make every diff noise.
378
+ return `---\n${YAML.stringify(doc, { compat: 'yaml-1.1', indentSeq: false, lineWidth: 0 })}`;
379
+ }
380
+ /**
381
+ * Register an ACME account in the cluster and wait for it. Idempotent.
382
+ *
383
+ * The wait is the same one `ensureCaIssuer` makes, but the failure it catches is different
384
+ * and more common: this issuer makes a real network call to Let's Encrypt to register an
385
+ * account, so a cluster with no egress, a wrong email or a rate-limited account fails HERE
386
+ * -- once, with a reason -- rather than silently per Certificate afterwards.
387
+ */
388
+ async function ensureAcmeIssuer(spec, { context, ingressClass, emit = events_1.nullEmit, sleep = realSleep, }) {
389
+ const which = spec.acmeStaging === true ? 'staging' : 'production';
390
+ const name = issuerName(spec);
391
+ (0, events_1.info)(emit, `issuer ${name} — Let's Encrypt ${which}, http-01 via ${ingressClass} (once per cluster)`, { phase: 'tls' });
392
+ await (0, release_1.apply)(acmeIssuerManifest(spec, { ingressClass }), {
393
+ namespace: monitoring_1.CERT_MANAGER_NAMESPACE,
394
+ context,
395
+ });
396
+ for (let attempt = 0; attempt < names_1.tuning.ISSUER_WAIT_TRIES; attempt += 1) {
397
+ const seen = await (0, ask_1.askObject)('clusterissuer', name, { context });
398
+ if ((0, ask_1.present)(seen)) {
399
+ const message = readyCondition(seen.doc);
400
+ if (message !== null) {
401
+ (0, events_1.info)(emit, `issuer ${name} ready — ${message || 'ACME account registered'}`, {
402
+ phase: 'tls',
403
+ });
404
+ return;
405
+ }
406
+ }
407
+ if (attempt < names_1.tuning.ISSUER_WAIT_TRIES - 1)
408
+ await sleep(exports.ISSUER_WAIT_INTERVAL);
409
+ }
410
+ throw new errors_1.PreflightError(`the ClusterIssuer ${name} did not become ready in cluster '${context}'. Registering an ` +
411
+ `ACME account is a real call to ${issuerDirectory(spec)} from inside the cluster, so ` +
412
+ 'this is usually no egress from the pods, or a rejected contact address. `kubectl ' +
413
+ `describe clusterissuer ${name}\` says which.`);
414
+ }
415
+ /**
416
+ * Make the issuer this workspace's Ingress is about to name.
417
+ *
418
+ * One call site, two mechanisms, chosen by the spec rather than by a branch at the caller --
419
+ * which is what keeps `--https` and `--domain` the same code path with a different issuer.
420
+ */
421
+ async function ensureIssuer(spec, { context, ingressClass, emit = events_1.nullEmit, }) {
422
+ if (spec.mode === 'acme') {
423
+ await ensureAcmeIssuer(spec, { context, ingressClass, emit });
424
+ }
425
+ else {
426
+ await ensureCaIssuer({ context, emit });
427
+ }
428
+ }
429
+ /**
430
+ * Wait for cert-manager to issue `name`. Returns whether it did.
431
+ *
432
+ * NOT fatal, and deliberately: the workspace itself is up and reachable on its port-forward
433
+ * whatever the certificate does, so a certificate that has not arrived is a thing to SAY
434
+ * rather than a reason to destroy a workspace somebody waited minutes for.
435
+ */
436
+ async function waitForCertificate(name, { namespace, context, emit = events_1.nullEmit, sleep = realSleep, }) {
437
+ for (let attempt = 0; attempt < exports.CERT_WAIT_TRIES; attempt += 1) {
438
+ const seen = await (0, ask_1.askObject)('certificate', name, { namespace, context });
439
+ if ((0, ask_1.present)(seen) && readyCondition(seen.doc) !== null)
440
+ return true;
441
+ if (attempt < exports.CERT_WAIT_TRIES - 1)
442
+ await sleep(exports.CERT_WAIT_INTERVAL);
443
+ }
444
+ (0, events_1.warn)(emit, `the certificate ${name} in ${namespace} is not Ready yet — the workspace is up either ` +
445
+ `way. \`kubectl -n ${namespace} describe certificate ${name}\` says what cert-manager ` +
446
+ 'is waiting for.', { phase: 'tls' });
447
+ return false;
448
+ }
449
+ /** The Secret cert-manager fills for a workspace's Ingress. */
450
+ function tlsSecretFor(name) {
451
+ return `${name}-tls`;
452
+ }