bazelmodules

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package bazelmodules validates Bazel module registry uploads. A hosted version is modules/<name>/<version>/MODULE.bazel with one source archive (.tar.gz, .tgz, .tar or .zip) beside it: the MODULE.bazel must declare that name and version literally, and the archive must be a safe archive of the type its name gives. A registry's metadata.json and source.json are never uploaded; the slice's protocol derives them from the stored files on each request.

Role

artifacts module, ecosystem layer: the Bazel module registry upload validation of the Bazel modules slice. Its Handler plugs into the item service through the format hooks (decision 0032); the slice's http package (artifacts/ecosystem/bazelmodules/http) serves the Bazel index registry protocol over what it keeps.

Inputs

  • Driving: the format registry (artifacts/ecosystem), which hands the item service's hooks for bazelmodules repositories to Handler, and the work queue, which runs every format's reindex through it; and the protocol, which parses paths and modules (ValidName, ValidVersion, ParseFile, ParseModule) and builds a version's source.json (Integrity, ArchiveStripPrefix).
  • Driven: the format hooks' environment (format.Env), whose blobs hold the uploads and through whose store Handler lists a version's archives and a repository's publications; the archive scanner (platform/archive), which reads an archive within bounds; and the generic deploy policy (artifacts/ecosystem/generic), which Admit applies after the Bazel checks.
  • Settings: none.

Outputs

  • Handler: the hooks that check an upload before its transaction (Inspect), admit only a valid publication (Admit), refuse a second archive for one version (GuardWrite) and re-check every publication (Reindex).
  • The rules the protocol shares: File, ParseFile, ParseModule, ValidName, ValidVersion, Serves, Integrity and ArchiveStripPrefix.

Invariants

  • A module's identity comes from the literal name and version of its single module() call, never from running Starlark, and must match its path.
  • A version has at most one archive, since its source.json can name only one.
  • An archive's content has the type its name gives, and holds only regular files and folders with clean paths, within 10,000 entries and 512 MiB.
  • Only an upload that breaks those rules is refused (409). A stored upload that cannot be read is no invalid publication: the read's error fails the write (500).
  • Nothing is derived into storage: the registry view is computed from the current stored files, so no second copy of the metadata can go stale.

References

Status

Implemented P9c, which delivered the plan's P31 group (issues #770 to #775). Moved here in P9d.

Testing

  • bazelmodules_test.go: paths and module identity, the integrity encoding, the strip prefix of real archive layouts, and admission of invalid paths.
  • readfault_test.go: an upload whose content fails a read at any point, on a store with ReadAt or one that can only seek, is an error, not an invalid publication, and invalid uploads are still refused 409.

The hooks are also tested end to end through the protocol, whose package runs the pinned Bazel client (TestAccBazelClient).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArchiveStripPrefix

func ArchiveStripPrefix(body io.ReadSeeker, size int64, name string) (string, error)

ArchiveStripPrefix returns a single enclosing directory shared by every regular archive entry, the layout Bazel's archive repository must strip. A flat or mixed archive is already rooted and needs no prefix.

func Integrity

func Integrity(hexDigest string) (string, error)

Integrity is Bazel's Subresource Integrity encoding of a stored SHA-256.

func ParseModule

func ParseModule(body []byte) (string, string, error)

ParseModule reads literal module name/version attributes. Dynamic module declarations and duplicate attributes are rejected because identity would otherwise depend on executing arbitrary Starlark at publication time.

func Serves

func Serves(t repo.PackageType) bool

Serves reports whether t is the Bazel modules package type.

func ValidName

func ValidName(name string) bool

ValidName and ValidVersion are deliberately narrower than arbitrary item names. An ambiguous registry path cannot become an upload or a fetch target.

func ValidVersion

func ValidVersion(version string) bool

ValidVersion reports whether version is a module version the registry accepts: a digit, then up to 127 letters, digits, dots, underscores, pluses and hyphens.

Types

type File

type File struct{ Name, Version, Kind, ArchiveType string }

File identifies a native local publication file.

func ParseFile

func ParseFile(path string) (File, bool)

ParseFile reads path as a hosted publication file, modules/<name>/<version>/<file>, where file is MODULE.bazel or an archive named *.tar.gz, *.tgz, *.tar or *.zip, a .tgz being typed tar.gz. It reports false for any other path, metadata.json and source.json included, since the protocol derives those.

type Handler

type Handler struct{ generic.Handler }

Handler is the Bazel modules format's hooks. It embeds the generic hooks, so a deploy, a delete and the class of a path are handled as for generic content.

func (Handler) Admit

func (Handler) Admit(
	ctx context.Context,
	env format.Env,
	c repo.Config,
	w format.Write,
) (format.Write, error)

Admit refuses with 409 a hosted upload outside the publication layout or whose inspection failed, then applies the generic deploy policy, wrapping its refusal. A remote's cached write and a checksum deploy go straight to the generic policy.

func (Handler) GuardWrite

func (Handler) GuardWrite(
	ctx context.Context,
	env format.Env,
	c repo.Config,
	w format.Write,
) error

GuardWrite prevents two archives from claiming one module version. Bazel's source.json can name only one archive, so ambiguity must fail at upload.

func (Handler) Inspect

func (Handler) Inspect(
	ctx context.Context,
	env format.Env,
	_ repo.Config,
	w format.Write,
) (any, error)

Inspect checks a hosted upload before the write's transaction: a MODULE.bazel must parse with ParseModule and match its path, and an archive must have the type its name gives and hold only clean regular files and folders, within 10,000 entries and 512 MiB. The outcome, valid or not, is returned for Admit, so an upload is read once. Failing to open or read the stored content is an error, which fails the write (500): it says nothing of whether the upload is valid, so Admit's 409 does not answer it. A remote's cached write and a checksum deploy inspect nothing.

func (Handler) Reindex

func (Handler) Reindex(ctx context.Context, env format.Env, c repo.Config) error

Reindex re-checks, as Inspect does, every file under modules/ in repository c's own items, and fails on the first that is outside the layout or does not pass. The native view is derived from the current stored items, so there is no second, mutable copy of the metadata to rebuild.

Directories

Path Synopsis
Package bazelmoduleshttp serves the Bazel index registry protocol at /artifactory/api/bazelmodules/{repoKey}: GET and HEAD of bazel_registry.json, a module's metadata.json, a version's MODULE.bazel and source.json, its archive under archives/, and a remote version's patches.
Package bazelmoduleshttp serves the Bazel index registry protocol at /artifactory/api/bazelmodules/{repoKey}: GET and HEAD of bazel_registry.json, a module's metadata.json, a version's MODULE.bazel and source.json, its archive under archives/, and a remote version's patches.

Jump to

Keyboard shortcuts

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