chore: 新增签名凭据 pre-commit 拦截钩子,防止 signingConfigs 入库

This commit is contained in:
AndyChen1024
2026-09-11 17:26:33 +08:00
parent a25eab2d61
commit a0e0758b6b
3 changed files with 61 additions and 2 deletions

View File

@@ -33,12 +33,38 @@ hvigorw assembleHap --mode module -p product=default -p buildMode=release
## 签名 Signing
`build-profile.json5` 里 `signingConfigs` 目前为**空**,且 `products[].signingConfig` 引用了 `"default"` —— **签名尚未配置**。
### 现状与原则
- `build-profile.json5` 里 `signingConfigs` 在**仓库中必须保持为空 `[]`**(`products[].signingConfig` 仍引用 `"default"`)——签名是机器相关的,禁止入库。
- 真正的密钥物料(`.p12` / `.cer` / `.p7b`)由 DevEco 生成在 `~/.ohos/config/` 下,**本来就在仓库外**;`build-profile.json5` 里只有「文件路径 + 加密后的密码」,但同样属敏感信息,不得提交。
### 本地配置签名(不入库)
要跑真机/模拟器需先配置签名:
- DevEco Studio → File → Project Structure → Signing Configs → 勾选自动签名(登录华为账号)。
- 或手动配置 `.p12` + `.cer` / `.p7b`。
> 该文件的签名部分属于 **Agent 禁止修改** 范围(见 `AGENTS.md`)。
DevEco 自动签名会把凭据写进 `build-profile.json5`,这属于**本地未提交状态**,不要 `git add` 它。
### 防泄露:pre-commit 钩子
仓库内置了 pre-commit 钩子 `scripts/git-hooks/pre-commit`:只要暂存区的 `build-profile.json5` 出现 `keyPassword` / `storePassword` / `certpath` 等签名字段,就**拒绝提交**。
每个克隆启用一次:
```bash
git config core.hooksPath scripts/git-hooks
```
验证:临时在 `build-profile.json5` 里塞一个 `"keyPassword"` 再 `git add build-profile.json5 && git commit`,应被拦截。
> 确需临时绕过时用 `git commit --no-verify`(仅应急,不建议)。
### 彻底外部化(可选)
若想连本地也不出现凭据,可走「动态配置签名」:用 `hvigorfile.ts` 从 gitignore 的本地文件或环境变量读取签名注入,让 `build-profile.json5` 始终保持空。参考华为官方《基于动态配置签名的多人协同开发应用签名解决方案》。
> `build-profile.json5` 的签名部分属于 **Agent 禁止修改** 范围(见 `AGENTS.md`)。
## 产品与构建模式 Products & Build Modes