文章摘要
ENVeil是一款保护.env文件中敏感信息的工具,通过将密钥存储在本地加密库而非明文文件中,运行时直接注入应用,避免AI工具或他人窥探。它解决了.env文件被AI代码工具读取的安全隐患,无需依赖第三方服务。
文章总结
ENVeil:保护.env机密信息不被AI窥探的开源工具
项目概述 ENVeil是一款开源工具,旨在解决AI编程工具(如Claude Code、Copilot等)可能读取项目目录中敏感信息的问题。它通过加密存储和运行时注入的方式,确保.env文件中的机密信息永远不会以明文形式存在于磁盘上。
核心功能 1. 加密存储机制 - 使用AES-256-GCM加密算法 - 采用Argon2id密钥派生函数(64MB内存,3次迭代) - 每次写入生成12字节随机nonce,防止nonce重用
- 安全特性
- 主密码输入不显示且不存入shell历史
- 内存中的密钥和密码会被清零
- 存储文件无法通过二进制检查或字符串提取获取信息
- 任何篡改都会导致解密失败
- 使用方式
- .env文件中使用"ev://"前缀引用加密值
- 支持通过命令行工具管理密钥
- 运行时将解密后的值直接注入子进程环境
安装与使用
1. 安装方式
- 通过Cargo安装:cargo install enveil
- 从源码编译(需要Rust 1.70+)
- 基本操作
- 初始化项目:
enveil init - 添加密钥:
enveil set key_name - 运行应用:
enveil run -- command
- 安全验证
- 包含31项自动化测试
- 支持手动验证加密存储、nonce更新、密码错误处理等安全特性
- 提供篡改检测功能
设计理念 1. 安全原则 - 机密信息永不写入磁盘明文 - 不提供获取明文值的命令 - 所有值都通过交互式输入
- 未来规划
- 全局存储功能
- 系统密钥链集成
- 减少密码输入需求
技术细节 - 存储文件结构:12字节随机nonce + 认证密文 - 完整的环境变量解析支持 - 严格的错误处理机制
该项目受Filip Hric的解决方案启发,但采用自包含设计,不依赖第三方服务。值得注意的是,该项目本身主要使用Claude Code开发,经过大量人工验证和测试。
(注:原文中的安装命令、测试命令等具体操作细节已精简,保留了技术实现的关键信息和安全特性说明)
评论总结
以下是评论内容的总结:
支持观点
解决实际问题:加密.env文件可防止AI代理读取原始密钥,比依赖.gitignore更安全。
- "this solves a real problem... the agent never sees the raw secrets" (评论1)
- "much better than the current best practice of just hoping your .gitignore is correct" (评论1)
实用功能建议:建议增加"dry run"模式以验证配置。
- "it would be useful to have a 'dry run' mode... helps verify the config is correct" (评论1)
替代方案
使用代理和替代凭证:通过代理替换真实密钥,限制AI代理的访问范围。
- "give the agent surrogate credentials and replace them on the way out in a proxy" (评论5)
- "I’ve built this in Airut... seems to handle all the common cases" (评论5)
现有工具:推荐使用现有工具如Hashicorp Vault、sops、1Password等。
- "What about something like Hashicorp secrets?" (评论2)
- "This software has done this for years" (评论9, 关于sops)
批评与质疑
安全漏洞:加密.env文件无法防止AI代理通过其他方式获取密钥(如打印环境变量)。
- "This doesn’t really fix that it can echo the secrets and read the logs" (评论3)
- "the AI agent could simply run: enveil run -- printenv" (评论27)
过度依赖.env文件:批评开发者将生产密钥存储在本地.env文件是不安全的做法。
- "Why, WHY for the love of fucking milk and cookies are you storing production secrets in a text file on your workstation?" (评论12)
- "People have production secrets in the open on their development machines?" (评论29)
其他建议
沙盒和权限控制:建议使用沙盒技术限制AI代理的访问权限。
- "Sandbox the agent and provision unique credentials to that environment" (评论22)
- "Combine that with global default deny permissions for read & edit on your SSH, GPG keys" (评论25)
内存安全问题:指出加密方案在内存处理上的潜在漏洞。
- "Your rotation doesn’t rotate the salt...
importholds the whole plain text file in memory" (评论18)
- "Your rotation doesn’t rotate the salt...
总结
评论中既有支持加密.env文件的观点,也有对其安全性的质疑,并提出了多种替代方案(如代理、沙盒、现有工具)。核心争议在于是否应该依赖本地存储的.env文件,以及加密是否能真正解决AI代理访问密钥的问题。