Hacker News 中文摘要

RSS订阅

Vet是高风险curl | bash模式的安全网 -- Vet is a safety net for the risky curl | bash pattern

文章摘要

vet 是一个命令行工具,旨在解决常见的 curl | bash 模式的安全隐患。它允许用户检查远程脚本的变更、通过 linter 分析脚本,并在执行前要求用户明确确认。vet 的流程包括下载脚本、显示变更、自动分析脚本,并在用户确认后执行。安装 vet 本身也体现了其安全性理念,推荐通过 Homebrew 安装。

文章总结

vet:安全执行远程脚本的命令行工具

概述
vet 是一个命令行工具,旨在解决常见的 curl | bash 模式的安全隐患。它允许用户检查远程脚本的变更、通过代码检查工具(如 shellcheck)分析脚本,并在执行前要求用户明确确认。

问题背景
许多软件安装方式采用以下模式:
bash curl -sSL https://example.com/install.sh | bash
这种方式虽然方便,但存在风险:脚本可能包含恶意代码,服务器可能被攻击,或者网络错误可能导致部分脚本被执行。

解决方案:vet
vet 提供了一个安全的交互式工作流程:
1. 获取:将远程脚本下载到临时位置。
2. 对比与审查:显示脚本自上次运行以来的变更。
3. 代码检查:如果安装了 shellcheck,自动分析脚本中的潜在问题或恶意模式。
4. 确认:在执行前提示用户明确批准。
示例:
bash vet https://example.com/install.sh

安装方式
1. 推荐方式:Homebrew(macOS/Linux)
bash brew tap vet-run/vet brew install vet-run
2. 手动安装(安全优先)
- 下载安装脚本:
bash curl -o install_vet.sh https://getvet.sh/install.sh
- 审查脚本内容:
bash less install_vet.sh
- 运行安装脚本:
bash bash install_vet.sh
3. 不推荐方式:直接执行(反模式)
bash curl -sL https://getvet.sh/install.sh | bash

使用示例
- 基本用法:
bash vet <URL>
- 传递参数:
bash vet https://example.com/setup.sh --user myuser --version latest
- 非交互模式(适用于自动化环境):
bash vet --force https://my-trusted-internal-script.sh

选项
- -f, --force:跳过所有交互提示,立即执行。
- -h, --help:显示帮助信息。

技术决策
vet 依赖于 Bash 4+,以利用现代 Bash 特性(如数组、[[ ... ]]pipefail)。对于安全工具来说,牺牲 POSIX sh 兼容性以换取健壮性和可读性是必要的。

贡献指南
欢迎贡献!请遵循以下步骤:
1. Fork 仓库。
2. 创建新分支:git checkout -b feature/my-amazing-feature
3. 提交更改:git commit -am 'Add some amazing feature'
4. 推送分支:git push origin feature/my-amazing-feature
5. 提交 Pull Request。

许可证
本项目采用 MIT 许可证,详情请参阅 LICENSE 文件。

评论总结

评论主要围绕“curl | bash”模式的安全性和替代方案展开,观点分为支持和反对两派。

支持“curl | bash”的观点: 1. 便捷性:该模式跳过包管理器,适合在裸机上安装软件。 - "The whole point of 'curl|bash' is to skip dependency on package managers and install on a barebone machine." (Galanwe) - "I was hoping this would have a curl | bash installer. Was not disappointed!" (exitb)

  1. 安全性可通过工具提升:使用工具如vetvipe可以增强安全性。
    • "I like that vet, which wraps the curl | bash pattern, can be installed via the curl | bash pattern." (gchamonlive)
    • "You can also use vipe from moreutils... This will open the output of the curl command in your editor and let you review and modify it before passing it on to the shell." (networked)

反对“curl | bash”的观点: 1. 安全风险:该模式可能导致恶意脚本执行,且与下载未审计的软件风险相同。 - "Reminder that the pattern has the same risk as downloading software that you haven’t audited and verified the binary matches the source." (nailer) - "The solution to executing untrusted code is not to execute more untrusted code, especially through a tool which has not itself been 'vetted'." (bugsMarathon88)

  1. 安装方式不标准:脚本可能编写不当,导致安装过程不标准或损坏系统。
    • "My problem with curl|bash is not that the script might be malicious... It's that it may be written incompetently, or just not with users like me in mind, and so the installation gets done in some broken, brittle, or non-standard way on my system." (pxeger1)

其他观点: 1. 替代方案:使用如Nix等包管理器可以避免“curl | bash”模式。 - "Switched to nix + home-manager as a package manager to replace defacto package managers on some operating systems." (xyst)

  1. 历史对比:该模式与Windows下载安装程序类似,且现代开发中如npm和Docker也存在类似风险。
    • "we've been curl | bashing software on windows since forever, it was called 'downloading and running an installer'." (baq)

总结:评论中对“curl | bash”模式的态度分歧较大,支持者认为其便捷且可通过工具提升安全性,反对者则强调其安全风险和安装方式的不标准性。同时,部分评论提出了替代方案,如使用Nix等包管理器。