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
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:
1 parent
66537f4e65
commit
5934bd74e8
16 files changed
+1132
-307
No files matched your search
@@ -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
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user