Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permit turtles controller to access the cluster #804

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions exp/etcdrestore/webhooks/rbac.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ limitations under the License.
package webhooks

import (
"cmp"
"context"
"fmt"
"os"

authv1 "k8s.io/api/authorization/v1"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
Expand All @@ -32,6 +34,13 @@ func validateRBAC(ctx context.Context, cl client.Client, clusterName, clusterNam
return fmt.Errorf("failed to get admission request from context: %w", err)
}

namespace := cmp.Or(os.Getenv("POD_NAMESPACE"), "rancher-turtles-system")

turtlesController := fmt.Sprintf("system:serviceaccount:%s:rancher-turtles-etcdsnapshotrestore-manager", namespace)
if admissionRequest.UserInfo.Username == turtlesController {
return nil
}

sar := authv1.SubjectAccessReview{
Spec: authv1.SubjectAccessReviewSpec{
ResourceAttributes: &authv1.ResourceAttributes{
Expand Down
10 changes: 10 additions & 0 deletions exp/etcdrestore/webhooks/rbac_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,14 @@ var _ = Describe("RBAC tests", func() {
},
}), cl, "test-cluster", namespace)).ToNot(Succeed())
})

It("should allow turtles controller to access cluster", func() {
Expect(validateRBAC(admission.NewContextWithRequest(ctx, admission.Request{
AdmissionRequest: admissionv1.AdmissionRequest{
UserInfo: authenticationv1.UserInfo{
Username: "system:serviceaccount:rancher-turtles-system:rancher-turtles-etcdsnapshotrestore-manager",
},
},
}), cl, "test-cluster", namespace)).To(Succeed())
})
})
Loading