Disallow root disk to be used for cache drives (#14513)

This commit is contained in:
Poorna 2022-03-10 02:45:31 -08:00 committed by GitHub
parent 41079f1015
commit 7ce91ea1a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -20,10 +20,12 @@ package cache
import ( import (
"encoding/json" "encoding/json"
"errors" "errors"
"os"
"path/filepath" "path/filepath"
"strings" "strings"
"github.com/minio/minio/internal/config" "github.com/minio/minio/internal/config"
"github.com/minio/minio/internal/disk"
"github.com/minio/pkg/ellipses" "github.com/minio/pkg/ellipses"
) )
@ -115,11 +117,20 @@ func parseCacheDrives(drives string) ([]string, error) {
endpoints = append(endpoints, d) endpoints = append(endpoints, d)
} }
} }
isCICD := os.Getenv("MINIO_CI_CD") != "" || os.Getenv("CI") != ""
for _, d := range endpoints { for _, d := range endpoints {
if !filepath.IsAbs(d) { if !filepath.IsAbs(d) {
return nil, config.ErrInvalidCacheDrivesValue(nil).Msg("cache dir should be absolute path: %s", d) return nil, config.ErrInvalidCacheDrivesValue(nil).Msg("cache dir should be absolute path: %s", d)
} }
if !isCICD {
rootDsk, err := disk.IsRootDisk(d, "/")
if err != nil {
return nil, config.ErrInvalidCacheDrivesValue(nil).Msg("Invalid cache dir %s err : %s", d, err.Error())
}
if rootDsk {
return nil, config.ErrInvalidCacheDrivesValue(nil).Msg("cache dir cannot be part of root disk: %s", d)
}
}
} }
return endpoints, nil return endpoints, nil
} }