Skip to content

Commit

Permalink
Merge pull request #50623 from mikedanese/automated-cherry-pick-of-#4…
Browse files Browse the repository at this point in the history
…9788-release-1.7

Automatic merge from submit-queue

Automated cherry pick of #49788 release 1.7

Automated cherry pick of #49788 release 1.7

Makes cluster create without ABAC less flaky

Fixes #49787
  • Loading branch information
Kubernetes Submit Queue committed Aug 16, 2017
2 parents 6ac2e71 + 8ad0e91 commit 4f113c8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
10 changes: 10 additions & 0 deletions pkg/controller/certificates/approver/sarapprove.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,15 @@ func (a *sarApprover) handle(csr *capi.CertificateSigningRequest) error {
return fmt.Errorf("unable to parse csr %q: %v", csr.Name, err)
}

tried := []string{}

for _, r := range a.recognizers {
if !r.recognize(csr, x509cr) {
continue
}

tried = append(tried, r.permission.Subresource)

approved, err := a.authorize(csr, r.permission)
if err != nil {
return err
Expand All @@ -107,6 +112,11 @@ func (a *sarApprover) handle(csr *capi.CertificateSigningRequest) error {
return nil
}
}

if len(tried) != 0 {
return fmt.Errorf("recognized csr %q as %v but subject access review was not approved", csr.Name, tried)
}

return nil
}

Expand Down
6 changes: 4 additions & 2 deletions pkg/controller/certificates/approver/sarapprove_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func TestHandle(t *testing.T) {
message string
allowed bool
recognized bool
err bool
verify func(*testing.T, []testclient.Action)
}{
{
Expand Down Expand Up @@ -118,6 +119,7 @@ func TestHandle(t *testing.T) {
}
_ = as[0].(testclient.CreateActionImpl)
},
err: true,
},
{
recognized: true,
Expand Down Expand Up @@ -154,7 +156,7 @@ func TestHandle(t *testing.T) {
}

for _, c := range cases {
t.Run(fmt.Sprintf("recognized:%v,allowed: %v", c.recognized, c.allowed), func(t *testing.T) {
t.Run(fmt.Sprintf("recognized:%v,allowed: %v,err: %v", c.recognized, c.allowed, c.err), func(t *testing.T) {
client := &fake.Clientset{}
client.AddReactor("create", "subjectaccessreviews", func(action testclient.Action) (handled bool, ret runtime.Object, err error) {
return true, &authorization.SubjectAccessReview{
Expand All @@ -176,7 +178,7 @@ func TestHandle(t *testing.T) {
},
}
csr := makeTestCsr()
if err := approver.handle(csr); err != nil {
if err := approver.handle(csr); err != nil && !c.err {
t.Errorf("unexpected err: %v", err)
}
c.verify(t, client.Actions())
Expand Down

0 comments on commit 4f113c8

Please sign in to comment.