Adding init container to properly permission home directory
@@ -36,7 +36,7 @@ hub:
def qhub_generate_nss_files():
passwd = []
- passwd_format = '{username}:x:{uid}:{gid}:{username}:/home/{username}:/bin/false'
+ passwd_format = '{username}:x:{uid}:{gid}:{username}:/home/jovyan:/bin/bash'
for username, config in QHUB_USER_MAPPING.items():
uid = config['uid']
gid = QHUB_GROUP_MAPPING[config['primary_group']]['gid']
@@ -73,7 +73,8 @@ hub:
profile['kubespawner_override']['environment'] = {
'LD_PRELOAD': 'libnss_wrapper.so',
'NSS_WRAPPER_PASSWD': '/tmp/passwd',
- 'NSS_WRAPPER_GROUP': '/tmp/group'
+ 'NSS_WRAPPER_GROUP': '/tmp/group',
+ 'HOME': '/home/jovyan',
}
passwd, group = qhub_generate_nss_files()
@@ -83,12 +84,28 @@ hub:
"command": ["/bin/sh", "-c", (
"echo '{passwd}' > /tmp/passwd && "
"echo '{group}' > /tmp/group && "
- "ln -sfn /home/shared $HOME/shared"
+ "ln -sfn /home/shared /home/jovyan/shared"
).format(passwd=passwd, group=group)]
}
}
}
+ profile['kubespawner_override']['init_containers'] = [
+ {
+ "name": "init-nfs",
+ "image": "busybox:1.31",
+ "command": ["sh", "-c", (
+ "mkdir -p /mnt/home/{username} && "
+ "chmod 700 /mnt/home/{username} && "
+ "chown {uid}:{primary_gid} /mnt/home/{username} && "
+ "mkdir -p /mnt/home/shared && "
+ "chmod 777 /mnt/home/shared"
+ ).format(username=username, uid=uid, primary_gid=primary_gid)],
+ "securityContext": {"runAsUser": 0},
+ "volumeMounts": [{"mountPath": "/mnt", "name": "home"}]
+ }
+ ]
+
profile['kubespawner_override']['uid'] = uid
profile['kubespawner_override']['gid'] = primary_gid
profile['kubespawner_override']['supplemental_gids'] = secondary_gids
