s3: add errors if requests are signed by no authentication is setup

fix https://github.com/chrislusf/seaweedfs/issues/2075
This commit is contained in:
Chris Lu 2021-05-21 14:08:47 -07:00
parent 2f136a04a1
commit 431684798b
2 changed files with 12 additions and 0 deletions

View file

@ -62,6 +62,12 @@ func (s3a *S3ApiServer) PutObjectHandler(w http.ResponseWriter, r *http.Request)
writeErrorResponse(w, s3ErrCode, r.URL) writeErrorResponse(w, s3ErrCode, r.URL)
return return
} }
} else {
rAuthType := getRequestAuthType(r)
if authTypeAnonymous != rAuthType {
writeErrorResponse(w, s3err.ErrAuthNotSetup, r.URL)
return
}
} }
defer dataReader.Close() defer dataReader.Close()

View file

@ -91,6 +91,7 @@ const (
ErrRequestNotReadyYet ErrRequestNotReadyYet
ErrMissingDateHeader ErrMissingDateHeader
ErrInvalidRequest ErrInvalidRequest
ErrAuthNotSetup
ErrNotImplemented ErrNotImplemented
ErrExistingObjectIsDirectory ErrExistingObjectIsDirectory
@ -341,6 +342,11 @@ var errorCodeResponse = map[ErrorCode]APIError{
Description: "Invalid Request", Description: "Invalid Request",
HTTPStatusCode: http.StatusBadRequest, HTTPStatusCode: http.StatusBadRequest,
}, },
ErrAuthNotSetup : {
Code: "InvalidRequest",
Description: "Signed request requires setting up SeaweedFS S3 authentication",
HTTPStatusCode: http.StatusBadRequest,
},
ErrNotImplemented: { ErrNotImplemented: {
Code: "NotImplemented", Code: "NotImplemented",
Description: "A header you provided implies functionality that is not implemented", Description: "A header you provided implies functionality that is not implemented",