cansjt opened a new issue #9963:
URL: https://github.com/apache/airflow/issues/9963


   **Apache Airflow version**: 1.10.11
   
   
   **Kubernetes version (if you are using kubernetes)** (use `kubectl 
version`): 1.18.4
   
   **Environment**:
   
   - **Cloud provider or hardware configuration**:
   - **OS** (e.g. from /etc/os-release):
   - **Kernel** (e.g. `uname -a`):
   - **Install tools**:
   - **Others**:
   
   **What happened**:
   
   There are many call occurrences to `getpass.getuser()` in the code. None are 
fenced with a try/except to protect them from failures. Though, in a 
containerized environment, using a process with an uid that is not defined in 
`/etc/passwd` is not uncommon when using a existing image. This makes airflow 
crash with errors like the one below, though the call to `getpass.getuid()` 
serves no critical purposes (it is sometimes used to annotate metrics...) 
AFAICT.
   
   ```
   Traceback (most recent call last):
     File "/usr/local/bin/airflow", line 37, in <module>
       args.func(args)
     File "/usr/local/lib/python3.8/site-packages/airflow/utils/cli.py", line 
76, in wrapper
       return f(*args, **kwargs)
     File "/usr/local/lib/python3.8/site-packages/airflow/bin/cli.py", line 
1189, in scheduler
       job = jobs.SchedulerJob(
     File "<string>", line 4, in __init__
     File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/state.py", 
line 433, in _initialize_instance
       manager.dispatch.init_failure(self, args, kwargs)
     File 
"/usr/local/lib/python3.8/site-packages/sqlalchemy/util/langhelpers.py", line 
68, in __exit__
       compat.raise_(
     File "/usr/local/lib/python3.8/site-packages/sqlalchemy/util/compat.py", 
line 178, in raise_
       raise exception
     File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/state.py", 
line 430, in _initialize_instance
       return manager.original_init(*mixed[1:], **kwargs)
     File 
"/usr/local/lib/python3.8/site-packages/airflow/jobs/scheduler_job.py", line 
387, in __init__
       super(SchedulerJob, self).__init__(*args, **kwargs)
     File "<string>", line 6, in __init__
     File "/usr/local/lib/python3.8/site-packages/airflow/jobs/base_job.py", 
line 92, in __init__
       self.unixname = getpass.getuser()
     File "/usr/local/lib/python3.8/getpass.py", line 169, in getuser
       return pwd.getpwuid(os.getuid())[0]
   KeyError: 'getpwuid(): uid not found: 1000'
   ```
   I think i many cases it could be simply replaced with:
   ```python
   try:
       <var> = getpass.getuser()
   except KeyError:
       <var> = str(os.getuid())
   ```
   
   
   **What you expected to happen**:
   
   I expected Airflow to not crash because the uid is not mapped to a user 
defined in `/etc/passwd`
   
   **How to reproduce it**:
   
   Deploy the official airflow image in docker with `--user=9999` (or any other 
uid that is not 50000) or in k8s with a security context like:
   ```
   securityContext:
     runAsUser: 9999
   ```
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to