feat(api): organization-owned regions, checkers and status page servers

Organizations create regions and agents for themselves under Regions &
checkers; an org checker only receives its org's monitors. Platform admins
manage shared regions and agents in the admin panel or with the CLI,
which gains 'api admin grant|revoke'. The first user of a self-hosted
installation becomes a platform admin. Region lists show the org's own
regions first.

Closes #52
Refs #29

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:36:02 +01:00
1 parent 607798d742
commit 22f0740056
19 files changed
+1932 -301

No files matched your search

+21 -9
View File
@@ -58,7 +58,7 @@ func (s *Server) agentAuth() gin.HandlerFunc {
return
}
ctx := c.Request.Context()
var a store.Agent
var a store.GetAgentByHashRow
release := truncate(c.GetHeader(agentapi.ReleaseHeader), 64)
err = s.db.Tx(ctx, tenant.System(), func(q *store.Queries) error {
var err error
@@ -91,11 +91,21 @@ func requireAgentKind(kind string) gin.HandlerFunc {
}
}
func agentOf(c *gin.Context) store.Agent { return c.MustGet(ctxAgent).(store.Agent) }
func agentOf(c *gin.Context) store.GetAgentByHashRow {
return c.MustGet(ctxAgent).(store.GetAgentByHashRow)
}
func instanceOf(c *gin.Context) uuid.UUID { return c.MustGet(ctxInstance).(uuid.UUID) }
func regionOf(c *gin.Context) string { return deref(agentOf(c).Region) }
func (s *Server) cloud() bool { return s.cfg.Edition == config.EditionCloud }
func (s *Server) allowPrivate(a store.Agent) bool {
// regionOf returns the agent's region ID in the string form used for the
// schedule and check results.
func regionOf(c *gin.Context) string {
if id := agentOf(c).RegionID; id != nil {
return id.String()
}
return ""
}
func (s *Server) cloud() bool { return s.cfg.Edition == config.EditionCloud }
func (s *Server) allowPrivate(a store.GetAgentByHashRow) bool {
// Operator checkers in the cloud share our network; customers must not
// reach it through them. Customer-run checkers and self-hosted
// installations check whatever their operator can reach.
@@ -105,7 +115,8 @@ func (s *Server) allowPrivate(a store.Agent) bool {
func (s *Server) agentHello(c *gin.Context) {
a := agentOf(c)
c.JSON(http.StatusOK, agentapi.Hello{
AgentID: a.ID, Name: a.Name, Kind: a.Kind, Region: deref(a.Region), Protocol: agentapi.Version,
AgentID: a.ID, Name: a.Name, Kind: a.Kind, Region: deref(a.RegionKey), RegionID: a.RegionID,
RegionName: deref(a.RegionName), OrgOwned: a.OrgID != nil, Protocol: agentapi.Version,
})
}
@@ -136,7 +147,7 @@ func (s *Server) agentJobs(c *gin.Context) {
// resolveJobs attaches the current monitor settings to dispatched runs.
// Checking is cross-tenant work, hence the system scope.
func (s *Server) resolveJobs(ctx context.Context, a store.Agent, entries []schedule.Entry) ([]agentapi.Job, error) {
func (s *Server) resolveJobs(ctx context.Context, a store.GetAgentByHashRow, entries []schedule.Entry) ([]agentapi.Job, error) {
jobs := []agentapi.Job{}
if len(entries) == 0 {
return jobs, nil
@@ -148,7 +159,7 @@ func (s *Server) resolveJobs(ctx context.Context, a store.Agent, entries []sched
var rows []store.Monitor
err := s.db.Tx(ctx, tenant.System(), func(q *store.Queries) error {
var err error
rows, err = q.MonitorsForJobs(ctx, store.MonitorsForJobsParams{Region: deref(a.Region), Ids: ids})
rows, err = q.MonitorsForJobs(ctx, store.MonitorsForJobsParams{RegionID: deref(a.RegionID), Ids: ids, AgentOrg: a.OrgID})
return err
})
if err != nil {
@@ -190,7 +201,8 @@ func (s *Server) agentResults(c *gin.Context) {
monitors := map[uuid.UUID]store.MonitorsForResultsRow{}
var accepted []agentapi.Result
err := s.db.Tx(ctx, tenant.System(), func(q *store.Queries) error {
rows, err := q.MonitorsForResults(ctx, store.MonitorsForResultsParams{Region: region, Ids: ids})
a := agentOf(c)
rows, err := q.MonitorsForResults(ctx, store.MonitorsForResultsParams{RegionID: deref(a.RegionID), Ids: ids, AgentOrg: a.OrgID})
if err != nil {
return err
}