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

Commit

Permalink
Merge pull request #1274 from kinvolk/knrt10/calico-host-protection-p…
Browse files Browse the repository at this point in the history
…sp-update

calico-host-protection: add psp rule
  • Loading branch information
knrt10 authored Dec 24, 2020
2 parents 003dc6d + e10865e commit a6113fe
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 11 deletions.
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
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
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"])
}
}
}

0 comments on commit a6113fe

Please sign in to comment.