@@ -1840,6 +1840,16 @@ function update-node-label() {
1840
1840
done
1841
1841
}
1842
1842
1843
+ # A helper function that sets file permissions for kube-controller-manager to
1844
+ # run as non root.
1845
+ function run-kube-controller-manager-as-non-root {
1846
+ prepare-log-file /var/log/kube-controller-manager.log ${KUBE_CONTROLLER_MANAGER_RUNASUSER} ${KUBE_CONTROLLER_MANAGER_RUNASGROUP}
1847
+ setfacl -m u:${KUBE_CONTROLLER_MANAGER_RUNASUSER} :r " ${CA_CERT_BUNDLE_PATH} "
1848
+ setfacl -m u:${KUBE_CONTROLLER_MANAGER_RUNASUSER} :r " ${SERVICEACCOUNT_CERT_PATH} "
1849
+ setfacl -m u:${KUBE_CONTROLLER_MANAGER_RUNASUSER} :r " ${SERVICEACCOUNT_KEY_PATH} "
1850
+ }
1851
+
1852
+
1843
1853
# Starts kubernetes controller manager.
1844
1854
# It prepares the log file, loads the docker image, calculates variables, sets them
1845
1855
# in the manifest file, and then copies the manifest file to /etc/kubernetes/manifests.
@@ -1937,6 +1947,15 @@ function start-kube-controller-manager {
1937
1947
sed -i -e " s@{{flexvolume_hostpath}}@${FLEXVOLUME_HOSTPATH_VOLUME} @g" " ${src_file} "
1938
1948
sed -i -e " s@{{cpurequest}}@${KUBE_CONTROLLER_MANAGER_CPU_REQUEST} @g" " ${src_file} "
1939
1949
1950
+ if [[ -n " ${KUBE_CONTROLLER_MANAGER_RUNASUSER:- } " && -n " ${KUBE_CONTROLLER_MANAGER_RUNASGROUP:- } " ]]; then
1951
+ run-kube-controller-manager-as-non-root
1952
+ sed -i -e " s@{{runAsUser}}@${KUBE_CONTROLLER_MANAGER_RUNASUSER} @g" " ${src_file} "
1953
+ sed -i -e " s@{{runAsGroup}}@${KUBE_CONTROLLER_MANAGER_RUNASGROUP} @g" " ${src_file} "
1954
+ else
1955
+ sed -i -e " s@{{runAsUser}}@0@g" " ${src_file} "
1956
+ sed -i -e " s@{{runAsGroup}}@0@g" " ${src_file} "
1957
+ fi
1958
+
1940
1959
cp " ${src_file} " /etc/kubernetes/manifests
1941
1960
}
1942
1961
0 commit comments