error out by default beyond 10000 versions per object (#17803)

```
You've exceeded the limit on the number of versions you can create on this object
```
This commit is contained in:
Harshavardhana
2023-08-04 10:40:21 -07:00
committed by GitHub
parent e0329cfdbb
commit cb089dcb52
6 changed files with 266 additions and 223 deletions

View File

@@ -26,6 +26,7 @@ import (
"fmt"
"io"
"sort"
"strconv"
"strings"
"sync"
"time"
@@ -37,9 +38,31 @@ import (
"github.com/minio/minio/internal/bucket/replication"
xhttp "github.com/minio/minio/internal/http"
"github.com/minio/minio/internal/logger"
"github.com/minio/pkg/env"
"github.com/tinylib/msgp/msgp"
)
// Reject creating new versions when a single object is cross maxObjectVersions
var maxObjectVersions = 10000
func init() {
v := env.Get("_MINIO_OBJECT_MAX_VERSIONS", "")
if v != "" {
maxv, err := strconv.Atoi(v)
if err != nil {
logger.Info("invalid _MINIO_OBJECT_MAX_VERSIONS value: %s, defaulting to '10000'", v)
maxObjectVersions = 10000
} else {
if maxv < 10 {
logger.Info("invalid _MINIO_OBJECT_MAX_VERSIONS value: %s, minimum allowed is '10' defaulting to '10000'", v)
maxObjectVersions = 10000
} else {
maxObjectVersions = maxv
}
}
}
}
var (
// XL header specifies the format
xlHeader = [4]byte{'X', 'L', '2', ' '}
@@ -1070,6 +1093,12 @@ func (x *xlMetaV2) addVersion(ver xlMetaV2Version) error {
if err != nil {
return err
}
// returns error if we have exceeded maxObjectVersions
if len(x.versions)+1 > maxObjectVersions {
return errMaxVersionsExceeded
}
// Add space at the end.
// Will have -1 modtime, so it will be inserted there.
x.versions = append(x.versions, xlMetaV2ShallowVersion{header: xlMetaV2VersionHeader{ModTime: -1}})