using-sops
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseUsing sops
使用sops
Repositories that use this layout commit their secrets to git as sops-encrypted
dotenv files, one per deployment environment: , . The
files decrypt with age identities. There is no , no secrets service, and no session
to log in to. Every checkout, worktree, and cloud sandbox has the encrypted files at
clone; the only input anywhere is an age private key.
secrets/dev.envsecrets/prod.env.envpnpm secretstools/secrets.tssops采用此结构的仓库会将密钥以sops加密的dotenv文件形式提交至Git,每个部署环境对应一个文件:、。这些文件通过age身份进行解密。无需文件、密钥服务,也无需登录会话。每次克隆代码时,所有检出目录、工作树和云沙箱都会包含加密文件;唯一需要输入的内容就是age私钥。
secrets/dev.envsecrets/prod.env.envpnpm secretstools/secrets.tssopsIdentities
身份标识
| Identity | Scope | Where the private key lives | Decrypts |
|---|---|---|---|
| user-wide | | |
| user-wide | the user's password manager | every file |
| per project | that project's production platform only | |
.sops.yamlagentpersonalprod| 身份标识 | 适用范围 | 私钥存储位置 | 可解密文件 |
|---|---|---|---|
| 全局用户级 | 所有运行agent的机器上的 | |
| 全局用户级 | 用户的密码管理器 | 所有文件 |
| 项目级 | 仅对应项目的生产平台 | |
.sops.yamlagentpersonalprodAgent workflow
Agent工作流
Dev secrets are yours to manage without asking:
sh
pnpm secrets show dev # everything, decrypted
pnpm secrets get dev STRIPE_KEY
pnpm secrets set dev STRIPE_KEY sk_test_1
pnpm secrets unset dev STRIPE_KEY
pnpm secrets exec dev -- node apps/worker/src/main.tsexecSOPS_AGE_KEY*Prod secrets need elevation. When a task requires reading or writing :
prod.env- Check for in this checkout. If present, prod commands work; carry on.
.age/elevated - If absent, ask the user to run, in a terminal of their own:
(or however their password manager prints the key). Say why you need it.
op read 'op://Personal/age-personal/private key' | pnpm secrets elevate - Elevation is per checkout and lasts until is deleted. Do not copy it into another worktree.
.age/elevated
When you add a variable, add it to the env schema and to every you can
decrypt. If you cannot decrypt prod, say so in the PR: the typed env check fails the prod
boot until the value is set, which is the intended signal.
secrets/<env>.envNever write an into a tracked file, a log, or a commit. Never put or in a cloud
environment.
AGE-SECRET-KEY-...personalprod开发环境密钥可自行管理,无需申请:
sh
pnpm secrets show dev # 解密并显示所有密钥
pnpm secrets get dev STRIPE_KEY
pnpm secrets set dev STRIPE_KEY sk_test_1
pnpm secrets unset dev STRIPE_KEY
pnpm secrets exec dev -- node apps/worker/src/main.tsexecSOPS_AGE_KEY*生产环境密钥需要权限提升。当任务需要读取或写入时:
prod.env- 检查当前检出目录中是否存在文件。如果存在,生产环境相关命令可正常执行;继续操作即可。
.age/elevated - 如果不存在,请让用户在自己的终端中运行以下命令:
(或使用其密码管理器输出私钥的其他方式)。同时说明需要权限的原因。
op read 'op://Personal/age-personal/private key' | pnpm secrets elevate - 权限提升仅对当前检出目录有效,直到文件被删除。请勿将该文件复制到其他工作树中。
.age/elevated
添加变量时,请将其添加到环境变量 schema 中,以及所有你能解密的文件中。如果你无法解密生产环境文件,请在PR中说明:类型化环境检查会导致生产环境启动失败,直到变量被设置,这是预期的提示信号。
secrets/<env>.env切勿将写入已追踪的文件、日志或提交记录中。切勿将或密钥放入云环境中。
AGE-SECRET-KEY-...personalprodHuman setup
人工配置
For the one-time steps (generating keys, installing and , wiring the
key into agent tools and cloud sandboxes, configuring the prod platform, and rotating
keys), read . When the user asks
to be reminded of the steps, walk them through that file in order.
sopsageagentreferences/setup.mdFor the sops and age behavior the design relies on (identity union, ,
limitations, dotenv quirks), read .
updatekeysexec-envreferences/sops-notes.md关于一次性配置步骤(生成密钥、安装和工具、将密钥接入agent工具和云沙箱、配置生产平台以及密钥轮换),请阅读文件。当用户需要提醒配置步骤时,请引导他们按顺序阅读该文件。
sopsageagentreferences/setup.md关于本设计所依赖的sops和age特性(身份联合、、限制、dotenv特性),请阅读文件。
updatekeysexec-envreferences/sops-notes.md