Skip to content

Instantly share code, notes, and snippets.

@nwstephens
Last active April 3, 2021 05:57
Show Gist options
  • Save nwstephens/255be56b99f1700acfd7a7f8b69da103 to your computer and use it in GitHub Desktop.
Save nwstephens/255be56b99f1700acfd7a7f8b69da103 to your computer and use it in GitHub Desktop.
Storing secrets with R. Using the keyring package you can stole encrypted secrets on disk or store them as environment variables in memory.
library(keyring)
options("keyring_backend" = "file") # set this in .Rprofile for convenience
### Store secrets encrypted at rest
keyring_create("kr")
key_set("foobar", keyring = "kr")
key_get("foobar", keyring = "kr")
### Store multiple secrets
keyring_create("DBs")
key_set("db1", "user", keyring = "DBs")
key_set_with_value("db2", "user", "password", keyring = "DBs")
keyring_lock("DBs")
keyring_unlock("DBs")
key_get("db1", "user", keyring = "DBs")
key_get("db2", "user", keyring = "DBs")
### Retrieve with RStudio
options("keyring_backend" = "file")
keyring::keyring_create("system")
rstudioapi::askForSecret("psql")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment