#2279·paramiko

[BUG] - getuser() fails in CI environment when paramiko is upgraded from 3.2.0 on version 3.3.1

Author: xaver-kCreated Aug 2, 2023Updated Jul 17, 2026
LabelsBug

Are you using paramiko as a client or server?

Client

What feature(s) aren't working right?

SSH

What version(s) of paramiko are you using?

3.3.1

What version(s) of Python are you using?

3.11 and 3.8

What operating system and version are you using?

python:3.11 docker container on Jenkins CI

If you're connecting as a client, which SSH server are you connecting to?

No response

If you're using paramiko as part of another tool, which tool/version?

Fabric 3.1.0

Expected/desired behavior

Running with fabric, create a Connection object for password-based connection to a host:

python
# relevant lines from our internal test pipeline
from fabric import Connection
connection = Connection(host=ip_address, user="my_user_name", connect_kwargs={'password': 'my_secret_password'})

This works fine on Fabric 3.1.0 with paramiko 3.20

Actual behavior

Using paramiko 3.3.1, the following failure occurs:

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
 .local/lib/python3.11/site-packages/fabric/connection.py:405: in __init__
     self.ssh_config = self.config.base_ssh_config.lookup(host)
 .local/lib/python3.11/site-packages/paramiko/config.py:244: in lookup
     options = self._lookup(
 .local/lib/python3.11/site-packages/paramiko/config.py:281: in _lookup
     options = self._expand_variables(options, hostname)
 .local/lib/python3.11/site-packages/paramiko/config.py:502: in _expand_variables
     config[k] = tokenizer(config[k])
 .local/lib/python3.11/site-packages/paramiko/config.py:437: in _tokenize
     user = getpass.getuser()
 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
 
     def getuser():
         """Get the username from the environment or password database.
     
         First try various environment variables, then the password
         database.  This works on Windows as long as USERNAME is set.
     
         """
     
         for name in ('LOGNAME', 'USER', 'LNAME', 'USERNAME'):
             user = os.environ.get(name)
             if user:
                 return user
     
         # If this fails, the exception will "explain" why
         import pwd
 >       return pwd.getpwuid(os.getuid())[0]
 E       KeyError: 'getpwuid(): uid not found: 1005'
 
 /usr/local/lib/python3.11/getpass.py:169: KeyError

Note that UID 1005 is the CI user that jenkins injects when starting the docker container.

How to reproduce

In case it is relevant, we are running in Jenkins with docker agents. I can unfortunately not share the whole pipeline definition, but the part that matters is roughly:

stage("my stage") {
    agent { docker { image "python:3.11"} }
    steps {
            script{
               sh "pip3 install --user -r requirements.txt"  // install fabric, paramiko etc.
               // stuff here
               sh "python3 -m pytest"  // fails when running tests here
            }
    }
}

Anything else?

Note that probing the environment that jenkins sets up in the container gives the following:

  • whoami -> whoami: cannot find name for user ID 1005
  • as expected, neither of the following variables are defined: 'LOGNAME', 'USER', 'LNAME', 'USERNAME'