feat: verify custom domains by a CNAME unique to the page
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (pull_request) Successful in 7m28s
ci / test (pull_request) Successful in 12m52s
ci / build (pull_request) Successful in 11m21s
ci / image (pull_request) Successful in 4m38s

A custom domain now needs a single record: a CNAME to
<label>.<status page host>, where the label is derived from the page's
domain token. The wildcard record of the status page host routes it, and
since the target belongs to one page alone it also proves who set it up;
a CNAME to the shared host would not, as any organization could then
claim a domain pointing at the platform. The TXT record stays for domains
whose CNAME cannot be seen, behind a proxy or without a subdomain.

- The domain watch looks for the records of a new domain every minute for
  a quarter of an hour, then every ten minutes for two days, and verifies
  it on its own; "Check now" still works.
- Verified domains are checked daily. When the record is gone the owners
  are told, and a week later the domain is switched off, so a record left
  behind cannot be taken over. Domains verified before keep working
  without checks.
- The editor shows the CNAME record first, the TXT way for proxies and
  apex domains, how the domain was verified and when a missing record will
  switch it off. The API returns cname_record and domain_missing_since.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
Sebastian UnterschützandClaude Opus 5.5 committed 2026-11-25 22:58:54 +01:00
1 parent 66537f4e65
commit 5934bd74e8
16 files changed
+1132 -307

No files matched your search

