-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Allow projected volumes for elasticsearch, logstash and metricbeat #496
Allow projected volumes for elasticsearch, logstash and metricbeat #496
Conversation
Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually? |
bab6cab
to
510f33b
Compare
f1519d9
to
69f69a4
Compare
eed0f62
to
52c3449
Compare
52c3449
to
d4402df
Compare
Allow specification of PodSecurityPolicy in metricbeat/values.yml Signed-off-by: Karl-Philipp Richter <krichter@posteo.de>
d4402df
to
c68b80e
Compare
Hi @krichter722, thank you for this PR. |
Thanks for the details. Do you have any source mentioning that projected volumes are required on GKE 1.16? I didn't find any and would be greatly interested by that. |
@jmlrt No, they seem to be the default if nothing else is specified. Maybe the problem that the deployment on a cluster with pod security policy enabled fails with default values can be solved differently. |
FYI, we just merged #635 which is adding tests on K8S 1.16. |
jenkins test this please |
@jmlrt There's no rush. I you have a plan for 1.16 and maybe even 1.17 tests, you should prioritize them and save the manual tests. |
I did some tests with GKE 1.16 and PSP and was able to deploy Elasticsearch and Logstash charts without projected volumes. Can you post your other values?
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metricbeat ClusterRole
needs a rule for podsecuritypolicies
resource:
{{- if .Values.managedServiceAccount }}
{{- $fullName := include "metricbeat.fullname" . -}}
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRole
metadata:
name: {{ template "metricbeat.serviceAccount" . }}-cluster-role
labels:
app: "{{ template "metricbeat.fullname" . }}"
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
heritage: {{ .Release.Service | quote }}
release: {{ .Release.Name | quote }}
rules:
- apiGroups:
- extensions
resources:
- podsecuritypolicies
resourceNames:
{{- if eq .Values.podSecurityPolicy.name "" }}
- {{ $fullName | quote }}
{{- else }}
- {{ .Values.podSecurityPolicy.name | quote }}
{{- end }}
verbs:
- use
{{ toYaml .Values.clusterRoleRules | nindent 2 -}}
{{- end -}}
rule: RunAsAny | ||
supplementalGroups: | ||
rule: RunAsAny | ||
volumes: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hostPath
is also required for Metricbeat daemonset
During my tests |
@@ -114,6 +114,7 @@ podSecurityPolicy: | |||
- secret | |||
- configMap | |||
- persistentVolumeClaim | |||
- projected |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While projected
doesn't seem required in my tests with GKE 1.16 it is mentionned as part of the recommended minimum set of allowed volumes for new PSPs in https://kubernetes.io/docs/concepts/policy/pod-security-policy/#volumes-and-file-systems.
Note that we could also add downwardAPI
and emptyDir
which are also part of the recommendations (same for the other charts)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also can you please add podSecurityPolicy
value description to the README doc and some python tests for the pod security policy like in
helm-charts/logstash/tests/logstash_test.py
Lines 583 to 672 in 4f40f6d
def test_pod_security_policy(): | |
## Make sure the default config is not creating any resources | |
config = "" | |
resources = ("role", "rolebinding", "serviceaccount", "podsecuritypolicy") | |
r = helm_template(config) | |
for resource in resources: | |
assert resource not in r | |
assert ( | |
"serviceAccountName" not in r["statefulset"][name]["spec"]["template"]["spec"] | |
) | |
## Make sure all the resources are created with default values | |
config = """ | |
rbac: | |
create: true | |
serviceAccountName: "" | |
podSecurityPolicy: | |
create: true | |
name: "" | |
""" | |
r = helm_template(config) | |
for resource in resources: | |
assert resource in r | |
assert r["role"][name]["rules"][0] == { | |
"apiGroups": ["extensions"], | |
"verbs": ["use"], | |
"resources": ["podsecuritypolicies"], | |
"resourceNames": [name], | |
} | |
assert r["rolebinding"][name]["subjects"] == [ | |
{"kind": "ServiceAccount", "namespace": "default", "name": name} | |
] | |
assert r["rolebinding"][name]["roleRef"] == { | |
"apiGroup": "rbac.authorization.k8s.io", | |
"kind": "Role", | |
"name": name, | |
} | |
assert ( | |
r["statefulset"][name]["spec"]["template"]["spec"]["serviceAccountName"] == name | |
) | |
psp_spec = r["podsecuritypolicy"][name]["spec"] | |
assert psp_spec["privileged"] is True | |
def test_external_pod_security_policy(): | |
## Make sure we can use an externally defined pod security policy | |
config = """ | |
rbac: | |
create: true | |
serviceAccountName: "" | |
podSecurityPolicy: | |
create: false | |
name: "customPodSecurityPolicy" | |
""" | |
resources = ("role", "rolebinding") | |
r = helm_template(config) | |
for resource in resources: | |
assert resource in r | |
assert r["role"][name]["rules"][0] == { | |
"apiGroups": ["extensions"], | |
"verbs": ["use"], | |
"resources": ["podsecuritypolicies"], | |
"resourceNames": ["customPodSecurityPolicy"], | |
} | |
def test_external_service_account(): | |
## Make sure we can use an externally defined service account | |
config = """ | |
rbac: | |
create: false | |
serviceAccountName: "customServiceAccountName" | |
podSecurityPolicy: | |
create: false | |
name: "" | |
""" | |
resources = ("role", "rolebinding", "serviceaccount") | |
r = helm_template(config) | |
assert ( | |
r["statefulset"][name]["spec"]["template"]["spec"]["serviceAccountName"] | |
== "customServiceAccountName" | |
) | |
# When referencing an external service account we do not want any resources to be created. | |
for resource in resources: | |
assert resource not in r |
This PR has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. To track this PR (even if closed), please open a corresponding issue if one does not already exist. |
This PR has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. To track this PR (even if closed), please open a corresponding issue if one does not already exist. |
closing as stale |
Projected volumes are the default volume type on Google Kubernetes Engine (GKE) with cluster >= 1.16. This PR allows to use them out-of-the-box more easily if pod security policy is enabled. This is only relevant for clusters with pod security policy enabled. By default >= 1.16 clusters should work with this PR.
Furthermore, it adds a missing pod security policy for metricbeat for this case.
${CHART}/tests/*.py
${CHART}/examples/*/test/goss.yaml