Skip to content

Commit 034d133

Browse files
authored
FEATURE/MAJOR: haproxy: add PSP for sysctl and remove privileged containers use (#144)
* feat(haproxy): added PSP for sysctl, not used privileged containers * fix(haproxy): added Values.serviceAccount.annotations
1 parent 13e5568 commit 034d133

File tree

4 files changed

+128
-4
lines changed

4 files changed

+128
-4
lines changed

haproxy/templates/podsecuritypolicy.yaml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,35 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/}}
1616

17-
{{- if .Values.podSecurityPolicy.create -}}
17+
{{- if and .Values.rbac.create .Values.podSecurityPolicy.enabled -}}
1818
{{- $useHostNetwork := .Values.daemonset.useHostNetwork -}}
1919
{{- $useHostPort := .Values.daemonset.useHostPort -}}
2020
{{- $hostPorts := .Values.daemonset.hostPorts -}}
21+
{{- if .Capabilities.APIVersions.Has "policy/v1/PodSecurityPolicy" }}
22+
apiVersion: policy/v1
23+
{{- else }}
2124
apiVersion: policy/v1beta1
25+
{{- end }}
2226
kind: PodSecurityPolicy
2327
metadata:
2428
name: {{ include "haproxy.fullname" . }}
2529
labels:
2630
{{- include "haproxy.labels" . | nindent 4 }}
31+
{{- if .Values.podSecurityPolicy.annotations }}
32+
annotations:
33+
{{ toYaml .Values.podSecurityPolicy.annotations | indent 4 }}
34+
{{- else }}
2735
annotations:
2836
seccomp.security.alpha.kubernetes.io/allowedProfileNames: 'docker/default,runtime/default'
2937
apparmor.security.beta.kubernetes.io/allowedProfileNames: 'runtime/default'
3038
seccomp.security.alpha.kubernetes.io/defaultProfileName: 'runtime/default'
3139
apparmor.security.beta.kubernetes.io/defaultProfileName: 'runtime/default'
40+
{{- end }}
3241
spec:
33-
allowPrivilegeEscalation: true # to be able to use privileged containers for initContainers
42+
allowPrivilegeEscalation: false
3443
allowedCapabilities:
3544
- NET_BIND_SERVICE
45+
defaultAllowPrivilegeEscalation: false
3646
fsGroup:
3747
rule: MustRunAs
3848
ranges:
@@ -50,7 +60,7 @@ spec:
5060
{{- end }}
5161
hostIPC: false
5262
hostPID: false
53-
privileged: true
63+
privileged: false
5464
runAsUser:
5565
rule: RunAsAny
5666
seLinux:
@@ -65,4 +75,8 @@ spec:
6575
- emptyDir
6676
- projected
6777
- secret
78+
{{- with .Values.podSecurityPolicy.allowedUnsafeSysctls }}
79+
allowedUnsafeSysctls:
80+
{{- toYaml . | nindent 4 }}
81+
{{- end }}
6882
{{- end }}

