Skip to content

Commit 327f53b

Browse files
authored
Merge pull request kubernetes#83064 from liggitt/propagate-context
Propagate context to remote authorize/authenticate webhook calls
2 parents 948870b + b78edd8 commit 327f53b

File tree

61 files changed

+270
-93
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+270
-93
lines changed

pkg/auth/authorizer/abac/abac.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package abac
1919

2020
import (
2121
"bufio"
22+
"context"
2223
"fmt"
2324
"os"
2425
"strings"
@@ -224,7 +225,7 @@ func resourceMatches(p abac.Policy, a authorizer.Attributes) bool {
224225
}
225226

226227
// Authorize implements authorizer.Authorize
227-
func (pl PolicyList) Authorize(a authorizer.Attributes) (authorizer.Decision, string, error) {
228+
func (pl PolicyList) Authorize(ctx context.Context, a authorizer.Attributes) (authorizer.Decision, string, error) {
228229
for _, p := range pl {
229230
if matches(*p, a) {
230231
return authorizer.DecisionAllow, "", nil

pkg/auth/authorizer/abac/abac_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package abac
1818

1919
import (
20+
"context"
2021
"io/ioutil"
2122
"os"
2223
"reflect"
@@ -133,7 +134,7 @@ func TestAuthorizeV0(t *testing.T) {
133134

134135
ResourceRequest: len(tc.NS) > 0 || len(tc.Resource) > 0,
135136
}
136-
decision, _, _ := a.Authorize(attr)
137+
decision, _, _ := a.Authorize(context.Background(), attr)
137138
if tc.ExpectDecision != decision {
138139
t.Logf("tc: %v -> attr %v", tc, attr)
139140
t.Errorf("%d: Expected allowed=%v but actually allowed=%v\n\t%v",
@@ -451,7 +452,7 @@ func TestAuthorizeV1beta1(t *testing.T) {
451452
Path: tc.Path,
452453
}
453454
// t.Logf("tc %2v: %v -> attr %v", i, tc, attr)
454-
decision, _, _ := a.Authorize(attr)
455+
decision, _, _ := a.Authorize(context.Background(), attr)
455456
if tc.ExpectDecision != decision {
456457
t.Errorf("%d: Expected allowed=%v but actually allowed=%v, for case %+v & %+v",
457458
i, tc.ExpectDecision, decision, tc, attr)

pkg/kubelet/server/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ func (s *Server) InstallAuthFilter() {
260260
attrs := s.auth.GetRequestAttributes(info.User, req.Request)
261261

262262
// Authorize
263-
decision, _, err := s.auth.Authorize(attrs)
263+
decision, _, err := s.auth.Authorize(req.Request.Context(), attrs)
264264
if err != nil {
265265
msg := fmt.Sprintf("Authorization error (user=%s, verb=%s, resource=%s, subresource=%s)", attrs.GetUser().GetName(), attrs.GetVerb(), attrs.GetResource(), attrs.GetSubresource())
266266
klog.Errorf(msg, err)

pkg/kubelet/server/server_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ func (f *fakeAuth) AuthenticateRequest(req *http.Request) (*authenticator.Respon
284284
func (f *fakeAuth) GetRequestAttributes(u user.Info, req *http.Request) authorizer.Attributes {
285285
return f.attributesFunc(u, req)
286286
}
287-
func (f *fakeAuth) Authorize(a authorizer.Attributes) (authorized authorizer.Decision, reason string, err error) {
287+
func (f *fakeAuth) Authorize(ctx context.Context, a authorizer.Attributes) (authorized authorizer.Decision, reason string, err error) {
288288
return f.authorizeFunc(a)
289289
}
290290

pkg/registry/authorization/localsubjectaccessreview/rest.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func (r *REST) Create(ctx context.Context, obj runtime.Object, createValidation
7070
}
7171

7272
authorizationAttributes := authorizationutil.AuthorizationAttributesFrom(localSubjectAccessReview.Spec)
73-
decision, reason, evaluationErr := r.authorizer.Authorize(authorizationAttributes)
73+
decision, reason, evaluationErr := r.authorizer.Authorize(ctx, authorizationAttributes)
7474

7575
localSubjectAccessReview.Status = authorizationapi.SubjectAccessReviewStatus{
7676
Allowed: (decision == authorizer.DecisionAllow),

pkg/registry/authorization/selfsubjectaccessreview/rest.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func (r *REST) Create(ctx context.Context, obj runtime.Object, createValidation
7373
authorizationAttributes = authorizationutil.NonResourceAttributesFrom(userToCheck, *selfSAR.Spec.NonResourceAttributes)
7474
}
7575

76-
decision, reason, evaluationErr := r.authorizer.Authorize(authorizationAttributes)
76+
decision, reason, evaluationErr := r.authorizer.Authorize(ctx, authorizationAttributes)
7777

7878
selfSAR.Status = authorizationapi.SubjectAccessReviewStatus{
7979
Allowed: (decision == authorizer.DecisionAllow),

pkg/registry/authorization/subjectaccessreview/rest.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func (r *REST) Create(ctx context.Context, obj runtime.Object, createValidation
6262
}
6363

6464
authorizationAttributes := authorizationutil.AuthorizationAttributesFrom(subjectAccessReview.Spec)
65-
decision, reason, evaluationErr := r.authorizer.Authorize(authorizationAttributes)
65+
decision, reason, evaluationErr := r.authorizer.Authorize(ctx, authorizationAttributes)
6666

6767
subjectAccessReview.Status = authorizationapi.SubjectAccessReviewStatus{
6868
Allowed: (decision == authorizer.DecisionAllow),

pkg/registry/authorization/subjectaccessreview/rest_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package subjectaccessreview
1818

1919
import (
20+
"context"
2021
"errors"
2122
"strings"
2223
"testing"
@@ -39,7 +40,7 @@ type fakeAuthorizer struct {
3940
err error
4041
}
4142

42-
func (f *fakeAuthorizer) Authorize(attrs authorizer.Attributes) (authorizer.Decision, string, error) {
43+
func (f *fakeAuthorizer) Authorize(ctx context.Context, attrs authorizer.Attributes) (authorizer.Decision, string, error) {
4344
f.attrs = attrs
4445
return f.decision, f.reason, f.err
4546
}

pkg/registry/rbac/escalation_check.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func RoleEscalationAuthorized(ctx context.Context, a authorizer.Authorizer) bool
8787
ResourceRequest: true,
8888
}
8989

90-
decision, _, err := a.Authorize(attrs)
90+
decision, _, err := a.Authorize(ctx, attrs)
9191
if err != nil {
9292
utilruntime.HandleError(fmt.Errorf(
9393
"error authorizing user %#v to escalate %#v named %q in namespace %q: %v",
@@ -135,7 +135,7 @@ func BindingAuthorized(ctx context.Context, roleRef rbac.RoleRef, bindingNamespa
135135
return false
136136
}
137137

138-
decision, _, err := a.Authorize(attrs)
138+
decision, _, err := a.Authorize(ctx, attrs)
139139
if err != nil {
140140
utilruntime.HandleError(fmt.Errorf(
141141
"error authorizing user %#v to bind %#v in namespace %s: %v",

plugin/pkg/admission/gc/gc_admission.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func (a *gcPermissionsEnforcement) Validate(ctx context.Context, attributes admi
112112
ResourceRequest: true,
113113
Path: "",
114114
}
115-
decision, reason, err := a.authorizer.Authorize(deleteAttributes)
115+
decision, reason, err := a.authorizer.Authorize(ctx, deleteAttributes)
116116
if decision != authorizer.DecisionAllow {
117117
return admission.NewForbidden(attributes, fmt.Errorf("cannot set an ownerRef on a resource you can't delete: %v, %v", reason, err))
118118
}
@@ -131,7 +131,7 @@ func (a *gcPermissionsEnforcement) Validate(ctx context.Context, attributes admi
131131
// resources. User needs to have delete permission on all the
132132
// matched Resources.
133133
for _, record := range records {
134-
decision, reason, err := a.authorizer.Authorize(record)
134+
decision, reason, err := a.authorizer.Authorize(ctx, record)
135135
if decision != authorizer.DecisionAllow {
136136
return admission.NewForbidden(attributes, fmt.Errorf("cannot set blockOwnerDeletion if an ownerReference refers to a resource you can't set finalizers on: %v, %v", reason, err))
137137
}

0 commit comments

Comments
 (0)