@@ -1804,6 +1804,16 @@ function update-node-label() {
1804
1804
done
1805
1805
}
1806
1806
1807
+ # A helper function that sets file permissions for kube-controller-manager to
1808
+ # run as non root.
1809
+ function run-kube-controller-manager-as-non-root {
1810
+ prepare-log-file /var/log/kube-controller-manager.log ${KUBE_CONTROLLER_MANAGER_RUNASUSER} ${KUBE_CONTROLLER_MANAGER_RUNASGROUP}
1811
+ setfacl -m u:${KUBE_CONTROLLER_MANAGER_RUNASUSER} :r " ${CA_CERT_BUNDLE_PATH} "
1812
+ setfacl -m u:${KUBE_CONTROLLER_MANAGER_RUNASUSER} :r " ${SERVICEACCOUNT_CERT_PATH} "
1813
+ setfacl -m u:${KUBE_CONTROLLER_MANAGER_RUNASUSER} :r " ${SERVICEACCOUNT_KEY_PATH} "
1814
+ }
1815
+
1816
+
1807
1817
# Starts kubernetes controller manager.
1808
1818
# It prepares the log file, loads the docker image, calculates variables, sets them
1809
1819
# in the manifest file, and then copies the manifest file to /etc/kubernetes/manifests.
@@ -1901,6 +1911,15 @@ function start-kube-controller-manager {
1901
1911
sed -i -e " s@{{flexvolume_hostpath}}@${FLEXVOLUME_HOSTPATH_VOLUME} @g" " ${src_file} "
1902
1912
sed -i -e " s@{{cpurequest}}@${KUBE_CONTROLLER_MANAGER_CPU_REQUEST} @g" " ${src_file} "
1903
1913
1914
+ if [[ -n " ${KUBE_CONTROLLER_MANAGER_RUNASUSER:- } " && -n " ${KUBE_CONTROLLER_MANAGER_RUNASGROUP:- } " ]]; then
1915
+ run-kube-controller-manager-as-non-root
1916
+ sed -i -e " s@{{runAsUser}}@${KUBE_CONTROLLER_MANAGER_RUNASUSER} @g" " ${src_file} "
1917
+ sed -i -e " s@{{runAsGroup}}@${KUBE_CONTROLLER_MANAGER_RUNASGROUP} @g" " ${src_file} "
1918
+ else
1919
+ sed -i -e " s@{{runAsUser}}@0@g" " ${src_file} "
1920
+ sed -i -e " s@{{runAsGroup}}@0@g" " ${src_file} "
1921
+ fi
1922
+
1904
1923
cp " ${src_file} " /etc/kubernetes/manifests
1905
1924
}
1906
1925
0 commit comments