feat: choose which checkers may check private addresses, check types per organization
Whether platform checkers may check private addresses, including the host's Docker socket, is now a platform setting; unset, it stays as before: allowed self-hosted, forbidden in the cloud edition. Each of an organization's checkers has its own switch, on by default, settable at creation and toggled in the checker list. Both apply from the checker's next poll. Organizations choose in their settings which of the platform's check types their members are offered; existing monitors keep running, and if the platform later switches off everything an organization kept, it is offered the platform's types again rather than none. Forms marked data-autosave are sent when a field changes. 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
0b7f48a609
commit
465fda60dc
26 files changed
+984
-281
No files matched your search
@@ -13,18 +13,19 @@ import (
|
||||
)
|
||||
|
||||
const createAgent = `-- name: CreateAgent :one
|
||||
INSERT INTO agents (org_id, kind, name, region_id, token_hash, prefix)
|
||||
VALUES ($1, $2, $3, $4, $5, $6)
|
||||
RETURNING id, org_id, kind, name, token_hash, prefix, last_seen_at, release, created_at, region_id
|
||||
INSERT INTO agents (org_id, kind, name, region_id, token_hash, prefix, allow_private)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
||||
RETURNING id, org_id, kind, name, token_hash, prefix, last_seen_at, release, created_at, region_id, allow_private
|
||||
`
|
||||
|
||||
type CreateAgentParams struct {
|
||||
OrgID *uuid.UUID
|
||||
Kind string
|
||||
Name string
|
||||
RegionID *uuid.UUID
|
||||
TokenHash []byte
|
||||
Prefix string
|
||||
OrgID *uuid.UUID
|
||||
Kind string
|
||||
Name string
|
||||
RegionID *uuid.UUID
|
||||
TokenHash []byte
|
||||
Prefix string
|
||||
AllowPrivate bool
|
||||
}
|
||||
|
||||
func (q *Queries) CreateAgent(ctx context.Context, arg CreateAgentParams) (Agent, error) {
|
||||
@@ -35,6 +36,7 @@ func (q *Queries) CreateAgent(ctx context.Context, arg CreateAgentParams) (Agent
|
||||
arg.RegionID,
|
||||
arg.TokenHash,
|
||||
arg.Prefix,
|
||||
arg.AllowPrivate,
|
||||
)
|
||||
var i Agent
|
||||
err := row.Scan(
|
||||
@@ -48,6 +50,7 @@ func (q *Queries) CreateAgent(ctx context.Context, arg CreateAgentParams) (Agent
|
||||
&i.Release,
|
||||
&i.CreatedAt,
|
||||
&i.RegionID,
|
||||
&i.AllowPrivate,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -133,25 +136,26 @@ func (q *Queries) EnsurePlatformRegion(ctx context.Context, arg EnsurePlatformRe
|
||||
}
|
||||
|
||||
const getAgentByHash = `-- name: GetAgentByHash :one
|
||||
SELECT a.id, a.org_id, a.kind, a.name, a.token_hash, a.prefix, a.last_seen_at, a.release, a.created_at, a.region_id, r.key AS region_key, r.name AS region_name
|
||||
SELECT a.id, a.org_id, a.kind, a.name, a.token_hash, a.prefix, a.last_seen_at, a.release, a.created_at, a.region_id, a.allow_private, r.key AS region_key, r.name AS region_name
|
||||
FROM agents a
|
||||
LEFT JOIN regions r ON r.id = a.region_id
|
||||
WHERE a.token_hash = $1
|
||||
`
|
||||
|
||||
type GetAgentByHashRow struct {
|
||||
ID uuid.UUID
|
||||
OrgID *uuid.UUID
|
||||
Kind string
|
||||
Name string
|
||||
TokenHash []byte
|
||||
Prefix string
|
||||
LastSeenAt *time.Time
|
||||
Release *string
|
||||
CreatedAt time.Time
|
||||
RegionID *uuid.UUID
|
||||
RegionKey *string
|
||||
RegionName *string
|
||||
ID uuid.UUID
|
||||
OrgID *uuid.UUID
|
||||
Kind string
|
||||
Name string
|
||||
TokenHash []byte
|
||||
Prefix string
|
||||
LastSeenAt *time.Time
|
||||
Release *string
|
||||
CreatedAt time.Time
|
||||
RegionID *uuid.UUID
|
||||
AllowPrivate bool
|
||||
RegionKey *string
|
||||
RegionName *string
|
||||
}
|
||||
|
||||
// System scope.
|
||||
@@ -169,6 +173,7 @@ func (q *Queries) GetAgentByHash(ctx context.Context, tokenHash []byte) (GetAgen
|
||||
&i.Release,
|
||||
&i.CreatedAt,
|
||||
&i.RegionID,
|
||||
&i.AllowPrivate,
|
||||
&i.RegionKey,
|
||||
&i.RegionName,
|
||||
)
|
||||
@@ -193,7 +198,7 @@ func (q *Queries) GetRegion(ctx context.Context, id uuid.UUID) (Region, error) {
|
||||
}
|
||||
|
||||
const listAgents = `-- name: ListAgents :many
|
||||
SELECT a.id, a.org_id, a.kind, a.name, a.token_hash, a.prefix, a.last_seen_at, a.release, a.created_at, a.region_id, r.key AS region_key, r.name AS region_name
|
||||
SELECT a.id, a.org_id, a.kind, a.name, a.token_hash, a.prefix, a.last_seen_at, a.release, a.created_at, a.region_id, a.allow_private, r.key AS region_key, r.name AS region_name
|
||||
FROM agents a
|
||||
LEFT JOIN regions r ON r.id = a.region_id
|
||||
WHERE a.org_id IS NOT DISTINCT FROM $1::uuid
|
||||
@@ -201,18 +206,19 @@ ORDER BY a.kind, r.name, a.name
|
||||
`
|
||||
|
||||
type ListAgentsRow struct {
|
||||
ID uuid.UUID
|
||||
OrgID *uuid.UUID
|
||||
Kind string
|
||||
Name string
|
||||
TokenHash []byte
|
||||
Prefix string
|
||||
LastSeenAt *time.Time
|
||||
Release *string
|
||||
CreatedAt time.Time
|
||||
RegionID *uuid.UUID
|
||||
RegionKey *string
|
||||
RegionName *string
|
||||
ID uuid.UUID
|
||||
OrgID *uuid.UUID
|
||||
Kind string
|
||||
Name string
|
||||
TokenHash []byte
|
||||
Prefix string
|
||||
LastSeenAt *time.Time
|
||||
Release *string
|
||||
CreatedAt time.Time
|
||||
RegionID *uuid.UUID
|
||||
AllowPrivate bool
|
||||
RegionKey *string
|
||||
RegionName *string
|
||||
}
|
||||
|
||||
// Agents owned by org, or platform agents when org is NULL.
|
||||
@@ -236,6 +242,7 @@ func (q *Queries) ListAgents(ctx context.Context, orgID *uuid.UUID) ([]ListAgent
|
||||
&i.Release,
|
||||
&i.CreatedAt,
|
||||
&i.RegionID,
|
||||
&i.AllowPrivate,
|
||||
&i.RegionKey,
|
||||
&i.RegionName,
|
||||
); err != nil {
|
||||
@@ -311,6 +318,25 @@ func (q *Queries) ListVisibleRegions(ctx context.Context) ([]Region, error) {
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const setAgentAllowPrivate = `-- name: SetAgentAllowPrivate :execrows
|
||||
UPDATE agents SET allow_private = $1
|
||||
WHERE id = $2 AND kind = 'checker' AND org_id = $3
|
||||
`
|
||||
|
||||
type SetAgentAllowPrivateParams struct {
|
||||
AllowPrivate bool
|
||||
ID uuid.UUID
|
||||
OrgID *uuid.UUID
|
||||
}
|
||||
|
||||
func (q *Queries) SetAgentAllowPrivate(ctx context.Context, arg SetAgentAllowPrivateParams) (int64, error) {
|
||||
result, err := q.db.Exec(ctx, setAgentAllowPrivate, arg.AllowPrivate, arg.ID, arg.OrgID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected(), nil
|
||||
}
|
||||
|
||||
const touchAgent = `-- name: TouchAgent :exec
|
||||
UPDATE agents SET last_seen_at = now(), release = $2
|
||||
WHERE id = $1 AND (last_seen_at IS NULL OR last_seen_at < now() - interval '30 seconds' OR release IS DISTINCT FROM $2)
|
||||
|
||||
+20
-18
@@ -12,16 +12,17 @@ import (
|
||||
)
|
||||
|
||||
type Agent struct {
|
||||
ID uuid.UUID
|
||||
OrgID *uuid.UUID
|
||||
Kind string
|
||||
Name string
|
||||
TokenHash []byte
|
||||
Prefix string
|
||||
LastSeenAt *time.Time
|
||||
Release *string
|
||||
CreatedAt time.Time
|
||||
RegionID *uuid.UUID
|
||||
ID uuid.UUID
|
||||
OrgID *uuid.UUID
|
||||
Kind string
|
||||
Name string
|
||||
TokenHash []byte
|
||||
Prefix string
|
||||
LastSeenAt *time.Time
|
||||
Release *string
|
||||
CreatedAt time.Time
|
||||
RegionID *uuid.UUID
|
||||
AllowPrivate bool
|
||||
}
|
||||
|
||||
type AgentInstance struct {
|
||||
@@ -254,14 +255,15 @@ type NotificationChannel struct {
|
||||
}
|
||||
|
||||
type Org struct {
|
||||
ID uuid.UUID
|
||||
Slug string
|
||||
Name string
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
RequireTotp bool
|
||||
RequireSso bool
|
||||
ApiTokenMaxDays *int32
|
||||
ID uuid.UUID
|
||||
Slug string
|
||||
Name string
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
RequireTotp bool
|
||||
RequireSso bool
|
||||
ApiTokenMaxDays *int32
|
||||
DisabledCheckTypes []string
|
||||
}
|
||||
|
||||
type PlatformSetting struct {
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
|
||||
const createOrg = `-- name: CreateOrg :one
|
||||
INSERT INTO orgs (id, slug, name) VALUES ($1, $2, $3)
|
||||
RETURNING id, slug, name, created_at, updated_at, require_totp, require_sso, api_token_max_days
|
||||
RETURNING id, slug, name, created_at, updated_at, require_totp, require_sso, api_token_max_days, disabled_check_types
|
||||
`
|
||||
|
||||
type CreateOrgParams struct {
|
||||
@@ -34,6 +34,7 @@ func (q *Queries) CreateOrg(ctx context.Context, arg CreateOrgParams) (Org, erro
|
||||
&i.RequireTotp,
|
||||
&i.RequireSso,
|
||||
&i.ApiTokenMaxDays,
|
||||
&i.DisabledCheckTypes,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -51,7 +52,7 @@ func (q *Queries) DeleteOrg(ctx context.Context, id uuid.UUID) (int64, error) {
|
||||
}
|
||||
|
||||
const getOrg = `-- name: GetOrg :one
|
||||
SELECT id, slug, name, created_at, updated_at, require_totp, require_sso, api_token_max_days FROM orgs WHERE id = $1
|
||||
SELECT id, slug, name, created_at, updated_at, require_totp, require_sso, api_token_max_days, disabled_check_types FROM orgs WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetOrg(ctx context.Context, id uuid.UUID) (Org, error) {
|
||||
@@ -66,12 +67,13 @@ func (q *Queries) GetOrg(ctx context.Context, id uuid.UUID) (Org, error) {
|
||||
&i.RequireTotp,
|
||||
&i.RequireSso,
|
||||
&i.ApiTokenMaxDays,
|
||||
&i.DisabledCheckTypes,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getOrgBySlug = `-- name: GetOrgBySlug :one
|
||||
SELECT id, slug, name, created_at, updated_at, require_totp, require_sso, api_token_max_days FROM orgs WHERE slug = $1
|
||||
SELECT id, slug, name, created_at, updated_at, require_totp, require_sso, api_token_max_days, disabled_check_types FROM orgs WHERE slug = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetOrgBySlug(ctx context.Context, slug string) (Org, error) {
|
||||
@@ -86,12 +88,13 @@ func (q *Queries) GetOrgBySlug(ctx context.Context, slug string) (Org, error) {
|
||||
&i.RequireTotp,
|
||||
&i.RequireSso,
|
||||
&i.ApiTokenMaxDays,
|
||||
&i.DisabledCheckTypes,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const listOrgs = `-- name: ListOrgs :many
|
||||
SELECT id, slug, name, created_at, updated_at, require_totp, require_sso, api_token_max_days FROM orgs ORDER BY name
|
||||
SELECT id, slug, name, created_at, updated_at, require_totp, require_sso, api_token_max_days, disabled_check_types FROM orgs ORDER BY name
|
||||
`
|
||||
|
||||
func (q *Queries) ListOrgs(ctx context.Context) ([]Org, error) {
|
||||
@@ -112,6 +115,7 @@ func (q *Queries) ListOrgs(ctx context.Context) ([]Org, error) {
|
||||
&i.RequireTotp,
|
||||
&i.RequireSso,
|
||||
&i.ApiTokenMaxDays,
|
||||
&i.DisabledCheckTypes,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -123,10 +127,24 @@ func (q *Queries) ListOrgs(ctx context.Context) ([]Org, error) {
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const setOrgDisabledCheckTypes = `-- name: SetOrgDisabledCheckTypes :exec
|
||||
UPDATE orgs SET disabled_check_types = $2, updated_at = now() WHERE id = $1
|
||||
`
|
||||
|
||||
type SetOrgDisabledCheckTypesParams struct {
|
||||
ID uuid.UUID
|
||||
DisabledCheckTypes []string
|
||||
}
|
||||
|
||||
func (q *Queries) SetOrgDisabledCheckTypes(ctx context.Context, arg SetOrgDisabledCheckTypesParams) error {
|
||||
_, err := q.db.Exec(ctx, setOrgDisabledCheckTypes, arg.ID, arg.DisabledCheckTypes)
|
||||
return err
|
||||
}
|
||||
|
||||
const updateOrgPolicy = `-- name: UpdateOrgPolicy :one
|
||||
UPDATE orgs SET require_totp = $2, require_sso = $3, api_token_max_days = $4, updated_at = now()
|
||||
WHERE id = $1
|
||||
RETURNING id, slug, name, created_at, updated_at, require_totp, require_sso, api_token_max_days
|
||||
RETURNING id, slug, name, created_at, updated_at, require_totp, require_sso, api_token_max_days, disabled_check_types
|
||||
`
|
||||
|
||||
type UpdateOrgPolicyParams struct {
|
||||
@@ -153,6 +171,7 @@ func (q *Queries) UpdateOrgPolicy(ctx context.Context, arg UpdateOrgPolicyParams
|
||||
&i.RequireTotp,
|
||||
&i.RequireSso,
|
||||
&i.ApiTokenMaxDays,
|
||||
&i.DisabledCheckTypes,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -239,6 +239,8 @@ type Querier interface {
|
||||
// The organization's latest results run by one checker instance.
|
||||
ResultsByChecker(ctx context.Context, arg ResultsByCheckerParams) ([]ResultsByCheckerRow, error)
|
||||
ScrubAuditEmail(ctx context.Context, email string) error
|
||||
SetAgentAllowPrivate(ctx context.Context, arg SetAgentAllowPrivateParams) (int64, error)
|
||||
SetOrgDisabledCheckTypes(ctx context.Context, arg SetOrgDisabledCheckTypesParams) error
|
||||
SetPasswordHash(ctx context.Context, arg SetPasswordHashParams) error
|
||||
SetPlatformSetting(ctx context.Context, arg SetPlatformSettingParams) error
|
||||
// Changing the domain drops a previous verification.
|
||||
|
||||
@@ -25,8 +25,8 @@ SELECT * FROM regions WHERE org_id IS NULL ORDER BY name, key;
|
||||
DELETE FROM regions WHERE id = $1;
|
||||
|
||||
-- name: CreateAgent :one
|
||||
INSERT INTO agents (org_id, kind, name, region_id, token_hash, prefix)
|
||||
VALUES ($1, $2, $3, $4, $5, $6)
|
||||
INSERT INTO agents (org_id, kind, name, region_id, token_hash, prefix, allow_private)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
||||
RETURNING *;
|
||||
|
||||
-- name: GetAgentByHash :one
|
||||
@@ -50,3 +50,7 @@ DELETE FROM agents WHERE id = sqlc.arg(id) AND org_id IS NOT DISTINCT FROM sqlc.
|
||||
-- name: TouchAgent :exec
|
||||
UPDATE agents SET last_seen_at = now(), release = $2
|
||||
WHERE id = $1 AND (last_seen_at IS NULL OR last_seen_at < now() - interval '30 seconds' OR release IS DISTINCT FROM $2);
|
||||
|
||||
-- name: SetAgentAllowPrivate :execrows
|
||||
UPDATE agents SET allow_private = sqlc.arg(allow_private)
|
||||
WHERE id = sqlc.arg(id) AND kind = 'checker' AND org_id = sqlc.arg(org_id);
|
||||
@@ -18,3 +18,6 @@ DELETE FROM orgs WHERE id = $1;
|
||||
UPDATE orgs SET require_totp = $2, require_sso = $3, api_token_max_days = $4, updated_at = now()
|
||||
WHERE id = $1
|
||||
RETURNING *;
|
||||
|
||||
-- name: SetOrgDisabledCheckTypes :exec
|
||||
UPDATE orgs SET disabled_check_types = $2, updated_at = now() WHERE id = $1;
|
||||
Reference in new issue
Block a user