Git Product home page Git Product logo

1pass's Introduction

1pass

1pass is a caching wrapper for the 1Password CLI op.

Shellcheck

NO LONGER MAINTAINED

I am no longer maintaining this software, as the 1Password CLI version 2 provides all of the features I need.

WARNING 1password 2 CLI compatibility

Do not upgrade to 1password CLI version 2! This 1pass tool is not yet compatible with it.

UPGRADE NOTE

Upgrading to version 1.1 requires installation of the expect tool. 1pass will check for this (and other) dependencies and remind you to install them.

Introduction

1pass is designed to make using your 1Password usernames and passwords quick and easy. It is intended for use within an interactive shell as well as from scripts. Once installed and configured as described below, you can obtain an account password in a shell simply by typing:

$ 1pass Github

and your Github password will be copied to the clipboard.

The official 1Password CLI application (op) can be difficult to use interactively, and unlike the macOS or Windows 1Password native applications, requires an internet connection to fetch data from your password vaults. 1pass solves both of these problems. Op needs session tokens to be revalidated manually after 30 minutes of inactivity and produces rich output in JSON format. The JSON output is easy for a program to use, but is not trivially consumed by humans without help. 1pass provides that help, with two main features:

  • a simplified interface for listing and fetching usernames, passwords, and other fields for individual items.
  • an encrypted local cache of 1Password CLI results.

Together these features enable easy use of 1Password-stored credentials.

Installation

First make sure that the op 1Password CLI and the jq JQ and expect requirements are installed. If you use homebrew cask on macOS, this works well:

$ brew install 1password-cli
$ brew install jq expect

If you want to automate 2FA (TOTP) logging into 1password.com, then also install the oathtool, and see further instructions below.

$ brew install oath-toolkit

Copy the 1pass executable file to a suitable location on your PATH (for example, /usr/local/bin) and ensure that it is executable. For example:

curl https://raw.githubusercontent.com/dcreemer/1pass/master/1pass > /usr/local/bin/1pass
chmod a+x /usr/local/bin/1pass

Bash Completion

If you would like to install bash-completion for 1pass, place the bash-completion.sh script in and accessible location and then source it from your .bash_profile. For example:

mkdir -p /usr/local/etc/1pass
curl https://raw.githubusercontent.com/dcreemer/1pass/master/bash_completion.sh > /usr/local/etc/1pass/bash_completion.sh
echo "source /usr/local/etc/1pass/bash_completion.sh" >> ~/.bash_profile

By default the completion script will look for fzf completion support in your environment. If present, it will use fzf completion (see here).

Note: If you have installed fzf using homebrew on macOS, make sure you have enabled completion by running $(brew --prefix)/opt/fzf/install --completion and follow the prompts.

If you do not have fzf or if you turn this feature off it will revert to standard bash completion behavior. If you would like to explicitly disable FZF completion for 1pass, you can do so as follows:

export ONEPASS_FZF_COMPLETE=false

This line should be added to your .bash_profile

Security and Warning

1pass requires you to store your 1Password master password in a local GPG-encrypted file. You should inspect the source code to ensure that you trust the software, as well as read this documentation to understand the security tradeoffs.

Like the 1Password application itself, 1pass relies on one password. However that password is not your 1Password "master password" -- it is your Gnu Privacy Guard (gpg) private key. GPG, when configured to use the GPG-agent, will cache your private key password for a configurable length of time (a few hours to a day is perhaps reasonable). 1pass uses your GPG key to store an encrypted copies of your 1Password master password and your 1Password account secret key.

When data is needed from your online 1Password data store, the master password and secret key are temporarily decrypted and exchanged for a session token, which is also then encrypted and stored. The session token will be refreshed as needed. These actions happen automatically once your GPG key is available in the GPG-agent.

The data that is fetched from the 1Password service is cached in local files -- once again also encrypted using your GPG private key.

You can "lock" your 1pass session by running the "forget" command:

$ 1pass -f
cleared local session

which removes the local session token (if any), and calls gpgconf --kill gpg-agent to purge any running gpg-agent of your GPG secret keys.

Configuration

In order to run with minimum user input, 1pass relies on the Gnu Privacy Guard gpg to encrypt all locally stored data. 1Password needs both a master password and a secret key to access your vault. Each of these must be stored in an encrypted file (in ~/.1pass or $XDG_CONFIG_HOME/1pass) for 1pass to work correctly. 1pass encrypts these and all other files with your own gpg key. This key, as well as your 1Password login email and domain must be configured in the ~/.1pass/config file. The domain is the full domain name that you use to sign-in when you use the 1Password website, for example example.1password.com or subdomain.1password.ca.

GPG can be configured to use the gpg-agent, which can prompt for your gpg password, and cache it in a local agent for a fixed amount of time. If you configure GPG this way, you will only need to enter you GPG password (e.g.) once a day, and then seldom need to enter your 1Password master password.

Running 1pass -rv repeatedly will output instructions on how to configure this file and safely store your master password and secret key.

$ ./1pass -rv
please config 1pass by editing /home/me/.1pass/config
$ vi ~/.1pass/config
$ ./1pass -rv
please put your master password into /home/me/.1pass/_master.gpg
ex: echo "master-password" | gpg -er [email protected] > /home/me/.1pass/_master.gpg
$ echo "sEcre77" | gpg -er [email protected] > /home/me/.1pass/_master.gpg
$ ./1pass -rv
please put your mysubdomain.1password.com secret key into /home/me/.1pass/_secret.gpg
ex: echo "A3-XXXXXX-XXXXXX-XXXXX-XXXXX-XXXXX-XXXXX" | gpg -er [email protected] > /home/me/.1pass/_secret.gpg
$ echo "A3-XXXXXX-XXXXXX-XXXXX-XXXXX-XXXXX-XXXXX" | gpg -er [email protected] > /home/me/.1pass/_secret.gpg
$ ./1pass -rv
signing in to mysubdomain.1password.com [email protected]
...

Usage

Once you are configured and signed in, you are ready to use 1pass. The simplest command is 1pass with no arguments to list all items in your vault:

$ 1pass
Github
MyBankAccount
gmail.com
...

The list consists of the titles of each item. You can then retrieve the password of an item:

$ 1pass -p Github
sjd$kh23@0dfjs1DDj

The password is echoed to the standard output (when the '-p' option is used). You can easily use this in scripts, for example:

export PGPASSWORD=$(1pass -p MyPostgresServer)

Without the '-p' option, 1pass copies the password to the clipboard:

$ 1pass Github

The contents of the clipboard will be automatically cleared after 30 seconds. You can also pass 1pass an optional field argument -- for example "username" to retrieve that field from the item:

$ 1pass -p MyBankAccount username
[email protected]

Sometimes it's easier to pass the title to search for via stdin, rather than as a command line argument. Use the - character to force 1pass to read from stdin for the value.

$ echo "MyBankAccount" | 1pass -p - username
[email protected]

1pass can lookup other fields besides username or password. They field name is the "label" for the field in the 1Password GUI.

$ 1pass -p MyBankAccount pin
1234

