httr2 icon indicating copy to clipboard operation
httr2 copied to clipboard

Mention keyring package in Wrapping APIs vignette?

Open maelle opened this issue 2 years ago • 11 comments

More precisely, should this workflow be added to that vignette: In an API package doc, recommend the user store their API key with keyring and retrieve it with Sys.getenv(API_KEY=keyring::key_get("API-NAME")?

maelle avatar Oct 13 '23 05:10 maelle

What’s the advantage of doing that that you’re thinking of?

hadley avatar Oct 13 '23 06:10 hadley

Storing the secrets in the OS' credentials store is supposed to be safer than storing them in .Renviron.

maelle avatar Oct 13 '23 07:10 maelle

I too noticed keyring is not in the httr2 docs, whereas httr has this vignette: Managing secrets.

Interested in this discussion as e.g. qualtRics wraps an API and depends on the user having secrets stored in .Renviron.

asadow avatar Oct 13 '23 13:10 asadow

Hmmm, I guess since I wrote that httr vignette I'm no longer sure that the keyring is that much more secure. I think it's theoretically more secure, but in practice it's unlikely to make much difference because for an attacker to have access to your .Renviron then that implies they have access to your computer, and are thus can already access your OS keychain.

OTOH maybe people are using project specific .Renviron files which are much more dangerous because they're more likely to end up accidentally committed into git?

hadley avatar Oct 13 '23 20:10 hadley

Right, maybe it just feels more secure but your point about git seems important.

More niche and less important:

  • I like that the OS keychain really feels more different from writing a secret in a script (compared to .Renviron vs secret in script, in both cases you write things in clear in a file which seems to be a bad habit like having a docx with all your passwords).
  • I know screen-sharing Renviron by mistake is not a big risk but I also like that this couldn't happen with the OS keychain.

maelle avatar Oct 16 '23 08:10 maelle

Hmmmm, this all feels like it should maybe be a separate vignette that's env vars vs keychain, but then httr2 doesn't feel like quite the right place for it. Maybe it would be better as a keyring vignette?

hadley avatar Oct 16 '23 13:10 hadley

but how would httr2 users even think of reading keyring docs, could there be a pointer, even small? :slightly_smiling_face:

maelle avatar Oct 16 '23 13:10 maelle

Right, we'd point to it everywhere we mention env vars.

hadley avatar Oct 16 '23 13:10 hadley

I updated the keyring readme: https://keyring.r-lib.org/dev/. Do you think that's sufficient for selling it as an alternative to env vars or do I need to write more?

hadley avatar Oct 19 '23 22:10 hadley

Nice, thank you! I added comments in https://github.com/r-lib/keyring/pull/139 :smile_cat:

maelle avatar Oct 20 '23 05:10 maelle

I think this requires more than just a change to the docs: for it to be a useful (and meaningfully more secure workflow), secret_encrypt() and friends need to know to look in the keychain. I think that's probably still worth doing, but I won't get to it in this release.

hadley avatar Oct 26 '23 20:10 hadley

See notes in related PR; need more work in keyring until we can enable this automatically.

hadley avatar Jan 06 '25 13:01 hadley

Just to add to the previous points that have been made. Using a keyring is more secure when backing up data on an external hard drive because credentials should still be password protected as opposed to a file like .Renviron that will be accessible by anyone who has the hard drive (unless you explicitly protect the hard drive or .Renviron with a password).

arnaudgallou avatar Feb 16 '25 09:02 arnaudgallou

@arnaudgallou I'm not sure that's a compelling argument — if you're worried about the physical security of the hard drive, you should be encrypting the whole thing.

hadley avatar Feb 17 '25 18:02 hadley

I agree that's what you should do in practice but for an average user like me who only has a couple of API keys to secure and regularly back up my computer, the simplicity and convenience of keyring is appealing. I wouldn't use keyring for that purpose only but it's a little plus to me.

arnaudgallou avatar Feb 19 '25 11:02 arnaudgallou