Documentation
¶
Overview ¶
Package server is the meles web UI and JSON API: configured scans with schedules, scan runs with their results, reports, and the MalwareReports of the meles operator.
Index ¶
- type ClusterIgnores
- type ClusterReports
- type Config
- type EngineStatus
- type IgnoreObject
- type KubeIgnores
- func (i *KubeIgnores) ClusterRules(ctx context.Context) (*ignore.Rules, error)
- func (i *KubeIgnores) Create(ctx context.Context, namespace string, rule v1alpha1.IgnoreRule, ...) (string, error)
- func (i *KubeIgnores) Delete(ctx context.Context, namespace, name string) error
- func (i *KubeIgnores) List(ctx context.Context) ([]IgnoreObject, error)
- type KubeReports
- func (k *KubeReports) Get(ctx context.Context, namespace, name string) (*v1alpha1.MalwareReport, error)
- func (k *KubeReports) Ignores() *KubeIgnores
- func (k *KubeReports) List(ctx context.Context) ([]v1alpha1.MalwareReport, error)
- func (k *KubeReports) OnChange(ctx context.Context, fn func(rep *v1alpha1.MalwareReport, deleted bool)) error
- func (k *KubeReports) RequestRescan(ctx context.Context, namespace, name string) error
- func (k *KubeReports) Start(ctx context.Context) error
- func (k *KubeReports) WaitSynced(ctx context.Context) bool
- type OperatorStatus
- type SelftestStatus
- type Server
- func (s *Server) Engine() EngineStatus
- func (s *Server) Handler() http.Handler
- func (s *Server) RunClusterHistory(ctx context.Context, k *KubeReports, keep time.Duration) error
- func (s *Server) Selftest() SelftestStatus
- func (s *Server) WatchEngine(ctx context.Context, interval time.Duration)
- func (s *Server) WatchSelftest(ctx context.Context, interval time.Duration)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ClusterIgnores ¶
type ClusterIgnores interface {
// List returns all ignore objects, ClusterMalwareIgnores first.
List(ctx context.Context) ([]IgnoreObject, error)
// Create creates a ClusterMalwareIgnore (empty namespace) or a
// MalwareIgnore with one rule and returns its name.
Create(ctx context.Context, namespace string, rule v1alpha1.IgnoreRule, createdBy string) (string, error)
// Delete deletes an object the server created: store.ErrNotFound
// (wrapped) for a missing one, errNotManaged for any other.
Delete(ctx context.Context, namespace, name string) error
}
ClusterIgnores manages MalwareIgnores and ClusterMalwareIgnores from the UI. Every rule created there is an object of its own, labelled as the server's; only those can be deleted from the UI.
type ClusterReports ¶
type ClusterReports interface {
List(ctx context.Context) ([]v1alpha1.MalwareReport, error)
// Get returns store.ErrNotFound (wrapped) for a missing report.
Get(ctx context.Context, namespace, name string) (*v1alpha1.MalwareReport, error)
// RequestRescan sets the meles.io/rescan annotation.
RequestRescan(ctx context.Context, namespace, name string) error
}
ClusterReports gives the server the MalwareReports the operator writes.
type Config ¶
type Config struct {
Store *store.Store
Runner *runner.Runner
Scheduler *schedule.Scheduler
Engine engine.Engine
Cache *scan.Cache
Location *time.Location
Logger *slog.Logger
Version string
// Cluster, if set, shows the operator's MalwareReports.
Cluster ClusterReports
// ClusterRescan allows requesting a rescan from the UI.
ClusterRescan bool
// Ignores, if set, allows creating ignore rules from the UI.
Ignores ClusterIgnores
// ClusterName tags the history of the cluster's reports, for several
// clusters later; empty for one.
ClusterName string
// Operator, if set, shows what the operator does on the Cluster page.
Operator OperatorStatus
// Selftest, if set, is run regularly by WatchSelftest and shows its
// result in the UI.
Selftest func(context.Context) (*selftest.Result, error)
}
Config configures a Server.
type EngineStatus ¶
EngineStatus is the last result of the engine health check.
type IgnoreObject ¶
type IgnoreObject struct {
Namespace string
Name string
Labels map[string]string
Annotations map[string]string
Created time.Time
Spec v1alpha1.IgnoreSpec
Status v1alpha1.IgnoreStatus
}
IgnoreObject is a MalwareIgnore (Namespace set) or ClusterMalwareIgnore.
func (IgnoreObject) CreatedBy ¶
func (o IgnoreObject) CreatedBy() string
CreatedBy is the user who created the object in the UI.
func (IgnoreObject) Managed ¶
func (o IgnoreObject) Managed() bool
Managed reports whether the server created the object.
func (IgnoreObject) Origin ¶
func (o IgnoreObject) Origin() string
Origin tells where an object comes from, as far as its metadata shows: "UI", or the tool that applied it. Objects applied with kubectl carry no mark, so "kubectl or Git" is a guess.
func (IgnoreObject) Source ¶
func (o IgnoreObject) Source() string
Source is the name rules of the object carry in reports.
type KubeIgnores ¶
type KubeIgnores struct {
// contains filtered or unexported fields
}
KubeIgnores implements ClusterIgnores on the cache of KubeReports.
func (*KubeIgnores) ClusterRules ¶
ClusterRules returns the valid rules of all ClusterMalwareIgnores, for the server's own runs: they belong to no namespace.
func (*KubeIgnores) Create ¶
func (i *KubeIgnores) Create(ctx context.Context, namespace string, rule v1alpha1.IgnoreRule, createdBy string) (string, error)
func (*KubeIgnores) Delete ¶
func (i *KubeIgnores) Delete(ctx context.Context, namespace, name string) error
func (*KubeIgnores) List ¶
func (i *KubeIgnores) List(ctx context.Context) ([]IgnoreObject, error)
type KubeReports ¶
type KubeReports struct {
// contains filtered or unexported fields
}
KubeReports reads MalwareReports from the Kubernetes API through an informer cache.
func NewKubeReports ¶
func NewKubeReports(cfg *rest.Config, ignores bool) (*KubeReports, error)
NewKubeReports creates the cache; Start fills it. With ignores it also caches MalwareIgnores and ClusterMalwareIgnores for Ignores.
func (*KubeReports) Get ¶
func (k *KubeReports) Get(ctx context.Context, namespace, name string) (*v1alpha1.MalwareReport, error)
func (*KubeReports) Ignores ¶
func (k *KubeReports) Ignores() *KubeIgnores
Ignores returns the ignore objects, nil unless created with ignores.
func (*KubeReports) List ¶
func (k *KubeReports) List(ctx context.Context) ([]v1alpha1.MalwareReport, error)
func (*KubeReports) OnChange ¶
func (k *KubeReports) OnChange(ctx context.Context, fn func(rep *v1alpha1.MalwareReport, deleted bool)) error
OnChange calls fn for every report added, changed or deleted, including all existing reports once the cache starts.
func (*KubeReports) RequestRescan ¶
func (k *KubeReports) RequestRescan(ctx context.Context, namespace, name string) error
func (*KubeReports) Start ¶
func (k *KubeReports) Start(ctx context.Context) error
Start runs the cache until ctx is canceled.
func (*KubeReports) WaitSynced ¶
func (k *KubeReports) WaitSynced(ctx context.Context) bool
WaitSynced blocks until the reports were read once, or ctx is canceled.
type OperatorStatus ¶
OperatorStatus fetches the status of the meles operator; *opstatus.Client implements it.
type SelftestStatus ¶ added in v0.3.1
type SelftestStatus struct {
// Enabled is false if the server does not run the selftest.
Enabled bool `json:"enabled"`
// Passed is true if every test image gave the expected result. Without
// CheckedAt the selftest has not finished yet.
Passed bool `json:"passed"`
CheckedAt time.Time `json:"checkedAt,omitzero"`
Engine string `json:"engine,omitempty"`
// Failed lists the test images with a wrong result.
Failed []string `json:"failed,omitempty"`
// Error says why the selftest could not finish.
Error string `json:"error,omitempty"`
}
SelftestStatus is the last result of the regular selftest. It stays in memory: the server runs the selftest again when it starts.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server serves the UI and API.
func (*Server) Engine ¶
func (s *Server) Engine() EngineStatus
Engine returns the last engine health check.
func (*Server) RunClusterHistory ¶
RunClusterHistory records every change of the cluster's reports in the database until ctx is canceled: new results and deletions, including those missed while the server was down. Events older than keep are deleted daily, except the last one of each report.
func (*Server) Selftest ¶ added in v0.3.1
func (s *Server) Selftest() SelftestStatus
Selftest returns the last result of the regular selftest.
func (*Server) WatchEngine ¶
WatchEngine checks the engine every interval until ctx is canceled.
func (*Server) WatchSelftest ¶ added in v0.3.1
WatchSelftest runs the selftest every interval until ctx is canceled. It waits for the engine: an unreachable clamd shows in the UI by itself and says nothing about the result of the last selftest.