Files
nexus/wiki/concepts/Gatekeeper.md
2026-04-27 20:02:52 +08:00

70 lines
2.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Gatekeeper
> macOS 的安全机制,用于验证应用程序是否来自已识别的开发者可信来源。
## Overview
Gatekeeper 是 macOS 的应用安全验证系统,旨在保护用户免受恶意软件的侵害。它会检查应用程序的来源和签名状态,拒绝运行未授权的软件。
## How It Works
Gatekeeper 会在用户尝试运行从互联网下载的应用程序时触发验证流程:
1. 检查应用是否来自 App Store
2. 检查是否有有效的 Developer ID 签名
3. 检查是否被标记为已隔离quarantined
## Quarantine Attribute
macOS 使用扩展属性Extended Attributes来标记从互联网下载的文件
- `com.apple.quarantine`:标记文件来自互联网下载
- `com.apple.metadata`:包含下载来源 URL 等元数据
## Removing Quarantine
```bash
# 递归移除 quarantine 属性(适用于目录)
xattr -rd com.apple.quarantine /path/to/application/
# 验证(无输出表示解除成功)
xattr /path/to/application/binary
# 查看 quarantine 状态
xattr -l /path/to/application/binary
```
## Gatekeeper Modes
```bash
# 查看当前 Gatekeeper 状态
spctl --status
# 允许所有来源(不推荐,存在安全风险)
sudo spctl --master-disable
# 查看应用状态
spctl --assess --verbose /path/to/application
```
## Use Cases
- **Homebrew**:安装后需解除 quarantine 才能运行
- **FRP**:从 GitHub 下载的二进制文件需解除限制
- **第三方工具**:任何未签名的可执行文件
## Security Considerations
| 方法 | 安全性 | 适用场景 |
|------|--------|----------|
| Developer ID 签名 | 最高 | 正式发布的软件 |
| App Store | 高 | 仅限 App Store 应用 |
| 解除 quarantine | 低 | 自托管工具/开发环境 |
## Best Practices
1. **仅对可信来源解除限制**:如 GitHub Release 官方二进制文件
2. **使用 -r 递归参数**:确保目录内所有文件解除限制
3. **验证文件完整性**:下载后检查 SHA256 校验和
4. **保持 Gatekeeper 开启**:除非完全了解风险,否则不要禁用
## Related Concepts
- [[launchd]] — macOS 服务管理器
- [[frp]] — 需要解除 Gatekeeper 才能运行
- [[Mac Mini M4]] — 需要处理 Gatekeeper 问题
## References
- Apple Support: Safely open apps on your Mac
- `man xattr`
- `man spctl`