feat: guard certificate orders for custom domains and explain the setup
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / test (pull_request) Successful in 8m21s
ci / lint (pull_request) Successful in 11m0s
ci / build (pull_request) Canceled after 8m49s
ci / image (pull_request) Canceled after 0s
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / test (pull_request) Successful in 8m21s
ci / lint (pull_request) Successful in 11m0s
ci / build (pull_request) Canceled after 8m49s
ci / image (pull_request) Canceled after 0s
Status page servers order certificates on demand. Verified domains were already the only ones they would order for, but nothing bounded how many: an organization switching domains, or many organizations at once, could use up the CA's rate limits that all servers sharing an ACME account depend on, and every handshake or request for a made-up name was passed on to the API. - Before a new order (not a renewal) the server asks the API (POST /agent/v1/certificates). It allows verified domains of pages that server serves, within limits per domain and day, per organization and day, and per ACME account owner and hour (UPTIME_CERTS_*), counted across all instances. - An organization can set a new custom domain at most 10 times a day. - The server remembers names without a page for a minute and passes at most 20 unknown names a second on to the API; pages the sync cached are not affected. Only real pages are recorded as visited. - The page editor explains the three steps: the TXT record, the CNAME record with the platform's status page host as its target (or the organization's own servers), apex domains, and when HTTPS follows. 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
7509b8c429
commit
db36d918fe
18 files changed
+787
-161
No files matched your search
+53
-20
@@ -35,6 +35,9 @@ const (
|
||||
// verifyPrefix is the label under which customers publish the TXT record
|
||||
// proving control of a custom domain.
|
||||
verifyPrefix = "_uptimesebi."
|
||||
// domainChangesPerDay bounds how often an organization may set a new
|
||||
// custom domain.
|
||||
domainChangesPerDay = 10
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -359,29 +362,15 @@ func (s *Server) agentPage(c *gin.Context) {
|
||||
fail(c, http.StatusBadRequest, "invalid_input")
|
||||
return
|
||||
}
|
||||
var (
|
||||
page store.StatusPage
|
||||
own bool
|
||||
)
|
||||
a := agentOf(c)
|
||||
err := s.db.Tx(ctx, tenant.System(), func(q *store.Queries) error {
|
||||
var err error
|
||||
if page, err = q.FindPublishedPage(ctx, store.FindPublishedPageParams{Host: host, Slug: slug}); err != nil || a.OrgID != nil {
|
||||
return err
|
||||
}
|
||||
own, err = q.OrgServesOwnPages(ctx, &page.OrgID)
|
||||
return err
|
||||
})
|
||||
// The platform's servers leave the pages of organizations that serve
|
||||
// them on their own servers to those.
|
||||
if errors.Is(err, pgx.ErrNoRows) || (err == nil && (own || a.OrgID != nil && *a.OrgID != page.OrgID)) {
|
||||
fail(c, http.StatusNotFound, "not_found")
|
||||
return
|
||||
}
|
||||
page, ok, err := s.agentServes(ctx, agentOf(c), host, slug)
|
||||
if err != nil {
|
||||
internalError(c, err)
|
||||
return
|
||||
}
|
||||
if !ok {
|
||||
fail(c, http.StatusNotFound, "not_found")
|
||||
return
|
||||
}
|
||||
snap, err := s.buildSnapshot(ctx, page)
|
||||
if err != nil {
|
||||
internalError(c, err)
|
||||
@@ -398,6 +387,32 @@ func (s *Server) agentPage(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, snap)
|
||||
}
|
||||
|
||||
// agentServes finds the published page a status page agent serves at host
|
||||
// or slug. The platform's servers leave the pages of organizations that
|
||||
// serve them on their own servers to those, which receive only their own
|
||||
// organization's pages.
|
||||
func (s *Server) agentServes(ctx context.Context, a store.GetAgentByHashRow, host, slug *string) (store.StatusPage, bool, error) {
|
||||
var (
|
||||
page store.StatusPage
|
||||
own bool
|
||||
)
|
||||
err := s.db.Tx(ctx, tenant.System(), func(q *store.Queries) error {
|
||||
var err error
|
||||
if page, err = q.FindPublishedPage(ctx, store.FindPublishedPageParams{Host: host, Slug: slug}); err != nil || a.OrgID != nil {
|
||||
return err
|
||||
}
|
||||
own, err = q.OrgServesOwnPages(ctx, &page.OrgID)
|
||||
return err
|
||||
})
|
||||
switch {
|
||||
case errors.Is(err, pgx.ErrNoRows):
|
||||
return page, false, nil
|
||||
case err != nil:
|
||||
return page, false, err
|
||||
}
|
||||
return page, !own && (a.OrgID == nil || *a.OrgID == page.OrgID), nil
|
||||
}
|
||||
|
||||
// agentPageIndex lists the pages the status page server serves.
|
||||
func (s *Server) agentPageIndex(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
@@ -724,12 +739,30 @@ func (s *Server) setPageDomain(c *gin.Context) {
|
||||
p := current(c)
|
||||
ctx := c.Request.Context()
|
||||
var row store.StatusPage
|
||||
limited := false
|
||||
err := s.db.Tx(ctx, p.scope(), func(q *store.Queries) error {
|
||||
var err error
|
||||
cur, err := q.GetStatusPage(ctx, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Every new domain may end in a certificate order; switching domains
|
||||
// over and over would use up the CA's limits for everyone.
|
||||
if domain != "" && domain != deref(cur.CustomDomain) {
|
||||
ok, err := s.limiter.Allow(ctx, "domain_change:"+p.Org.ID.String(), domainChangesPerDay, 24*time.Hour)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !ok {
|
||||
limited = true
|
||||
return nil
|
||||
}
|
||||
}
|
||||
row, err = q.SetStatusPageDomain(ctx, store.SetStatusPageDomainParams{ID: id, CustomDomain: nonEmpty(domain)})
|
||||
return err
|
||||
})
|
||||
switch {
|
||||
case limited:
|
||||
fail(c, http.StatusTooManyRequests, "domain_changes_exceeded", "Count", domainChangesPerDay)
|
||||
case isUniqueViolation(err, "status_pages_custom_domain_key"):
|
||||
fail(c, http.StatusConflict, "domain_taken")
|
||||
case errors.Is(err, pgx.ErrNoRows):
|
||||
|
||||
Reference in new issue
Block a user