-
Notifications
You must be signed in to change notification settings - Fork 7.2k
feat(apikey): Allow apikeys loaded from commands #2405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
ac9a9c1 to
0c72694
Compare
| import { Instance } from "../../project/instance" | ||
|
|
||
| // Simple command parser that handles quoted strings | ||
| function parseCommand(input: string): string[] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is admittedly a bit "sloppy", I'm open to other approaches. Initially I just wanted to enable the command format in config. Adding the prompts to auth login required parsing user input though (that would invariably include some type of quote).
|
I'd heard there was a recent supply chain attack involving It sounds like the malicious package would scan for credentials to upload, putting 1password's own instructions will have you replace the key in configuration with a 1password ref. Then when it comes time to run a command that requires the secret, you just wrap it in an FWIW I did try this; simply configured an env variable as a 1pass reference and tried to Anyways, in light of the attack elsewhere, I just thought I'd come back and reiterate how enabling a change like this could help users protect themselves in similar situations. Let me know if you want any changes or whatever, hopefully it's helpful. |
0c72694 to
f6a0d8d
Compare
f6a0d8d to
aa1563c
Compare
f16de3d to
cc0d460
Compare
|
I figured out how to get |
👋 I'm interested in what the fix was if you have it handy to share. I think I'm running up against the same tui issue... |
|
If you're using Otherwise, I just launch opencode with a shell alias: # ~/.config/opencode/.env
# You can put the 1pass env file wherever you want ofc
# Environment/api keys while working in Opencode
ANTHROPIC_API_KEY="op://..."
OPENAI_API_KEY="op://..."
OPENCODE_API_KEY="op://..."alias opncd='op run --env-file=$HOME/.config/opencode/.env --no-masking -- opencode' |
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.jsonwould allow for a new "type" of apikey:cmd, with the value saved as an array (command plus args). Theopencode auth logincommand 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 loginand 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.jsonis saved as an array:['op', 'read', "op://some vault/some key/password"](with type "cmd")