+4
View File
@@ -418,6 +418,10 @@ type StatusPage struct {
ShowComponentDetails bool
SuspendedAt *time.Time
SuspendedReason string
DomainSetAt *time.Time
DomainCheckedAt *time.Time
DomainFailingSince *time.Time
DomainVerifyMethod *string
}
type StatusPageGroup struct {
+13 -2
View File
@@ -118,6 +118,11 @@ type Querier interface {
DeleteSuccessEvidence(ctx context.Context, arg DeleteSuccessEvidenceParams) error
DeleteUser(ctx context.Context, id uuid.UUID) (int64, error)
DisableTOTP(ctx context.Context, id uuid.UUID) error
// System scope: domains due for a look at their DNS records. A new one is
// looked at every minute for a quarter of an hour, then every ten minutes
// for two days, after which only the verify button tries again. A verified
// one is checked daily, hourly once its record went missing.
DomainsToCheck(ctx context.Context, arg DomainsToCheckParams) ([]DomainsToCheckRow, error)
EmailKeyTaken(ctx context.Context, emailKey *string) (bool, error)
EnableTOTP(ctx context.Context, arg EnableTOTPParams) error
EnqueueNotification(ctx context.Context, arg EnqueueNotificationParams) error
@@ -261,7 +266,11 @@ type Querier interface {
// their group or one of its ancestors.
MaintenanceForMonitors(ctx context.Context, ids []uuid.UUID) ([]MaintenanceForMonitorsRow, error)
MakeAdmin(ctx context.Context, id uuid.UUID) error
MarkDomainVerified(ctx context.Context, id uuid.UUID) error
// The record of a domain was not found. Returns since when it has not
// been, for a verified domain.
MarkDomainUnconfirmed(ctx context.Context, arg MarkDomainUnconfirmedParams) (*time.Time, error)
// The domain's record was found: verified, or still in place.
MarkDomainVerified(ctx context.Context, arg MarkDomainVerifiedParams) error
MarkEmailVerified(ctx context.Context, id uuid.UUID) (User, error)
MarkInvitationAccepted(ctx context.Context, id uuid.UUID) (int64, error)
MarkNotificationFailed(ctx context.Context, arg MarkNotificationFailedParams) error
@@ -353,7 +362,7 @@ type Querier interface {
SetOwner(ctx context.Context, arg SetOwnerParams) (int64, error)
SetPasswordHash(ctx context.Context, arg SetPasswordHashParams) error
SetPlatformSetting(ctx context.Context, arg SetPlatformSettingParams) error
// Changing the domain drops a previous verification.
// Changing the domain drops a previous verification and its checks.
SetStatusPageDomain(ctx context.Context, arg SetStatusPageDomainParams) (StatusPage, error)
SetStatusPageMonitorGroup(ctx context.Context, arg SetStatusPageMonitorGroupParams) error
SetSupportTicketStatus(ctx context.Context, arg SetSupportTicketStatusParams) (int64, error)
@@ -391,6 +400,8 @@ type Querier interface {
TouchAgentInstance(ctx context.Context, arg TouchAgentInstanceParams) error
TouchIdentity(ctx context.Context, arg TouchIdentityParams) error
TouchPlatformIdentity(ctx context.Context, arg TouchPlatformIdentityParams) error
// A verified domain whose record stayed missing past the grace period.
UnverifyDomain(ctx context.Context, id uuid.UUID) error
UpdateAlertGroup(ctx context.Context, arg UpdateAlertGroupParams) (AlertGroup, error)
UpdateChannel(ctx context.Context, arg UpdateChannelParams) (NotificationChannel, error)
UpdateGroup(ctx context.Context, arg UpdateGroupParams) (MonitorGroup, error)
+50 -3
View File
@@ -16,16 +16,63 @@ WHERE id = $1
RETURNING *;
-- name: SetStatusPageDomain :one
-- Changing the domain drops a previous verification.
-- Changing the domain drops a previous verification and its checks.
UPDATE status_pages SET
custom_domain = sqlc.narg(custom_domain),
domain_verified_at = CASE WHEN custom_domain IS NOT DISTINCT FROM sqlc.narg(custom_domain) THEN domain_verified_at END,
domain_verify_method = CASE WHEN custom_domain IS NOT DISTINCT FROM sqlc.narg(custom_domain) THEN domain_verify_method END,
domain_failing_since = CASE WHEN custom_domain IS NOT DISTINCT FROM sqlc.narg(custom_domain) THEN domain_failing_since END,
domain_checked_at = CASE WHEN custom_domain IS NOT DISTINCT FROM sqlc.narg(custom_domain) THEN domain_checked_at END,
domain_set_at = CASE WHEN custom_domain IS NOT DISTINCT FROM sqlc.narg(custom_domain) THEN domain_set_at ELSE now() END,
custom_domain = sqlc.narg(custom_domain),
updated_at = now()
WHERE id = sqlc.arg(id)
RETURNING *;
-- name: MarkDomainVerified :exec
UPDATE status_pages SET domain_verified_at = now() WHERE id = $1;
-- The domain's record was found: verified, or still in place.
UPDATE status_pages SET
domain_verified_at = coalesce(domain_verified_at, sqlc.arg(now)::timestamptz),
domain_verify_method = sqlc.arg(method)::text,
domain_checked_at = sqlc.arg(now)::timestamptz,
domain_failing_since = NULL
WHERE id = sqlc.arg(id);
-- name: MarkDomainUnconfirmed :one
-- The record of a domain was not found. Returns since when it has not
-- been, for a verified domain.
UPDATE status_pages SET
domain_checked_at = sqlc.arg(now)::timestamptz,
domain_failing_since = CASE WHEN domain_verified_at IS NULL THEN NULL
ELSE coalesce(domain_failing_since, sqlc.arg(now)::timestamptz) END
WHERE id = sqlc.arg(id)
RETURNING domain_failing_since;
-- name: UnverifyDomain :exec
-- A verified domain whose record stayed missing past the grace period.
UPDATE status_pages SET
domain_verified_at = NULL, domain_verify_method = NULL, domain_failing_since = NULL
WHERE id = $1;
-- name: DomainsToCheck :many
-- System scope: domains due for a look at their DNS records. A new one is
-- looked at every minute for a quarter of an hour, then every ten minutes
-- for two days, after which only the verify button tries again. A verified
-- one is checked daily, hourly once its record went missing.
SELECT id, org_id, title, custom_domain::text AS domain, domain_token,
domain_verified_at, domain_failing_since
FROM status_pages
WHERE custom_domain IS NOT NULL
AND (sqlc.narg(page_id)::uuid IS NULL OR id = sqlc.narg(page_id))
AND (
(domain_verified_at IS NULL AND domain_set_at > sqlc.arg(now)::timestamptz - interval '48 hours'
AND (domain_checked_at IS NULL OR domain_checked_at <= sqlc.arg(now)::timestamptz - CASE
WHEN domain_set_at > sqlc.arg(now)::timestamptz - interval '15 minutes' THEN interval '50 seconds'
ELSE interval '10 minutes' END))
OR (domain_verified_at IS NOT NULL AND domain_verify_method IS NOT NULL
AND (domain_checked_at IS NULL OR domain_checked_at <= sqlc.arg(now)::timestamptz - CASE
WHEN domain_failing_since IS NULL THEN interval '24 hours' ELSE interval '1 hour' END)))
ORDER BY domain_checked_at NULLS FIRST
LIMIT 500;
-- name: GetStatusPage :one
SELECT * FROM status_pages WHERE id = $1;
+153 -12
View File
@@ -7,6 +7,7 @@ package store
import (
"context"
"time"
"github.com/google/uuid"
)
@@ -60,7 +61,7 @@ func (q *Queries) ClearStatusPageMonitors(ctx context.Context, pageID uuid.UUID)
const createStatusPage = `-- name: CreateStatusPage :one
INSERT INTO status_pages (org_id, slug, title, description, published, show_component_details, domain_token, theme)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
RETURNING id, org_id, slug, title, description, published, custom_domain, domain_token, domain_verified_at, theme, created_at, updated_at, show_component_details, suspended_at, suspended_reason
RETURNING id, org_id, slug, title, description, published, custom_domain, domain_token, domain_verified_at, theme, created_at, updated_at, show_component_details, suspended_at, suspended_reason, domain_set_at, domain_checked_at, domain_failing_since, domain_verify_method
`
type CreateStatusPageParams struct {
@@ -102,6 +103,10 @@ func (q *Queries) CreateStatusPage(ctx context.Context, arg CreateStatusPagePara
&i.ShowComponentDetails,
&i.SuspendedAt,
&i.SuspendedReason,
&i.DomainSetAt,
&i.DomainCheckedAt,
&i.DomainFailingSince,
&i.DomainVerifyMethod,
)
return i, err
}
@@ -171,8 +176,73 @@ func (q *Queries) DeleteStatusPageGroup(ctx context.Context, arg DeleteStatusPag
return result.RowsAffected(), nil
}
const domainsToCheck = `-- name: DomainsToCheck :many
SELECT id, org_id, title, custom_domain::text AS domain, domain_token,
domain_verified_at, domain_failing_since
FROM status_pages
WHERE custom_domain IS NOT NULL
AND ($1::uuid IS NULL OR id = $1)
AND (
(domain_verified_at IS NULL AND domain_set_at > $2::timestamptz - interval '48 hours'
AND (domain_checked_at IS NULL OR domain_checked_at <= $2::timestamptz - CASE
WHEN domain_set_at > $2::timestamptz - interval '15 minutes' THEN interval '50 seconds'
ELSE interval '10 minutes' END))
OR (domain_verified_at IS NOT NULL AND domain_verify_method IS NOT NULL
AND (domain_checked_at IS NULL OR domain_checked_at <= $2::timestamptz - CASE
WHEN domain_failing_since IS NULL THEN interval '24 hours' ELSE interval '1 hour' END)))
ORDER BY domain_checked_at NULLS FIRST
LIMIT 500
`
type DomainsToCheckParams struct {
PageID *uuid.UUID
Now time.Time
}
type DomainsToCheckRow struct {
ID uuid.UUID
OrgID uuid.UUID
Title string
Domain string
DomainToken string
DomainVerifiedAt *time.Time
DomainFailingSince *time.Time
}
// System scope: domains due for a look at their DNS records. A new one is
// looked at every minute for a quarter of an hour, then every ten minutes
// for two days, after which only the verify button tries again. A verified
// one is checked daily, hourly once its record went missing.
func (q *Queries) DomainsToCheck(ctx context.Context, arg DomainsToCheckParams) ([]DomainsToCheckRow, error) {
rows, err := q.db.Query(ctx, domainsToCheck, arg.PageID, arg.Now)
if err != nil {
return nil, err
}
defer rows.Close()
items := []DomainsToCheckRow{}
for rows.Next() {
var i DomainsToCheckRow
if err := rows.Scan(
&i.ID,
&i.OrgID,
&i.Title,
&i.Domain,
&i.DomainToken,
&i.DomainVerifiedAt,
&i.DomainFailingSince,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const findPublishedPage = `-- name: FindPublishedPage :one
SELECT id, org_id, slug, title, description, published, custom_domain, domain_token, domain_verified_at, theme, created_at, updated_at, show_component_details, suspended_at, suspended_reason FROM status_pages
SELECT id, org_id, slug, title, description, published, custom_domain, domain_token, domain_verified_at, theme, created_at, updated_at, show_component_details, suspended_at, suspended_reason, domain_set_at, domain_checked_at, domain_failing_since, domain_verify_method FROM status_pages
WHERE published AND suspended_at IS NULL
AND NOT EXISTS (SELECT 1 FROM orgs o WHERE o.id = status_pages.org_id AND o.suspended_at IS NOT NULL)
AND (($1::citext IS NOT NULL AND custom_domain = $1 AND domain_verified_at IS NOT NULL)
@@ -205,12 +275,16 @@ func (q *Queries) FindPublishedPage(ctx context.Context, arg FindPublishedPagePa
&i.ShowComponentDetails,
&i.SuspendedAt,
&i.SuspendedReason,
&i.DomainSetAt,
&i.DomainCheckedAt,
&i.DomainFailingSince,
&i.DomainVerifyMethod,
)
return i, err
}
const getStatusPage = `-- name: GetStatusPage :one
SELECT id, org_id, slug, title, description, published, custom_domain, domain_token, domain_verified_at, theme, created_at, updated_at, show_component_details, suspended_at, suspended_reason FROM status_pages WHERE id = $1
SELECT id, org_id, slug, title, description, published, custom_domain, domain_token, domain_verified_at, theme, created_at, updated_at, show_component_details, suspended_at, suspended_reason, domain_set_at, domain_checked_at, domain_failing_since, domain_verify_method FROM status_pages WHERE id = $1
`
func (q *Queries) GetStatusPage(ctx context.Context, id uuid.UUID) (StatusPage, error) {
@@ -232,6 +306,10 @@ func (q *Queries) GetStatusPage(ctx context.Context, id uuid.UUID) (StatusPage,
&i.ShowComponentDetails,
&i.SuspendedAt,
&i.SuspendedReason,
&i.DomainSetAt,
&i.DomainCheckedAt,
&i.DomainFailingSince,
&i.DomainVerifyMethod,
)
return i, err
}
@@ -272,7 +350,7 @@ func (q *Queries) ListStatusPageGroups(ctx context.Context, pageID uuid.UUID) ([
}
const listStatusPages = `-- name: ListStatusPages :many
SELECT id, org_id, slug, title, description, published, custom_domain, domain_token, domain_verified_at, theme, created_at, updated_at, show_component_details, suspended_at, suspended_reason FROM status_pages ORDER BY title
SELECT id, org_id, slug, title, description, published, custom_domain, domain_token, domain_verified_at, theme, created_at, updated_at, show_component_details, suspended_at, suspended_reason, domain_set_at, domain_checked_at, domain_failing_since, domain_verify_method FROM status_pages ORDER BY title
`
func (q *Queries) ListStatusPages(ctx context.Context) ([]StatusPage, error) {
@@ -300,6 +378,10 @@ func (q *Queries) ListStatusPages(ctx context.Context) ([]StatusPage, error) {
&i.ShowComponentDetails,
&i.SuspendedAt,
&i.SuspendedReason,
&i.DomainSetAt,
&i.DomainCheckedAt,
&i.DomainFailingSince,
&i.DomainVerifyMethod,
); err != nil {
return nil, err
}
@@ -311,12 +393,47 @@ func (q *Queries) ListStatusPages(ctx context.Context) ([]StatusPage, error) {
return items, nil
}
const markDomainVerified = `-- name: MarkDomainVerified :exec
UPDATE status_pages SET domain_verified_at = now() WHERE id = $1
const markDomainUnconfirmed = `-- name: MarkDomainUnconfirmed :one
UPDATE status_pages SET
domain_checked_at = $1::timestamptz,
domain_failing_since = CASE WHEN domain_verified_at IS NULL THEN NULL
ELSE coalesce(domain_failing_since, $1::timestamptz) END
WHERE id = $2
RETURNING domain_failing_since
`
func (q *Queries) MarkDomainVerified(ctx context.Context, id uuid.UUID) error {
_, err := q.db.Exec(ctx, markDomainVerified, id)
type MarkDomainUnconfirmedParams struct {
Now time.Time
ID uuid.UUID
}
// The record of a domain was not found. Returns since when it has not
// been, for a verified domain.
func (q *Queries) MarkDomainUnconfirmed(ctx context.Context, arg MarkDomainUnconfirmedParams) (*time.Time, error) {
row := q.db.QueryRow(ctx, markDomainUnconfirmed, arg.Now, arg.ID)
var domain_failing_since *time.Time
err := row.Scan(&domain_failing_since)
return domain_failing_since, err
}
const markDomainVerified = `-- name: MarkDomainVerified :exec
UPDATE status_pages SET
domain_verified_at = coalesce(domain_verified_at, $1::timestamptz),
domain_verify_method = $2::text,
domain_checked_at = $1::timestamptz,
domain_failing_since = NULL
WHERE id = $3
`
type MarkDomainVerifiedParams struct {
Now time.Time
Method string
ID uuid.UUID
}
// The domain's record was found: verified, or still in place.
func (q *Queries) MarkDomainVerified(ctx context.Context, arg MarkDomainVerifiedParams) error {
_, err := q.db.Exec(ctx, markDomainVerified, arg.Now, arg.Method, arg.ID)
return err
}
@@ -394,11 +511,15 @@ func (q *Queries) ServablePages(ctx context.Context, agentOrg *uuid.UUID) ([]Ser
const setStatusPageDomain = `-- name: SetStatusPageDomain :one
UPDATE status_pages SET
custom_domain = $1,
domain_verified_at = CASE WHEN custom_domain IS NOT DISTINCT FROM $1 THEN domain_verified_at END,
domain_verify_method = CASE WHEN custom_domain IS NOT DISTINCT FROM $1 THEN domain_verify_method END,
domain_failing_since = CASE WHEN custom_domain IS NOT DISTINCT FROM $1 THEN domain_failing_since END,
domain_checked_at = CASE WHEN custom_domain IS NOT DISTINCT FROM $1 THEN domain_checked_at END,
domain_set_at = CASE WHEN custom_domain IS NOT DISTINCT FROM $1 THEN domain_set_at ELSE now() END,
custom_domain = $1,
updated_at = now()
WHERE id = $2
RETURNING id, org_id, slug, title, description, published, custom_domain, domain_token, domain_verified_at, theme, created_at, updated_at, show_component_details, suspended_at, suspended_reason
RETURNING id, org_id, slug, title, description, published, custom_domain, domain_token, domain_verified_at, theme, created_at, updated_at, show_component_details, suspended_at, suspended_reason, domain_set_at, domain_checked_at, domain_failing_since, domain_verify_method
`
type SetStatusPageDomainParams struct {
@@ -406,7 +527,7 @@ type SetStatusPageDomainParams struct {
ID uuid.UUID
}
// Changing the domain drops a previous verification.
// Changing the domain drops a previous verification and its checks.
func (q *Queries) SetStatusPageDomain(ctx context.Context, arg SetStatusPageDomainParams) (StatusPage, error) {
row := q.db.QueryRow(ctx, setStatusPageDomain, arg.CustomDomain, arg.ID)
var i StatusPage
@@ -426,6 +547,10 @@ func (q *Queries) SetStatusPageDomain(ctx context.Context, arg SetStatusPageDoma
&i.ShowComponentDetails,
&i.SuspendedAt,
&i.SuspendedReason,
&i.DomainSetAt,
&i.DomainCheckedAt,
&i.DomainFailingSince,
&i.DomainVerifyMethod,
)
return i, err
}
@@ -506,6 +631,18 @@ func (q *Queries) StatusPageMonitors(ctx context.Context, pageID uuid.UUID) ([]S
return items, nil
}
const unverifyDomain = `-- name: UnverifyDomain :exec
UPDATE status_pages SET
domain_verified_at = NULL, domain_verify_method = NULL, domain_failing_since = NULL
WHERE id = $1
`
// A verified domain whose record stayed missing past the grace period.
func (q *Queries) UnverifyDomain(ctx context.Context, id uuid.UUID) error {
_, err := q.db.Exec(ctx, unverifyDomain, id)
return err
}
const updateStatusPage = `-- name: UpdateStatusPage :one
UPDATE status_pages
SET slug = $2,
@@ -516,7 +653,7 @@ SET slug = $2,
theme = $7,
updated_at = now()
WHERE id = $1
RETURNING id, org_id, slug, title, description, published, custom_domain, domain_token, domain_verified_at, theme, created_at, updated_at, show_component_details, suspended_at, suspended_reason
RETURNING id, org_id, slug, title, description, published, custom_domain, domain_token, domain_verified_at, theme, created_at, updated_at, show_component_details, suspended_at, suspended_reason, domain_set_at, domain_checked_at, domain_failing_since, domain_verify_method
`
type UpdateStatusPageParams struct {
@@ -556,6 +693,10 @@ func (q *Queries) UpdateStatusPage(ctx context.Context, arg UpdateStatusPagePara
&i.ShowComponentDetails,
&i.SuspendedAt,
&i.SuspendedReason,
&i.DomainSetAt,
&i.DomainCheckedAt,
&i.DomainFailingSince,
&i.DomainVerifyMethod,
)
return i, err
}