haproxy/templates/role.yaml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{{/*
2+
Copyright 2019 HAProxy Technologies LLC
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/}}
16+
17+
{{- if and .Values.rbac.create .Values.podSecurityPolicy.enabled -}}
18+
apiVersion: rbac.authorization.k8s.io/v1
19+
kind: Role
20+
metadata:
21+
name: {{ include "haproxy.fullname" . }}
22+
namespace: {{ .Release.Namespace }}
23+
labels:
24+
{{- include "haproxy.labels" . | nindent 4 }}
25+
rules:
26+
- apiGroups:
27+
- "policy"
28+
resources:
29+
- podsecuritypolicies
30+
verbs:
31+
- use
32+
resourceNames:
33+
- {{ include "haproxy.fullname" . }}
34+
{{- end -}}

haproxy/templates/rolebinding.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{{/*
2+
Copyright 2019 HAProxy Technologies LLC
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/}}
16+
17+
{{- if and .Values.rbac.create .Values.podSecurityPolicy.enabled -}}
18+
apiVersion: rbac.authorization.k8s.io/v1
19+
kind: RoleBinding
20+
metadata:
21+
name: {{ include "haproxy.fullname" . }}
22+
namespace: {{ .Release.Namespace }}
23+
labels:
24+
{{- include "haproxy.labels" . | nindent 4 }}
25+
roleRef:
26+
apiGroup: rbac.authorization.k8s.io
27+
kind: Role
28+
name: {{ include "haproxy.fullname" . }}
29+
subjects:
30+
- kind: ServiceAccount
31+
name: {{ include "haproxy.serviceAccountName" . }}
32+
namespace: {{ .Release.Namespace }}
33+
{{- end -}}

haproxy/values.yaml

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
## Configure Service Account
1818
## ref: https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/
1919
serviceAccount:
20+
annotations: {}
2021
create: true
2122
name:
2223

@@ -297,14 +298,56 @@ podLabels: {}
297298
podAnnotations: {}
298299
# key: value
299300

301+
## Enable RBAC Authorization
302+
## ref: https://kubernetes.io/docs/reference/access-authn-authz/rbac/
303+
rbac:
304+
create: true
305+
300306
## Disableable use of Pod Security Policy
301307
## ref: https://kubernetes.io/docs/concepts/policy/pod-security-policy/
302308
podSecurityPolicy:
303-
create: true
309+
annotations: {}
310+
## Specify pod annotations
311+
## Ref: https://kubernetes.io/docs/concepts/policy/pod-security-policy/#apparmor
312+
## Ref: https://kubernetes.io/docs/concepts/policy/pod-security-policy/#seccomp
313+
## Ref: https://kubernetes.io/docs/concepts/policy/pod-security-policy/#sysctl
314+
315+
### WARNING!!! "Apparmor is only available Ubuntu/Debian distributions of Linux."
316+
317+
# apparmor.security.beta.kubernetes.io/allowedProfileNames: runtime/default
318+
# apparmor.security.beta.kubernetes.io/defaultProfileName: runtime/default
319+
# seccomp.security.alpha.kubernetes.io/allowedProfileNames: runtime/default
320+
# seccomp.security.alpha.kubernetes.io/defaultProfileName: runtime/default
321+
enabled: false
322+
# ref: https://kubernetes.io/docs/reference/command-line-tools-reference/kubelet/
323+
# Enable only when added kublet arg: --allowed-unsafe-sysctls strings
324+
allowedUnsafeSysctls:
325+
# - net.*
304326

305327
## Pod Security Context
306328
## ref: https://kubernetes.io/docs/tasks/configure-pod-container/security-context/
307329
podSecurityContext: {}
330+
### ref: https://kubernetes.io/docs/tasks/administer-cluster/sysctl-cluster/
331+
### Sysctls enable only when added kublet arg: --allowed-unsafe-sysctls strings
332+
# sysctls:
333+
# - name: net.ipv4.tcp_rmem
334+
# value: 4096 16060 262144
335+
# - name: net.ipv4.tcp_wmem
336+
# value: 4096 16384 262144
337+
# - name: net.ipv4.tcp_tw_reuse
338+
# value: "1"
339+
# - name: net.ipv4.ip_local_port_range
340+
# value: 1024 65023
341+
# - name: net.ipv4.tcp_max_syn_backlog
342+
# value: "60000"
343+
# - name: net.ipv4.tcp_fin_timeout
344+
# value: "30"
345+
# - name: net.ipv4.tcp_synack_retries
346+
# value: "3"
347+
# - name: net.ipv4.ip_nonlocal_bind
348+
# value: "1"
349+
# - name: net.core.somaxconn
350+
# value: "60000"
308351

309352
## Container Security Context
310353
## ref: https://kubernetes.io/docs/tasks/configure-pod-container/security-context/

0 commit comments

Comments
 (0)