operator

package
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 5, 2026 License: Apache-2.0 Imports: 50 Imported by: 0

Documentation

Overview

Package operator scans the images of all pods in the cluster and writes the results as MalwareReports, one per workload and container. Every image digest is scanned once; further workloads with the same image get a copy of the result. Results are rescanned when the signature database changed (at most once per RescanInterval), after RetryAfter if the scan failed and after RetryIncompleteAfter if files were skipped, or right away if the report is annotated with meles.io/rescan. A new result is copied into all reports of the digest.

Index

Constants

View Source
const PlatformsNodes = "nodes"

PlatformsNodes selects the architectures of the cluster's nodes.

Variables

This section is empty.

Functions

func RegisterGateWebhooks

func RegisterGateWebhooks(mgr ctrl.Manager)

RegisterGateWebhooks serves the scan gate's webhooks at /gate/enforce and /gate/audit.

func RegisterReportMetrics

func RegisterReportMetrics(reader client.Reader, isLeader func() bool) error

RegisterReportMetrics exports meles_operator_reports, counted from the reports reader (the manager's cache) lists.

func SetLeader

func SetLeader()

SetLeader records that this replica became the leader.

Types

type EngineVersioner

type EngineVersioner interface {
	Version(ctx context.Context) (engine.Version, error)
}

EngineVersioner reports the current engine and signature version; engine.Engine implements it.

type GateWebhook

type GateWebhook struct {
	Mode    string
	Decoder admission.Decoder
}

GateWebhook is the mutating admission webhook of the scan gate: it adds the scheduling gate to new pods and records the mode of the namespace. The webhook configuration selects the namespaces, one path per mode.

func (*GateWebhook) Handle

Handle adds the gate unless the pod opts out or is bound to a node already (scheduling gates are refused then, e.g. static pods). It sets the mode of the namespace also on a pod that carries the gate already: the mode must come from the namespace, not from whoever created the pod (a pod created with the gate and gate-mode audit would otherwise be held only in audit mode in an enforce namespace).

type IgnoreStatusReconciler

type IgnoreStatusReconciler struct {
	Client client.Client
	// Cluster selects ClusterMalwareIgnores instead of MalwareIgnores.
	Cluster bool
}

IgnoreStatusReconciler validates the rules of MalwareIgnores and ClusterMalwareIgnores and writes the result to their status, so that the owner of a rule sees why it is not in effect.

func (*IgnoreStatusReconciler) Reconcile

func (r *IgnoreStatusReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error)

Reconcile writes the status of one ignore object. It runs again when a rule expires.

func (*IgnoreStatusReconciler) SetupWithManager

func (r *IgnoreStatusReconciler) SetupWithManager(mgr ctrl.Manager) error

SetupWithManager registers the reconciler.

type ImageScanner

type ImageScanner interface {
	Scan(ctx context.Context, ref string, platforms source.PlatformFilter, progress func(scan.Progress), opts ...scan.Option) (*scan.Report, error)
}

ImageScanner scans one image reference; *scan.Scanner implements it.

type Reconciler

type Reconciler struct {
	Client  client.Client
	Scanner ImageScanner
	// Engine is asked for the signature version, to find outdated reports.
	Engine EngineVersioner
	// Version of meles, recorded in the reports.
	Version string
	// Platforms is PlatformsNodes, "all" or a list such as "linux/amd64".
	Platforms string
	// Workers is the number of images scanned in parallel.
	Workers int
	// APIReader reads the pull secrets and service accounts of pods
	// uncached, so that the operator neither lists nor keeps the cluster's
	// secrets. It may read them only where it was granted.
	APIReader client.Reader
	// PullSecretRole and ServiceAccount ("namespace:name") of the operator
	// complete the command in the error of a refused pull.
	PullSecretRole string
	ServiceAccount string
	// ScanTimeout bounds a single image scan.
	ScanTimeout time.Duration
	// RetryAfter is the wait before an image whose scan failed is retried.
	RetryAfter time.Duration
	// RetryIncompleteAfter is the wait before an image with skipped files is
	// rescanned. Usually clamd's limits are the cause, so a retry only helps
	// once they were raised, and it scans the large files again.
	RetryIncompleteAfter time.Duration
	// RescanInterval is the minimum age of a result before it is rescanned
	// because the signature database changed. 0 disables rescans.
	RescanInterval time.Duration
	// Gate releases pods held by the scan gate once their images are
	// scanned. GateFailOpen releases them, too, when the scan failed in the
	// engine (an outage of meles); otherwise they wait for clamd.
	Gate         bool
	GateFailOpen bool
	// Source configures resolving tags for the gate (plain HTTP, mirrors,
	// network restrictions), as when scanning.
	Source source.Options
	// Recorder emits the gate's events on held and released pods.
	Recorder events.EventRecorder
	// IsLeader reports whether this replica scans, for the status.
	IsLeader func() bool
	Logger   *slog.Logger
	// contains filtered or unexported fields
}

Reconciler writes the MalwareReports of a pod's containers.

func (*Reconciler) Reconcile

func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error)

Reconcile writes or updates the reports of all containers of a pod.

func (*Reconciler) RunPrune

func (r *Reconciler) RunPrune(ctx context.Context, interval time.Duration) error

RunPrune deletes reports of workloads without pods every interval until ctx is canceled. Scaled up again, a workload gets its report back from the next pod event.

func (*Reconciler) SetupWithManager

func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error

SetupWithManager registers the reconciler. Pods are reconciled when they are created, whenever the images their containers run change, and when a report of their workload is deleted or annotated with meles.io/rescan.

func (*Reconciler) Status

func (r *Reconciler) Status() opstatus.Status

Status returns the operator's status. Only the leader has a queue.

func (*Reconciler) StatusHandler

func (r *Reconciler) StatusHandler() http.Handler

StatusHandler serves Status as JSON.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL