Skip to content
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

bitwarden: check local env vars for password or api key #11

Closed
jessebot opened this issue Dec 6, 2022 · 9 comments · Fixed by #51
Closed

bitwarden: check local env vars for password or api key #11

jessebot opened this issue Dec 6, 2022 · 9 comments · Fixed by #51
Assignees
Labels
🔐 Bitwarden anything to do with bitwarden ✨ enhancement New feature request

Comments

@jessebot
Copy link
Collaborator

jessebot commented Dec 6, 2022

No description provided.

@jessebot jessebot added the ✨ enhancement New feature request label Dec 6, 2022
@cloudymax
Copy link
Collaborator

cloudymax commented Dec 7, 2022

Looks like this can be accomplished via using the bw login --apikey option

according to: https://bitwarden.com/help/cli/#using-an-api-key

In scenarios where automated work is being done with the Bitwarden CLI, you can save environment variables to prevent the need for manual intervention at authentication.

Environment Variable Name Required Value
BW_CLIENTID client_id
BW_CLIENTSECRET client_secret

to get the api-key you have to login to the web-vault via bitwarden.com..

From there you need to click on the user icon at the top-right of the page and select account settings

Screenshot 2022-12-07 at 19 46 02

Next you'll need to select the Security option form the menu on the left, and then select the Keys tab.

Screenshot 2022-12-07 at 19 46 34

At the bottom of the page you should get the options to view the key:

Screenshot 2022-12-07 at 19 47 33

Enter your password at the following screen, and get your api key

Screenshot 2022-12-07 at 19 47 02

Then export the client and client secret values as BW_CLIENTID and BW_CLIENTSECRET.

bw login --apikey
You are logged in!

To unlock your vault, use the `unlock` command. ex:
$ bw unlock

@jessebot
Copy link
Collaborator Author

jessebot commented Dec 7, 2022

Amazing writeup, thank you! :D

@jessebot jessebot added the 🔐 Bitwarden anything to do with bitwarden label Dec 7, 2022
@cloudymax
Copy link
Collaborator

Amazing writeup, thank you! :D

no problem! 🥳

@jessebot
Copy link
Collaborator Author

jessebot commented Dec 24, 2022

Checked and it looks like even with the api key, you still need to enter in the password to unlock the vault. I don't knoow that we're gaining anything by introducing the API key :(

Unlock

Using an API key or SSO to log in will require you to follow-up the login command with an explicit bw unlock if you'll be working with vault data directly.

Unlocking your vault generates a session key which acts as a decryption key used to interact with data in your vault. The session key must be used to perform any command that touches vault data (for example, list, get, edit). Session keys are valid until invalidated using bw lock or bw logout, however they will not persist if you open a new terminal window. Generate a new session key at any time using:

bw unlock

When you're finished, always end your session using the bw lock command.

Unlock options

You can use the --passwordenv or --passwordfile options with bw unlock to retrieve your master password rather than enter it manually

Source: https://bitwarden.com/help/cli/#unlock

@jessebot
Copy link
Collaborator Author

Well, it's hacky, but we can maybe suggest local users use libsecret to grab their bitwarden password and then export that in their shell on login, and then that can be used to unlock the vault. So, going back to the default option for this ticket: We should check local env vars for password. More importantly, it might make sense to add a "add to vault command" option, where we can add things to your vault of any password manager of your choice, but this would still require the user to know that they need to export certain env variables ahead of time to have the vault command work 🤔

I hate this for us. D: I wish that the API key actually worked like a normal API key and didn't still require the password key. This feels like it just adds complexity and no extra security, because you can't even set "require api key".

@jessebot jessebot linked a pull request Jan 8, 2023 that will close this issue
@jessebot
Copy link
Collaborator Author

jessebot commented Jan 8, 2023

Reopening because although we now check for session tokens in the env vars, we do not accept API keys yet.

@jessebot jessebot reopened this Jan 8, 2023
@jessebot
Copy link
Collaborator Author

jessebot commented Jan 8, 2023

#45 is semi related to this.

@jessebot jessebot self-assigned this Jan 8, 2023
@jessebot
Copy link
Collaborator Author

jessebot commented Jan 8, 2023

I guess if the user is not logged in already, we could potentially try logging in via an api key, but after that, I am closing this ticket, because this is a lot to handle for the scope of this project currently.

@jessebot
Copy link
Collaborator Author

Ok, we will now check local env vars not only for a password but also the api key in #79 Closing and we can handle local keyring in #45

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔐 Bitwarden anything to do with bitwarden ✨ enhancement New feature request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants