r-lib / keyring

:closed_lock_with_key: Access the system credential store from R

Home Page:https://keyring.r-lib.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Loading keyring from project library on Linux

mafw opened this issue · comments

commented

I am trying to use the keyring package on Ubuntu 20.04 to get passwords stored in my keyring. Unfortunately the backend_secret_service$new()$is_available() function cannot find the secret service daemon on Linux if the keyring package is loaded from a local library within a project. This causes the package to default to using environmental variables and throws the following warning:

"Warning message:In default_backend_auto() :Selecting ‘env’ backend. Secrets are stored in environment variables"

This in turn means that I cannot access secrets stored in the GNOME keyring using the key_get() function.

I can solve this problem by loading the keyring package from the default user R library instead of the project library. I use the renv package to create the local library.

# Create project, activate renv and install keyring
library(usethis)
library(renv)
create_project(path = "MyNewProject", open = TRUE, rstudio = TRUE)

renv::activate()
renv::install("keyring")

# Load keyring using project library
library(keyring, lib.loc = "renv/library/R-4.0/x86_64-pc-linux-gnu-library")
backend_secret_service$new()$is_available()
#> [1] "FALSE"

# Install keyring in user library and load it from there
utils::install.packages("keyring", lib = "~/R/x86_64-pc-linux-gnu-library/4.0") 
library(keyring, lib.loc = "~/R/x86_64-pc-linux-gnu-library/4.0")
backend_secret_service$new()$is_available()
#> [1] "TRUE"

Keyring also finds secret service if I simply load it outside a project, which makes sense since the package is then loaded from the user library by default.

My first thought is that this has something to do with permissions on Linux? I use the keyring package on a Windows 10 machine without this problem.

R version 4.0.3 (2020-10-10)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.2 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=nb_NO.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=nb_NO.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=nb_NO.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=nb_NO.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods  
[7] base     

other attached packages:
[1] keyring_1.1.0

loaded via a namespace (and not attached):
[1] compiler_4.0.3   assertthat_0.2.1 R6_2.5.0        
[4] tools_4.0.3      renv_0.12.5     

One keyring install did not have the required system libraries available, this is why it does not support the secret service backend. Reinstall/recompile it with once you have the system libs.

commented

OK this makes sense. When I reinstall the package I get the same error for the user package library. How do I check which libraries are missing? I am not getting any error saying I am missing libraries when installing the package and the keyring is working outside R.

Seems like you need libsecret-1-dev on Ubuntu.

commented

My bad, there is a message when installing the package that on Ubuntu you should install libsecret-1-dev. I removed the keyring packaged, installed this library and then reinstalled keyring and now it works. Thanks and sorry about the confusion!