1pass has special support for TOTP fields -- these are fetched directly via op rather than a local cache. (Thanks to (@ev0rtex)[https://github.com/ev0rtex]). Note that this is different from using TOTP 2FA to log into your 1Password account (that is supported too -- see below)

$ 1pass -p MyBankAccount totp
9865432

FZF Integration

1pass can be nicely combined with fzf for fuzzy search and completion.

Starting with 1pass v1.5:

$ 1pass | fzf | 1pass -p -

which can be easily created as an alias in your .bashrc or equivalent:

alias fp="1pass | fzf | 1pass -p -"

In older versions: See fuzzpass.sh or fuzzpass.fish for sample integration functions.

Emacs

For the brave, a trivial Emacs wrapper library is included. E.g.

(setq freenode-nick-username (1pass--item-username "Freenode/nick1"))
(setq freenode-nick-password (1pass--item-password "Freenode/nick1"))
(setq freenode-nick-password (1pass--item-field "Freenode" "server"))

Iterm2 integration

(This work is thanks to birlog). This integration lets you select and insert passwords into programs running in iTerm2(shell). If you are tired of typing in your sudo password, this is for you.

This is effectively a clone of sudolikeaboss functionality. with the caveat that all of your passwords are available, not just ones tagged x-sudolikeaboss

Using choose (a GUI fzf clone)

in iTerm2, go to preferences, then keys, add a new key open-apple+/ to run coprocess and then copy paste in the command to run box:

export PATH="/usr/local/bin:/usr/bin"; 1pass | choose | 1pass -p -

Then start a program asking for input like sudo -s and then at the password prompt push the key you assigned earlier(open-apple+/ above) and select the password title by typing or arrowing down/up and then hit enter. It might take a second, as 1pass has to go fetch your password from 1pass, but it then should type in your password and hit enter for you.

If you run into trouble, iTerm2 should attach a little yellow bar at the top, select 'view errors' and it should then open a new window showing the output of the commands above, you will need to work through whatever issue comes up.

If you get a Command not found error You installed choose, 1pass or op other than /usr/local/bin/, you will need to edit the PATH part of the line above.

FZF will not work in place of choose, as coprocesses if they want to ask for user input need to happen in their own window.

Caching and Sessions

When using 1pass, all response data from 1Password is encrypted and then cached to ~/.1pass/cache. Sometimes this cache will be out of date -- for example if you have created a new password entry via the 1Password application. Passing -r to 1pass will force a refresh from the online 1Password vault.

Similarly, 1Password CLI sessions last for 30 minutes from the time of last use. 1pass will manage the session for you, and refresh it as needed.

2FA for 1Password

If you have turned on two-factor authentication (2FA) support for your 1Password account, then 1pass will prompt for you to enter a TOTP code when creating a session. You can either re-enter this code after every session expiration (30 minutes of inactivity), or automate entry of the code using the oath-toolkit oathtool command. If you wish to automate the 2FA process, add use_totp="1" to your config file, and follow the instructions to store the TOTP secret:

$ ./1pass -rv
please put your ${domain} totp secret into /home/me/.1pass/_totp.gpg
ex: echo \"XXXXXXXXXXXXXXXX\" | $GPG -er $email > /home/me/.1pass/_totp.gpg

License

Copyright (c) 2017-2021, David Creemer (twitter: @dcreemer) with some components from other GPL 2+ software.

GPL3

Credits

Some ideas, and a tiny bit of code are taken from pass by Jason A. Donenfeld. Please see the git commit log for contributions from others.

1pass's People

Contributors

2bithacker avatar ahesford avatar arressjay avatar busla avatar caglar10ur avatar ceaser avatar dbingham avatar dcreemer avatar ev0rtex avatar eval-on-point avatar joest67 avatar kovstas avatar maricn avatar meatcar avatar wesselvdv avatar wpcarro avatar zaph-x avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

1pass's Issues

xclip error

thank you for making this. very useful.

I changed it to xclip -i and it works for me.

$ xclip -version
xclip version 0.12
Copyright (C) 2001-2008 Kim Saunders et al.
Distributed under the terms of the GNU GPL
$ xclip -c
xclip: -c: No such file or directory

line 511: get_fields_003: command not found

First, thanks for contributing this amazing tool!

And now the bug ๐Ÿ˜„

I have a secure note in 1pass and when querying the fields for the item I get the following error:

line 511: get_fields_003: command not found

Looking at the source code, I can see that the function does not exist.

Perhaps only login items are supported?

1pass & iTerm2 integration.

Hi!

So I wanted iterm integration like sudolikeaboss did. This was quite easy, but ran into a few little issues(which I worked around).

  1. 1pass doesn't accept STDIN for the name of the item to fetch, which makes fzf and friends integration more annoying.

  2. it doesn't search default paths, like /usr/local/bin or /usr/bin

This is how I worked around the issues:

create file /usr/local/bin/1piterm

#!/bin/sh
PATH=/usr/local/bin:/usr/bin
item=`/usr/local/bin/1pass | /usr/local/bin/choose`
/usr/local/bin/1pass -p $item

in iTerm2, go to preferences, then keys, add a new key open-apple+/ to run coprocess and run /usr/local/bin/1piterm

This uses the choose app instead of fzf, but you can replace choose with fzf without harm.

This then lets you get passwords into commands from iTerm2 by pressing the openapple+/ key searching for the name in the GUI that pops up and hitting enter.

Anyways, thanks for the awesome 1pass! made doing this very easy!

GitHub Typo

The title for 1pass on GitHub has a typo. It says: "A caching wrapper for the 1Passworld CLI". I believe that it should say '1Password CLI".

xclip command when copying get_result

Hi,
It should be xclip -selection clipboard selection instead of xclip -i.

With xclip -i nothing gets copied to the clipboard if you are using Linux.

By the way, great wrapper!
Nicolas

Disable cache & master password storage?

Hey,

is it be possible to use 1pass without the option to locally cache any entries and without storing the 1pasword account master password?

I am no security expert but I don't feel very confident in storing my master password in a local file.

Investigate local cached performance.

I wanted to switch to 1pass instead of op in order to gain speed as the core CLI tool is incredibly slow. As 1pass caches all the entries, I expected it to work instantly. But unfortunately, it doesn't.

A normal 1pass -p Google query takes ~2 seconds.

What can be the cause of this? Maybe it's the gpg keys decryption? Any ideas? ๐Ÿ˜„

Support TFA for 1password accounts

I have TFA enabled for my 1password account. Unfortunately, 1pass can't handle this and instead of letting me input the token, the TFA prompt instantly returns and fails.

signing in to xxx.1password.com [email protected]
Enter your six-digit authentication code: [LOG] 2019/03/17 12:53:25 (ERROR) Incorrect One-Time Password length. Expected 6.
1pass failed to signin to xxx.1password.com

It'd be great if TFA support could be added.

Can't login, what am I missing?

I followed the instructions, created a _master.gpg and _secret.gpg files, but when I try:

> 1pass -rv

I got:

checking for op
checking for jq
checking for /usr/local/Cellar/gnupg/2.3.1_1/bin/gpg
checking for expect
signing in to my.1password.com <hiding email>
gpg: _master.gpg: skipped: No public key
gpg: [stdin]: encryption failed: No public key

And I have a gpg key created:

> gpg --list-public-keys
/Users/leonnardo.rabello/.gnupg/pubring.kbx
-------------------------------------------
pub   rsa2048 2021-06-18 [SC]
      D0040C15366FE9698F36D645032984594CD300AF
uid           [ultimate] Leonnardo Rabello <hiding email>
sub   rsa2048 2021-06-18 [E]

What am I missing?

Show which vault passwords come from

I have more than one vault where passwords in different vaults may have the same name. It'd be nice to have the option to show the vault after or before the item name like

Vault : Item
Item : Vault

Or something of the sort

Allow tighter integration with `fzf`

Would be nice that instead of directly copying passwords with fzf, there was a way to invoke 1pass to display the details (overview) of the login/note/etc in the fzf preview pane.

Rationale

  1. I sometimes have logins/notes/etc. in multiple vaults that have similar or same name, and are for different users.
  2. Currently only thing that can be previewed with 1pass is list of fields available on the item and the associated password (or note content). The latter is dangerous to be displayed due to over-the-sholder eavesdropping, and the former is not very usable if we need to distinguish between users or URLs of the items.
  3. I could use op directly for that, but if 1pass already provides a caching layer, I'd prefer to use it. Also, I like having a single interface authenticating me.

add support for multiple accounts

Currently 1pass only manages credentials for a single account. Add support for multiple accounts, preferably not forcing the user to remember which one to use.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.