policy

package
v1.115.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: MIT Imports: 9 Imported by: 0

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. A fake, environment-driven Checker exists for testing; the REST-backed Checker that calls the real policy API lands in a follow-up. Callers wrap the chosen Checker in a CachingChecker.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotImplemented = errors.New("policy: real checker not yet implemented")

ErrNotImplemented is returned by the placeholder checker until the REST-backed checker is wired in a follow-up. It fails closed so a misconfigured build denies rather than silently allows.

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

func (c *CachingChecker) Check(ctx context.Context, r Request) (Result, error)

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

type Checker interface {
	Check(ctx context.Context, req Request) (Result, error)
}

Checker answers policy questions.

func New

func New(client *gitlab.Client, projectID string) Checker

New returns the fake checker when any GLAB_DF_FAKE_* variable is set. Until the REST checker lands, the non-fake path returns a placeholder that fails closed. Callers wrap the result in a CachingChecker.

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

type Logf func(format string, a ...any)

Logf logs a diagnostic line. It matches iostreams.IOStreams.LogErrorf so callers can pass io.LogErrorf directly; nil is allowed (no logging).

type Operation

type Operation int

Operation is the package-manager action that triggered a check.

const (
	// Download is an artifact fetch (tarball, wheel, jar, gem).
	Download Operation = iota
	// Upload is a publish/push of a package.
	Upload
)

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.

func (Request) Key

func (r Request) Key() string

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 per operation (download vs upload), so keying on the coordinate alone would leak one project's or operation's verdict to another once the real checker lands.

type Result

type Result struct {
	Verdict verdict.Verdict // verdict.Blocked, verdict.Warning, or "" (allow)
	Reason  string          // human-readable; used in the 403 body and summary
}

Result is the outcome of a policy check. A zero Verdict means allow.

func (Result) Blocked

func (r Result) Blocked() bool

Blocked reports whether the result denies the coordinate.

Jump to

Keyboard shortcuts

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