简单的 1Password CLI 通过查询本地 sqlite 数据库来列出和解密秘密
项目描述
1密码本地搜索
这是一个非官方工具,专注于列出和解密秘密,与原生 op CLI 相比具有更高的性能
1密码版本兼容性
- 1.0.0 以下的版本适用于 1Password7
- 1.0.0 之后的版本适用于 1Password8
如何使用 ?
此工具不替代op
1Password 的官方 CLI。您仍然需要它来执行登录和获取会话密钥。
因此,请确保您已在您的环境中注册了 OP_SESSION_team。
数据库路径
该脚本将尝试根据您的平台以标准路径搜索数据库。它失败了,或者如果你想使用另一个数据库,你可以使用你想使用的 B5.sqlite 数据库的路径设置环境变量 ONEPASSWORD_LOCAL_DATABASE_PATH。
获取解密值
op-local get uuid [field] [--use-custom-uuid] [--use-lastpass-uuid]
TOTP
如果您创建了一个字段类型为“一次性密码”且名称为“一次性密码”的字段,则可以使用特殊字段检索 totp 的值totp
。例如:op-local get uuid totp
。
列出项目
op-local list [--format='{uuid} {title}'] [--filter=''] [--output-encoding=json]
格式字符串允许您自定义列表项的输出格式。您可以使用任何字段,将使用任何部分中的第一个匹配项。
op-local list --format='{uuid}|{title}|{username}|{password}'
过滤器将只返回标题包含过滤器字符串的条目。
通过附加 ,--output-encoding=json
您可以生成正确的 JSON 编码列表。例如:
op-local list --format='{{"uuid": "{uuid}", "title": "{title}"}},' --output-encoding=json
已通过身份验证
op-local is-authenticated
检查 1Password 会话是否已打开。
UUID 映射
当您将项目从一个保管库移动到另一个保管库时,1Password 中的 uuid 会发生变化。为防止此问题,已实现自定义 uuid 映射功能。
您需要在每个项目上添加一个名为UUID
.
然后运行op-local mapping update
生成映射表关系。
您现在可以通过将标志UUID
附加到命令来使用您自己的项目。--use-custom-uuid
get
--use-lastpass-uuid
flag 做同样的事情,但有一个LASTPASS_ID
字段。
您可以通过运行显示 UUID 映射op-local mapping list
。
由于 0.16 和 UUID v4、Lastpass ID 和 1Password UUID 完全不同,搜索将在有关给出哪种类型的 uuid 的适当字段上执行,而无需使用任何特殊标志。
多个帐户
本项目支持多账号解密。但是,请记住,您需要:
- 使用 1Password 桌面客户端的主帐户进行身份验证
- 与您要使用的其他帐户进行身份验证
已知限制
- 目前,不支持类型 E(家庭共享?)的保管库。我目前不需要这种保险库。不确定我是否会解决这个问题。
- 未与您共享的保管库不会被排除在外,并且会导致列表过程失败。我想这是一个简单的修复,将在下一个版本中出现。
- 未实施组权限。用户必须手动附加到每个保管库。
为什么这个项目?
我们使用 Ansible 来管理基础设施并使用查找插件来获取数百个秘密。我们曾经使用 LastPass,但由于 API 调用不可靠和 CLI 不受支持,我们决定放弃。本机工具的第一个基准测试op
表明,检索一个秘密大约需要 3 到 4 秒的性能非常差。由于 CLI 工具确实请求 1Password 服务器检索机密,因此性能直接受到您与服务器之间的距离的影响。
基准
获取命令
官方op cli 50,6s
性能可能取决于您与 1Password 数据中心的距离。我住在法国南部,最近的是法兰克福。
# Replace UUIDS and session key with your own values
time (for i in {1..20}; do UUIDS=('u5qwa2th7ptrb5leozq2sa2gke' 'opbyml76ircfxchjp7d5oa6lm4' ); eval "time op get item ${UUIDS[$((RANDOM % ${#UUIDS[@]}+1))]} --session="XXX" > /dev/null"; done)
op item get 6rtzezejb7saty4nbzdqsbgplu > /dev/null 1,50s user 0,09s system 60% cpu 2,655 total
op item get opbyml76ircfxchjp7d5oa6lm4 > /dev/null 1,46s user 0,08s system 61% cpu 2,491 total
op item get opbyml76ircfxchjp7d5oa6lm4 > /dev/null 1,50s user 0,09s system 63% cpu 2,527 total
op item get opbyml76ircfxchjp7d5oa6lm4 > /dev/null 1,46s user 0,08s system 62% cpu 2,461 total
op item get opbyml76ircfxchjp7d5oa6lm4 > /dev/null 1,49s user 0,09s system 64% cpu 2,449 total
op item get 6rtzezejb7saty4nbzdqsbgplu > /dev/null 1,50s user 0,09s system 63% cpu 2,509 total
op item get 6rtzezejb7saty4nbzdqsbgplu > /dev/null 1,54s user 0,10s system 63% cpu 2,593 total
op item get opbyml76ircfxchjp7d5oa6lm4 > /dev/null 1,50s user 0,09s system 63% cpu 2,512 total
op item get opbyml76ircfxchjp7d5oa6lm4 > /dev/null 1,48s user 0,09s system 62% cpu 2,527 total
op item get opbyml76ircfxchjp7d5oa6lm4 > /dev/null 1,47s user 0,08s system 59% cpu 2,618 total
op item get opbyml76ircfxchjp7d5oa6lm4 > /dev/null 1,55s user 0,09s system 59% cpu 2,759 total
op item get opbyml76ircfxchjp7d5oa6lm4 > /dev/null 1,50s user 0,09s system 61% cpu 2,567 total
op item get 6rtzezejb7saty4nbzdqsbgplu > /dev/null 1,52s user 0,10s system 62% cpu 2,597 total
op item get 6rtzezejb7saty4nbzdqsbgplu > /dev/null 1,48s user 0,09s system 61% cpu 2,536 total
op item get opbyml76ircfxchjp7d5oa6lm4 > /dev/null 1,56s user 0,10s system 62% cpu 2,649 total
op item get 6rtzezejb7saty4nbzdqsbgplu > /dev/null 1,57s user 0,11s system 56% cpu 2,991 total
op item get opbyml76ircfxchjp7d5oa6lm4 > /dev/null 1,81s user 0,14s system 54% cpu 3,597 total
op item get opbyml76ircfxchjp7d5oa6lm4 > /dev/null 1,64s user 0,12s system 57% cpu 3,051 total
op item get 6rtzezejb7saty4nbzdqsbgplu > /dev/null 1,75s user 0,14s system 61% cpu 3,050 total
op item get opbyml76ircfxchjp7d5oa6lm4 > /dev/null 1,55s user 0,10s system 59% cpu 2,786 total
( for i in {1..20}; do; IDS=('opbyml76ircfxchjp7d5oa6lm4' ) ; eval ; done; ) 30,83s user 1,98s system 60% cpu 53,935 total
op-local 2,3s(快 22 倍)
time (for i in {1..20}; do UUIDS=('6rtzezejb7saty4nbzdqsbgplu' 'opbyml76ircfxchjp7d5oa6lm4' ) FIELDS=('password' 'title'); eval "time op-local get ${UUIDS[$((RANDOM % ${#UUIDS[@]}+1))]} ${FIELDS[$((RANDOM % ${#FIELDS[@]}+1))]} > /dev/null"; done)
op-local get opbyml76ircfxchjp7d5oa6lm4 title > /dev/null 0,08s user 0,03s system 61% cpu 0,179 total
op-local get 6rtzezejb7saty4nbzdqsbgplu title > /dev/null 0,07s user 0,03s system 90% cpu 0,109 total
op-local get opbyml76ircfxchjp7d5oa6lm4 title > /dev/null 0,07s user 0,03s system 92% cpu 0,108 total
op-local get 6rtzezejb7saty4nbzdqsbgplu title > /dev/null 0,07s user 0,03s system 91% cpu 0,110 total
op-local get opbyml76ircfxchjp7d5oa6lm4 password > /dev/null 0,07s user 0,03s system 91% cpu 0,109 total
op-local get 6rtzezejb7saty4nbzdqsbgplu title > /dev/null 0,07s user 0,03s system 91% cpu 0,110 total
op-local get 6rtzezejb7saty4nbzdqsbgplu title > /dev/null 0,07s user 0,03s system 91% cpu 0,109 total
op-local get 6rtzezejb7saty4nbzdqsbgplu title > /dev/null 0,07s user 0,03s system 92% cpu 0,108 total
op-local get 6rtzezejb7saty4nbzdqsbgplu password > /dev/null 0,08s user 0,03s system 91% cpu 0,116 total
op-local get 6rtzezejb7saty4nbzdqsbgplu password > /dev/null 0,07s user 0,03s system 92% cpu 0,109 total
op-local get opbyml76ircfxchjp7d5oa6lm4 password > /dev/null 0,08s user 0,03s system 92% cpu 0,113 total
op-local get 6rtzezejb7saty4nbzdqsbgplu password > /dev/null 0,08s user 0,03s system 93% cpu 0,124 total
op-local get opbyml76ircfxchjp7d5oa6lm4 title > /dev/null 0,08s user 0,03s system 93% cpu 0,111 total
op-local get opbyml76ircfxchjp7d5oa6lm4 password > /dev/null 0,08s user 0,03s system 93% cpu 0,114 total
op-local get 6rtzezejb7saty4nbzdqsbgplu password > /dev/null 0,08s user 0,03s system 93% cpu 0,113 total
op-local get 6rtzezejb7saty4nbzdqsbgplu title > /dev/null 0,08s user 0,03s system 92% cpu 0,113 total
op-local get opbyml76ircfxchjp7d5oa6lm4 title > /dev/null 0,08s user 0,03s system 93% cpu 0,113 total
op-local get 6rtzezejb7saty4nbzdqsbgplu title > /dev/null 0,08s user 0,03s system 93% cpu 0,117 total
op-local get opbyml76ircfxchjp7d5oa6lm4 password > /dev/null 0,08s user 0,03s system 92% cpu 0,122 total
op-local get opbyml76ircfxchjp7d5oa6lm4 title > /dev/null 0,08s user 0,03s system 92% cpu 0,113 total
( for i in {1..20}; do; UUIDS=('6rtzezejb7saty4nbzdqsbgplu' ) FIELDS=( 'title) 1,52s user 0,57s system 90% cpu 2,322 total
列出命令
2,1s 列出和解密 3290 个条目
time op-local list | wc -l
3290
op-local list 0,68s user 0,05s system 99% cpu 0,741 total
wc -l 0,00s user 0,00s system 0% cpu 0,740 total
发展
开发需求列在 requirements/dev.txt
mkvirtualenv3 op-local-search
workon op-local-search
pip3 install -r requirements/dev.txt
测试
测试是通过pytest
. 1.0.0 之后的版本没有更新测试。它需要一个新格式为 1Password8 的新测试数据库。
致谢
如果没有David Schuetz 的出色工作,这个工具是不可能实现的。(@dschuetz) https://github.com/dschuetz/1password
我还要感谢 1Password 的支持团队,特别是 @cohix,它帮助我了解了 1Password 的其余内部结构。
还要非常感谢 Joël Franusic 和他在 JWK https://github.com/jpf/okta-jwks-to-pem上的工作。这帮助我极大地提高了应用程序的性能。
非常感谢大家!
执照
GPLv3
项目详情
下载文件
下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。