op-cli
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese1Password CLI (op
) — Secure Handling
op1Password CLI(op
)——安全操作规范
opCore Rule: Never Print Secrets
核心规则:绝不打印密钥
NEVER use commands that would print secret values into the conversation. Always pipe directly to the consuming tool or use / redaction to verify without exposing.
opwc -cbash
undefined绝对不要使用会将密钥值输出到会话中的命令。应始终直接通过管道传递给消费工具,或使用/脱敏方式在不暴露内容的情况下进行验证。
opwc -cbash
undefinedWRONG — would print secret to stdout (do not run)
错误示例——会将密钥打印到标准输出(请勿执行)
op item get ITEM_ID --vault VAULT --fields label=PASSWORD --reveal
op item get ITEM_ID --vault VAULT --fields label=PASSWORD --reveal
RIGHT — pipe directly to consumer
正确示例——直接通过管道传递给消费工具
op item get ITEM_ID --vault VAULT --fields label=PASSWORD --reveal |
wrangler secret put SECRET_NAME --env ENV
wrangler secret put SECRET_NAME --env ENV
op item get ITEM_ID --vault VAULT --fields label=PASSWORD --reveal |
wrangler secret put SECRET_NAME --env ENV
wrangler secret put SECRET_NAME --env ENV
RIGHT — verify a value exists without exposing it
正确示例——在不暴露内容的情况下验证值是否存在
op item get ITEM_ID --vault VAULT --fields label=PASSWORD --reveal 2>/dev/null | wc -c
undefinedop item get ITEM_ID --vault VAULT --fields label=PASSWORD --reveal 2>/dev/null | wc -c
undefinedItem Titles with Slashes
包含斜杠的条目名称
Many 1Password items use path-style titles (e.g. ). The URI format breaks with these because it uses as a delimiter.
pool-party/testnet-pool-party-public/credentialsop:///bash
undefined许多1Password条目使用路径式名称(例如)。URI格式会因此失效,因为它使用作为分隔符。
pool-party/testnet-pool-party-public/credentialsop:///bash
undefinedBROKEN — too many '/' segments
失效示例——斜杠分段过多
op read "op://pool-party-testnet/pool-party/testnet-pool-party-public/credentials/PASSWORD"
op read "op://pool-party-testnet/pool-party/testnet-pool-party-public/credentials/PASSWORD"
ERROR: too many '/': secret references should match op://<vault>/<item>[/<section>]/<field>
错误:斜杠数量过多:密钥引用应符合 op://<vault>/<item>[/<section>]/<field> 格式
WORKS — use item ID instead (avoid printing values)
有效示例——改用条目ID(避免输出值)
op item get ITEM_ID --vault VAULT --fields label=FIELD --reveal 2>/dev/null | wc -c
undefinedop item get ITEM_ID --vault VAULT --fields label=FIELD --reveal 2>/dev/null | wc -c
undefinedDiscovery Workflow
发现流程
When you don't know the item ID:
bash
undefined当你不知道条目ID时:
bash
undefined1. List items in a vault to find the title and ID
1. 列出指定保险库中的条目,找到名称和ID
op item list --vault VAULT_NAME
op item list --vault VAULT_NAME
2. Use the ID (first column) for all subsequent reads
2. 使用ID(第一列)执行后续所有读取操作
op item get ITEM_ID --vault VAULT_NAME --fields label=FIELD_NAME --reveal 2>/dev/null | wc -c
undefinedop item get ITEM_ID --vault VAULT_NAME --fields label=FIELD_NAME --reveal 2>/dev/null | wc -c
undefinedReading Multiple Fields from One Item
从单个条目读取多个字段
bash
undefinedbash
undefinedVerify which fields exist (safe — shows labels not values)
验证存在哪些字段(安全操作——仅显示标签不显示值)
op item get ITEM_ID --vault VAULT_NAME --format json 2>/dev/null |
python3 -c "import json,sys; [print(f['label']) for s in json.load(sys.stdin).get('fields',[]) for f in [s] if f.get('label')]"
python3 -c "import json,sys; [print(f['label']) for s in json.load(sys.stdin).get('fields',[]) for f in [s] if f.get('label')]"
op item get ITEM_ID --vault VAULT_NAME --format json 2>/dev/null |
python3 -c "import json,sys; [print(f['label']) for s in json.load(sys.stdin).get('fields',[]) for f in [s] if f.get('label')]"
python3 -c "import json,sys; [print(f['label']) for s in json.load(sys.stdin).get('fields',[]) for f in [s] if f.get('label')]"
Pipe each field to its destination
将每个字段通过管道传递到目标位置
op item get ITEM_ID --vault VAULT --fields label=USERNAME --reveal | consumer_cmd ...
op item get ITEM_ID --vault VAULT --fields label=PASSWORD --reveal | consumer_cmd ...
undefinedop item get ITEM_ID --vault VAULT --fields label=USERNAME --reveal | consumer_cmd ...
op item get ITEM_ID --vault VAULT --fields label=PASSWORD --reveal | consumer_cmd ...
undefinedCommon Piping Patterns
常见管道使用模式
Cloudflare Workers (wrangler)
Cloudflare Workers(wrangler)
bash
op item get ITEM_ID --vault VAULT --fields label=PASSWORD --reveal | \
npx wrangler secret put POOL_PARTY_PUBLIC_PASSWORD --env testnetbash
op item get ITEM_ID --vault VAULT --fields label=PASSWORD --reveal | \
npx wrangler secret put POOL_PARTY_PUBLIC_PASSWORD --env testnetEnvironment Variable (subshell)
环境变量(子shell)
bash
SECRET="$(op item get ITEM_ID --vault VAULT --fields label=TOKEN --reveal 2>/dev/null)"bash
SECRET="$(op item get ITEM_ID --vault VAULT --fields label=TOKEN --reveal 2>/dev/null)"Use $SECRET in subsequent commands within the same shell — it won't appear in output
在同一个shell的后续命令中使用$SECRET——它不会出现在输出中
undefinedundefinedkubectl
kubectl
bash
op item get ITEM_ID --vault VAULT --fields label=PASSWORD --reveal | \
kubectl create secret generic my-secret --from-file=password=/dev/stdinbash
op item get ITEM_ID --vault VAULT --fields label=PASSWORD --reveal | \
kubectl create secret generic my-secret --from-file=password=/dev/stdinVerification Without Exposure
无暴露验证
bash
undefinedbash
undefinedCheck a value is non-empty (char count)
检查值是否非空(字符计数)
op item get ITEM_ID --vault VAULT --fields label=PASSWORD --reveal 2>/dev/null | wc -c
op item get ITEM_ID --vault VAULT --fields label=PASSWORD --reveal 2>/dev/null | wc -c
Compare two sources match (exit code only)
比较两个来源是否匹配(仅返回退出码)
if cmp -s <(op item get ID1 --vault V --fields label=F --reveal 2>/dev/null)
<(op item get ID2 --vault V --fields label=F --reveal 2>/dev/null); then echo "match" else echo "differ" fi
<(op item get ID2 --vault V --fields label=F --reveal 2>/dev/null); then echo "match" else echo "differ" fi
undefinedif cmp -s <(op item get ID1 --vault V --fields label=F --reveal 2>/dev/null)
<(op item get ID2 --vault V --fields label=F --reveal 2>/dev/null); then echo "match" else echo "differ" fi
<(op item get ID2 --vault V --fields label=F --reveal 2>/dev/null); then echo "match" else echo "differ" fi
undefinedTroubleshooting
故障排查
| Error | Cause | Fix |
|---|---|---|
| Item title has slashes, | Use item ID with |
| Wrong vault or title mismatch | Run |
| Empty output | Missing | Add |
| Session expired | Run |
| 错误 | 原因 | 解决方法 |
|---|---|---|
| 条目名称包含斜杠, | 使用条目ID搭配 |
| 保险库错误或名称不匹配 | 执行 |
| 输出为空 | 缺少 | 添加 |
| 会话已过期 | 执行 |