mirror of
https://github.com/minio/minio.git
synced 2025-11-07 12:52:58 -05:00
fix: reject ilm rule when bucket LockEnabled (#19785)
This commit is contained in:
@@ -27,6 +27,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/minio/minio/internal/bucket/object/lock"
|
||||
xhttp "github.com/minio/minio/internal/http"
|
||||
)
|
||||
|
||||
@@ -236,7 +237,7 @@ func ParseLifecycleConfig(reader io.Reader) (*Lifecycle, error) {
|
||||
}
|
||||
|
||||
// Validate - validates the lifecycle configuration
|
||||
func (lc Lifecycle) Validate() error {
|
||||
func (lc Lifecycle) Validate(lr lock.Retention) error {
|
||||
// Lifecycle config can't have more than 1000 rules
|
||||
if len(lc.Rules) > 1000 {
|
||||
return errLifecycleTooManyRules
|
||||
@@ -251,6 +252,12 @@ func (lc Lifecycle) Validate() error {
|
||||
if err := r.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
if (r.Expiration.DeleteMarker.val || // DeleteVersionAction
|
||||
!r.DelMarkerExpiration.Empty() || // DelMarkerDeleteAllVersionsAction
|
||||
!r.NoncurrentVersionExpiration.IsDaysNull() || // DeleteVersionAction
|
||||
!r.Expiration.IsDaysNull()) && lr.LockEnabled {
|
||||
return fmt.Errorf("DeleteAllVersions and DeleteMarkerDeleteAllVersions cannot be set when bucket lock is enabled")
|
||||
}
|
||||
}
|
||||
// Make sure Rule ID is unique
|
||||
for i := range lc.Rules {
|
||||
|
||||
@@ -30,6 +30,7 @@ import (
|
||||
|
||||
"github.com/dustin/go-humanize"
|
||||
"github.com/google/uuid"
|
||||
"github.com/minio/minio/internal/bucket/object/lock"
|
||||
xhttp "github.com/minio/minio/internal/http"
|
||||
)
|
||||
|
||||
@@ -144,7 +145,7 @@ func TestParseAndValidateLifecycleConfig(t *testing.T) {
|
||||
// no need to continue this test.
|
||||
return
|
||||
}
|
||||
err = lc.Validate()
|
||||
err = lc.Validate(lock.Retention{})
|
||||
if err != tc.expectedValidationErr {
|
||||
t.Fatalf("%d: Expected %v during validation but got %v", i+1, tc.expectedValidationErr, err)
|
||||
}
|
||||
@@ -779,7 +780,7 @@ func TestHasActiveRules(t *testing.T) {
|
||||
t.Fatalf("Got unexpected error: %v", err)
|
||||
}
|
||||
// To ensure input lifecycle configurations are valid
|
||||
if err := lc.Validate(); err != nil {
|
||||
if err := lc.Validate(lock.Retention{}); err != nil {
|
||||
t.Fatalf("Invalid test case: %d %v", i+1, err)
|
||||
}
|
||||
if got := lc.HasActiveRules(tc.prefix); got != tc.want {
|
||||
@@ -1365,7 +1366,7 @@ func TestFilterRules(t *testing.T) {
|
||||
|
||||
for i, tc := range tests {
|
||||
t.Run(fmt.Sprintf("test-%d", i+1), func(t *testing.T) {
|
||||
if err := tc.lc.Validate(); err != nil {
|
||||
if err := tc.lc.Validate(lock.Retention{}); err != nil {
|
||||
t.Fatalf("Lifecycle validation failed - %v", err)
|
||||
}
|
||||
rules := tc.lc.FilterRules(tc.opts)
|
||||
|
||||
Reference in New Issue
Block a user