Documentation
¶
Overview ¶
Package vulnerability owns vulnerability scanning, persistence, and HTTP routes.
Index ¶
- Constants
- type Module
- type VulnerabilityIgnore
- type VulnerabilityReportRecord
- type VulnerabilityScanItem
- type VulnerabilityScanRecord
- func (v *VulnerabilityScanRecord) GetHighestSeverity() string
- func (v *VulnerabilityScanRecord) GetTotalVulnerabilities() int
- func (v *VulnerabilityScanRecord) IsCompleted() bool
- func (v *VulnerabilityScanRecord) IsFailed() bool
- func (v *VulnerabilityScanRecord) IsScanning() bool
- func (v *VulnerabilityScanRecord) TableName() string
- type VulnerabilityService
- func (s *VulnerabilityService) ActionableCountExcludingIgnored(ctx context.Context) (int, error)
- func (s *VulnerabilityService) BackfillScanItems(ctx context.Context)
- func (s *VulnerabilityService) CleanupOrphanedScanRecords(ctx context.Context) (int64, error)
- func (s *VulnerabilityService) DeleteScanResultsByImageIDs(ctx context.Context, imageIDs []string) error
- func (s *VulnerabilityService) GetScanSummariesByImageIDs(ctx context.Context, imageIDs []string) (map[string]*vulnerability.ScanSummary, error)
- func (s *VulnerabilityService) ImportLegacyReportFiles(ctx context.Context)
- func (s *VulnerabilityService) RecordRiskSnapshot(ctx context.Context) error
- func (s *VulnerabilityService) RegisterWorkflows(engine *flow.Engine) error
- func (s *VulnerabilityService) ScanImage(ctx context.Context, envID, imageID string, user usertypes.Actor) (*vulnerability.ScanResult, error)
- func (s *VulnerabilityService) ScanWorkflow() *flow.Workflow
- func (s *VulnerabilityService) SyncThreatIntel(ctx context.Context, force bool) error
- type VulnerabilityThreatIntel
Constants ¶
const ( ScanStatusPending = "pending" ScanStatusScanning = "scanning" ScanStatusCompleted = "completed" ScanStatusFailed = "failed" )
Scan status constants
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Module ¶
type Module struct {
// contains filtered or unexported fields
}
func New ¶
func New(service *VulnerabilityService) *Module
New wires vulnerability routes and registers the arcane.vulnerability.* gauges once.
func (*Module) RegisterRoutes ¶
func (m *Module) RegisterRoutes(api huma.API, appCtx handlerutil.ActivityAppContext)
RegisterRoutes mounts the vulnerability endpoints behind the vulnerability management feature gate. A nil module still registers for OpenAPI generation.
func (*Module) Service ¶
func (m *Module) Service() *VulnerabilityService
type VulnerabilityIgnore ¶ added in v2.8.1
type VulnerabilityIgnore struct {
// ID is the unique identifier for this ignore record
ID string `json:"id" gorm:"primaryKey;type:text"`
// EnvironmentID is the environment where this ignore applies
EnvironmentID string `json:"environmentId" gorm:"column:environment_id;index"`
// ImageID is the Docker image ID
ImageID string `json:"imageId" gorm:"column:image_id;index"`
// VulnerabilityID is the CVE or vulnerability identifier (e.g., CVE-2023-1234)
VulnerabilityID string `json:"vulnerabilityId" gorm:"column:vulnerability_id;index"`
// PkgName is the package name containing the vulnerability
PkgName string `json:"pkgName" gorm:"column:pkg_name"`
// InstalledVersion is the version of the package with the vulnerability
InstalledVersion string `json:"installedVersion" gorm:"column:installed_version"`
// Reason is an optional reason for ignoring this vulnerability
Reason *string `json:"reason,omitempty" gorm:"column:reason"`
// CreatedBy is the user ID who created this ignore record
CreatedBy string `json:"createdBy" gorm:"column:created_by"`
// CreatedAt is when this ignore record was created
CreatedAt time.Time `json:"createdAt" gorm:"column:created_at"`
}
VulnerabilityIgnore stores ignored vulnerability records
func (*VulnerabilityIgnore) BeforeCreate ¶ added in v2.8.1
func (v *VulnerabilityIgnore) BeforeCreate(db *gorm.DB) error
BeforeCreate sets the ID and CreatedAt before inserting
func (*VulnerabilityIgnore) CompositeKey ¶ added in v2.8.1
func (v *VulnerabilityIgnore) CompositeKey() string
CompositeKey generates a composite key for deduplication. This helps prevent duplicate ignore records for the same vulnerability.
func (*VulnerabilityIgnore) TableName ¶ added in v2.8.1
func (v *VulnerabilityIgnore) TableName() string
type VulnerabilityReportRecord ¶ added in v2.10.0
type VulnerabilityReportRecord struct {
ImageID string `json:"imageId" gorm:"column:image_id;primaryKey;type:text"`
Data string `json:"-" gorm:"column:data;type:text"`
CreatedAt time.Time `json:"createdAt" gorm:"column:created_at"`
UpdatedAt *time.Time `json:"updatedAt,omitempty" gorm:"column:updated_at"`
}
VulnerabilityReportRecord stores the raw Trivy JSON report used for report-based image patching, one row per image, replaced on rescan.
func (VulnerabilityReportRecord) TableName ¶ added in v2.10.0
func (VulnerabilityReportRecord) TableName() string
type VulnerabilityScanItem ¶ added in v2.10.2
type VulnerabilityScanItem struct {
ID int64 `json:"id" gorm:"primaryKey;autoIncrement;column:id"`
ImageID string `json:"imageId" gorm:"column:image_id;index"`
VulnerabilityID string `json:"vulnerabilityId" gorm:"column:vulnerability_id;index"`
PkgName string `json:"pkgName" gorm:"column:pkg_name"`
InstalledVersion string `json:"installedVersion" gorm:"column:installed_version"`
FixedVersion string `json:"fixedVersion" gorm:"column:fixed_version"`
Severity string `json:"severity" gorm:"column:severity;index"`
SeverityRank int `json:"severityRank" gorm:"column:severity_rank"`
PkgClass string `json:"pkgClass" gorm:"column:pkg_class"`
PkgType string `json:"pkgType" gorm:"column:pkg_type"`
Title string `json:"title" gorm:"column:title"`
CVSSScore *float64 `json:"cvssScore,omitempty" gorm:"column:cvss_score"`
Details *string `json:"-" gorm:"column:details"`
}
VulnerabilityScanItem is one CVE finding from a completed scan, normalized for list queries.
func (VulnerabilityScanItem) TableName ¶ added in v2.10.2
func (VulnerabilityScanItem) TableName() string
type VulnerabilityScanRecord ¶ added in v2.8.1
type VulnerabilityScanRecord struct {
database.BaseModel
// ImageID is the Docker image ID (primary key)
ID string `json:"id" gorm:"primaryKey;type:text"`
// ImageName is the image name with tag (e.g., nginx:latest)
ImageName string `json:"imageName" gorm:"column:image_name" sortable:"true"`
// Status is the status of the scan (pending, scanning, completed, failed)
Status string `json:"status" gorm:"column:status"`
// ScanTime is the timestamp when the scan was performed
ScanTime time.Time `json:"scanTime" gorm:"column:scan_time" sortable:"true"`
// Duration is the duration of the scan in milliseconds
Duration int64 `json:"duration" gorm:"column:duration"`
// Total vulnerability counts by severity
CriticalCount int `json:"criticalCount" gorm:"column:critical_count"`
HighCount int `json:"highCount" gorm:"column:high_count"`
MediumCount int `json:"mediumCount" gorm:"column:medium_count"`
LowCount int `json:"lowCount" gorm:"column:low_count"`
UnknownCount int `json:"unknownCount" gorm:"column:unknown_count"`
TotalCount int `json:"totalCount" gorm:"column:total_count"`
// Vulnerabilities stores the JSON encoded vulnerabilities list
Vulnerabilities database.StringSlice `json:"vulnerabilities" gorm:"column:vulnerabilities;type:text"`
// Error contains the error message if the scan failed
Error *string `json:"error,omitempty" gorm:"column:error"`
// ScannerVersion is the version of the scanner used
ScannerVersion string `json:"scannerVersion" gorm:"column:scanner_version"`
// FixableCount is the number of vulnerabilities with a known fix, stored at
// scan time so image patching can query it without parsing the JSON blob.
// NULL on records written before the column existed.
FixableCount *int `json:"fixableCount,omitempty" gorm:"column:fixable_count" sortable:"true"`
ScanPolicy string `json:"-" gorm:"column:scan_policy"`
}
VulnerabilityScanRecord stores vulnerability scan results for images
func (*VulnerabilityScanRecord) GetHighestSeverity ¶ added in v2.8.1
func (v *VulnerabilityScanRecord) GetHighestSeverity() string
GetHighestSeverity returns the highest severity level found
func (*VulnerabilityScanRecord) GetTotalVulnerabilities ¶ added in v2.8.1
func (v *VulnerabilityScanRecord) GetTotalVulnerabilities() int
GetTotalVulnerabilities returns the total count of vulnerabilities
func (*VulnerabilityScanRecord) IsCompleted ¶ added in v2.8.1
func (v *VulnerabilityScanRecord) IsCompleted() bool
IsCompleted returns true if the scan has completed
func (*VulnerabilityScanRecord) IsFailed ¶ added in v2.8.1
func (v *VulnerabilityScanRecord) IsFailed() bool
IsFailed returns true if the scan has failed
func (*VulnerabilityScanRecord) IsScanning ¶ added in v2.8.1
func (v *VulnerabilityScanRecord) IsScanning() bool
IsScanning returns true if the scan is in progress
func (*VulnerabilityScanRecord) TableName ¶ added in v2.8.1
func (v *VulnerabilityScanRecord) TableName() string
type VulnerabilityService ¶
type VulnerabilityService struct {
// contains filtered or unexported fields
}
VulnerabilityService coordinates vulnerability scanning, findings, ignores, and risk, and owns the scan record and raw report persistence.
func NewVulnerabilityService ¶
func NewVulnerabilityService( db *database.DB, cfg *config.Config, dockerService *docker.DockerClientService, eventService *event.EventService, settingsService *settings.SettingsService, notificationService *notification.NotificationService, activityService *activity.ActivityService, registryService *registry.ContainerRegistryService, kvService *kv.KVService, httpClient *http.Client, ) *VulnerabilityService
NewVulnerabilityService creates a new VulnerabilityService instance
func (*VulnerabilityService) ActionableCountExcludingIgnored ¶
func (s *VulnerabilityService) ActionableCountExcludingIgnored(ctx context.Context) (int, error)
ActionableCountExcludingIgnored counts critical and high findings that are not ignored.
func (*VulnerabilityService) BackfillScanItems ¶ added in v2.10.2
func (s *VulnerabilityService) BackfillScanItems(ctx context.Context)
BackfillScanItems populates finding rows for scans recorded before they existed.
func (*VulnerabilityService) CleanupOrphanedScanRecords ¶
func (s *VulnerabilityService) CleanupOrphanedScanRecords(ctx context.Context) (int64, error)
CleanupOrphanedScanRecords removes scan records of images that no longer exist.
func (*VulnerabilityService) DeleteScanResultsByImageIDs ¶
func (s *VulnerabilityService) DeleteScanResultsByImageIDs(ctx context.Context, imageIDs []string) error
DeleteScanResultsByImageIDs deletes scan results for multiple images.
func (*VulnerabilityService) GetScanSummariesByImageIDs ¶
func (s *VulnerabilityService) GetScanSummariesByImageIDs(ctx context.Context, imageIDs []string) (map[string]*vulnerability.ScanSummary, error)
GetScanSummariesByImageIDs retrieves scan summaries for multiple images.
func (*VulnerabilityService) ImportLegacyReportFiles ¶ added in v2.10.0
func (s *VulnerabilityService) ImportLegacyReportFiles(ctx context.Context)
ImportLegacyReportFiles moves raw Trivy report files of older versions into the database.
func (*VulnerabilityService) RecordRiskSnapshot ¶ added in v2.14.0
func (s *VulnerabilityService) RecordRiskSnapshot(ctx context.Context) error
RecordRiskSnapshot stores today's environment risk snapshot.
func (*VulnerabilityService) RegisterWorkflows ¶ added in v2.16.0
func (s *VulnerabilityService) RegisterWorkflows(engine *flow.Engine) error
RegisterWorkflows defines the scheduled scan: discover due images, scan each as its own retryable task, then notify. Call it before the host starts.
func (*VulnerabilityService) ScanImage ¶
func (s *VulnerabilityService) ScanImage(ctx context.Context, envID, imageID string, user usertypes.Actor) (*vulnerability.ScanResult, error)
ScanImage queues a vulnerability scan of an image.
func (*VulnerabilityService) ScanWorkflow ¶ added in v2.16.0
func (s *VulnerabilityService) ScanWorkflow() *flow.Workflow
ScanWorkflow is the scheduled vulnerability scan workflow.
func (*VulnerabilityService) SyncThreatIntel ¶ added in v2.14.0
func (s *VulnerabilityService) SyncThreatIntel(ctx context.Context, force bool) error
SyncThreatIntel refreshes the KEV and EPSS threat intelligence cache.
type VulnerabilityThreatIntel ¶ added in v2.14.0
type VulnerabilityThreatIntel struct {
CVEID string `gorm:"column:cve_id;primaryKey"`
KnownExploited bool `gorm:"column:known_exploited"`
KEVDateAdded string `gorm:"column:kev_date_added"`
KEVDueDate string `gorm:"column:kev_due_date"`
KEVRansomware bool `gorm:"column:kev_ransomware"`
EPSSScore *float64 `gorm:"column:epss_score"`
EPSSPercentile *float64 `gorm:"column:epss_percentile"`
EPSSCheckedAt *time.Time `gorm:"column:epss_checked_at"`
UpdatedAt *time.Time `gorm:"column:updated_at"`
}
VulnerabilityThreatIntel caches CISA KEV and FIRST EPSS data per CVE.
func (VulnerabilityThreatIntel) TableName ¶ added in v2.14.0
func (VulnerabilityThreatIntel) TableName() string