From 4e3157bf4c3271d2d01d72b1ea6bc5407dbc296a Mon Sep 17 00:00:00 2001 From: Lucas Cavalcante Date: Mon, 20 Dec 2021 17:19:09 -0300 Subject: [PATCH] Fix nova-compute-ssh On stx-openstack, we run the nova-compute containers as user 0 (root) to get privileged access to some of the host resources. During the latest upversion of openstack-helm, we got in some commits that were incompatible with our usage of the root user since the keys for ssh access to a different compute were always placed under the 'nova' user's folder. This commit fixes that behavior while we don't merge a definitive fix on openstack-helm and go through a new upversion. Test Plan: PASS - nova-compute-ssh starting correctly after change the sshd->ssh parameter PASS - migrate/resize vm Closes-Bug: #1956229 Signed-off-by: Lucas Cavalcante Signed-off-by: Hugo Brito Change-Id: Ic90e8e64670b8314b9a2f38b93a59361dcb7ecc9 --- openstack-helm/centos/openstack-helm.spec | 2 + openstack-helm/debian/deb_folder/rules | 1 + ...ute-ssh-init-to-execute-as-runAsUser.patch | 172 ++++++++++++++++++ .../k8sapp_openstack/helm/nova.py | 21 ++- .../manifests/manifest.yaml | 11 +- 5 files changed, 200 insertions(+), 7 deletions(-) create mode 100644 openstack-helm/files/0011-Fix-nova-compute-ssh-init-to-execute-as-runAsUser.patch diff --git a/openstack-helm/centos/openstack-helm.spec b/openstack-helm/centos/openstack-helm.spec index 1b586b08..d7fb66cf 100644 --- a/openstack-helm/centos/openstack-helm.spec +++ b/openstack-helm/centos/openstack-helm.spec @@ -29,6 +29,7 @@ Patch07: 0007-Add-stx_admin-account.patch Patch08: 0008-Disabling-helm3_hook.patch Patch09: 0009-Add-flavor-extra-spec-hw-pci_irq_affinity_mask.patch Patch10: 0010-Enable-taint-toleration-for-Openstack-services.patch +Patch11: 0011-Fix-nova-compute-ssh-init-to-execute-as-runAsUser.patch BuildRequires: helm BuildRequires: openstack-helm-infra @@ -50,6 +51,7 @@ Openstack Helm charts %patch08 -p1 %patch09 -p1 %patch10 -p1 +%patch11 -p1 %build # Stage helm-toolkit in the local repo diff --git a/openstack-helm/debian/deb_folder/rules b/openstack-helm/debian/deb_folder/rules index 33d7c2f1..eb9242c7 100755 --- a/openstack-helm/debian/deb_folder/rules +++ b/openstack-helm/debian/deb_folder/rules @@ -26,6 +26,7 @@ override_dh_auto_build: patch --no-backup-if-mismatch --fuzz=0 -p1 < 0008-Disabling-helm3_hook.patch patch --no-backup-if-mismatch --fuzz=0 -p1 < 0009-Add-flavor-extra-spec-hw-pci_irq_affinity_mask.patch patch --no-backup-if-mismatch --fuzz=0 -p1 < 0010-Enable-taint-toleration-for-Openstack-services.patch + patch --no-backup-if-mismatch --fuzz=0 -p1 < 0011-Fix-nova-compute-ssh-init-to-execute-as-runAsUser.patch # Host a server for the helm charts. chartmuseum --debug --port=8879 --context-path='/charts' --storage="local" \ --storage-local-rootdir="." & diff --git a/openstack-helm/files/0011-Fix-nova-compute-ssh-init-to-execute-as-runAsUser.patch b/openstack-helm/files/0011-Fix-nova-compute-ssh-init-to-execute-as-runAsUser.patch new file mode 100644 index 00000000..d4c3afcc --- /dev/null +++ b/openstack-helm/files/0011-Fix-nova-compute-ssh-init-to-execute-as-runAsUser.patch @@ -0,0 +1,172 @@ +From fc736ec3993ff18b6380d2016060991e2c3a11f4 Mon Sep 17 00:00:00 2001 +From: Thiago Brito +Date: Fri, 7 Jan 2022 15:59:41 -0300 +Subject: [PATCH] Fix nova-compute-ssh init to execute as runAsUser + +On _ssh-init.sh.tpl, despite one change the runAsUser for the +nova-compute container on the securityContext, the ssh keys are always +being copied into the 'nova' user's folder. This change fixes it by +getting the correct user defined on the securityContext and copying the +keys to its correct folder. + +Signed-off-by: Thiago Brito +Change-Id: Ia7883dc4626a295892eb4637ef717b0b1725ac89 +--- + nova/templates/bin/_ssh-init.sh.tpl | 13 ++++++++----- + nova/templates/daemonset-compute.yaml | 16 ++++++++++++---- + nova/values.yaml | 4 +++- + 3 files changed, 23 insertions(+), 10 deletions(-) + +diff --git a/nova/templates/bin/_ssh-init.sh.tpl b/nova/templates/bin/_ssh-init.sh.tpl +index be2e33a4..fbd96f04 100644 +--- a/nova/templates/bin/_ssh-init.sh.tpl ++++ b/nova/templates/bin/_ssh-init.sh.tpl +@@ -16,10 +16,13 @@ limitations under the License. + + set -ex + +-mkdir -p ~nova/.ssh +-chown -R nova:nova ~nova/.ssh ++export NOVA_USERNAME=$(id -u ${NOVA_USER_UID} -n) ++export NOVA_USER_HOME=$(eval echo ~${NOVA_USERNAME}) + +-cat > ~nova/.ssh/config < ${NOVA_USER_HOME}/.ssh/config <