Using sudo with virtualenvwrapper causes $HOME/.virtualenvs/hook.log to have have wrong acces rights

Bug #870097 reported by Stephan Wienczny
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
virtualenvwrapper (Ubuntu)
Invalid
Undecided
Unassigned

Bug Description

When virutalenvwrapper is installed and you open a new a sudo shell the file hook.log is owned by root but located in the user's home.

ls -la .virtualenvs/
insgesamt 72
drwxr-xr-x 2 stephan stephan 4096 2011-10-06 23:56 .
drwxr-xr-x 121 stephan stephan 12288 2011-10-07 17:55 ..
-rwxrwxr-x 1 stephan stephan 106 2011-08-25 02:01 get_env_details
-rw-r--r-- 1 root root 1160 2011-10-07 15:10 hook.log
-rw-r--r-- 1 stephan stephan 10208 2011-10-06 23:56 hook.log.1
-rwxrwxr-x 1 stephan stephan 92 2011-08-25 02:01 initialize
-rwxrwxr-x 1 stephan stephan 69 2011-08-25 02:01 postactivate
-rwxrwxr-x 1 stephan stephan 71 2011-08-25 02:01 postdeactivate
-rwxrwxr-x 1 stephan stephan 69 2011-08-25 02:01 postmkvirtualenv
-rwxrwxr-x 1 stephan stephan 63 2011-08-25 02:01 postrmvirtualenv
-rwxrwxr-x 1 stephan stephan 70 2011-08-25 02:01 preactivate
-rwxrwxr-x 1 stephan stephan 72 2011-08-25 02:01 predeactivate
-rwxrwxr-x 1 stephan stephan 94 2011-08-25 02:01 premkvirtualenv
-rwxrwxr-x 1 stephan stephan 64 2011-08-25 02:01 prermvirtualenv

This causes an error message like this

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/pymodules/python2.7/virtualenvwrapper/hook_loader.py", line 72, in main
    backupCount=1,
  File "/usr/lib/python2.7/logging/handlers.py", line 118, in __init__
    BaseRotatingHandler.__init__(self, filename, mode, encoding, delay)
  File "/usr/lib/python2.7/logging/handlers.py", line 65, in __init__
    logging.FileHandler.__init__(self, filename, mode, encoding, delay)
  File "/usr/lib/python2.7/logging/__init__.py", line 893, in __init__
    StreamHandler.__init__(self, self._open())
  File "/usr/lib/python2.7/logging/__init__.py", line 912, in _open
    stream = open(self.baseFilename, self.mode)
IOError: [Errno 13] Permission denied: '/home/stephan/.virtualenvs/hook.log'
virtualenvwrapper.sh: There was a problem running the initialization hooks. If Python could not import the module virtualenvwrapper.hook_loader, check that virtualenv has been installed for VIRTUALENVWRAPPER_PYTHON=/usr/bin/python and that PATH is set properly.
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/pymodules/python2.7/virtualenvwrapper/hook_loader.py", line 72, in main
    backupCount=1,
  File "/usr/lib/python2.7/logging/handlers.py", line 118, in __init__
    BaseRotatingHandler.__init__(self, filename, mode, encoding, delay)
  File "/usr/lib/python2.7/logging/handlers.py", line 65, in __init__
    logging.FileHandler.__init__(self, filename, mode, encoding, delay)
  File "/usr/lib/python2.7/logging/__init__.py", line 893, in __init__
    StreamHandler.__init__(self, self._open())
  File "/usr/lib/python2.7/logging/__init__.py", line 912, in _open
    stream = open(self.baseFilename, self.mode)
IOError: [Errno 13] Permission denied: '/home/stephan/.virtualenvs/hook.log'
virtualenvwrapper.sh: There was a problem running the initialization hooks. If Python could not import the module virtualenvwrapper.hook_loader, check that virtualenv has been installed for VIRTUALENVWRAPPER_PYTHON=/usr/bin/python and that PATH is set properly.

ProblemType: Bug
DistroRelease: Ubuntu 11.10
Package: virtualenvwrapper 2.7.1-1
ProcVersionSignature: Ubuntu 3.0.0-12.19-generic 3.0.4
Uname: Linux 3.0.0-12-generic x86_64
NonfreeKernelModules: nvidia
ApportVersion: 1.23-0ubuntu2
Architecture: amd64
Date: Fri Oct 7 17:56:48 2011
InstallationMedia: Kubuntu 11.04 "Natty Narwhal" - Beta 1 amd64 (20110329.1)
PackageArchitecture: all
ProcEnviron:
 LANGUAGE=de_DE
 LANG=de_DE.UTF-8
 LC_MESSAGES=de_DE.UTF-8
 SHELL=/bin/bash
SourcePackage: virtualenvwrapper
UpgradeStatus: Upgraded to oneiric on 2011-06-23 (106 days ago)

Revision history for this message
Stephan Wienczny (stephan-wienczny) wrote :
Revision history for this message
Julian Taylor (jtaylor) wrote :

this is how sudo works on ubunt, you run as root but retain the users HOME variable. This can configured in sudo with env_reset, see the manpage.
I don't think there is anything virtualenvwrapper can do about that.

Changed in virtualenvwrapper (Ubuntu):
status: New → Invalid
Revision history for this message
Craig Maloney (craig-decafbad) wrote :

Unfortunately if you use the Ubuntu package, you don't get the benefit of using what appears to be the solution:

https://bitbucket.org/dhellmann/virtualenvwrapper/issue/62/

That's because the bash_completion.d/virtualenvwrapper script is run for you, and sets up the environment.

It's currently impossible for someone using the Ubuntu packaged version of virtualenvwrapper to not source the virtualenvwrapper completion script as root, and thereby cause the hook.log to become owned by root when the log file is re-created. You'd either have to disable completions (which degrades functionality) or stop using the Ubuntu package (which also degrades functionality).

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.