F-catalog-B: distribution removes a tagged version's tag alone when another tag names its digest

Deleting the manifest by its digest removed every tag on it, and reproducible builds share a digest
between a branch's tagged version and the trunk's numbered one, so a branch's end deleted the trunk's
image (security review F1). The fake catalog now deletes by digest as the store does; a store that
cannot delete a tag alone removes nothing and the removal is refused.

Claude-Session: https://claude.ai/code/session_01JG73KJNrH5EgFXMKKYSrig
This commit is contained in:
2026-11-04 17:04:46 +01:00
parent 3079b7f115
commit 1bdca045c2
3 changed files with 85 additions and 3 deletions
+39 -2
View File
@@ -18,8 +18,12 @@ type Catalog interface {
Versions(name string) ([]string, error)
// Digest is the digest name holds at version, empty when none.
Digest(name, version string) (string, error)
// Remove deletes name at version (its manifest); the store's collector frees its blobs.
// Remove deletes name at version by its manifest's digest, every tag naming that digest with it; the store's
// collector frees its blobs.
Remove(name, version string) error
// RemoveTag deletes the tag version of name alone, the manifest staying under every other tag naming it; a store
// that cannot delete a tag alone answers an error and removes nothing.
RemoveTag(name, version string) error
// RemoveDigest deletes an untagged manifest of name by its digest (retention).
RemoveDigest(name, digest string) error
// Platforms are the manifests an index of name names; none for a manifest that is not an index or is not held.
@@ -149,7 +153,18 @@ func (v *Verbs) Remove(seat, caller string, r RemoveRequest) error {
return fmt.Errorf("remove: the store cannot read %s@%s: %w", r.Name, r.Version, err)
}
if d != "" {
if err := v.Catalog.Remove(r.Name, r.Version); err != nil {
// Reproducible builds share a digest between a branch's tagged version and the trunk's numbered one: a
// manifest deleted by its digest would take the trunk's version with it (security review F1). When another
// tag names the digest, the tag alone goes; when the store cannot do that, nothing goes, said.
others, err := v.otherTags(r.Name, r.Version, d)
if err != nil {
return fmt.Errorf("remove: the store cannot say which other tags of %s name %s, so nothing is removed: %w", r.Name, d, err)
}
if len(others) > 0 {
if err := v.Catalog.RemoveTag(r.Name, r.Version); err != nil {
return fmt.Errorf("remove: refused: %s@%s shares its digest %s with %v, and the store did not remove the tag alone, so nothing is removed: %w", r.Name, r.Version, d, others, err)
}
} else if err := v.Catalog.Remove(r.Name, r.Version); err != nil {
return fmt.Errorf("remove: the store did not remove %s@%s: %w", r.Name, r.Version, err)
}
}
@@ -158,6 +173,28 @@ func (v *Verbs) Remove(seat, caller string, r RemoveRequest) error {
return v.Say(seat, EventRemoved, ev)
}
// otherTags are the tags of name but version that name digest.
func (v *Verbs) otherTags(name, version, digest string) ([]string, error) {
tags, err := v.Catalog.Versions(name)
if err != nil {
return nil, err
}
var out []string
for _, t := range tags {
if t == version {
continue
}
d, err := v.Catalog.Digest(name, t)
if err != nil {
return nil, err
}
if d == digest {
out = append(out, t)
}
}
return out, nil
}
// HoldRequest is `hold` and `release`.
type HoldRequest struct {
Name string `json:"name"`