Skip to content

Commit fbfbb26

Browse files
committed
fix(ci): 将 gosec 集成到 golangci-lint 解决安全扫描超时
standalone gosec 扫描 24 万行 Go 代码在 CI 中持续超时, 将其作为 golangci-lint 的内置 linter 运行,复用 AST 解析和缓存大幅提速。 - 在 .golangci.yml 中启用 gosec 并迁移原有排除规则 - golangci-lint timeout 从 5m 提升到 30m - 从 security-scan.yml 移除 standalone gosec 步骤 - 删除不再需要的 .gosec.json 配置文件
1 parent 493bd18 commit fbfbb26

4 files changed

Lines changed: 18 additions & 12 deletions

File tree

.github/workflows/backend-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,5 @@ jobs:
4343
uses: golangci/golangci-lint-action@v9
4444
with:
4545
version: v2.7
46-
args: --timeout=5m
46+
args: --timeout=30m
4747
working-directory: backend

.github/workflows/security-scan.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,6 @@ jobs:
2929
run: |
3030
go install golang.org/x/vuln/cmd/govulncheck@latest
3131
govulncheck ./...
32-
- name: Run gosec
33-
working-directory: backend
34-
run: |
35-
go install github.com/securego/gosec/v2/cmd/gosec@latest
36-
# exclude ent/ — auto-generated ORM code, not subject to manual security review
37-
gosec -conf .gosec.json -severity high -confidence high -exclude-generated -exclude-dir=ent ./...
3832
3933
frontend-security:
4034
runs-on: ubuntu-latest

backend/.golangci.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ linters:
55
enable:
66
- depguard
77
- errcheck
8+
- gosec
89
- govet
910
- ineffassign
1011
- staticcheck
@@ -42,6 +43,22 @@ linters:
4243
desc: "handler must not import gorm"
4344
- pkg: github.com/redis/go-redis/v9
4445
desc: "handler must not import redis"
46+
gosec:
47+
excludes:
48+
- G101
49+
- G103
50+
- G104
51+
- G109
52+
- G115
53+
- G201
54+
- G202
55+
- G301
56+
- G302
57+
- G304
58+
- G306
59+
- G404
60+
severity: high
61+
confidence: high
4562
errcheck:
4663
# Report about not checking of errors in type assertions: `a := b.(MyStruct)`.
4764
# Such cases aren't reported by default.

backend/.gosec.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)