Skip to content

Commit e5b67c2

Browse files
committed
Add golangci-lint job, enhance Trivy and govulncheck workflows
- Introduced a new `GolangCI` job for linting using `golangci-lint`. - Updated `Trivy` job to include `HIGH` severity findings. - Improved `govulncheck` workflow with optimized logic and naming fixes. - Adjusted permissions and hardened runner configurations across jobs. - Fixed linter findings. Signed-off-by: Alexander Adam <alphaone23@gmail.com>
1 parent 6db1c12 commit e5b67c2

6 files changed

Lines changed: 46 additions & 23 deletions

File tree

.github/workflows/security.yml

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,41 @@ on:
1111
branches:
1212
- master
1313

14-
# Declare default permissions as read only.
14+
# Declare default permissions as read-only.
1515
permissions: read-all
1616

1717
jobs:
18+
GolangCI:
19+
runs-on: ubuntu-latest
20+
permissions:
21+
contents: read
22+
security-events: write
23+
steps:
24+
- name: Harden Runner
25+
uses: step-security/harden-runner@a90bcbc6539c36a85cdfeb73f7e2f433735f215b # v2.15.0
26+
with:
27+
egress-policy: audit
28+
29+
- name: Checkout
30+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
31+
with:
32+
fetch-depth: 1
33+
34+
- name: Run golangci-lint
35+
uses: golangci/golangci-lint-action@1e7e51e771db61008b38414a730f564565cf7c20 # v9.2.0
36+
with:
37+
version: latest
38+
args: --timeout=5m --output.sarif.path=golangci-lint-results.sarif --output.text.path=stdout
39+
40+
- name: Upload golangci-lint results to GitHub Security tab
41+
uses: github/codeql-action/upload-sarif@c793b717bc78562f491db7b0e93a3a178b099162 # v4.32.5
42+
with:
43+
sarif_file: golangci-lint-results.sarif
44+
1845
TrivyCode:
1946
runs-on: ubuntu-latest
2047
permissions:
48+
contents: read
2149
security-events: write
2250
steps:
2351
- name: Harden Runner
@@ -28,14 +56,14 @@ jobs:
2856
- name: Checkout code
2957
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
3058

31-
- name: Run Trivy vulnerability scanner in repo mode
59+
- name: Run Trivy vulnerability scanner in fs mode
3260
uses: aquasecurity/trivy-action@97e0b3872f55f89b95b2f65b3dbab56962816478 # 0.34.2
3361
with:
3462
scan-type: 'fs'
3563
ignore-unfixed: true
3664
format: 'sarif'
3765
output: 'trivy-results.sarif'
38-
severity: 'CRITICAL'
66+
severity: 'CRITICAL,HIGH'
3967

4068
- name: Upload Trivy scan results to GitHub Security tab
4169
uses: github/codeql-action/upload-sarif@c793b717bc78562f491db7b0e93a3a178b099162 # v4.32.5
@@ -46,43 +74,38 @@ jobs:
4674
strategy:
4775
matrix:
4876
go-version:
49-
- stable
77+
- "stable"
5078
runs-on: ubuntu-latest
5179
permissions:
80+
contents: read
5281
security-events: write
5382
steps:
5483
- name: Harden Runner
5584
uses: step-security/harden-runner@a90bcbc6539c36a85cdfeb73f7e2f433735f215b # v2.15.0
5685
with:
5786
egress-policy: audit
5887

59-
- name: Checkout
60-
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
61-
with:
62-
fetch-depth: 1
63-
64-
- name: VulnerabilityCheck
88+
- name: Vulnerability Check
6589
uses: golang/govulncheck-action@b625fbe08f3bccbe446d94fbf87fcc875a4f50ee # v1.0.4
6690
with:
67-
repo-checkout: false
6891
go-version-input: ${{matrix.go-version}}
6992
output-format: sarif
7093
output-file: govulncheck-results.sarif
7194

72-
- name: PrintSarif
73-
id: PrintSarif
95+
- name: Print Sarif
96+
id: printSarif
7497
run: |
7598
cat govulncheck-results.sarif
7699
77-
if grep "'results'" govulncheck-results.sarif
100+
if grep results govulncheck-results.sarif
78101
then
79102
echo "hasResults=true" >> $GITHUB_OUTPUT
80103
else
81104
echo "hasResults=false" >> $GITHUB_OUTPUT
82105
fi
83106
84-
- name: Upload govolncheck results to GitHub Security tab
85-
if: ${{ steps.PrintSarif.outputs.hasResults == 'true' }}
107+
- name: Upload govulncheck results to Security tab
108+
if: ${{ steps.printSarif.outputs.hasResults == 'true' }}
86109
uses: github/codeql-action/upload-sarif@c793b717bc78562f491db7b0e93a3a178b099162 # v4.32.5
87110
with:
88111
sarif_file: govulncheck-results.sarif

example/example_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func TestExampleMain(t *testing.T) {
2323

2424
req.Header.Add("Origin", "localhost")
2525

26-
res, resErr := http.DefaultClient.Do(req)
26+
res, resErr := http.DefaultClient.Do(req) //nolint:gosec // all inputs are fixed, this is a test
2727

2828
if resErr != nil {
2929
t.Errorf("got error for hello test page: %v", resErr)

handler/basicauth/basic_auth_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func TestBasicAuth(t *testing.T) {
3333

3434
tests := []struct {
3535
User string
36-
Pass string
36+
Pass string //nolint:gosec
3737
WantState int
3838
}{
3939
{

handler/basicauth/htpasswdauth/htpasswd_auth_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func TestHtpasswdAuth(t *testing.T) {
1717

1818
tests := []struct {
1919
Username string
20-
Password string
20+
Password string //nolint:gosec
2121
Valid bool
2222
}{
2323
{

handler/basicauth/mapauth/map_auth.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
// Package mapauth implements the basic auth functionality using a user-pass-map.
55
package mapauth
66

7+
import "maps"
8+
79
import "errors"
810

911
// ErrNoAuthorizations is returned when no authorizations are configured.
@@ -46,9 +48,7 @@ func WithAuths(auths map[string]string) func(a *MapAuthenticator) error {
4648
a.auths = make(map[string]string, len(auths))
4749
}
4850

49-
for k, v := range auths {
50-
a.auths[k] = v
51-
}
51+
maps.Copy(a.auths, auths)
5252

5353
return nil
5454
}

handler/basicauth/mapauth/map_auth_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func TestMapAuthenticator(t *testing.T) {
1717
tests := []struct {
1818
Auths map[string]string
1919
User string
20-
Pass string
20+
Pass string //nolint:gosec
2121
WantNewErr bool
2222
Want bool
2323
WantError bool

0 commit comments

Comments
 (0)