Skip to content

Commit e23c15a

Browse files
committed
Only check caller-controlled attribute size for max cache key
1 parent ea1b4eb commit e23c15a

File tree

1 file changed

+12
-1
lines changed
  • staging/src/k8s.io/apiserver/plugin/pkg/authorizer/webhook

1 file changed

+12
-1
lines changed

staging/src/k8s.io/apiserver/plugin/pkg/authorizer/webhook/webhook.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ func (w *WebhookAuthorizer) Authorize(attr authorizer.Attributes) (decision auth
200200
if r.Status.Allowed {
201201
w.responseCache.Add(string(key), r.Status, w.authorizedTTL)
202202
} else {
203-
if len(key) <= maxUnauthorizedCachedKeySize {
203+
if callerControlledAttributeSize(attr) < maxUnauthorizedCachedKeySize {
204204
w.responseCache.Add(string(key), r.Status, w.unauthorizedTTL)
205205
}
206206
}
@@ -268,3 +268,14 @@ func (t *subjectAccessReviewClient) Create(subjectAccessReview *authorization.Su
268268
err := t.w.RestClient.Post().Body(subjectAccessReview).Do().Into(result)
269269
return result, err
270270
}
271+
272+
func callerControlledAttributeSize(attr authorizer.Attributes) int64 {
273+
return int64(len(attr.GetNamespace())) +
274+
int64(len(attr.GetVerb())) +
275+
int64(len(attr.GetAPIGroup())) +
276+
int64(len(attr.GetAPIVersion())) +
277+
int64(len(attr.GetResource())) +
278+
int64(len(attr.GetSubresource())) +
279+
int64(len(attr.GetName())) +
280+
int64(len(attr.GetPath()))
281+
}

0 commit comments

Comments
 (0)