feat(apikey): Allow apikeys loaded from commands #2405
+113
−7
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Heyo, hopefully you don't consider this new functionality, but feel free to reject if you have another plan. Still, I'm filing this under either "fixes for env specific quirks" (this enables environments that load secrets differently) or "missing standard behavior" (some tools that also use api keys already provide this (or similar methods) for loading secrets).
The big thing this partially/kinda helps protect against is rogue users skimming keys. For security reasons, many users avoid leaving secrets in plain text or even environment variables. Some tooling will allow reading secrets from a command instead. For example, gp.nvim's instructions for password managers, or CodeCompanion's "cmd:" prefix
The main change here is to allow api keys to (also) be loaded from the output of a command.
auth.json
would allow for a new "type" of apikey:cmd
, with the value saved as an array (command plus args). Theopencode auth login
command is also updated to now let you users pick whether to paste just a key, or use the new command format.Here's what it looks like:
opencode auth login
and when it's time for the key, choose to enter a command instead.op read "op://some vault/some key/password"
. See their docs.~/.local/share/opencode/auth.json
is saved as an array:['op', 'read', "op://some vault/some key/password"]
(with type "cmd")