Skip to content

Commit 79a7ba8

Browse files
committed
.github security
1 parent f44f9ac commit 79a7ba8

3 files changed

Lines changed: 70 additions & 26 deletions

File tree

‎.github/workflows/go-presubmit.yml‎

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ on:
77
pull_request:
88
types: [opened, reopened, synchronize]
99

10+
permissions:
11+
contents: read
12+
1013
jobs:
1114
build:
1215
name: Go presubmit
@@ -16,10 +19,29 @@ jobs:
1619
go-version: ['1.22']
1720
steps:
1821
- name: Install Go ${{ matrix.go-version }}
19-
uses: actions/setup-go@v3
22+
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
2023
with:
2124
go-version: ${{ matrix.go-version }}
22-
- uses: actions/checkout@v3
23-
- uses: creachadair/go-presubmit-action@v2
25+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
26+
27+
- name: Security scan for dangerous Go patterns
28+
run: |
29+
# Detect go:generate directives (potential code execution)
30+
if grep -rn '//go:generate' --include='*.go' .; then
31+
echo "::error::Detected //go:generate directive - requires manual review"
32+
exit 1
33+
fi
34+
# Detect CGo usage (native code execution during build)
35+
if grep -rn 'import "C"' --include='*.go' .; then
36+
echo "::error::Detected CGo import - requires manual review"
37+
exit 1
38+
fi
39+
# Detect #cgo directives
40+
if grep -rn '#cgo' --include='*.go' .; then
41+
echo "::error::Detected #cgo directive - requires manual review"
42+
exit 1
43+
fi
44+
45+
- uses: creachadair/go-presubmit-action@4f7a734aa8275675a945fbf589734f8cf7dda58a # v2.0.3
2446
with:
2547
staticcheck-version: "2023.1.6"

‎.github/workflows/goreleaser.yml‎

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,63 @@ on:
55
branches:
66
- main
77
tags:
8-
- '*'
8+
- 'v[0-9]+.[0-9]+.[0-9]+*' # Only semver tags (v1.2.3, v1.2.3-rc1, etc.)
99
pull_request:
1010
types: [opened, reopened, synchronize]
1111

12-
permissions:
13-
contents: write
14-
1512
jobs:
16-
goreleaser:
13+
# PR and main branch: only build validation, NO goreleaser (prevents hook injection)
14+
validate:
15+
if: github.event_name == 'pull_request' || (github.event_name == 'push' && !startsWith(github.ref, 'refs/tags/'))
1716
runs-on: ubuntu-latest
17+
permissions:
18+
contents: read
1819
steps:
1920
- name: Checkout
20-
uses: actions/checkout@v4
21+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
2122

2223
- name: Set up Go
23-
uses: actions/setup-go@v4
24+
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
2425
with:
2526
go-version: 1.22
2627

27-
- name: Run GoReleaser release (SKIP publish)
28-
uses: goreleaser/goreleaser-action@v5
29-
if: startsWith(github.ref, 'refs/tags/') != true
28+
- name: Security scan for dangerous Go patterns
29+
run: |
30+
if grep -rn '//go:generate\|import "C"\|#cgo' --include='*.go' .; then
31+
echo "::error::Detected potentially dangerous Go directive"
32+
exit 1
33+
fi
34+
35+
- name: Build
36+
run: go build -v ./...
37+
38+
- name: Test
39+
run: go test -v ./...
40+
41+
# Release: only on semver tags, with environment protection
42+
release:
43+
if: startsWith(github.ref, 'refs/tags/v')
44+
runs-on: ubuntu-latest
45+
environment: production
46+
permissions:
47+
contents: write
48+
id-token: write
49+
steps:
50+
- name: Checkout
51+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
3052
with:
31-
distribution: goreleaser
32-
version: latest
33-
args: release --clean --skip=publish --snapshot
34-
env:
35-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
53+
fetch-depth: 0
54+
55+
- name: Set up Go
56+
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
57+
with:
58+
go-version: 1.22
3659

37-
- name: Run GoReleaser release
38-
uses: goreleaser/goreleaser-action@v5
39-
if: startsWith(github.ref, 'refs/tags/')
60+
- name: Run GoReleaser
61+
uses: goreleaser/goreleaser-action@9c156ee8a17a598857849441385a2041ef570552 # v6.3.0
4062
with:
4163
distribution: goreleaser
42-
version: latest
64+
version: "2.6.1"
4365
args: release --clean
4466
env:
4567
GITHUB_TOKEN: ${{ secrets.GH_PAT }}

‎protocol/transfer.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ type ListTeamsRequest struct {
154154
}
155155

156156
type Team struct {
157-
ID string `cbor:"1,keyasint,omitempty"`
158-
Name string `cbor:"2,keyasint,omitempty"`
157+
ID string `cbor:"1,keyasint,omitempty"`
158+
Name string `cbor:"2,keyasint,omitempty"`
159159
}
160160

161161
type ListTeamsResponse struct {
@@ -577,8 +577,8 @@ type ParallelDownloader struct {
577577
clients []*http.Client
578578
baseURL string
579579
encMode cbor.EncMode
580-
sem chan struct{} // semaphore for concurrent downloads
581-
clientIdx atomic.Uint64 // round-robin index for client selection
580+
sem chan struct{} // semaphore for concurrent downloads
581+
clientIdx atomic.Uint64 // round-robin index for client selection
582582
}
583583

584584
// NewParallelDownloader creates a downloader that spreads requests across IPs

0 commit comments

Comments
 (0)