The artifact registry refuses a held version published at another digest (H-A-393)

While the reserved digest is still empty, a second publish of the same
version with another digest passed the reservation check and the store's
Put moved the version's tag. Publish now refuses it in its held branch,
before the reservation is asked, naming both digests, with the publish's
finding and refused said as any refusal; the same digest is taken as before.
The store's Held answers the digest it holds at the version when it differs.

Builds: design 47 H H-A-393, design 47 G A-490j
This commit is contained in:
2026-11-22 00:18:20 +01:00
parent 69940d1019
commit 7765947476
3 changed files with 50 additions and 21 deletions
@@ -62,8 +62,9 @@ func (b fakeBuilder) Recorded(string, string, string) (bool, string, error) {
} }
type fakeStore struct { type fakeStore struct {
has map[string]bool has map[string]bool
put []map[string][]byte held map[string]string // name@version to the digest the store holds there
put []map[string][]byte
} }
func (s *fakeStore) Has(_, d string) (bool, error) { return s.has[d], nil } func (s *fakeStore) Has(_, d string) (bool, error) { return s.has[d], nil }
@@ -71,8 +72,17 @@ func (s *fakeStore) Put(t PublishRequest, parts map[string][]byte) (string, erro
s.put = append(s.put, parts) s.put = append(s.put, parts)
return t.Name + "@" + t.Digest, nil return t.Name + "@" + t.Digest, nil
} }
func (s *fakeStore) Held(string, string, string) (string, bool, error) { return "", false, nil } func (s *fakeStore) Held(name, version, digest string) (string, string, error) {
func (s *fakeStore) Holds(r PublishRequest) (bool, error) { return s.has[r.Digest], nil } switch d := s.held[name+"@"+version]; d {
case "":
return "", "", nil
case digest:
return name + "@" + d, "", nil
default:
return "", d, nil
}
}
func (s *fakeStore) Holds(r PublishRequest) (bool, error) { return s.has[r.Digest], nil }
type said struct { type said struct {
seat, event string seat, event string
@@ -317,6 +327,16 @@ func TestTheHolderOfTheTwoImageSeats(t *testing.T) {
_, err := b.h.Publish(ArtifactSeat, builder, req("t")) _, err := b.h.Publish(ArtifactSeat, builder, req("t"))
return err return err
}, "the builder did not reserve it"}, }, "the builder did not reserve it"},
{"a version the store holds at another digest", func(b *bed) error {
b.store.held = map[string]string{"m/program@0.1.4": "sha256:bb"}
r := req("t")
r.Digest = "sha256:aa"
_, err := b.h.Publish(ArtifactSeat, builder, r) // the reservation names no digest yet: the bed's builder says yes
if !b.findings["publish-refused m/program@0.1.4"] || len(b.store.put) != 0 {
return errors.New("not refused loudly, or stored")
}
return err
}, "the store holds m/program@0.1.4 at digest sha256:bb, not sha256:aa"},
{"an image on the artifact seat", func(b *bed) error { {"an image on the artifact seat", func(b *bed) error {
r := req("t") r := req("t")
r.Kind = KindImage r.Kind = KindImage
+4 -4
View File
@@ -208,15 +208,15 @@ func (o *OCI) layerSize(t PublishRequest, parts map[string][]byte) (int64, error
} }
// Held is the reference of name at version when the store holds digest under it. // Held is the reference of name at version when the store holds digest under it.
func (o *OCI) Held(name, version, digest string) (string, bool, error) { func (o *OCI) Held(name, version, digest string) (string, string, error) {
d, err := o.Digest(name, version) d, err := o.Digest(name, version)
if err != nil || d == "" { if err != nil || d == "" {
return "", false, err return "", "", err
} }
if d != digest { if d != digest {
return "", false, nil return "", d, nil
} }
return name + "@" + d, true, nil return name + "@" + d, "", nil
} }
// Holds is whether the store holds what r's digest names under r's name: an image's manifest by its digest, or a bundle's // Holds is whether the store holds what r's digest names under r's name: an image's manifest by its digest, or a bundle's
@@ -141,8 +141,9 @@ type Store interface {
// Put stores a publish's parts under its name and version and answers the reference's path (SeatReference). // Put stores a publish's parts under its name and version and answers the reference's path (SeatReference).
Put(r PublishRequest, parts map[string][]byte) (reference string, err error) Put(r PublishRequest, parts map[string][]byte) (reference string, err error)
// Held is the reference's path of name at version when the store already holds digest under it: a rebuild of a held // Held is the reference's path of name at version when the store already holds digest under it: a rebuild of a held
// fingerprint answers it and stores nothing. // fingerprint answers it and stores nothing. When the store holds the version at another digest, other names that digest
Held(name, version, digest string) (reference string, ok bool, err error) // and reference is empty; neither is set when the store holds no such version.
Held(name, version, digest string) (reference, other string, err error)
// Holds says whether the store holds what a publish's digest names under its name: an image's manifest, or a bundle's or // Holds says whether the store holds what a publish's digest names under its name: an image's manifest, or a bundle's or
// an archive's blob. The store is the artifact store (A-50): `artifact-store://<name>/blobs/<digest>` is that blob. // an archive's blob. The store is the artifact store (A-50): `artifact-store://<name>/blobs/<digest>` is that blob.
Holds(r PublishRequest) (bool, error) Holds(r PublishRequest) (bool, error)
@@ -266,15 +267,19 @@ func (h *Holder) Publish(seat, caller string, r PublishRequest) (PublishAnswer,
} }
// A rebuild of a held fingerprint answers the held version and stores nothing. // A rebuild of a held fingerprint answers the held version and stores nothing.
if r.Version != "" { if r.Version != "" {
var ref string var ref, other string
var ok bool
err := h.timed("the store's read of what it holds (the program's registry)", func() (err error) { err := h.timed("the store's read of what it holds (the program's registry)", func() (err error) {
ref, ok, err = h.Store.Held(r.Name, r.Version, r.Digest) ref, other, err = h.Store.Held(r.Name, r.Version, r.Digest)
return err return err
}) })
if err != nil { if err != nil {
return PublishAnswer{}, fmt.Errorf("publish: the store cannot say whether it holds %s@%s: %w", r.Name, r.Version, err) return PublishAnswer{}, fmt.Errorf("publish: the store cannot say whether it holds %s@%s: %w", r.Name, r.Version, err)
} else if ok { } else if other != "" {
// A second publish of a held version with another digest is refused before the reservation is asked, as the forge
// holds the first (A-490j, H-A-393): while the reserved digest is still empty it would pass, and the store's Put
// would move the version's tag.
return h.refusePublish(seat, r, fmt.Sprintf("the store holds %s@%s at digest %s, not %s", r.Name, r.Version, other, r.Digest))
} else if ref != "" {
return PublishAnswer{Transfer: r.Transfer, Ended: true}, h.timed("the published event on the seat", func() error { return PublishAnswer{Transfer: r.Transfer, Ended: true}, h.timed("the published event on the seat", func() error {
return h.Say(seat, EventPublished, h.eventOf(seat, r, SeatReference(seat, ref), "")) return h.Say(seat, EventPublished, h.eventOf(seat, r, SeatReference(seat, ref), ""))
}) })
@@ -298,6 +303,16 @@ func (h *Holder) Publish(seat, caller string, r PublishRequest) (PublishAnswer,
return answerOf(got), nil return answerOf(got), nil
} }
// refusePublish ends a publish refused before anything is stored: its finding raised, refused said on the seat, the reason
// answered.
func (h *Holder) refusePublish(seat string, r PublishRequest, reason string) (PublishAnswer, error) {
h.Finding("publish-refused", r.Name+"@"+r.Version, reason, true)
if err := h.Say(seat, EventRefused, h.eventOf(seat, r, "", reason)); err != nil {
return PublishAnswer{}, fmt.Errorf("publish: %s, and the refused is not said: %w", reason, err)
}
return PublishAnswer{Transfer: r.Transfer, Ended: true}, errors.New("publish: " + reason)
}
// tagHeld is a publish with a version, a digest and no parts (design 47 G A-417, A-73, A-50): what the store holds of that // tagHeld is a publish with a version, a digest and no parts (design 47 G A-417, A-73, A-50): what the store holds of that
// digest under the name (the build's untagged publish, the artifact store's blob) is checked against the builder's reservation // digest under the name (the build's untagged publish, the artifact store's blob) is checked against the builder's reservation
// and tagged with the version, and published is said; when the store holds none of it, the publish is refused as not stored, // and tagged with the version, and published is said; when the store holds none of it, the publish is refused as not stored,
@@ -311,13 +326,7 @@ func (h *Holder) tagHeld(seat string, r PublishRequest) (PublishAnswer, error) {
if err != nil { if err != nil {
return PublishAnswer{}, fmt.Errorf("publish: the store cannot say whether it holds %s of %s: %w", r.Digest, r.Name, err) return PublishAnswer{}, fmt.Errorf("publish: the store cannot say whether it holds %s of %s: %w", r.Digest, r.Name, err)
} }
refuse := func(reason string) (PublishAnswer, error) { refuse := func(reason string) (PublishAnswer, error) { return h.refusePublish(seat, r, reason) }
h.Finding("publish-refused", r.Name+"@"+r.Version, reason, true)
if err := h.Say(seat, EventRefused, h.eventOf(seat, r, "", reason)); err != nil {
return PublishAnswer{}, fmt.Errorf("publish: %s, and the refused is not said: %w", reason, err)
}
return PublishAnswer{Transfer: r.Transfer, Ended: true}, errors.New("publish: " + reason)
}
if !held { if !held {
return refuse(fmt.Sprintf("not stored: the store holds no %s of %s, so version %s names nothing", r.Digest, r.Name, r.Version)) return refuse(fmt.Sprintf("not stored: the store holds no %s of %s, so version %s names nothing", r.Digest, r.Name, r.Version))
} }