Documentation
¶
Index ¶
- Constants
- Variables
- func SetBuildInfo(version, commit, date string)
- type Actor
- type Config
- type Event
- type OIDCConfig
- type Server
- func (s *Server) Close()
- func (s *Server) Handler() http.Handler
- func (s *Server) ListenAndServe(addr string) error
- func (s *Server) ListenAndServeAdmin(addr string) error
- func (s *Server) PublishEvent(typ string, payload any)
- func (s *Server) ScanOnce(ctx context.Context, opts controller.ScanOptions) (controller.ScanSummary, error)
- func (s *Server) Shutdown(ctx context.Context) error
- func (s *Server) StartAuditRetention(ctx context.Context, retain time.Duration)
- func (s *Server) StartScheduler(_ context.Context, interval time.Duration, contexts []string)
Constants ¶
const ( // EventScanComplete fires once after each scan persists. EventScanComplete = "scan.complete" // EventScanFailed fires when a triggered scan errored out. EventScanFailed = "scan.failed" // EventKeyRevoked fires when an admin revokes an API key. EventKeyRevoked = "key.revoked" // EventAlertReceived fires for each alert delivered by AlertManager. EventAlertReceived = "alert.received" )
Event type constants. New event types must follow `<noun>.<verb>` so consumers can subscribe by prefix.
Variables ¶
var ( // ErrServer indicates a general server failure. ErrServer = errors.New("server") // ErrBadRequest indicates invalid client input. ErrBadRequest = errors.New("bad request") )
Functions ¶
func SetBuildInfo ¶
func SetBuildInfo(version, commit, date string)
SetBuildInfo records build metadata so the /admin/system endpoint can report it. The cmd package calls this once during startup.
Types ¶
type Actor ¶
type Actor struct {
// ID is the API key identifier, or "bootstrap" for --auth-token, or
// "anonymous" for --insecure mode.
ID string
// Name is a human-readable label for log lines and audit entries.
Name string
// Role is one of store.RoleAdmin, store.RoleOperator, store.RoleViewer.
Role string
// ClusterScope is the list of cluster names (or "group:<n>" entries) this
// actor may act upon. The single element "*" grants unrestricted access.
ClusterScope []string
}
Actor describes who is performing a request after authentication. An Actor is always present once authMiddleware has run, even in --insecure mode where it represents an anonymous admin.
func (*Actor) AllowsCluster ¶
AllowsCluster reports whether the actor may act on the given cluster. groupLookup, when non-nil, resolves "group:<name>" scope entries to their member cluster names so a group-scoped key authorises any current member.
func (*Actor) FilterClusters ¶
FilterClusters returns the subset of clusters the actor is permitted to act on.
func (*Actor) HasWildcardScope ¶
HasWildcardScope reports whether the actor may act on any cluster.
type Config ¶
type Config struct {
// Store is the database backend.
Store store.Store
// Registry is the scanner registry.
Registry *scanner.Registry
// Log is the zap logger.
Log *zap.Logger
// KubeconfigPath is the kubeconfig file path for scans.
KubeconfigPath string
// Workers is the max concurrent operations for scans.
Workers int
// AuthToken is the bearer token required for mutating endpoints. When
// empty and Insecure is false, mutating endpoints return 403.
AuthToken string
// Insecure disables authentication entirely when true.
Insecure bool
// CORSOrigins is the explicit allowlist of permitted cross-origin Origins.
// Wildcard is intentionally not supported.
CORSOrigins []string
// Demo, when true, causes /api/geo to return synthetic fleet data so the
// globe can be previewed without any real clusters or scans. Other
// endpoints behave normally; demo mode is read-only and additive.
Demo bool
// SlackWebhookURL, when non-empty, is the incoming-webhook URL that
// receives new critical findings.
SlackWebhookURL string
// FleetDriftOutputDir, when non-empty, is a local directory the server
// writes FleetDriftReport YAMLs into after every scan. One file per
// cluster, overwritten in place so the directory tracks the latest scan.
FleetDriftOutputDir string
// PolicyReportOutputDir, when non-empty, is a local directory the server
// writes wgpolicyk8s.io PolicyReport YAMLs to after every scan.
PolicyReportOutputDir string
// PolicyReportNamespace is the namespace placed on emitted PolicyReports.
// Defaults to "fleetsweeper" when empty.
PolicyReportNamespace string
// CostCSVPath, when non-empty, points at a CSV mapping clusters to costs.
// Loaded once at startup and refreshed on a periodic ticker so dashboard
// cost correlation reflects current billing without a restart.
CostCSVPath string
// WebhookConfigPath, when non-empty, points at a YAML file of outbound
// HTTP subscribers. See internal/webhooks for the schema.
WebhookConfigPath string
// WebhookSecret, when non-empty, is the HMAC-SHA256 shared secret an
// inbound webhook caller must use to authenticate scan-trigger calls.
WebhookSecret string
// SealKey, when non-empty, is the HMAC-SHA256 secret used to sign every
// saved scan report. Sealed scans can be verified later with
// `fleetsweeper verify`.
SealKey string
// OIDC configures browser SSO. When zero-valued the server runs in
// bearer-only mode.
OIDC OIDCConfig
// ReadRPM is the per-actor budget for GET/HEAD/OPTIONS requests.
// Zero disables read limiting; recommended default is 600 (10 per
// second per actor).
ReadRPM int
// WriteRPM is the per-actor budget for mutating requests. Zero
// disables write limiting; recommended default is 60 (one per
// second per actor).
WriteRPM int
}
Config holds server configuration.
type Event ¶
type Event struct {
// Type categorises the event (for example "scan.complete").
Type string `json:"type"`
// At is when the event was emitted.
At time.Time `json:"at"`
// Payload is the event-specific data.
Payload any `json:"payload,omitempty"`
}
Event is one server-sent event the dashboard or external consumers subscribe to. The Type field is the SSE event name; Data is JSON- serialized on the wire.
type OIDCConfig ¶
type OIDCConfig struct {
// IssuerURL is the OIDC discovery URL (e.g. https://accounts.google.com).
IssuerURL string
// ClientID identifies the fleetsweeper application at the IdP.
ClientID string
// ClientSecret is the matching client secret.
ClientSecret string
// RedirectURL is fleetsweeper's callback URL, e.g.
// https://fleetsweeper.example.com/oidc/callback. Must be registered
// with the IdP exactly.
RedirectURL string
// Scopes requested. Defaults to openid + email + profile.
Scopes []string
// SessionSecret is the HMAC-SHA256 key used to sign session cookies.
// Treat as a long-term server secret.
SessionSecret string
// SessionLifetime is the cookie validity window. Defaults to 8 hours.
SessionLifetime time.Duration
// AdminClaim is the JWT claim consulted to assign the admin role.
// Format: "<claim_name>:<value>" — e.g. "groups:fleetsweeper-admins"
// or "email:ops@example.com". Empty disables admin promotion via OIDC.
AdminClaim string
// OperatorClaim is the JWT claim for the operator role. Empty disables.
OperatorClaim string
// DefaultRole is the role granted to authenticated users who match no
// claim mapping. Defaults to viewer.
DefaultRole string
}
OIDCConfig configures the OIDC login flow. All fields are required when OIDC is enabled; the auth middleware silently ignores cookies when OIDCConfig.SessionSecret is empty.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server wraps the HTTP server with its dependencies.
func (*Server) Close ¶
func (s *Server) Close()
Close is a convenience wrapper that cancels the server context and waits for background goroutines to drain. Used by tests and offline tooling.
func (*Server) Handler ¶ added in v0.7.0
Handler returns the root HTTP handler. It exposes the configured mux so the server can be embedded behind another router or driven in tests without binding a socket.
func (*Server) ListenAndServe ¶
ListenAndServe starts the HTTP server on the given address with full timeouts.
func (*Server) ListenAndServeAdmin ¶
ListenAndServeAdmin starts a separate HTTP server with pprof and a basic metrics endpoint, intended for an internal address that is not exposed to untrusted networks. When addr is empty this is a no-op.
func (*Server) PublishEvent ¶
PublishEvent is the server-facing API for emitting events. Other handlers call it after persisting a scan or revoking a key.
func (*Server) ScanOnce ¶
func (s *Server) ScanOnce(ctx context.Context, opts controller.ScanOptions) (controller.ScanSummary, error)
ScanOnce executes a single scan with the given options and returns a summary. It satisfies the controller.ScanRunner interface so the ClusterScan operator can drive scans without depending on internal server types beyond Server. Concurrent calls are serialized by the same mutex that gates HTTP triggers so a controller-driven scan and an operator-driven scan cannot interleave.
func (*Server) Shutdown ¶
Shutdown gracefully stops both HTTP servers, cancels the server context, and waits for fire-and-forget background goroutines to drain.
func (*Server) StartAuditRetention ¶
StartAuditRetention launches a goroutine that periodically deletes audit_log rows older than retain. retain <= 0 disables retention pruning (the table grows unboundedly until pruned externally). The ticker runs every hour but the first prune fires immediately so a fresh deployment with an existing database does not wait an hour.
func (*Server) StartScheduler ¶
StartScheduler begins periodic scanning at the given interval. It runs until the server context is canceled. The supplied ctx is used only for the initial scan; subsequent ticks use the server context so a canceled parent does not silently kill the scheduler.
Source Files
¶
- ack_fingerprint.go
- acks_handler.go
- admin_keys_handler.go
- alertmanager_handler.go
- audit_handler.go
- audit_middleware.go
- audit_retention.go
- auth.go
- cost_handler.go
- demo.go
- demo_alerts_groups.go
- demo_results.go
- demo_series.go
- errors.go
- events.go
- falco_handler.go
- findings_timeline_handler.go
- fleetdrift_emit.go
- forecast_handler.go
- geo_handlers.go
- handlers.go
- history_findings.go
- inbound_webhook.go
- integrations_handler.go
- metrics.go
- metrics_otel.go
- middleware.go
- oidc.go
- openapi.go
- policyreport_emit.go
- ratelimit.go
- scan_once.go
- seal_handler.go
- server.go
- slack.go
- system_handler.go
- tag_filter.go
- tags_handler.go
- timeline_handler.go
- webhook_dispatcher_type.go
- webhook_emit.go