In our data science team we use the keyring package to handle credentials. Currently we all work on Windows desktops so the default windows credential store gets used.
Now, we are in the processing of operationalising some of our scripts and are setting up an Amazon EC2 instance to do this. However I've just found out that keyring doesn't play well on linux.
When I execute a key_set I get the following warning message.
keyring::key_set(service = "test", username = "test")
Password: *******
Warning message:
In default_backend_auto() :
Selecting ‘env’ backend. Secrets are stored in environment variables
I can retrieve the key using key_get but obviously if I leave the R session and come back into it I get an error.
keyring::key_get(service = "test", username = "test")
Error in b_env_get(self, private, service, username, keyring) :
Cannot find password
In addition: Warning message:
In default_backend_auto() :
Selecting ‘env’ backend. Secrets are stored in environment variables
I have installed libsodium-dev as it is an Ubuntu EC2 instance. A quick google seems to suggest the default backend can't be changed without a GUI
We were also pondering Rstudio connect on AWS in the future. Will this likely be an issue on that too?
What are other solutions you use/ have seen used to counter this?
Point to note: file based keyrings are locked with a password and need to be unlocked. Also might be worth setting the default backend to file using the .Renviron file
Very interesting! Good find! This is definitely something I want to dig into, because keyring on RStudio Server or RStudio Connect seems like a really compelling toolchain!
If you encounter problems (or solutions!) in either case, please do come create a thread to discuss here! I think you're definitely in the right place
I would guess that (on RStudio Connect) the environment pane would be something you'd use to pass the necessary secret to "unlock" the file, perhaps?
The keyring package now detects Linux server environments and sets the file backend by default. You should not need to set the backend manually any longer keyring::backend_file$new(). However, you still need to install the libsodium package as a server admin on Linux.
For a simpler interface to they keyring package, I suggest creating the system keyring keyring::keyring_create("system") and using rstudioapi::askForSecret().
Install the latest version of keyring from Github: