r-lib / keyring

:closed_lock_with_key: Access the system credential store from R
https://keyring.r-lib.org/
Other
196 stars 28 forks source link

Error in b_env_list(self, private, service, keyring) : 'service' is required for 'env' backend. #111

Closed moldach closed 2 years ago

moldach commented 3 years ago

Load dependencies

ml R/prd
ml libsodium

Error from Rscript (but not interactively)

I'm getting this error when trying to submit a script on our Linux server:

$ Rscript --vanilla --no-save datafeedv2-update.R
Error in b_env_list(self, private, service, keyring) : 
  'service' is required for 'env' backend.
Calls: print -> key_list -> <Anonymous> -> b_env_list
In addition: Warning message:
In default_backend_auto() :
  Selecting β€˜env’ backend. Secrets are stored in environment variables
Execution halted

Note: At first my script was trying key_get(), but the error above was triggered by key_list() specifically.

However, when I load R + libsodium modules and run the R code interactively, I'm able to key_set() and key_get():

Launch R

R --no-save
> library(keyring)
> key_list()
     service username
1 OFFX_TOKEN     <NA>
> key_get("OFFX_TOKEN")
Keyring password:  
πŸ”‘  OK
[1] "MY SECRET TOKEN"

What could be causing this issue and how should I debug?

gaborcsardi commented 3 years ago

--vanilla loads another installation of the package, maybe?

gaborcsardi commented 2 years ago

This works for me:

❯ R_KEYRING_BACKEND=env R -q -e 'keyring::key_set_with_value("serv", password = "secret"); keyring::key_get("serv")'
> keyring::key_set_with_value("serv", password = "secret"); keyring::key_get("serv")
[1] "secret"

So it is possible to use a key without a username, with the env backend.

Please reopen this if you still have issues.