From e1e8c588516115aca44f34d28a60e77257b3283e Mon Sep 17 00:00:00 2001 From: Vara Kumar <102720382+vara2504@users.noreply.github.com> Date: Thu, 19 Dec 2024 09:25:31 -0800 Subject: [PATCH] Retain the get/list/watch for calico-kube-controller SA (#3666) The Federated Services Controller needs access to the remote kubeconfig secret in order to create a remote syncer. --- pkg/render/kubecontrollers/kube-controllers.go | 7 +++++++ .../kubecontrollers/kube-controllers_test.go | 18 +++++++++++++++--- pkg/render/logstorage.go | 6 +++--- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/pkg/render/kubecontrollers/kube-controllers.go b/pkg/render/kubecontrollers/kube-controllers.go index 8965b3075c..6df0d13015 100644 --- a/pkg/render/kubecontrollers/kube-controllers.go +++ b/pkg/render/kubecontrollers/kube-controllers.go @@ -429,6 +429,13 @@ func kubeControllersRoleEnterpriseCommonRules(cfg *KubeControllersConfiguration) Resources: []string{"configmaps"}, Verbs: []string{"watch", "list", "get", "update", "create", "delete"}, }, + { + // The Federated Services Controller needs access to the remote kubeconfig secret + // in order to create a remote syncer. + APIGroups: []string{""}, + Resources: []string{"secrets"}, + Verbs: []string{"watch", "list", "get"}, + }, { // Needed to validate the license APIGroups: []string{"projectcalico.org"}, diff --git a/pkg/render/kubecontrollers/kube-controllers_test.go b/pkg/render/kubecontrollers/kube-controllers_test.go index e428ac35f3..b014685eba 100644 --- a/pkg/render/kubecontrollers/kube-controllers_test.go +++ b/pkg/render/kubecontrollers/kube-controllers_test.go @@ -254,7 +254,7 @@ var _ = Describe("kube-controllers rendering tests", func() { Expect(len(dp.Spec.Template.Spec.Volumes)).To(Equal(1)) clusterRole := rtest.GetResource(resources, kubecontrollers.KubeControllerRole, "", "rbac.authorization.k8s.io", "v1", "ClusterRole").(*rbacv1.ClusterRole) - Expect(clusterRole.Rules).To(HaveLen(20)) + Expect(clusterRole.Rules).To(HaveLen(21)) ms := rtest.GetResource(resources, kubecontrollers.KubeControllerMetrics, common.CalicoNamespace, "", "v1", "Service").(*corev1.Service) Expect(ms.Spec.ClusterIP).To(Equal("None"), "metrics service should be headless") @@ -341,13 +341,19 @@ var _ = Describe("kube-controllers rendering tests", func() { Expect(dp.Spec.Template.Spec.Volumes[0].ConfigMap.Name).To(Equal("tigera-ca-bundle")) clusterRole := rtest.GetResource(resources, kubecontrollers.EsKubeControllerRole, "", "rbac.authorization.k8s.io", "v1", "ClusterRole").(*rbacv1.ClusterRole) - Expect(clusterRole.Rules).To(HaveLen(19)) + Expect(clusterRole.Rules).To(HaveLen(20)) Expect(clusterRole.Rules).To(ContainElement( rbacv1.PolicyRule{ APIGroups: []string{""}, Resources: []string{"configmaps"}, Verbs: []string{"watch", "list", "get", "update", "create", "delete"}, })) + Expect(clusterRole.Rules).To(ContainElement( + rbacv1.PolicyRule{ + APIGroups: []string{""}, + Resources: []string{"secrets"}, + Verbs: []string{"watch", "list", "get"}, + })) }) It("should render all calico-kube-controllers resources for a default configuration using TigeraSecureEnterprise and ClusterType is Management", func() { @@ -544,13 +550,19 @@ var _ = Describe("kube-controllers rendering tests", func() { Expect(dp.Spec.Template.Spec.Containers[0].Image).To(Equal("test-reg/tigera/kube-controllers:" + components.ComponentTigeraKubeControllers.Version)) clusterRole := rtest.GetResource(resources, kubecontrollers.EsKubeControllerRole, "", "rbac.authorization.k8s.io", "v1", "ClusterRole").(*rbacv1.ClusterRole) - Expect(clusterRole.Rules).To(HaveLen(19)) + Expect(clusterRole.Rules).To(HaveLen(20)) Expect(clusterRole.Rules).To(ContainElement( rbacv1.PolicyRule{ APIGroups: []string{""}, Resources: []string{"configmaps"}, Verbs: []string{"watch", "list", "get", "update", "create", "delete"}, })) + Expect(clusterRole.Rules).To(ContainElement( + rbacv1.PolicyRule{ + APIGroups: []string{""}, + Resources: []string{"secrets"}, + Verbs: []string{"watch", "list", "get"}, + })) }) It("should include a ControlPlaneNodeSelector when specified", func() { diff --git a/pkg/render/logstorage.go b/pkg/render/logstorage.go index 14215cc367..a740f52413 100644 --- a/pkg/render/logstorage.go +++ b/pkg/render/logstorage.go @@ -1016,7 +1016,7 @@ func (es *elasticsearchComponent) elasticsearchRolesAndBindings() ([]*rbacv1.Rol { APIGroups: []string{""}, Resources: []string{"secrets"}, - Verbs: []string{"create", "delete", "deletecollection", "get", "list", "update", "watch"}, + Verbs: []string{"create", "delete", "deletecollection", "update"}, }, }, } @@ -1030,7 +1030,7 @@ func (es *elasticsearchComponent) elasticsearchRolesAndBindings() ([]*rbacv1.Rol { APIGroups: []string{""}, Resources: []string{"secrets"}, - Verbs: []string{"create", "delete", "deletecollection", "get", "list", "update", "watch"}, + Verbs: []string{"create", "delete", "deletecollection", "update"}, }, }, } @@ -1366,7 +1366,7 @@ func (m managedClusterLogStorage) kubeControllersRolesAndBindings() ([]*rbacv1.R { APIGroups: []string{""}, Resources: []string{"secrets"}, - Verbs: []string{"create", "delete", "deletecollection", "get", "list", "update", "watch"}, + Verbs: []string{"create", "delete", "deletecollection", "update"}, }, }, }