Skip to content

Commit

Permalink
Limit access for remote and istio namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
nesmabadr committed Jul 26, 2024
1 parent 294103d commit ed7e6b7
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 52 deletions.
25 changes: 25 additions & 0 deletions config/rbac/namespace_bindings/istio_namespace_role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: manager-role-istio-namespace
rules:
- apiGroups:
- ""
resources:
- secrets
verbs:
- list
- get
- apiGroups:
- cert-manager.io
resources:
- issuers
verbs:
- list
- apiGroups:
- cert-manager.io
resources:
- certificates
verbs:
- list
12 changes: 12 additions & 0 deletions config/rbac/namespace_bindings/istio_namespace_role_binding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: manager-rolebinding-istio-namespace
namespace: istio-system
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: manager-role-istio-namespace
subjects:
- kind: ServiceAccount
name: controller-manager
4 changes: 4 additions & 0 deletions config/rbac/namespace_bindings/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ resources:
- metrics_role_binding.yaml
# Comment the following to disable manifest integration
- manifest_role_binding.yaml
- istio_namespace_role.yaml
- remote_namespace_role.yaml
- istio_namespace_role_binding.yaml
- remote_namespace_role_binding.yaml
26 changes: 26 additions & 0 deletions config/rbac/namespace_bindings/remote_namespace_role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: manager-role-remote-namespace
rules:
- apiGroups:
- ""
resources:
- secrets
verbs:
- list
- get
- apiGroups:
- operator.kyma-project.io
resources:
- kymas
verbs:
- list
- get
- apiGroups:
- operator.kyma-project.io
resources:
- moduletemplates
verbs:
- list
12 changes: 12 additions & 0 deletions config/rbac/namespace_bindings/remote_namespace_role_binding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: manager-rolebinding-remote-namespace
namespace: kyma-system
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: manager-role-remote-namespace
subjects:
- kind: ServiceAccount
name: controller-manager
26 changes: 0 additions & 26 deletions config/rbac/namespace_bindings/role_binding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,6 @@ roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: manager-role
subjects:
- kind: ServiceAccount
name: controller-manager
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: manager-rolebinding-kyma-system
namespace: kyma-system
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: manager-role
subjects:
- kind: ServiceAccount
name: controller-manager
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: manager-rolebinding-istio-system
namespace: istio-system
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: manager-role
subjects:
- kind: ServiceAccount
name: controller-manager
53 changes: 27 additions & 26 deletions tests/e2e/rbac_privileges_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,32 +171,33 @@ var _ = Describe("RBAC Privileges", func() {
Expect(GetRoleBindingwithClusterRolePolicyRules(ctx, controlPlaneClient, "klm-manager-role-manifest",
kcpSystemKlmRoleBindings)).To(Equal(manifestRoleRules))

By("And KLM Service Account has the correct RoleBindings in istio-system namespaces")
istioSystemKlmRoleBindings, err := ListKlmRoleBindings(controlPlaneClient, ctx, "klm-controller-manager",
"istio-system")
Expect(err).ToNot(HaveOccurred())
Expect(istioSystemKlmRoleBindings.Items).To(HaveLen(1))

Expect(GetRoleBindingwithClusterRolePolicyRules(ctx, controlPlaneClient, "klm-manager-role",
istioSystemKlmRoleBindings)).To(Equal(klmManagerRoleRules))

By("And KLM Service Account has the correct RoleBindings in kyma-system namespaces")
kymaSystemKlmRoleBindings, err := ListKlmRoleBindings(controlPlaneClient, ctx, "klm-controller-manager",
"kyma-system")
Expect(err).ToNot(HaveOccurred())
Expect(kymaSystemKlmRoleBindings.Items).To(HaveLen(2))

Expect(GetRoleBindingwithClusterRolePolicyRules(ctx, controlPlaneClient, "klm-manager-role",
kymaSystemKlmRoleBindings)).To(Equal(klmManagerRoleRules))

metricsReaderRoleRules := []apirbacv1.PolicyRule{
{
NonResourceURLs: []string{"/metrics"},
Verbs: []string{"get"},
},
}
Expect(GetRoleBindingwithClusterRolePolicyRules(ctx, controlPlaneClient, "klm-metrics-reader",
kymaSystemKlmRoleBindings)).To(Equal(metricsReaderRoleRules))
// By("And KLM Service Account has the correct RoleBindings in istio-system namespaces")
// istioSystemKlmRoleBindings, err := ListKlmRoleBindings(controlPlaneClient, ctx, "klm-controller-manager",
// "istio-system")
// Expect(err).ToNot(HaveOccurred())
// Expect(istioSystemKlmRoleBindings.Items).To(HaveLen(1))
//
// Expect(GetRoleBindingwithClusterRolePolicyRules(ctx, controlPlaneClient, "klm-manager-role-istio-namespace",
// istioSystemKlmRoleBindings)).To(Equal(klmManagerRoleRules))
//
// By("And KLM Service Account has the correct RoleBindings in kyma-system namespaces")
// kymaSystemKlmRoleBindings, err := ListKlmRoleBindings(controlPlaneClient, ctx, "klm-controller-manager",
// "kyma-system")
// Expect(err).ToNot(HaveOccurred())
// Expect(kymaSystemKlmRoleBindings.Items).To(HaveLen(2))
//
// Expect(GetRoleBindingwithClusterRolePolicyRules(ctx, controlPlaneClient,
// "klm-manager-role-remote-namespace",
// kymaSystemKlmRoleBindings)).To(Equal(klmManagerRoleRules))
//
// metricsReaderRoleRules := []apirbacv1.PolicyRule{
// {
// NonResourceURLs: []string{"/metrics"},
// Verbs: []string{"get"},
// },
// }
// Expect(GetRoleBindingwithClusterRolePolicyRules(ctx, controlPlaneClient, "klm-metrics-reader",
// kymaSystemKlmRoleBindings)).To(Equal(metricsReaderRoleRules))
})
})
})

0 comments on commit ed7e6b7

Please sign in to comment.