Documentation
¶
Overview ¶
Package dtrack pushes OpenArtifact's SBOMs and VEX decisions to a Dependency-Track server (https://dependencytrack.org) and records how far each push got. See docs/security/dependency-track.md.
Index ¶
- Constants
- Variables
- func ArtifactIDFromPayload(payload map[string]any) string
- func Render(tmpl, def string, v ProjectVars) string
- func SaveGlobal(ctx context.Context, db SettingsStore, s Settings) error
- func ValidateTemplate(tmpl string) error
- type Client
- func (c *Client) Check(ctx context.Context, needVEX bool) (*Info, error)
- func (c *Client) Findings(ctx context.Context, projectUUID string) ([]Finding, error)
- func (c *Client) Processing(ctx context.Context, token string) (bool, error)
- func (c *Client) ProjectUUID(ctx context.Context, name, version string) (string, error)
- func (c *Client) UploadBOM(ctx context.Context, projectName, projectVersion string, bom []byte) (string, error)
- func (c *Client) UploadVEX(ctx context.Context, projectUUID string, vex []byte) (string, error)
- type Effective
- type Finding
- type HTTPError
- type Info
- type Job
- type ProjectVars
- type Pusher
- func (p *Pusher) Enqueue(j Job) bool
- func (p *Pusher) EnqueueIfEnabled(ctx context.Context, j Job)
- func (p *Pusher) ForwardTo(s *workq.Store)
- func (p *Pusher) ServeFrom(c *workq.Consumer)
- func (p *Pusher) Start(ctx context.Context)
- func (p *Pusher) Stop()
- func (p *Pusher) WithTimings(poll, maxWait time.Duration) *Pusher
- type Settings
- type SettingsStore
- type Sources
- type Store
- type Trigger
- type UploadPublisher
Constants ¶
const ( PermBOMUpload = "BOM_UPLOAD" PermProjectCreation = "PROJECT_CREATION_UPLOAD" PermViewPortfolio = "VIEW_PORTFOLIO" PermViewVuln = "VIEW_VULNERABILITY" PermVulnAnalysis = "VULNERABILITY_ANALYSIS" )
Permissions the integration uses; Check reports which ones the API key lacks.
const ( DefaultProjectName = "{repo}/{name}" DefaultProjectVersion = "{version}" )
Default project naming: one Dependency-Track project per artifact, "<repository>/<name>", at the artifact's version.
const ( SourceNone = "none" SourceGlobal = "global" SourceRepository = "repository" )
Sources of an effective configuration.
const RequestKind = "dtrack:push"
RequestKind is the kind of the worker request that asks for a push.
const SettingGlobal = "dependency_track.global"
SettingGlobal is the system_settings key of the global configuration.
Variables ¶
var ErrCrossOriginRedirect = errors.New("dependency-track: redirect to another origin refused")
ErrCrossOriginRedirect is returned when Dependency-Track answers with a redirect to another origin; the API key is never sent there.
var ErrInvalidURL = errors.New("dependency-track URL must be an absolute http(s) URL")
ErrInvalidURL is returned for a base URL that is not an absolute http(s) URL.
var ErrNotFound = errors.New("dependency-track: not found")
ErrNotFound is returned when Dependency-Track answers 404.
Functions ¶
func ArtifactIDFromPayload ¶
ArtifactIDFromPayload is the "name@version" id of an artifact event, "" when the event names no artifact.
func Render ¶
func Render(tmpl, def string, v ProjectVars) string
Render expands tmpl (default def when empty) with vars and bounds the result. A "unknown" version renders empty.
func SaveGlobal ¶
func SaveGlobal(ctx context.Context, db SettingsStore, s Settings) error
SaveGlobal stores the global settings, encrypting the API key.
func ValidateTemplate ¶
ValidateTemplate checks that tmpl only uses the known placeholders ({repo}, {name}, {version}, {artifact_id}, {format}), has no stray braces and fits Dependency-Track's 255 character limit with a margin for the values.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to the REST API of one Dependency-Track server.
func NewClient ¶
NewClient validates baseURL and returns a client that refuses to connect to internal addresses (netutil's SSRF guard, enforced at dial time).
func (*Client) Check ¶
Check verifies the server answers and the API key is accepted, and reports the key's permissions against the ones the integration needs.
func (*Client) Processing ¶
Processing reports whether Dependency-Track still processes the upload behind token.
func (*Client) ProjectUUID ¶
ProjectUUID resolves a project by name and version (ErrNotFound when absent).
type Effective ¶
type Effective struct {
Settings
// Source is where Enabled came from: SourceRepository (an override row),
// SourceGlobal, or SourceNone (nothing configured).
Source string
}
Effective is the configuration that applies to a repository.
func EffectiveFor ¶
EffectiveFor loads the global settings and the repository's override.
func Resolve ¶
func Resolve(global Settings, repo *models.RepositoryDependencyTrack) (Effective, error)
Resolve layers the repository override over the global settings. An override row applies explicitly (its enabled flag wins, so a repository can opt in or out); its empty strings and NULL booleans inherit the global values.
type Finding ¶
type Finding struct {
VulnID string
Source string
Aliases []string
Component string // purl, or name@version
State string // analysis state, "" when never analyzed
Suppress bool
}
Finding is one vulnerability Dependency-Track found in a project's component.
type HTTPError ¶
HTTPError is a non-2xx answer from Dependency-Track. The body is not kept: it can echo request data and is never shown to API clients.
type Info ¶
type Info struct {
Version string `json:"version"`
Permissions []string `json:"permissions"`
MissingPermissions []string `json:"missing_permissions"`
}
Info is the outcome of a connection test.
type Job ¶
type Job struct {
RepoID string `json:"repo_id"`
ArtifactID string `json:"artifact_id"`
Trigger Trigger `json:"trigger"`
}
Job is one artifact to push.
type ProjectVars ¶
type ProjectVars struct {
Repo, Name, Version, ArtifactID, Format string
}
ProjectVars are the values a project name / version template can use.
type Pusher ¶
type Pusher struct {
// contains filtered or unexported fields
}
Pusher pushes BOMs and VEX statements in the background. Jobs are de-duplicated per artifact: one waiting job absorbs further requests, and a request arriving while the artifact is being pushed runs again afterwards.
func (*Pusher) Enqueue ¶
Enqueue schedules a push without checking the configuration (use EnqueueIfEnabled for events). It reports false when the queue is full.
func (*Pusher) EnqueueIfEnabled ¶
EnqueueIfEnabled schedules a push when the repository's effective configuration is ready and has auto-push on; it is what upload and scan events call. Configuration errors are logged, never returned: an event must not fail because of the integration.
func (*Pusher) ForwardTo ¶ added in v0.15.0
ForwardTo turns the pusher into the front of a worker process (server.role=web): Enqueue writes a worker request to s, and nothing is pushed here. Call it before the first Enqueue.
func (*Pusher) ServeFrom ¶ added in v0.15.0
ServeFrom makes the pusher push what the requests claimed by c ask for. The pusher must be started.
type Settings ¶
type Settings struct {
Enabled bool `json:"enabled"`
BaseURL string `json:"base_url"`
APIKey string `json:"api_key"`
ProjectName string `json:"project_name"`
ProjectVersion string `json:"project_version"`
AutoPush bool `json:"auto_push"`
PushVEX bool `json:"push_vex"`
}
Settings is a Dependency-Track configuration in plaintext (the API key is encrypted at rest).
func LoadGlobal ¶
func LoadGlobal(ctx context.Context, db SettingsStore) (Settings, error)
LoadGlobal reads the global settings; none stored yields the zero value (disabled).
type SettingsStore ¶
type SettingsStore interface {
GetSystemSetting(ctx context.Context, key string) (string, error)
SetSystemSetting(ctx context.Context, key, value string) error
GetRepositoryDependencyTrack(ctx context.Context, repoID string) (*models.RepositoryDependencyTrack, error)
}
SettingsStore is the part of the database the configuration lives in.
type Sources ¶
type Sources interface {
// BOM returns the artifact's CycloneDX SBOM (without vulnerabilities:
// Dependency-Track runs its own analysis) and its component count.
BOM(ctx context.Context, repo *models.Repository, artifactID string) (doc []byte, components int, err error)
// VEX returns the artifact's CycloneDX VEX shaped by opts and its statement count.
VEX(ctx context.Context, repo *models.Repository, artifactID string, opts sbom.VEXOptions) (doc []byte, statements int, err error)
}
Sources builds the documents a push sends, from an artifact's stored state.
type Store ¶
type Store interface {
SettingsStore
GetRepositoryByID(ctx context.Context, id string) (*models.Repository, error)
UpsertDependencyTrackPush(ctx context.Context, s *models.DependencyTrackPush) error
GetDependencyTrackPush(ctx context.Context, repoID, artifactID string) (*models.DependencyTrackPush, error)
}
Store is the database part the pusher needs.
type UploadPublisher ¶
type UploadPublisher struct {
// contains filtered or unexported fields
}
UploadPublisher is a webhook.Publisher that forwards every event to the wrapped publisher and, for artifact uploads, schedules a Dependency-Track push when the repository has the integration and auto-push on.
func NewUploadPublisher ¶
func NewUploadPublisher(next webhook.Publisher, p *Pusher) *UploadPublisher
NewUploadPublisher wraps next (which may be nil).