From 7ce91ea1a1656484fb7eab18a1fa2287eb10b6ee Mon Sep 17 00:00:00 2001 From: Poorna Date: Thu, 10 Mar 2022 02:45:31 -0800 Subject: [PATCH] Disallow root disk to be used for cache drives (#14513) --- internal/config/cache/config.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/internal/config/cache/config.go b/internal/config/cache/config.go index 361c0ca8a..b4a0785b3 100644 --- a/internal/config/cache/config.go +++ b/internal/config/cache/config.go @@ -20,10 +20,12 @@ package cache import ( "encoding/json" "errors" + "os" "path/filepath" "strings" "github.com/minio/minio/internal/config" + "github.com/minio/minio/internal/disk" "github.com/minio/pkg/ellipses" ) @@ -115,11 +117,20 @@ func parseCacheDrives(drives string) ([]string, error) { endpoints = append(endpoints, d) } } - + isCICD := os.Getenv("MINIO_CI_CD") != "" || os.Getenv("CI") != "" for _, d := range endpoints { if !filepath.IsAbs(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 }