fallback to uid when no uname (#68466)

* fallback to uid when no uname

 fixes #68007

Co-Authored-By: Matt Clay <matt@mystile.com>
This commit is contained in:
Brian Coca 2020-03-27 22:09:51 -04:00 committed by GitHub
parent 835ad75a0a
commit 1570098e86
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- 'for those running uids for invalid users (containers), fallback to uid=<uid> when logging fixes #68007'

View file

@ -62,7 +62,12 @@ class FilterUserInjector(logging.Filter):
This is a filter which injects the current user as the 'user' attribute on each record. We need to add this filter
to all logger handlers so that 3rd party libraries won't print an exception due to user not being defined.
"""
username = getpass.getuser()
try:
username = getpass.getuser()
except KeyError:
# people like to make containers w/o actual valid passwd/shadow and use host uids
username = 'uid=%s' % os.getuid()
def filter(self, record):
record.user = FilterUserInjector.username