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

fix(core):patch apparmor annotations for cronjobs and updating rbac rules #1768

Merged
merged 2 commits into from
Jun 12, 2024
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
15 changes: 14 additions & 1 deletion KubeArmor/core/k8sHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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{})
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions deployments/get/objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions deployments/helm/KubeArmor/templates/RBAC/roles.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ rules:
- cronjobs
verbs:
- get
- patch
- list
- watch
- update
- apiGroups:
- security.kubearmor.com
resources:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ rules:
- cronjobs
verbs:
- get
- patch
- list
- watch
- update
- apiGroups:
- security.kubearmor.com
resources:
Expand Down
11 changes: 11 additions & 0 deletions deployments/operator/operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,17 @@ rules:
- list
- watch
- update
- apiGroups:
- batch
resources:
- jobs
- cronjobs
verbs:
- get
- patch
- list
- watch
- update
- apiGroups:
- security.kubearmor.com
resources:
Expand Down
4 changes: 4 additions & 0 deletions pkg/KubeArmorOperator/config/rbac/clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ rules:
- cronjobs
verbs:
- get
- patch
- list
- watch
- update
- apiGroups:
- security.kubearmor.com
resources:
Expand Down
Loading