r-lib / credentials

Tools for Managing SSH and Git Credentials
https://docs.ropensci.org/credentials
Other
72 stars 5 forks source link

Package cannot be installed when installing as another user on linux #11

Closed jefshe closed 3 years ago

jefshe commented 3 years ago

I'm trying to install this package on a system for another user: echo 'install.packages("credentials")' | sudo -u some_other_user R --no-save

This causes the following error to occur:

warning: unable to access '/home/jeff/.config/git/config': Permission denied
error: could not lock config file /home/jeff/.gitconfig: Permission denied
Error: package or namespace load failed for ‘credentials’:
 .onLoad failed in loadNamespace() for 'credentials', details:
  call: NULL
  error: Failed to call 'git config --global credential.helper cache'
Error: loading failed
Execution halted
ERROR: loading failed

I see that the error is occurring here where we set the global user git config to cache credentials: https://github.com/r-lib/credentials/blob/master/R/onattach.R#L22.

I can see it being useful to have this behaviour for the common user but I don't think it's necessarily desirable all the time. Could a flag be added to disable this behaviour?

jeroen commented 3 years ago

Does it work if you just switch to the new user first? I don't understand why a user wouldn't have permission to read their own git config files?

As a workaround maybe you can try this:

install.packages("credentials", INSTALL_opts="--no-test-load")
jefshe commented 3 years ago

Thanks for the fast response jeroen

Does it work if you just switch to the new user first?

yep

I don't understand why a user wouldn't have permission to read their own git config files?

Running this command from the command line results in the same behaviour

sudo -u otheruser git config --global credential.helper cache
error: could not lock config file /home/currentuser/.gitconfig: Permission denied

I guess git looks at the HOME variable to figure out where your git config file is.

running sudo with -H flag seems to resolve the problem too. So i'll close this out