You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
CASA won't run inside a container without user information:
# /casa-release-5.8.0-109.el7/lib/python2.7/getpass.pyc in getuser()
# 156 # If this fails, the exception will "explain" why
# 157 import pwd
# --> 158 return pwd.getpwuid(os.getuid())[0]
# 159
# 160 # Bind the name getpass to the appropriate function
#
# KeyError: 'getpwuid(): uid not found: 1000'
Under singularity this is no problem as it exposes the host's /etc/passwd and /etc/group. Under k8s, the container is "userless". Need to inject this info somehow. Here's a ChatGPT suggestion:
How to make pwd.getpwuid() work inside container without root access
If you need to use pwd.getpwuid() inside a container without root access and without altering system-wide configurations, you have a couple of alternatives:
Provide Necessary User Data:
Instead of altering /etc/passwd (which would require root access), you can provide a mock or substitute passwd file with the required user data and then leverage environment variables to make Python tools refer to this file.
First, create your custom passwd file, say custom_passwd, with the necessary user data.
myuser:x:1001:1001:My User:/home/myuser:/bin/bash
In your container, set the NSS_WRAPPER_PASSWD and NSS_WRAPPER_GROUP environment variables to point to this custom file and use nss_wrapper to make pwd.getpwuid() use this file:
nss_wrapper provides a way for your application to load /etc/passwd and /etc/group from a different location than the system defaults.
Reconsider the Need:
Check if you can refactor or adjust your code logic to avoid the need to call pwd.getpwuid(). Sometimes, the reason for needing user information can be rethought in the context of containerized applications.
Dynamic User Mapping:
Some container platforms, like OpenShift, often use random UIDs for containers for security reasons. They also provide mechanisms like the nss_wrapper mentioned above to help applications run without expecting specific UIDs. Ensure your application is resilient to running under different UIDs and can fetch or derive necessary user data without relying on system-wide user databases.
Remember to ensure your solutions adhere to best security practices, especially when working in environments that prioritize non-root container execution for safety reasons.
The text was updated successfully, but these errors were encountered:
As it turns out, libnss_wrapper is not even necessary. Just setting USER and HOME variables inside the container, and mounting an ephemeral home directory, looks sufficient to stop it from whining.
o-smirnov
added a commit
to caracal-pipeline/cult-cargo
that referenced
this issue
Sep 19, 2023
CASA won't run inside a container without user information:
Under singularity this is no problem as it exposes the host's /etc/passwd and /etc/group. Under k8s, the container is "userless". Need to inject this info somehow. Here's a ChatGPT suggestion:
How to make pwd.getpwuid() work inside container without root access
If you need to use
pwd.getpwuid()
inside a container without root access and without altering system-wide configurations, you have a couple of alternatives:Provide Necessary User Data:
Instead of altering
/etc/passwd
(which would require root access), you can provide a mock or substitutepasswd
file with the required user data and then leverage environment variables to make Python tools refer to this file.First, create your custom
passwd
file, saycustom_passwd
, with the necessary user data.In your container, set the
NSS_WRAPPER_PASSWD
andNSS_WRAPPER_GROUP
environment variables to point to this custom file and usenss_wrapper
to makepwd.getpwuid()
use this file:nss_wrapper
provides a way for your application to load/etc/passwd
and/etc/group
from a different location than the system defaults.Reconsider the Need:
Check if you can refactor or adjust your code logic to avoid the need to call
pwd.getpwuid()
. Sometimes, the reason for needing user information can be rethought in the context of containerized applications.Dynamic User Mapping:
Some container platforms, like OpenShift, often use random UIDs for containers for security reasons. They also provide mechanisms like the
nss_wrapper
mentioned above to help applications run without expecting specific UIDs. Ensure your application is resilient to running under different UIDs and can fetch or derive necessary user data without relying on system-wide user databases.Remember to ensure your solutions adhere to best security practices, especially when working in environments that prioritize non-root container execution for safety reasons.
The text was updated successfully, but these errors were encountered: