Skip to content

Commit 1c2736d

Browse files
fix(storage): handle dedupe disabled in GetAllDedupeReposCandidates() (#2533)
Signed-off-by: Petu Eusebiu <[email protected]>
1 parent aaee022 commit 1c2736d

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

pkg/api/config/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,10 @@ func (c *Config) IsLdapAuthEnabled() bool {
340340
return false
341341
}
342342

343+
func (c *Config) IsAuthzEnabled() bool {
344+
return c.HTTP.AccessControl != nil
345+
}
346+
343347
func (c *Config) IsMTLSAuthEnabled() bool {
344348
if c.HTTP.TLS != nil &&
345349
c.HTTP.TLS.Key != "" &&

pkg/api/routes.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -879,13 +879,11 @@ func canMount(userAc *reqCtx.UserAccessControl, imgStore storageTypes.ImageStore
879879
) (bool, error) {
880880
canMount := true
881881

882-
// authz enabled
883882
if userAc != nil {
884883
canMount = false
885884

886885
repos, err := imgStore.GetAllDedupeReposCandidates(digest)
887886
if err != nil {
888-
// first write
889887
return false, err
890888
}
891889

@@ -943,9 +941,12 @@ func (rh *RouteHandler) CheckBlob(response http.ResponseWriter, request *http.Re
943941
return
944942
}
945943

946-
userCanMount, err := canMount(userAc, imgStore, digest)
947-
if err != nil {
948-
rh.c.Log.Error().Err(err).Msg("unexpected error")
944+
userCanMount := true
945+
if rh.c.Config.IsAuthzEnabled() {
946+
userCanMount, err = canMount(userAc, imgStore, digest)
947+
if err != nil {
948+
rh.c.Log.Error().Err(err).Msg("unexpected error")
949+
}
949950
}
950951

951952
var blen int64
@@ -963,7 +964,7 @@ func (rh *RouteHandler) CheckBlob(response http.ResponseWriter, request *http.Re
963964

964965
if err != nil {
965966
details := zerr.GetDetails(err)
966-
if errors.Is(err, zerr.ErrBadBlobDigest) { //nolint:gocritic // errorslint conflicts with gocritic:IfElseChain
967+
if errors.Is(err, zerr.ErrBadBlobDigest) { //nolint:gocritic,dupl // errorslint conflicts with gocritic:IfElseChain
967968
details["digest"] = digest.String()
968969
e := apiErr.NewError(apiErr.DIGEST_INVALID).AddDetail(details)
969970
zcommon.WriteJSON(response, http.StatusBadRequest, apiErr.NewErrorList(e))
@@ -1254,9 +1255,12 @@ func (rh *RouteHandler) CreateBlobUpload(response http.ResponseWriter, request *
12541255
return
12551256
}
12561257

1257-
userCanMount, err := canMount(userAc, imgStore, mountDigest)
1258-
if err != nil {
1259-
rh.c.Log.Error().Err(err).Msg("unexpected error")
1258+
userCanMount := true
1259+
if rh.c.Config.IsAuthzEnabled() {
1260+
userCanMount, err = canMount(userAc, imgStore, mountDigest)
1261+
if err != nil {
1262+
rh.c.Log.Error().Err(err).Msg("unexpected error")
1263+
}
12601264
}
12611265

12621266
// zot does not support cross mounting directly and do a workaround creating using hard link.

pkg/storage/imagestore/imagestore.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,6 +1121,10 @@ func (is *ImageStore) GetAllDedupeReposCandidates(digest godigest.Digest) ([]str
11211121
return nil, err
11221122
}
11231123

1124+
if is.cache == nil {
1125+
return nil, nil
1126+
}
1127+
11241128
is.RLock(&lockLatency)
11251129
defer is.RUnlock(&lockLatency)
11261130

0 commit comments

Comments
 (0)