Limit the number of operations in a single json patch to be 10,000
Kubernetes-commit: 5e6fc5dce8b12c5ce80e016b208a51c81a8c9ce8
This commit is contained in:
parent
908ce86a0f
commit
3866fe78d2
|
@ -49,6 +49,11 @@ import (
|
||||||
utiltrace "k8s.io/utils/trace"
|
utiltrace "k8s.io/utils/trace"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// maximum number of operations a single json patch may contain.
|
||||||
|
maxJSONPatchOperations = 10000
|
||||||
|
)
|
||||||
|
|
||||||
// PatchResource returns a function that will handle a resource patch.
|
// PatchResource returns a function that will handle a resource patch.
|
||||||
func PatchResource(r rest.Patcher, scope RequestScope, admit admission.Interface, patchTypes []string) http.HandlerFunc {
|
func PatchResource(r rest.Patcher, scope RequestScope, admit admission.Interface, patchTypes []string) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, req *http.Request) {
|
return func(w http.ResponseWriter, req *http.Request) {
|
||||||
|
@ -331,6 +336,11 @@ func (p *jsonPatcher) applyJSPatch(versionedJS []byte) (patchedJS []byte, retErr
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.NewBadRequest(err.Error())
|
return nil, errors.NewBadRequest(err.Error())
|
||||||
}
|
}
|
||||||
|
if len(patchObj) > maxJSONPatchOperations {
|
||||||
|
return nil, errors.NewRequestEntityTooLargeError(
|
||||||
|
fmt.Sprintf("The allowed maximum operations in a JSON patch is %d, got %d",
|
||||||
|
maxJSONPatchOperations, len(patchObj)))
|
||||||
|
}
|
||||||
patchedJS, err := patchObj.Apply(versionedJS)
|
patchedJS, err := patchObj.Apply(versionedJS)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.NewGenericServerResponse(http.StatusUnprocessableEntity, "", schema.GroupResource{}, "", err.Error(), 0, false)
|
return nil, errors.NewGenericServerResponse(http.StatusUnprocessableEntity, "", schema.GroupResource{}, "", err.Error(), 0, false)
|
||||||
|
|
Loading…
Reference in New Issue