0
Fork 0
mirror of https://github.com/project-zot/zot.git synced 2024-12-16 21:56:37 -05:00

fix(storage): handle dedupe disabled in GetAllDedupeReposCandidates() (#2533)

Signed-off-by: Petu Eusebiu <peusebiu@cisco.com>
This commit is contained in:
peusebiu 2024-07-09 15:33:11 +03:00 committed by GitHub
parent aaee0220e4
commit 1c2736d970
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 21 additions and 9 deletions

View file

@ -340,6 +340,10 @@ func (c *Config) IsLdapAuthEnabled() bool {
return false
}
func (c *Config) IsAuthzEnabled() bool {
return c.HTTP.AccessControl != nil
}
func (c *Config) IsMTLSAuthEnabled() bool {
if c.HTTP.TLS != nil &&
c.HTTP.TLS.Key != "" &&

View file

@ -879,13 +879,11 @@ func canMount(userAc *reqCtx.UserAccessControl, imgStore storageTypes.ImageStore
) (bool, error) {
canMount := true
// authz enabled
if userAc != nil {
canMount = false
repos, err := imgStore.GetAllDedupeReposCandidates(digest)
if err != nil {
// first write
return false, err
}
@ -943,9 +941,12 @@ func (rh *RouteHandler) CheckBlob(response http.ResponseWriter, request *http.Re
return
}
userCanMount, err := canMount(userAc, imgStore, digest)
if err != nil {
rh.c.Log.Error().Err(err).Msg("unexpected error")
userCanMount := true
if rh.c.Config.IsAuthzEnabled() {
userCanMount, err = canMount(userAc, imgStore, digest)
if err != nil {
rh.c.Log.Error().Err(err).Msg("unexpected error")
}
}
var blen int64
@ -963,7 +964,7 @@ func (rh *RouteHandler) CheckBlob(response http.ResponseWriter, request *http.Re
if err != nil {
details := zerr.GetDetails(err)
if errors.Is(err, zerr.ErrBadBlobDigest) { //nolint:gocritic // errorslint conflicts with gocritic:IfElseChain
if errors.Is(err, zerr.ErrBadBlobDigest) { //nolint:gocritic,dupl // errorslint conflicts with gocritic:IfElseChain
details["digest"] = digest.String()
e := apiErr.NewError(apiErr.DIGEST_INVALID).AddDetail(details)
zcommon.WriteJSON(response, http.StatusBadRequest, apiErr.NewErrorList(e))
@ -1254,9 +1255,12 @@ func (rh *RouteHandler) CreateBlobUpload(response http.ResponseWriter, request *
return
}
userCanMount, err := canMount(userAc, imgStore, mountDigest)
if err != nil {
rh.c.Log.Error().Err(err).Msg("unexpected error")
userCanMount := true
if rh.c.Config.IsAuthzEnabled() {
userCanMount, err = canMount(userAc, imgStore, mountDigest)
if err != nil {
rh.c.Log.Error().Err(err).Msg("unexpected error")
}
}
// zot does not support cross mounting directly and do a workaround creating using hard link.

View file

@ -1121,6 +1121,10 @@ func (is *ImageStore) GetAllDedupeReposCandidates(digest godigest.Digest) ([]str
return nil, err
}
if is.cache == nil {
return nil, nil
}
is.RLock(&lockLatency)
defer is.RUnlock(&lockLatency)