Documentation
¶
Overview ¶
Package policy decides whether a package coordinate is allowed by the GitLab Dependency Firewall. It is the seam between the inspection proxy (which identifies a coordinate) and the verdict source. Two Checker implementations exist: a fake, environment-driven one for testing and a REST-backed one that calls the real policy API. Callers wrap the chosen Checker in a CachingChecker.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CachingChecker ¶
type CachingChecker struct {
// contains filtered or unexported fields
}
CachingChecker wraps a Checker with per-request memoization and a fail-closed error policy. It is the only place caching and fail-mode live, so both Checker implementations stay simple. Safe for concurrent use: the proxy calls Check from multiple tunnel goroutines.
Concurrent calls for the same request are coalesced: the first caller runs the inner check while the rest block on the entry's sync.Once, so a popular transitive dependency triggers a single inner check at cold start rather than one per tunnel goroutine.
Lifetime invariant: the cache grows unbounded and is never evicted. It is sized for a single package-manager run (the proxy's lifetime). Callers must not share one CachingChecker across unrelated or long-lived workloads.
func NewCachingChecker ¶
func NewCachingChecker(inner Checker, log Logf) *CachingChecker
NewCachingChecker wraps inner. log may be nil.
func (*CachingChecker) Check ¶
Check returns the policy result for r, memoized per request for the lifetime of the checker. The error return is always nil: an inner failure is mapped to a fail-closed Blocked result rather than surfaced, so callers get a verdict on every path. It is part of the signature only to satisfy Checker.
type Checker ¶
Checker answers policy questions.
type Coordinate ¶
type Coordinate struct {
Ecosystem string // "npm", "pypi", "maven", "gem"
Name string
Version string
}
Coordinate is the exact package identity a check is performed against.
func (Coordinate) Key ¶
func (c Coordinate) Key() string
Key is the cache and dedupe key for a coordinate.
type Logf ¶
Logf logs a diagnostic line. It matches iostreams.IOStreams.LogErrorf so callers can pass io.LogErrorf directly; nil is allowed (no logging).
type Request ¶
type Request struct {
Coordinate Coordinate
ProjectID string // project id or full-path slug, from git repo context
Operation Operation
}
Request is a single policy question. ProjectID selects the project whose firewall answers it; the REST checker evaluates against this field. Operation records the package-manager action for cache-key isolation and diagnostics; the evaluate API is scoped to project and coordinate only and does not accept an operation, so it is not transmitted.
func (Request) Key ¶
Key is the cache and dedupe key for a request. It includes the project and operation, not just the coordinate: the same package can get a different verdict per project (policies are project-scoped), and download and upload are tracked separately, so keying on the coordinate alone would let one project's or operation's cached verdict answer for another.
type Result ¶
type Result struct {
Verdict verdict.Verdict // verdict.Allowed, verdict.Blocked, or verdict.Warning
Reason string // human-readable; used in the 403 body and summary
}
Result is the outcome of a policy check. A zero Verdict (verdict.Allowed) means allow.
func (Result) Allowed ¶ added in v1.116.0
Allowed reports whether the result permits the coordinate.