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

Run the etcd as non-root #100635

Merged
merged 1 commit into from
Apr 9, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 17 additions & 2 deletions cluster/gce/gci/configure-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1858,6 +1858,18 @@ function prepare-etcd-manifest {
fi
# Replace the volume host path.
sed -i -e "s@/mnt/master-pd/var/etcd@/mnt/disks/master-pd/var/etcd@g" "${temp_file}"
# Replace the run as user and run as group
pod_run_as_user=""
pod_run_as_group=""
container_security_context=""
if [[ -n "${ETCD_RUNASUSER:-}" && -n "${ETCD_RUNASGROUP:-}" ]]; then
pod_run_as_user="\"runAsUser\": ${ETCD_RUNASUSER},"
pod_run_as_group="\"runAsGroup\": ${ETCD_RUNASGROUP},"
container_security_context="\"securityContext\": {\"allowPrivilegeEscalation\": false, \"capabilities\": {\"drop\": [\"all\"]}},"
fi
sed -i -e "s@{{ run_as_user }}@${pod_run_as_user}@g" "${temp_file}"
sed -i -e "s@{{ run_as_group }}@${pod_run_as_group}@g" "${temp_file}"
sed -i -e "s@{{security_context}}@${container_security_context}@g" "${temp_file}"
mv "${temp_file}" /etc/kubernetes/manifests
}

Expand All @@ -1878,10 +1890,13 @@ function start-etcd-servers {
if [[ -e /etc/init.d/etcd ]]; then
rm -f /etc/init.d/etcd
fi
prepare-log-file /var/log/etcd.log
if [[ -n "${ETCD_RUNASUSER:-}" && -n "${ETCD_RUNASGROUP:-}" ]]; then
wojtek-t marked this conversation as resolved.
Show resolved Hide resolved
chown -R "${ETCD_RUNASUSER}":"${ETCD_RUNASGROUP}" /var/etcd/
fi
prepare-log-file /var/log/etcd.log "${ETCD_RUNASUSER:-0}"
prepare-etcd-manifest "" "2379" "2380" "200m" "etcd.manifest"

prepare-log-file /var/log/etcd-events.log
prepare-log-file /var/log/etcd-events.log "${ETCD_RUNASUSER:-0}"
prepare-etcd-manifest "-events" "4002" "2381" "100m" "etcd-events.manifest"
}

Expand Down
7 changes: 7 additions & 0 deletions cluster/gce/manifests/etcd.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
},
"spec":{
"securityContext": {
{{ run_as_user }}
{{ run_as_group }}
"seccompProfile": {
"type": "RuntimeDefault"
}
Expand All @@ -17,6 +19,7 @@
"containers":[
{
"name": "etcd-container",
{{security_context}}
"image": "{{ pillar.get('etcd_docker_repository', 'k8s.gcr.io/etcd') }}:{{ pillar.get('etcd_docker_tag', '3.4.13-0') }}",
"resources": {
"requests": {
wojtek-t marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -35,6 +38,10 @@
{ "name": "TARGET_VERSION",
"value": "{{ pillar.get('etcd_version', '3.4.13') }}"
},
{
"name": "DO_NOT_MOVE_BINARIES",
"value": "true"
},
{ "name": "DATA_DIRECTORY",
"value": "/var/etcd/data{{ suffix }}"
},
Expand Down