feat(df): check golang PURLs in glab df package

Description

glab df package now accepts Go modules: pkg:golang/<module path>@<version> is checked against the project's Dependency Firewall policy with ecosystem golang.

packageurl-go lowercases golang namespaces and names, as the PURL spec says, but Go module paths are case-sensitive: github.com/BurntSushi/toml and github.com/burntsushi/toml are different modules to go. The golang name is rebuilt from the raw PURL path, so glab sends the module path as written. The upcoming glab df go command sends the same case-kept path, so both commands send the same coordinate and users see the real module path.

This is the first of four MRs that add Go support through a local module proxy instead of the closed !3928 (closed) matcher:

  1. This MR: golang in purl, the policy client and glab df package.
  2. !4168 (merged): the gomodproxy package on its own.
  3. !4169 (merged): the run-engine wiring, the Go manager and glab df go.
  4. !4170 (merged): the user's own GOPROXY as the upstream.

This MR and !4168 (merged) don't depend on each other and can merge in either order.

How the server matches golang names

The policy API folds case for golang, so a module can't get past a rule by changing case. EvaluatePackageService#normalized_name runs Sbom::PackageUrl::Normalizer, which lowercases golang names, and both the advisory lookup and the policy rules use that lowercased name.

One server-side quirk, read from the source and not exercised: Rule#purl_excepted? compares a policy's exception PURL to pkg:golang/<lowercased name> exactly, and the policy editor stores exceptions as typed. An exception written in mixed case, such as pkg:golang/github.com/Masterminds/goutils@v1.1.0, therefore never matches, and the module stays blocked. This fails safe and affects every client, not only glab.

How has this been tested?

  • Unit tests: golang PURL parsing (plain, mixed case, no namespace, +incompatible version, qualifiers and subpath ignored, a percent-encoded segment, the pkg:// form, and @ inside the qualifiers and subpath), the golang ecosystem mapping, and the evaluate request glab df package sends for pkg:golang/github.com/BurntSushi/toml@v1.4.0.
  • A real glab df package run against GDK (gitlab-org/df-test, which inherits the "Deny high volume" vulnerability policy):
PURL Name in GDK's api_json.log Result
pkg:golang/github.com/Masterminds/goutils@v1.1.0 github.com/Masterminds/goutils blocked, exit 3
pkg:golang/github.com/masterminds/goutils@v1.1.0 github.com/masterminds/goutils blocked, exit 3
pkg:golang/github.com/Masterminds/goutils@v1.1.1 (fixed version) github.com/Masterminds/goutils allowed, exit 0
pkg:golang/golang.org/x/net@v0.0.0-20181017193950-04a2e542c03f golang.org/x/net blocked, exit 3
  • A real glab df package run with the fake policy checker, which matches names exactly, blocking golang:github.com/BurntSushi/toml@v1.4.0. This shows the path glab sends keeps its case:
PURL Result
pkg:golang/github.com/BurntSushi/toml@v1.4.0 blocked, exit 3
pkg:golang/github.com/burntsushi/toml@v1.4.0 allowed, exit 0
pkg:golang/github.com/pkg/errors@v0.9.1 allowed, exit 0
Edited by Arpit Gogia

Merge request reports

Loading
Loading