#2850 read_environment_files() sets key u'', causes ValueError
Closed: fixed Opened by cheimes.

FreeIPA is running into an issue in pki.util.read_environment_files(). The function tries to set an env var with key u'' and value u''. Since an empty env var is not allowed, the operation fails with ValueError: illegal environment variable name.

Fix:

$ git diff
diff --git a/base/common/python/pki/util.py b/base/common/python/pki/util.py
index 5832f5562..871c899e9 100644
--- a/base/common/python/pki/util.py
+++ b/base/common/python/pki/util.py
@@ -272,4 +272,6 @@ def read_environment_files(env_file_list=None):
     for env_val in env_vals:
         (key, _, value) = env_val.partition("=")
+        if not key.strip() or key == u'_':
+            continue
         os.environ[key] = value

Could you attach these files?

  • /usr/share/pki/etc/pki.conf
  • /etc/pki/pki.conf

The code is actually parsing the output of 'env' command after sourcing those files, so I wonder where the blank key/value originally came from and why it's allowed by bash. Or, maybe the parsing code is incorrect.

Metadata Update from @edewata:
- Custom field component adjusted to None
- Custom field feature adjusted to None
- Custom field origin adjusted to None
- Custom field proposedmilestone adjusted to None
- Custom field proposedpriority adjusted to None
- Custom field reviewer adjusted to None
- Custom field type adjusted to None
- Custom field version adjusted to None

Metadata Update from @mharmsen:
- Issue set to the milestone: 0.0 NEEDS_TRIAGE

Could be caused by the env command having a final newline. Thus the final line
would be empty and could cause this failure.

Also if there are any commands in the 'env' output these could be spread across multiple lines,
though that would not be causing this error because the lines would not be empty.

I think we can take the fix as-is. And I see that there was a gerrit review and it
has already been merged: https://review.gerrithub.io/#/c/386331/. So I'll close this ticket now :)

Fixed in commit: a105341f777354429dfc9f28c7baf5bddd2d5e1f

Metadata Update from @ftweedal:
- Issue close_status updated to: fixed

Yes, it's the final newline from env:

>>> import subprocess
>>> output = subprocess.check_output(['bash', '-c', 'source /usr/share/pki/etc/pki.conf && source /etc/pki/pki.conf && env'])
>>> output
'PKI_SERVER_AUTO_ENABLE_SUBSYSTEMS=true\nSSL_STREAM_VERSION_MIN=TLS_1_0\nLANG=en_US.UTF-8\nSUDO_GID=5977\nHOSTNAME=vm-193.abc.idm.lab.eng.brq.redhat.com\nCOBBLER_SERVER=10.16.78.1\nSSL_STREAM_VERSION_MAX=TLS_1_2\nPKI_CLI_OPTIONS=\nLOGGING_CONFIG=/usr/share/pki/etc/logging.properties\nUSERNAME=root\nJAVA_HOME=/usr/lib/jvm/jre-1.8.0-openjdk\nKEY_WRAP_PARAMETER_SET=1\nSUDO_COMMAND=/bin/bash\nJNI_JAR_DIR=/usr/lib/java\nUSER=root\nPWD=/home/cheimes\nLINES=40\nHOME=/root\nSSL_DATAGRAM_VERSION_MAX=TLS_1_2\nSUDO_USER=cheimes\nSSL_DATAGRAM_VERSION_MIN=TLS_1_1\nSSL_CIPHERS=\nSUDO_UID=25879\nCOLUMNS=156\nMAIL=/var/spool/mail/cheimes\nPKI_LIB=/usr/share/pki/lib\nTERM=xterm-256color\nSHELL=/bin/bash\nSHLVL=2\nLOGNAME=root\nPATH=/sbin:/bin:/usr/sbin:/usr/bin\nHISTSIZE=1000\nSSL_DEFAULT_CIPHERS=true\nLESSOPEN=||/usr/bin/lesspipe.sh %s\n_=/bin/env\n'
>>> output.split('\n')
['PKI_SERVER_AUTO_ENABLE_SUBSYSTEMS=true', 'SSL_STREAM_VERSION_MIN=TLS_1_0', 'LANG=en_US.UTF-8', 'SUDO_GID=5977', 'HOSTNAME=vm-193.abc.idm.lab.eng.brq.redhat.com', 'COBBLER_SERVER=10.16.78.1', 'SSL_STREAM_VERSION_MAX=TLS_1_2', 'PKI_CLI_OPTIONS=', 'LOGGING_CONFIG=/usr/share/pki/etc/logging.properties', 'USERNAME=root', 'JAVA_HOME=/usr/lib/jvm/jre-1.8.0-openjdk', 'KEY_WRAP_PARAMETER_SET=1', 'SUDO_COMMAND=/bin/bash', 'JNI_JAR_DIR=/usr/lib/java', 'USER=root', 'PWD=/home/cheimes', 'LINES=40', 'HOME=/root', 'SSL_DATAGRAM_VERSION_MAX=TLS_1_2', 'SUDO_USER=cheimes', 'SSL_DATAGRAM_VERSION_MIN=TLS_1_1', 'SSL_CIPHERS=', 'SUDO_UID=25879', 'COLUMNS=156', 'MAIL=/var/spool/mail/cheimes', 'PKI_LIB=/usr/share/pki/lib', 'TERM=xterm-256color', 'SHELL=/bin/bash', 'SHLVL=2', 'LOGNAME=root', 'PATH=/sbin:/bin:/usr/sbin:/usr/bin', 'HISTSIZE=1000', 'SSL_DEFAULT_CIPHERS=true', 'LESSOPEN=||/usr/bin/lesspipe.sh %s', '_=/bin/env', '']
>>> ''.partition('=')
('', '', '')

Metadata Update from @mharmsen:
- Issue set to the milestone: 10.5.2 (was: 0.0 NEEDS_TRIAGE)

Metadata Update from @mharmsen:
- Custom field fixedinversion adjusted to pki-core-10.5.2-1.fc27

Dogtag PKI is moving from Pagure issues to GitHub issues. This means that existing or new
issues will be reported and tracked through Dogtag PKI's GitHub Issue tracker.

This issue has been cloned to GitHub and is available here:
https://github.com/dogtagpki/pki/issues/2970

If you want to receive further updates on the issue, please navigate to the
GitHub issue and click on Subscribe button.

Thank you for understanding, and we apologize for any inconvenience.

Metadata