return error for AppendObject() API (#21272)

This commit is contained in:
Harshavardhana 2025-05-07 08:37:12 -07:00 committed by GitHub
parent 9ea14c88d8
commit 6d18dba9a2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 33 additions and 2 deletions

View File

@ -387,6 +387,11 @@ func registerAPIRouter(router *mux.Router) {
HeadersRegexp(xhttp.AmzSnowballExtract, "true"). HeadersRegexp(xhttp.AmzSnowballExtract, "true").
HandlerFunc(s3APIMiddleware(api.PutObjectExtractHandler, traceHdrsS3HFlag)) HandlerFunc(s3APIMiddleware(api.PutObjectExtractHandler, traceHdrsS3HFlag))
// AppendObject to be rejected
router.Methods(http.MethodPut).Path("/{object:.+}").
HeadersRegexp(xhttp.AmzWriteOffsetBytes, "").
HandlerFunc(s3APIMiddleware(errorResponseHandler))
// PutObject // PutObject
router.Methods(http.MethodPut).Path("/{object:.+}"). router.Methods(http.MethodPut).Path("/{object:.+}").
HandlerFunc(s3APIMiddleware(api.PutObjectHandler, traceHdrsS3HFlag)) HandlerFunc(s3APIMiddleware(api.PutObjectHandler, traceHdrsS3HFlag))

View File

@ -25,6 +25,7 @@ import (
"net/textproto" "net/textproto"
"regexp" "regexp"
"strings" "strings"
"sync/atomic"
"github.com/minio/madmin-go/v3" "github.com/minio/madmin-go/v3"
"github.com/minio/minio/internal/auth" "github.com/minio/minio/internal/auth"
@ -427,9 +428,31 @@ func errorResponseHandler(w http.ResponseWriter, r *http.Request) {
HTTPStatusCode: http.StatusUpgradeRequired, HTTPStatusCode: http.StatusUpgradeRequired,
}, r.URL) }, r.URL)
default: default:
defer logger.AuditLog(r.Context(), w, r, mustGetClaimsFromToken(r))
defer atomic.AddUint64(&globalHTTPStats.rejectedRequestsInvalid, 1)
// When we are not running in S3 Express mode, generate appropriate error
// for x-amz-write-offset HEADER specified.
if _, ok := r.Header[xhttp.AmzWriteOffsetBytes]; ok {
tc, ok := r.Context().Value(mcontext.ContextTraceKey).(*mcontext.TraceCtxt)
if ok {
tc.FuncName = "s3.AppendObject"
tc.ResponseRecorder.LogErrBody = true
}
writeErrorResponse(r.Context(), w, getAPIError(ErrNotImplemented), r.URL)
return
}
tc, ok := r.Context().Value(mcontext.ContextTraceKey).(*mcontext.TraceCtxt)
if ok {
tc.FuncName = "s3.ValidRequest"
tc.ResponseRecorder.LogErrBody = true
}
writeErrorResponse(r.Context(), w, APIError{ writeErrorResponse(r.Context(), w, APIError{
Code: "BadRequest", Code: "BadRequest",
Description: fmt.Sprintf("An error occurred when parsing the HTTP request %s at '%s'", Description: fmt.Sprintf("An unsupported API call for method: %s at '%s'",
r.Method, r.URL.Path), r.Method, r.URL.Path),
HTTPStatusCode: http.StatusBadRequest, HTTPStatusCode: http.StatusBadRequest,
}, r.URL) }, r.URL)

View File

@ -758,7 +758,7 @@ func (r *metacacheReader) Close() error {
return nil return nil
} }
// metacacheBlockWriter collects blocks and provides a callaback to store them. // metacacheBlockWriter collects blocks and provides a callback to store them.
type metacacheBlockWriter struct { type metacacheBlockWriter struct {
wg sync.WaitGroup wg sync.WaitGroup
streamErr error streamErr error

View File

@ -181,6 +181,9 @@ const (
AmzChecksumTypeFullObject = "FULL_OBJECT" AmzChecksumTypeFullObject = "FULL_OBJECT"
AmzChecksumTypeComposite = "COMPOSITE" AmzChecksumTypeComposite = "COMPOSITE"
// S3 Express API related constant reject it.
AmzWriteOffsetBytes = "x-amz-write-offset-bytes"
// Post Policy related // Post Policy related
AmzMetaUUID = "X-Amz-Meta-Uuid" AmzMetaUUID = "X-Amz-Meta-Uuid"
AmzMetaName = "X-Amz-Meta-Name" AmzMetaName = "X-Amz-Meta-Name"