diff --git a/KubeArmor/core/k8sHandler.go b/KubeArmor/core/k8sHandler.go index f65f4c2e0e..7cac5da30f 100644 --- a/KubeArmor/core/k8sHandler.go +++ b/KubeArmor/core/k8sHandler.go @@ -230,6 +230,10 @@ func (kh *K8sHandler) PatchResourceWithAppArmorAnnotations(namespaceName, deploy } spec := `{"spec":{"template":{"metadata":{"annotations":{"kubearmor-policy":"enabled",` + if kind == "CronJob" { + spec = `{"spec":{"jobTemplate":{"spec":{"template":{"metadata":{"annotations":{"kubearmor-policy":"enabled",` + } + count := len(appArmorAnnotations) for k, v := range appArmorAnnotations { @@ -246,7 +250,11 @@ func (kh *K8sHandler) PatchResourceWithAppArmorAnnotations(namespaceName, deploy count-- } - spec = spec + `}}}}}` + if kind == "CronJob" { + spec = spec + `}}}}}}}` + } else { + spec = spec + `}}}}}` + } if kind == "StatefulSet" { _, err := kh.K8sClient.AppsV1().StatefulSets(namespaceName).Patch(context.Background(), deploymentName, types.StrategicMergePatchType, []byte(spec), metav1.PatchOptions{}) @@ -292,6 +300,11 @@ func (kh *K8sHandler) PatchResourceWithAppArmorAnnotations(namespaceName, deploy if err != nil { return err } + } else if kind == "CronJob" { + _, err := kh.K8sClient.BatchV1().CronJobs(namespaceName).Patch(context.Background(), deploymentName, types.StrategicMergePatchType, []byte(spec), metav1.PatchOptions{}) + if err != nil { + return err + } } else if kind == "Pod" { // this condition wont be triggered, handled by controller return nil diff --git a/deployments/get/objects.go b/deployments/get/objects.go index 692796dd2a..6ead7f5d63 100644 --- a/deployments/get/objects.go +++ b/deployments/get/objects.go @@ -54,7 +54,7 @@ func GetClusterRole() *rbacv1.ClusterRole { { APIGroups: []string{"batch"}, Resources: []string{"jobs", "cronjobs"}, - Verbs: []string{"get"}, + Verbs: []string{"get", "patch", "list", "watch", "update"}, }, { APIGroups: []string{"security.kubearmor.com"}, @@ -546,7 +546,6 @@ func GetKubeArmorControllerDeployment(namespace string) *appsv1.Deployment { Labels: KubeArmorControllerLabels, }, Spec: corev1.PodSpec{ - PriorityClassName: "system-node-critical", ServiceAccountName: KubeArmorControllerServiceAccountName, Volumes: []corev1.Volume{ KubeArmorControllerCertVolume, diff --git a/deployments/helm/KubeArmor/templates/RBAC/roles.yaml b/deployments/helm/KubeArmor/templates/RBAC/roles.yaml index c556f66b7e..96ceac7b4e 100644 --- a/deployments/helm/KubeArmor/templates/RBAC/roles.yaml +++ b/deployments/helm/KubeArmor/templates/RBAC/roles.yaml @@ -36,6 +36,10 @@ rules: - cronjobs verbs: - get + - patch + - list + - watch + - update - apiGroups: - security.kubearmor.com resources: diff --git a/deployments/helm/KubeArmorOperator/templates/clusterrole-rbac.yaml b/deployments/helm/KubeArmorOperator/templates/clusterrole-rbac.yaml index 4b06441df0..8075210e26 100644 --- a/deployments/helm/KubeArmorOperator/templates/clusterrole-rbac.yaml +++ b/deployments/helm/KubeArmorOperator/templates/clusterrole-rbac.yaml @@ -136,6 +136,10 @@ rules: - cronjobs verbs: - get + - patch + - list + - watch + - update - apiGroups: - security.kubearmor.com resources: diff --git a/deployments/operator/operator.yaml b/deployments/operator/operator.yaml index f3bacad8b1..4bf8da1485 100644 --- a/deployments/operator/operator.yaml +++ b/deployments/operator/operator.yaml @@ -377,6 +377,17 @@ rules: - list - watch - update +- apiGroups: + - batch + resources: + - jobs + - cronjobs + verbs: + - get + - patch + - list + - watch + - update - apiGroups: - security.kubearmor.com resources: diff --git a/pkg/KubeArmorOperator/config/rbac/clusterrole.yaml b/pkg/KubeArmorOperator/config/rbac/clusterrole.yaml index 156e279516..5a6a99e91e 100644 --- a/pkg/KubeArmorOperator/config/rbac/clusterrole.yaml +++ b/pkg/KubeArmorOperator/config/rbac/clusterrole.yaml @@ -130,6 +130,10 @@ rules: - cronjobs verbs: - get + - patch + - list + - watch + - update - apiGroups: - security.kubearmor.com resources: