Check expected digest when committing as a sanity check

This commit also adds an info-level log message for the case where the
registry doesn't send a digest header since the computed digest is a
valuable part of our content Commit interface.

Signed-off-by: Max Jonas Werner <max@coppersoft.com>
This commit is contained in:
Max Jonas Werner
2023-11-17 16:10:17 +01:00
parent f2b9ff67f3
commit 5243cdd2dc

View File

@@ -526,6 +526,8 @@ func (pw *pushWriter) Commit(ctx context.Context, size int64, expected digest.Di
if expected == "" {
expected = status.Expected
} else if expected != status.Expected {
return fmt.Errorf("unexpected digest received: got %q, expected %q", status.Expected, expected)
}
if dgstHdr := resp.Header.Get("Docker-Content-Digest"); dgstHdr != "" {
@@ -537,6 +539,8 @@ func (pw *pushWriter) Commit(ctx context.Context, size int64, expected digest.Di
if actual != expected {
return fmt.Errorf("got digest %s, expected %s", actual, expected)
}
} else {
log.G(ctx).Info("registry did not send a Docker-Content-Digest header")
}
status.Committed = true