The Entra ID rewrite
From the provider-abstraction design to the token validator and the install flow that configures it — and where the shipped code deliberately diverges from the plan.
backend/src/lib/install/manifest.ts749 lines · evaluateManifest L726–748
Outline 8 symbols
- defaultDisplay function
- redactedDisplay function
- CheckKvSecretOpts type
- isSecretNotFound function
- checkKvSecret function
- items const
- findManifestItem function export
- evaluateManifest function export
1// v1 manifest catalog and evaluator. See issue 023 §"v1 manifest item
2// catalog" for the full target list — this catalog covers the bulk of v1
3// across all sections. Each item knows how to verify itself (`check`)
4// and how the operator fixes it when the check fails (`fixedBy`).
5
6import { getConfig } from "../config";
7import { checkRedirectUris } from "./checks/redirectUris";
8import { checkInstallerAccessRevoked } from "./checks/installerAccess";
9import {
10 type CheckResult,
11 type EvaluatedItem,
12 type InstallContext,
13 type ManifestItem,
14} from "./types";
15
16// Default formatter: show the value as-is for short values (GUIDs,
17// URLs, mode strings), strip any `# display-name` suffix per the
18// install configurator surface (matches installAuth.ts:isInAdminGroup).
19function defaultDisplay(raw: string): string {
20 // Strip `# comment` if present — that's a documentation aid in the
21 // KV value, not part of the operative value.
22 const clean = raw.split("#")[0].trim();
23 return clean;
24}
25
26// Redacted display for secrets — first 4 chars then bullets. Tells the
27// operator the value IS set without revealing it.
28function redactedDisplay(raw: string): string {
29 if (raw.length === 0) return "";
30 if (raw.length <= 4) return "••••";
31 return `${raw.slice(0, 4)}••••`;
32}
33
34type CheckKvSecretOpts = {
35 format?: RegExp;
36 formatHint?: string;
37 /**
38 * How to render the value when the row is green. Defaults to
39 * showing the value as-is (safe for GUIDs, URLs, mode strings).
40 * Pass `redacted: true` for secrets, or a custom formatter for
41 * special cases (e.g., display-name extraction).
42 */
43 redacted?: boolean;
44 displayValue?: (raw: string) => string;
45};
46
47// Azure SDK throws a RestError with code 'SecretNotFound' (HTTP 404)
48// when the KV secret doesn't exist. We treat that as "operator hasn't
49// configured this yet" — semantically equivalent to value === "" — and
50// render a clean human message rather than leaking the SDK error.
51// Any other thrown error IS an unexpected failure (KV unreachable,
52// auth denied, etc.) and surfaces its message so we can diagnose.
53// Closes 040 Entry 1 problem 1.
54function isSecretNotFound(err: unknown): boolean {
55 if (!err || typeof err !== "object") return false;
56 const e = err as { code?: unknown; statusCode?: unknown };
57 return e.code === "SecretNotFound" || e.statusCode === 404;
58}
59
60async function checkKvSecret(
61 name: string,
62 opts: CheckKvSecretOpts = {},
63): Promise<CheckResult> {
64 try {
65 const value = await getConfig(name);
66 if (!value) return { status: "fail", detail: "Not yet configured." };
67 if (opts.format && !opts.format.test(value)) {
68 return {
69 status: "fail",
70 detail: `Format check failed${opts.formatHint ? ` (expected ${opts.formatHint})` : ""}.`,
71 };
72 }
73 // Show the current value on pass so operators can verify it's
74 // what they expect without clicking Edit. Sensitive values
75 // (client secrets, HMAC keys) pass `redacted: true` so the row
76 // shows that something is set without revealing the secret.
77 // See gap #30 in 036-marketplace-install-gaps.md.
78 const formatter = opts.displayValue ?? (opts.redacted ? redactedDisplay : defaultDisplay);
79 return { status: "pass", detail: formatter(value) };
80 } catch (err) {
81 if (isSecretNotFound(err)) {
82 return { status: "fail", detail: "Not yet configured." };
83 }
84 return {
85 status: "fail",
86 detail: err instanceof Error ? err.message : String(err),
87 };
88 }
89}
90
91const items: ManifestItem[] = [
92 // ── Foundations ──────────────────────────────────────────────────
93 {
94 id: "bicep-deployed",
95 label: "Mike's backend is up and running",
96 section: "Core setup",
97 required: true,
98 check: async () => ({
99 status: "pass",
100 detail: "If you can read this page, the Container App is up.",
101 }),
102 fixedBy: { type: "auto", description: "Bicep provisions the Container App." },
103 },
104 {
105 id: "mi-client-id",
106 label: "Backend can talk to Azure (managed identity wired)",
107 section: "Core setup",
108 required: true,
109 check: async () => {
110 const env = process.env.AZURE_CLIENT_ID ?? "";
111 if (!env) {
112 return { status: "fail", detail: "AZURE_CLIENT_ID env var is not set." };
113 }
114 return { status: "pass", detail: env };
115 },
116 fixedBy: { type: "auto", description: "Bicep threads `mi.outputs.miClientId` into the env." },
117 },
118 {
119 id: "kv-bootstrap-token",
120 label: "First-time setup password ready",
121 section: "Core setup",
122 required: true,
123 check: () => checkKvSecret("install-bootstrap-token", { redacted: true }),
124 fixedBy: { type: "auto", description: "Bicep generates and writes on greenfield deploy." },
125 },
126 {
127 id: "kv-auth-state-secret",
128 label: "Sign-in signing key ready",
129 section: "Core setup",
130 required: true,
131 check: () => checkKvSecret("auth-state-secret", { redacted: true }),
132 fixedBy: { type: "auto", description: "Bicep generates on greenfield deploy." },
133 },
134 {
135 id: "kv-backend-public-url",
136 label: "Backend's public web address",
137 section: "Core setup",
138 required: true,
139 check: () => checkKvSecret("backend-public-url", {
140 format: /^https?:\/\/.+/,
141 formatHint: "URL with scheme",
142 }),
143 fixedBy: {
144 type: "in-app-form",
145 submitTo: "kv",
146 fields: [{
147 name: "backend-public-url",
148 label: "Backend public URL",
149 type: "url",
150 placeholder: "https://backend.<random>-<hash>.<region>.azurecontainerapps.io",
151 required: true,
152 pattern: "^https?:\\/\\/.+",
153 }],
154 },
155 },
156 {
157 // Optional override consumed by the script-arg renderer in
158 // install.ts: when set, every `<fqdn>` substitution uses this
159 // value instead of the host the operator reached /install on.
160 // Lets you register Entra redirect URIs against a custom domain
161 // (e.g. mike.altien.com) before the custom domain itself is
162 // wired up on Container Apps ingress.
163 id: "custom-backend-fqdn",
164 label: "Custom domain name (optional)",
165 section: "Core setup",
166 required: false,
167 check: async () => {
168 const value = await getConfig("custom-backend-fqdn").catch(() => "");
169 if (!value) {
170 return {
171 status: "info",
172 detail: "Not set — script <fqdn> defaults to the host you opened /install on.",
173 };
174 }
175 return { status: "pass", detail: value };
176 },
177 fixedBy: {
178 type: "in-app-form",
179 submitTo: "kv",
180 fields: [{
181 name: "custom-backend-fqdn",
182 label: "Custom backend FQDN",
183 type: "text",
184 placeholder: "mike.altien.com",
185 required: false,
186 pattern: "^[a-z0-9.-]+$",
187 helpText: "Hostname only, no scheme or path (e.g. mike.altien.com). Substituted into -BackendFqdn on the create-entra-apps and register-redirect-uris commands. Leave empty to use the host you reached /install on.",
188 }],
189 },
190 },
191
192 // ── AI providers ─────────────────────────────────────────────────
193 {
194 id: "ai-anthropic-key",
195 label: "Anthropic API key",
196 section: "AI providers",
197 required: false,
198 check: () => checkKvSecret("anthropic-api-key", {
199 format: /^sk-ant-/,
200 formatHint: "sk-ant- prefix",
201 redacted: true,
202 }),
203 fixedBy: {
204 type: "in-app-form",
205 submitTo: "kv",
206 fields: [{
207 name: "anthropic-api-key",
208 label: "Anthropic API key",
209 type: "password",
210 placeholder: "sk-ant-…",
211 required: true,
212 pattern: "^sk-ant-.+",
213 }],
214 },
215 },
216 {
217 id: "ai-openai-key",
218 label: "OpenAI API key",
219 section: "AI providers",
220 required: false,
221 check: () => checkKvSecret("openai-api-key", {
222 format: /^sk-(proj-)?/,
223 formatHint: "sk- or sk-proj- prefix",
224 redacted: true,
225 }),
226 fixedBy: {
227 type: "in-app-form",
228 submitTo: "kv",
229 fields: [{
230 name: "openai-api-key",
231 label: "OpenAI API key",
232 type: "password",
233 placeholder: "sk-…",
234 required: true,
235 }],
236 },
237 },
238 {
239 id: "ai-kimi-key",
240 label: "Kimi K3 API key",
241 section: "AI providers",
242 required: false,
243 check: () =>
244 checkKvSecret("moonshot-api-key", {
245 redacted: true,
246 }),
247 fixedBy: {
248 type: "in-app-form",
249 submitTo: "kv",
250 fields: [
251 {
252 name: "moonshot-api-key",
253 label: "Kimi API key",
254 type: "password",
255 placeholder: "Kimi API key",
256 required: true,
257 helpText:
258 "Organisation-wide Moonshot AI key for Kimi K3. " +
259 "Create or copy a key from the Kimi API Platform.",
260 },
261 ],
262 },
263 },
264 {
265 // Upstream 2f30082a added direct Mistral models with per-user keys;
266 // Dev keeps it an organisation credential in Key Vault.
267 id: "ai-mistral-key",
268 label: "Mistral AI API key",
269 section: "AI providers",
270 required: false,
271 check: () => checkKvSecret("mistral-api-key", { redacted: true }),
272 fixedBy: {
273 type: "in-app-form",
274 submitTo: "kv",
275 fields: [{
276 name: "mistral-api-key",
277 label: "Mistral AI API key",
278 type: "password",
279 required: true,
280 helpText:
281 "Organisation-wide key for direct Mistral models. " +
282 "Create one in Mistral Studio (console.mistral.ai).",
283 }],
284 },
285 },
286 {
287 id: "ai-gemini-key",
288 label: "Google Gemini API key",
289 section: "AI providers",
290 required: false,
291 check: () => checkKvSecret("gemini-api-key", {
292 format: /^AIza/,
293 formatHint: "AIza prefix",
294 redacted: true,
295 }),
296 fixedBy: {
297 type: "in-app-form",
298 submitTo: "kv",
299 fields: [{
300 name: "gemini-api-key",
301 label: "Google Gemini API key",
302 type: "password",
303 placeholder: "AIza…",
304 required: true,
305 pattern: "^AIza.+",
306 }],
307 },
308 },
309 {
310 id: "ai-openrouter-key",
311 label: "OpenRouter API key",
312 section: "AI providers",
313 required: false,
314 check: () => checkKvSecret("openrouter-api-key", {
315 format: /^sk-or-/,
316 formatHint: "sk-or- prefix",
317 redacted: true,
318 }),
319 fixedBy: {
320 type: "in-app-form",
321 submitTo: "kv",
322 fields: [{
323 name: "openrouter-api-key",
324 label: "OpenRouter API key",
325 type: "password",
326 placeholder: "sk-or-…",
327 required: true,
328 pattern: "^sk-or-.+",
329 helpText: "Organisation-wide OpenRouter key shared by this Mike installation. Get one at openrouter.ai → Keys.",
330 }],
331 },
332 },
333 {
334 id: "ai-opencode-go-key",
335 label: "OpenCode Go API key",
336 section: "AI providers",
337 required: false,
338 check: () => checkKvSecret("opencode-api-key", { redacted: true }),
339 fixedBy: {
340 type: "in-app-form",
341 submitTo: "kv",
342 fields: [{
343 name: "opencode-api-key",
344 label: "OpenCode Go API key",
345 type: "password",
346 required: true,
347 helpText: "Organisation-wide OpenCode Go key shared by this Mike installation.",
348 }],
349 },
350 },
351 {
352 id: "ai-courtlistener-token",
353 label: "CourtListener API token",
354 section: "AI providers",
355 required: false,
356 check: () => checkKvSecret("courtlistener-api-token", {
357 redacted: true,
358 }),
359 fixedBy: {
360 type: "in-app-form",
361 submitTo: "kv",
362 fields: [{
363 name: "courtlistener-api-token",
364 label: "CourtListener API token",
365 type: "password",
366 placeholder: "Token…",
367 required: true,
368 helpText: "Org-wide token for live CourtListener data in US legal research. Without it, Mike falls back to the hosted bulk data. Get one at courtlistener.com → Profile → API.",
369 }],
370 },
371 },
372 {
373 id: "ai-aoai-config",
374 label: "Azure OpenAI / AI Foundry",
375 section: "AI providers",
376 required: false,
377 check: async () => {
378 const endpoint = await checkKvSecret("azure-openai-endpoint", {
379 format: /^https:\/\/.+/,
380 formatHint: "https:// URL",
381 });
382 if (endpoint.status !== "pass") return endpoint;
383 const key = await checkKvSecret("azure-openai-api-key", { redacted: true });
384 if (key.status !== "pass") return key;
385 // Show the endpoint and a redacted-key marker so operators can
386 // verify the endpoint matches expectations at a glance (gap #30).
387 return { status: "pass", detail: `${endpoint.detail ?? ""} · key set` };
388 },
389 fixedBy: {
390 type: "in-app-form",
391 submitTo: "kv",
392 fields: [
393 {
394 name: "azure-openai-endpoint",
395 label: "AOAI endpoint",
396 type: "url",
397 placeholder: "https://<account>.openai.azure.com/",
398 required: true,
399 pattern: "^https:\\/\\/.+",
400 helpText: "The base URL of your Azure OpenAI or Azure AI Foundry resource. Find it in the Azure portal under your resource → Keys and Endpoint → Endpoint.",
401 },
402 {
403 name: "azure-openai-api-key",
404 label: "AOAI API key",
405 type: "password",
406 placeholder: "AOAI account key",
407 required: true,
408 helpText: "Either KEY 1 or KEY 2 from your resource's Keys and Endpoint blade. Mike treats them interchangeably; rotate by running the script in provision mode (or via the Azure portal).",
409 },
410 ],
411 alsoAsScript: {
412 scriptName: "setup-aoai.ps1",
413 argsTemplate: "-KeyVaultName <kv> -Provision -ResourceGroup <rg> -Region <region> -Model <model>",
414 description: "Need to provision a brand-new AOAI / Foundry resource and a model deployment in one step? Pick region + model below, copy the command, and run it locally.",
415 tweakOptions: [
416 {
417 name: "region",
418 label: "Region",
419 defaultValue: "uksouth",
420 // AOAI quota varies sharply by region. These regions are
421 // the most commonly available; others throttle hard or
422 // gate behind capacity requests.
423 options: [
424 "uksouth",
425 "westeurope",
426 "northeurope",
427 "swedencentral",
428 "francecentral",
429 "switzerlandnorth",
430 "eastus",
431 "eastus2",
432 "southcentralus",
433 "canadaeast",
434 "australiaeast",
435 "japaneast",
436 ],
437 },
438 {
439 name: "model",
440 label: "Model",
441 defaultValue: "gpt-4o-mini",
442 options: [
443 "gpt-4o-mini",
444 "gpt-4o",
445 "gpt-4-turbo",
446 "gpt-4",
447 "gpt-35-turbo",
448 ],
449 },
450 ],
451 },
452 },
453 },
454
455 // ── Entra ID ─────────────────────────────────────────────────────
456 // The three identity items below all read from KV secrets that
457 // create-entra-apps.ps1 writes. Each item has its own paste form so
458 // operators who created the apps in the portal (or in another
459 // automation) can fill the values manually. Only the first item
460 // (entra-tenant-id) renders the script Run block via `alsoAsScript`
461 // — the script writes ALL FIVE secrets in one pass (tenant id,
462 // backend app id, frontend app id, frontend client secret, plus a
463 // backend-scope row that is no longer manifest-tracked because it's
464 // deterministic from the backend client id; see gap #4 in
465 // docs/issues/azure-migration/036-marketplace-install-gaps.md), so
466 // showing the same command three times added no value and obscured
467 // the independent paste paths.
468 {
469 id: "entra-tenant-id",
470 label: "Microsoft tenant (your organization)",
471 section: "Microsoft sign-in",
472 required: true,
473 // Marketplace operators should run create-entra-apps.ps1 (offered
474 // via alsoAsScript below) — that single command writes tenant id,
475 // both app reg ids, and the frontend client secret to KV in one
476 // pass. The paste form is retained for OSS deployments and
477 // operators who created the apps in the portal. Marked `advanced`
478 // so the UI de-emphasizes it. 036a Phase 6 (B6).
479 advanced: true,
480 check: () => checkKvSecret("entra-tenant-id", {
481 format: /^[0-9a-f-]{36}$/i,
482 formatHint: "GUID",
483 }),
484 fixedBy: {
485 type: "in-app-form",
486 submitTo: "kv",
487 fields: [{
488 name: "entra-tenant-id",
489 label: "Tenant ID",
490 type: "text",
491 placeholder: "00000000-0000-0000-0000-000000000000",
492 required: true,
493 pattern: "^[0-9a-fA-F-]{36}$",
494 helpText: "The unique ID of your Microsoft organization. Mike uses this to know which Microsoft accounts can sign in. Find it in the Azure portal → Microsoft Entra ID → Overview → Tenant ID.",
495 }],
496 alsoAsScript: {
497 scriptName: "create-entra-apps.ps1",
498 argsTemplate: "-KeyVaultName <kv> -BackendFqdn <fqdn> -ResourceGroup <rg>",
499 description: "Recommended: run this script to create the backend + frontend app registrations and write all the Entra secrets (tenant ID, both app reg ids, frontend client secret) to KV in one pass. Resource group is used to look up the backend UAMI and grant it ownership of the frontend app reg, which lets /install read the redirect URIs back via Graph for slice 9 verification.",
500 },
501 },
502 },
503 {
504 id: "entra-backend-app",
505 label: "Sign-in: backend identity",
506 section: "Microsoft sign-in",
507 required: true,
508 requires: ["entra-tenant-id"],
509 // Same rationale as entra-tenant-id: marketplace path is the
510 // script. Paste form retained for OSS / portal-created apps.
511 advanced: true,
512 check: () => checkKvSecret("entra-backend-client-id", {
513 format: /^[0-9a-f-]{36}$/i,
514 formatHint: "GUID",
515 }),
516 fixedBy: {
517 type: "in-app-form",
518 submitTo: "kv",
519 fields: [{
520 name: "entra-backend-client-id",
521 label: "Backend app (API) client ID",
522 type: "text",
523 placeholder: "00000000-0000-0000-0000-000000000000",
524 required: true,
525 pattern: "^[0-9a-fA-F-]{36}$",
526 helpText: "The ID Microsoft uses to identify Mike's backend when validating sign-ins. Find it in the Azure portal → Microsoft Entra ID → App registrations → your backend app → Overview → Application (client) ID.",
527 }],
528 },
529 },
530 {
531 id: "entra-frontend-app",
532 label: "Sign-in: user-facing identity",
533 section: "Microsoft sign-in",
534 required: true,
535 requires: ["entra-tenant-id"],
536 // Same rationale as entra-tenant-id / entra-backend-app.
537 advanced: true,
538 check: () => checkKvSecret("entra-client-id", {
539 format: /^[0-9a-f-]{36}$/i,
540 formatHint: "GUID",
541 }),
542 fixedBy: {
543 type: "in-app-form",
544 submitTo: "kv",
545 fields: [
546 {
547 name: "entra-client-id",
548 label: "Frontend (sign-in) client ID",
549 type: "text",
550 placeholder: "00000000-0000-0000-0000-000000000000",
551 required: true,
552 pattern: "^[0-9a-fA-F-]{36}$",
553 helpText: "The ID Microsoft uses to identify Mike to your users when they sign in. Find it in the Azure portal → Microsoft Entra ID → App registrations → your sign-in app → Overview → Application (client) ID.",
554 },
555 {
556 name: "entra-client-secret",
557 label: "Sign-in client secret",
558 type: "password",
559 placeholder: "Paste the secret VALUE (not the Secret ID)",
560 required: true,
561 helpText: "A password Microsoft generates for Mike to prove its identity. Mint a new one in the Azure portal → Microsoft Entra ID → App registrations → your sign-in app → Certificates & secrets → New client secret. Copy the VALUE column (not Secret ID).",
562 },
563 ],
564 },
565 },
566 // entra-backend-scope row removed: the scope is `api://<backend-client-id>/access_as_user`,
567 // fully derivable at runtime in routes/auth.ts's entraScopes(). Tracking it as a separate
568 // KV secret was the source of "all green except this row, with no fix path" failures.
569 // create-entra-apps.ps1 still writes the KV secret for backward compatibility with older
570 // installs; no code consults it. Gap #4 in 036-marketplace-install-gaps.md.
571 {
572 id: "entra-frontend-redirect-uris",
573 label: "Sign-in callback URLs registered",
574 section: "Microsoft sign-in",
575 required: true,
576 requires: ["entra-frontend-app", "kv-backend-public-url"],
577 // Real Microsoft Graph round-trip — see checks/redirectUris.ts.
578 check: (ctx) => checkRedirectUris(ctx),
579 fixedBy: {
580 type: "external-script",
581 scriptName: "register-redirect-uris.ps1",
582 argsTemplate: "-KeyVaultName <kv> -BackendFqdn <fqdn>",
583 },
584 },
585
586 // ── Tenant policy ────────────────────────────────────────────────
587 {
588 id: "entra-admin-group-id",
589 label: "Admins (who can configure Mike)",
590 section: "Access rules",
591 required: true,
592 requires: ["entra-frontend-app"],
593 check: () => checkKvSecret("entra-admin-group-ids", {
594 format: /^[0-9a-f-]{36}/i,
595 formatHint: "GUID (the secret may also include a display-name comment)",
596 }),
597 // Picker only. Issue 023 invariant: NEVER expose a GUID-paste
598 // fallback — operators don't know GUIDs by heart, pasted GUIDs
599 // are unverified, every other Azure picker is searchable. Slice 8
600 // wires the Graph-backed picker; until then this item is action-
601 // less by design (no FORM, no SCRIPT, just a planned milestone).
602 fixedBy: {
603 type: "auto",
604 description: "Group picker UI lands in slice 8 (Graph /me/memberOf + search).",
605 },
606 },
607 {
608 id: "entra-member-group-id",
609 label: "Users (who can use Mike)",
610 section: "Access rules",
611 required: false,
612 requires: ["entra-frontend-app"],
613 // Default behaviour: empty member-group ID list means anyone in
614 // your tenant can use Mike (resolveRoles grants Member to any
615 // authenticated tenant user). Pick a group to restrict access
616 // to a subset. The row passes either way — empty is a valid
617 // intentional choice, not a missing setting. Closes 040 Entry
618 // 7 fix A's labelling problem.
619 check: async () => {
620 const value = (await getConfig("entra-member-group-ids").catch(() => "")).trim();
621 if (!value) {
622 // Info (not pass) so the row draws operator attention.
623 // Green ✓ misled operators on rg-mike-mtest1 2026-05-20 into
624 // thinking they'd made a deliberate restrict-access decision.
625 // Default-behaviour-but-worth-deliberate-choice is exactly
626 // what info status is for. Closes 040 Entry 15 fix C.
627 return {
628 status: "info",
629 detail: "Anyone in your Microsoft organisation can use Mike right now (default). Pick a group below to restrict access to a subset.",
630 };
631 }
632 return { status: "pass", detail: value };
633 },
634 fixedBy: {
635 type: "auto",
636 description: "Pick a group to restrict who can use Mike, or leave unset for tenant-wide access.",
637 },
638 },
639 {
640 id: "tenant-onboarding-mode",
641 label: "New sign-up handling (auto vs manual)",
642 section: "Access rules",
643 required: true,
644 check: async () => {
645 const value = await getConfig("tenant-onboarding-mode").catch(() => "");
646 if (value === "auto" || value === "manual") {
647 return { status: "pass", detail: value };
648 }
649 return { status: "fail", detail: "Set to 'auto' or 'manual'." };
650 },
651 fixedBy: {
652 type: "in-app-form",
653 submitTo: "kv",
654 fields: [{
655 name: "tenant-onboarding-mode",
656 label: "Tenant onboarding mode",
657 type: "text",
658 required: true,
659 options: ["auto", "manual"],
660 helpText: "auto: any user from your Microsoft organization can sign in straight away — best for single-tenant installs. manual: an admin must explicitly enrol each new Microsoft organization before its users can sign in — best for multi-tenant SaaS scenarios.",
661 }],
662 },
663 },
664
665 // ── Lifecycle ────────────────────────────────────────────────────
666 {
667 id: "bootstrap-retired",
668 label: "First-time setup completed (bootstrap retired)",
669 section: "Cleanup",
670 required: true,
671 check: async () => {
672 const tok = await getConfig("install-bootstrap-token").catch(() => "");
673 if (!tok) {
674 return { status: "pass", detail: "Token is empty/missing — bootstrap retired." };
675 }
676 return {
677 status: "info",
678 detail: "Bootstrap still active; first Entra admin sign-in retires it (slice 8).",
679 };
680 },
681 fixedBy: {
682 type: "auto",
683 description: "Auto-retires when the first valid Entra admin session loads /install.",
684 },
685 },
686 {
687 id: "installer-access-revoked",
688 label: "Installer's setup access removed",
689 section: "Cleanup",
690 required: false,
691 // Real ARM round-trip — see checks/installerAccess.ts.
692 check: (ctx) => checkInstallerAccessRevoked(ctx),
693 fixedBy: {
694 type: "external-script",
695 scriptName: "revoke-installer-access.ps1",
696 argsTemplate: "-KeyVaultName <kv>",
697 },
698 },
699
700 {
701 id: "app-insights-connection",
702 label: "Application Insights (telemetry / monitoring)",
703 section: "Core setup",
704 required: true,
705 check: async () => {
706 if (!process.env.APPLICATIONINSIGHTS_CONNECTION_STRING) {
707 return {
708 status: "fail",
709 detail: "Backend telemetry is not wired into this Container App revision.",
710 };
711 }
712 return checkKvSecret("appinsights-connection-string", { redacted: true });
713 },
714 fixedBy: {
715 type: "external-script",
716 scriptName: "upgrade-marketplace.ps1",
717 argsTemplate: "-ResourceGroup <rg>",
718 },
719 },
720];
721
722export function findManifestItem(id: string): ManifestItem | undefined {
723 return items.find((i) => i.id === id);
724}
725
726export async function evaluateManifest(
727 ctx: InstallContext,
728): Promise<EvaluatedItem[]> {
729 const results = await Promise.all(
730 items.map(async (item) => {
731 const result = await item.check(ctx).catch(
732 (err): CheckResult => ({
733 status: "fail",
734 detail: err instanceof Error ? err.message : String(err),
735 }),
736 );
737 return { ...item, result };
738 }),
739 );
740 const byId = new Map(results.map((r) => [r.id, r]));
741 return results.map((r) => {
742 const requires = r.requires ?? [];
743 const canAct = requires.every(
744 (reqId) => byId.get(reqId)?.result.status === "pass",
745 );
746 return { ...r, canAct };
747 });
748}
749