Skip to content
This repository has been archived by the owner on Jun 29, 2022. It is now read-only.

calico-host-protection: add psp rule #1274

Merged
merged 3 commits into from
Dec 24, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ spec:
containers:
- image: quay.io/kinvolk/calico-hostendpoint-controller:v0.0.4
name: calico-hostendpoint-controller
securityContext:
runAsNonRoot: true
runAsUser: 65534
runAsGroup: 65534
volumeMounts:
- mountPath: /tmp/
name: tmp-dir
Expand All @@ -43,7 +47,7 @@ spec:

---
# rbac.yaml
apiVersion: rbac.authorization.k8s.io/v1beta1
apiVersion: rbac.authorization.k8s.io/v1
knrt10 marked this conversation as resolved.
Show resolved Hide resolved
kind: ClusterRole
metadata:
name: calico-hostendpoint-controller-role
Expand All @@ -54,15 +58,19 @@ rules:
- apiGroups: ["crd.projectcalico.org"]
resources: ["hostendpoints"]
verbs:
- create
- get
- list
- update
- delete
# To use kubectl apply on resources that already exist
- patch
- create
- get
- list
- update
- delete
# To use kubectl apply on resources that already exist
- patch
- apiGroups: ["policy"]
resources: ["podsecuritypolicies"]
verbs: ["use"]
resourceNames: ["calico-hostendpoint-controller-psp"]
---
apiVersion: rbac.authorization.k8s.io/v1beta1
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: calico-hostendpoint-controller-role-binding
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: policy/v1beta1
kind: PodSecurityPolicy
knrt10 marked this conversation as resolved.
Show resolved Hide resolved
metadata:
annotations:
seccomp.security.alpha.kubernetes.io/allowedProfileNames: '*'
name: calico-hostendpoint-controller-psp
spec:
privileged: false
fsGroup:
rule: RunAsAny
runAsUser:
rule: MustRunAsNonRoot
seLinux:
rule: RunAsAny
supplementalGroups:
rule: RunAsAny
volumes:
- emptyDir
- secret
12 changes: 10 additions & 2 deletions pkg/assets/generated_assets.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions test/platform/packet/packet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,22 @@ func TestWhenBGPIsNotDisabledInConfigurationServersHasBGPSessionCreated(t *testi
t.Fatalf("Worker pool with BGP not disabled should have at least one BGP session")
}
}

func TestCalicoHostEndpointControllerRunsWithDedicatedPSP(t *testing.T) {
client := testutil.CreateKubeClient(t)
labelSelector := "app=calico-hostendpoint-controller"
expectedAnnotation := "calico-hostendpoint-controller-psp"

pods, err := client.CoreV1().Pods("kube-system").List(context.Background(), metav1.ListOptions{
LabelSelector: labelSelector,
})
if err != nil {
t.Fatalf("Listing pods with label %q: %v", labelSelector, err)
}

for _, v := range pods.Items {
if v.Annotations["kubernetes.io/psp"] != expectedAnnotation {
t.Fatalf("Pod: %s annotation expected: %s got: %s", v.Name, expectedAnnotation, v.Annotations["kubernetes.io/psp"])
}
}
}