Skip to content

Commit 1c19f8f

Browse files
committed
Also treat 401 as if it were 404
We recently ran into this again with `arm32v6/hello-world` where 401 from the proxy actually means 404 because of mixing + matching public/private repositories in the same registry/namespace and thus returning a true 404 would be an information leak. In our case, if we get a 401 at this point, we know for sure it might as well be a 404 because `ociauth` would already have handled any authentication we could possibly do.
1 parent cf871c9 commit 1c19f8f

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

registry/synthesize-index.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ func SynthesizeIndex(ctx context.Context, ref ociref.Reference) (*ocispec.Index,
3737
if errors.Is(err, ociregistry.ErrBlobUnknown) ||
3838
errors.Is(err, ociregistry.ErrManifestUnknown) ||
3939
errors.Is(err, ociregistry.ErrNameUnknown) ||
40-
strings.HasPrefix(err.Error(), "404 ") {
40+
strings.HasPrefix(err.Error(), "404 ") ||
41+
// 401 often means "repository not found" (due to the nature of public/private mixing on Hub and the fact that ociauth definitely handled any possible authentication for us, so if we're still getting 401 it's unavoidable and might as well be 404)
42+
strings.HasPrefix(err.Error(), "401 ") {
4143
return nil, nil
4244
}
4345
return nil, fmt.Errorf("%s: failed GET: %w", ref, err)

0 commit comments

Comments
 (0)