diff --git a/api/handler/put.go b/api/handler/put.go index 72794c6e..9f8f866b 100644 --- a/api/handler/put.go +++ b/api/handler/put.go @@ -813,7 +813,7 @@ func (h *handler) parseCommonCreateBucketParams(reqInfo *middleware.ReqInfo, box return nil, nil, fmt.Errorf("couldn't set placement policy: %w", err) } - p.ObjectLockEnabled = isLockEnabled(r.Header) + p.ObjectLockEnabled = isLockEnabled(h.reqLogger(r.Context()), r.Header) return key, p, nil } @@ -1096,9 +1096,17 @@ func (h handler) setPlacementPolicy(prm *layer.CreateBucketParams, namespace, lo return errors.GetAPIError(errors.ErrInvalidLocationConstraint) } -func isLockEnabled(header http.Header) bool { +func isLockEnabled(log *zap.Logger, header http.Header) bool { lockEnabledStr := header.Get(api.AmzBucketObjectLockEnabled) - lockEnabled, _ := strconv.ParseBool(lockEnabledStr) + if len(lockEnabledStr) == 0 { + return false + } + + lockEnabled, err := strconv.ParseBool(lockEnabledStr) + if err != nil { + log.Warn(logs.InvalidBucketObjectLockEnabledHeader, zap.String("header", lockEnabledStr), zap.Error(err)) + } + return lockEnabled } diff --git a/internal/logs/logs.go b/internal/logs/logs.go index 1e60ac57..41d6727d 100644 --- a/internal/logs/logs.go +++ b/internal/logs/logs.go @@ -147,4 +147,5 @@ const ( SuccessfulAuth = "successful auth" PolicyRequest = "policy request" FailedToGenerateRequestID = "failed to generate request id" + InvalidBucketObjectLockEnabledHeader = "invalid X-Amz-Bucket-Object-Lock-Enabled header" )