Repository navigation
feat(self-hosting): add an authenticated self-check and a helm test that proves a real install works #10769
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+2,365
−313
Merged
feat(self-hosting): add an authenticated self-check and a helm test that proves a real install works #10769
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ce56c0d
feat(self-hosting): add an authenticated self-check and a helm test t…
waleedlatif1 d8736b5
fix(self-hosting): fail-closed self-check, every database endpoint, a…
waleedlatif1 49d8a7c
improvement(self-hosting): simpler self-check, logged failures, every…
waleedlatif1 224ab35
improvement(self-hosting): share the release image list and fold upgr…
waleedlatif1 8280b4d
fix(self-hosting): probe metadata directly, cover IPv6 IMDS, and clas…
waleedlatif1 0fe9620
fix(self-hosting): keep a metadata 200 when its body fails to read
waleedlatif1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import { type NextRequest, NextResponse } from 'next/server' | ||
| import { type SelfCheckResponse, selfCheckContract } from '@/lib/api/contracts/self-check' | ||
| import { parseRequest } from '@/lib/api/server' | ||
| import { verifyCronAuth } from '@/lib/auth/internal' | ||
| import { withRouteHandler } from '@/lib/core/utils/with-route-handler' | ||
| import { runSelfCheck } from '@/lib/self-check/run' | ||
|
|
||
| export const dynamic = 'force-dynamic' | ||
| /** Above the sandbox check's own budget, so a slow sandbox start still reports. */ | ||
| export const maxDuration = 180 | ||
|
|
||
| /** | ||
| * Post-install self-check for self-hosted deployments, called by the Helm chart's `helm test` | ||
| * hook with the cron secret. 200 when nothing failed, 503 otherwise; the body is always the report. | ||
| */ | ||
| export const GET = withRouteHandler(async (request: NextRequest) => { | ||
| const authError = verifyCronAuth(request, 'Self-check') | ||
| if (authError) return authError | ||
|
|
||
| const parsed = await parseRequest(selfCheckContract, request, {}) | ||
| if (!parsed.success) return parsed.response | ||
|
|
||
| const report: SelfCheckResponse = await runSelfCheck({ | ||
| sandbox: parsed.data.query.sandbox === '1', | ||
| realtime: parsed.data.query.realtime === '1', | ||
| }) | ||
| return NextResponse.json(report, { status: report.ok ? 200 : 503 }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import { z } from 'zod' | ||
| import { defineRouteContract } from '@/lib/api/contracts/types' | ||
| import { SELF_CHECK_NAMES, SELF_CHECK_STATUSES } from '@/lib/self-check/types' | ||
|
|
||
| const flagSchema = z.enum(['0', '1']).optional() | ||
|
|
||
| const selfCheckQuerySchema = z | ||
| .object({ | ||
| /** Runs user code in a sandbox and checks it is confined (Kubernetes provider only). */ | ||
| sandbox: flagSchema, | ||
| /** Checks the realtime server's health endpoint. */ | ||
| realtime: flagSchema, | ||
| }) | ||
| .strict() | ||
|
|
||
| const selfCheckResponseSchema = z.object({ | ||
| ok: z.boolean(), | ||
| checks: z.array( | ||
| z.object({ | ||
| name: z.enum(SELF_CHECK_NAMES), | ||
| status: z.enum(SELF_CHECK_STATUSES), | ||
| durationMs: z.number().int().min(0), | ||
| detail: z.string().max(500), | ||
| }) | ||
| ), | ||
| }) | ||
|
|
||
| export type SelfCheckResponse = z.output<typeof selfCheckResponseSchema> | ||
|
|
||
| /** 200 when every check passed, warned, or was skipped; 503 when any failed. */ | ||
| export const selfCheckContract = defineRouteContract({ | ||
| method: 'GET', | ||
| path: '/api/cron/self-check', | ||
| query: selfCheckQuerySchema, | ||
| response: { mode: 'json', schema: selfCheckResponseSchema, status: [200, 503] }, | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.