feat!: let checkers and status page servers reach data only through the api

Only cmd/api connects to Postgres and Redis. Agents authenticate with
tokens created by 'api agent create' and use /agent/v1: checkers long
poll for jobs, which doubles as heartbeat, and report results in
batches. Organizations manage monitors through /api/v1/org/monitors.

BREAKING CHANGE: cmd/checker and cmd/statuspage no longer read
UPTIME_DATABASE_URL or UPTIME_REDIS_*; they need UPTIME_API_URL and
UPTIME_AGENT_TOKEN. UPTIME_CHECKER_REGION is replaced by the region bound
to the agent token.

Closes #10
Closes #11
Closes #12
Closes #13
Closes #49

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-22 01:12:53 +01:00
1 parent 56862dce84
commit d9891bb050
23 files changed
+1361 -45

No files matched your search

+13
View File
@@ -16,6 +16,7 @@ import (
"git.zb-server.de/ZB-Server/uptimesebi/internal/config"
"git.zb-server.de/ZB-Server/uptimesebi/internal/i18n"
"git.zb-server.de/ZB-Server/uptimesebi/internal/requestid"
"git.zb-server.de/ZB-Server/uptimesebi/internal/schedule"
"git.zb-server.de/ZB-Server/uptimesebi/internal/sealed"
"git.zb-server.de/ZB-Server/uptimesebi/internal/sso"
"git.zb-server.de/ZB-Server/uptimesebi/internal/store"
@@ -36,6 +37,7 @@ type Server struct {
limiter *auth.Limiter
totp *auth.TOTPVerifier
sso *sso.Client
sched *schedule.Scheduler
}
// Deps are the external resources a Server needs.
@@ -61,16 +63,22 @@ func New(cfg config.API, d Deps) *Server {
limiter: auth.NewLimiter(d.Redis),
totp: auth.NewTOTPVerifier(d.Redis),
sso: sso.New(sso.SafeHTTPClient(allowPrivate), cfg.PublicURL+"/sso/callback", allowPrivate),
sched: schedule.New(d.Redis),
}
}
// Mount installs session loading, locale resolution and CSRF protection and
// registers the JSON API and the console pages below them.
func (s *Server) Mount(r gin.IRouter) {
// Agents authenticate with tokens and never carry cookies, so they skip
// the session and CSRF middleware.
s.mountAgentAPI(r)
g := r.Group("/", s.sessions.Load(), s.localize(), auth.CSRF())
v1 := g.Group("/api/v1")
v1.POST("/locale", s.setLocale)
v1.GET("/regions", auth.Require(), s.listRegions)
a := v1.Group("/auth")
a.POST("/signup", s.signup)
@@ -92,6 +100,11 @@ func (s *Server) Mount(r gin.IRouter) {
org := v1.Group("/org", s.orgAccess())
org.PUT("/policy", sessionOnly(), can(authz.OrgManage), s.updatePolicy)
org.GET("/monitors", can(authz.MonitorsRead), s.listMonitors)
org.POST("/monitors", can(authz.MonitorsWrite), s.createMonitor)
org.PUT("/monitors/:id", can(authz.MonitorsWrite), s.updateMonitor)
org.DELETE("/monitors/:id", can(authz.MonitorsWrite), s.deleteMonitor)
org.GET("/sso", can(authz.OrgManage), s.listSSOProviders)
org.POST("/sso", sessionOnly(), can(authz.OrgManage), s.createSSOProvider)
org.PUT("/sso/:id", sessionOnly(), can(authz.OrgManage), s.updateSSOProvider)