From 200099631c2f25e9d0eaa0a23b62df4cf6597651 Mon Sep 17 00:00:00 2001 From: Adam Lewis <23342526+Adam-D-Lewis@users.noreply.github.com> Date: Wed, 24 Jul 2024 14:48:38 -0500 Subject: [PATCH] stop copying unneccesary files into user home directory (#2578) --- .../jupyterhub/files/jupyterhub/03-profiles.py | 10 ++++++++-- tests/tests_deployment/test_jupyterhub_ssh.py | 3 +++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/_nebari/stages/kubernetes_services/template/modules/kubernetes/services/jupyterhub/files/jupyterhub/03-profiles.py b/src/_nebari/stages/kubernetes_services/template/modules/kubernetes/services/jupyterhub/files/jupyterhub/03-profiles.py index 8ccac70ca0..22193e79dc 100644 --- a/src/_nebari/stages/kubernetes_services/template/modules/kubernetes/services/jupyterhub/files/jupyterhub/03-profiles.py +++ b/src/_nebari/stages/kubernetes_services/template/modules/kubernetes/services/jupyterhub/files/jupyterhub/03-profiles.py @@ -48,10 +48,16 @@ def base_profile_home_mounts(username): } MKDIR_OWN_DIRECTORY = ( - "mkdir -p /mnt/{path} && chmod 777 /mnt/{path} && cp -r /etc/skel/. /mnt/{path}" + "mkdir -p /mnt/{path} && chmod 777 /mnt/{path} && " + # Copy skel files/folders not starting with '..' to user home directory. + # Filtering out ..* removes some unneeded folders (k8s configmap mount implementation details). + "find /etc/skel/. -maxdepth 1 -not -name '.' -not -name '..*' -exec " + "cp -rL {escaped_brackets} /mnt/{path} \;" ) command = MKDIR_OWN_DIRECTORY.format( - path=pvc_home_mount_path.format(username=username) + # have to escape the brackets since this string will be formatted later by KubeSpawner + escaped_brackets="{{}}", + path=pvc_home_mount_path.format(username=username), ) init_containers = [ { diff --git a/tests/tests_deployment/test_jupyterhub_ssh.py b/tests/tests_deployment/test_jupyterhub_ssh.py index fd6b0799d5..1e28226436 100644 --- a/tests/tests_deployment/test_jupyterhub_ssh.py +++ b/tests/tests_deployment/test_jupyterhub_ssh.py @@ -125,6 +125,9 @@ def test_contains_jupyterhub_ssh(paramiko_object): ("cat ~/.bashrc", "Managed by Nebari"), ("cat ~/.profile", "Managed by Nebari"), ("cat ~/.bash_logout", "Managed by Nebari"), + # ensure we don't copy over extra files from /etc/skel in init container + ("ls -la ~/..202*", "No such file or directory"), + ("ls -la ~/..data", "No such file or directory"), ] for command, output in commands_contain: