Skip to content

Commit 1dbcd05

Browse files
Merge pull request #1 from Xander-ByteDance/main
Init gitleaks scan workflow
2 parents 7355697 + d0cc9c5 commit 1dbcd05

2 files changed

Lines changed: 94 additions & 0 deletions

File tree

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Shared Gitleaks Scan
2+
3+
on:
4+
# 1. 代码推送到任何分支时触发(最常用的实时拦截)
5+
push:
6+
branches: [ "**" ]
7+
8+
# 2. 提交 Pull Request 时触发(防止合并到主分支)
9+
pull_request:
10+
11+
# 3. 合并队列触发(如果使用了 GitHub Merge Queue)
12+
merge_group:
13+
14+
# 4. 新增:允许手动点击按钮触发(用于安全审计或测试新规则)
15+
workflow_dispatch:
16+
17+
workflow_call:
18+
# 允许调用方传入参数(可选)
19+
inputs:
20+
config_path:
21+
required: false
22+
type: string
23+
default: "./gitleaks.toml"
24+
description: "Path to gitleaks config file"
25+
secrets:
26+
# 如果需要访问私有仓库下载配置,可能需要 Token
27+
ORG_PAT:
28+
required: false
29+
30+
jobs:
31+
gitleaks:
32+
name: Gitleaks Scan
33+
runs-on: ubuntu-latest
34+
steps:
35+
- name: Checkout Source Code
36+
uses: actions/checkout@v4
37+
with:
38+
fetch-depth: 0 # Gitleaks 需要完整的 git 历史
39+
40+
- name: Checkout Security Config
41+
uses: actions/checkout@v4
42+
with:
43+
repository: volcengine/security-ops # 替换为你的组织名/仓库名
44+
path: security-ops-config
45+
46+
- name: Run Gitleaks
47+
id: gitleaks # 添加 ID 以便后续步骤引用状态
48+
uses: gitleaks/gitleaks-action@v2
49+
env:
50+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
51+
GITLEAKS_LICENSE: ${{ secrets.GITLEAKS_LICENSE }}
52+
GITLEAKS_CONFIG: "security-ops-config/gitleaks.toml"
53+
54+
# 新增:当扫描失败时,在 Actions 摘要中显示具体的豁免指引
55+
- name: Report Gitleaks Failure
56+
if: failure() # 仅在扫描失败时运行
57+
run: |
58+
# 仅保留这一行 Error Annotation,用于在文件变动处高亮提醒
59+
echo "::error title=Gitleaks Scan Failed::发现潜在的敏感信息泄露!"
60+
61+
# 将详细说明输出到 Job Summary (支持 Markdown)
62+
cat <<EOF >> $GITHUB_STEP_SUMMARY
63+
## 🚨 Gitleaks Scan Failed
64+
发现潜在的敏感信息泄露!请检查代码。
65+
66+
**重要提示:** 一旦确认发生敏感信息泄露,应默认该信息已被公开访问。请务必立即采取止损措施,包括但不限于轮转密钥和吊销证书。
67+
68+
### 如何处理误报 (False Positive)?
69+
如果确认是误报,请在代码中添加豁免注释:
70+
71+
**方法 1 (单行):**
72+
\`\`\`javascript
73+
const token = 'fake'; // gitleaks:allow
74+
\`\`\`
75+
76+
EOF

gitleaks.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
title = "Organization Gitleaks Config"
2+
3+
[extend]
4+
useDefault = true
5+
6+
[allowlist]
7+
description = "Global allowlist for the organization"
8+
paths = [
9+
'''go\.sum''',
10+
'''yarn\.lock'''
11+
]
12+
13+
# 这里可以扩展自定义规则,例如内部特定的 Token 格式
14+
# [[rules]]
15+
# id = "internal-api-token"
16+
# description = "Internal API Token"
17+
# regex = '''IT-[a-z0-9]{16}'''
18+
# tags = ["secret", "internal"]

0 commit comments

Comments
 (0)