Skip to content

Commit 48a8fbc

Browse files
authored
Merge pull request #220 from arnested/govulncheck
Add security checks and hardening
2 parents 8e976e3 + 4ca78bf commit 48a8fbc

File tree

8 files changed

+57
-12
lines changed

8 files changed

+57
-12
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ permissions:
66
jobs:
77
go-version:
88
name: Lookup go versions
9-
runs-on: ubuntu-latest
9+
runs-on: ubuntu-22.04
1010
outputs:
1111
minimal: ${{ steps.go-version.outputs.minimal }}
1212
matrix: ${{ steps.go-version.outputs.matrix }}
@@ -17,7 +17,7 @@ jobs:
1717
go_generate:
1818
name: Check generated code is up to date
1919
needs: go-version
20-
runs-on: ubuntu-latest
20+
runs-on: ubuntu-22.04
2121
env:
2222
workdir: go/src/${{ github.repository }}
2323
steps:

.github/workflows/codeql-analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ permissions:
1616
jobs:
1717
analyse:
1818
name: Analyse
19-
runs-on: ubuntu-latest
19+
runs-on: ubuntu-22.04
2020

2121
steps:
2222
- name: Checkout repository

.github/workflows/dependency-review.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ permissions:
66

77
jobs:
88
dependency-review:
9-
runs-on: ubuntu-latest
9+
runs-on: ubuntu-22.04
1010
steps:
1111
- name: 'Checkout Repository'
1212
uses: actions/checkout@v3

.github/workflows/docker-image-security-scan.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
security-scan:
88
name: Docker build and scan
99
if: '!github.event.deleted'
10-
runs-on: ubuntu-latest
10+
runs-on: ubuntu-22.04
1111
steps:
1212
- uses: actions/checkout@v3
1313
- name: Set up Docker Buildx

.github/workflows/lint.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ permissions:
77
jobs:
88
dockerfile:
99
name: dockerfile
10-
runs-on: ubuntu-latest
10+
runs-on: ubuntu-22.04
1111
steps:
1212
- uses: actions/checkout@v3
1313
- name: Run hadolint
@@ -17,15 +17,15 @@ jobs:
1717

1818
markdownlint:
1919
name: markdown
20-
runs-on: ubuntu-latest
20+
runs-on: ubuntu-22.04
2121
steps:
2222
- uses: actions/checkout@v3
2323
- name: Run markdownlint
2424
uses: DavidAnson/markdownlint-cli2-action@v11
2525

2626
golangci:
2727
name: lint
28-
runs-on: ubuntu-latest
28+
runs-on: ubuntu-22.04
2929
steps:
3030
- uses: actions/checkout@v3
3131
- uses: arnested/go-version-action@v1

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ permissions:
1313
actions: read
1414
jobs:
1515
bump-version:
16-
runs-on: ubuntu-latest
16+
runs-on: ubuntu-22.04
1717
steps:
1818
- uses: actions/checkout@v3
1919
with:
@@ -86,7 +86,7 @@ jobs:
8686
message: "Released `${{ github.repository }}`@`${{ github.sha }}` as ${{ steps.version.outputs.tag }}: *${{ job.status }}*."
8787
docker-build:
8888
name: Docker build and push
89-
runs-on: ubuntu-latest
89+
runs-on: ubuntu-22.04
9090
steps:
9191
- uses: actions/checkout@v3
9292
- name: Set up Docker Buildx

.github/workflows/security.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Security Checks
2+
on:
3+
pull_request:
4+
branches: [main]
5+
push:
6+
branches: [main]
7+
schedule:
8+
- cron: '0 15 * * 0'
9+
10+
permissions:
11+
contents: read
12+
actions: read
13+
pull-requests: read
14+
security-events: write
15+
16+
jobs:
17+
gosec:
18+
name: Golang Security Checker
19+
runs-on: ubuntu-22.04
20+
env:
21+
GO111MODULE: on
22+
steps:
23+
- name: Checkout Source
24+
uses: actions/checkout@v3
25+
- name: Run Gosec Security Scanner
26+
uses: securego/gosec@master
27+
with:
28+
args: '-no-fail -fmt sarif -out results.sarif -tests ./...'
29+
- name: Upload SARIF file
30+
uses: github/codeql-action/upload-sarif@v2
31+
with:
32+
# Path to SARIF file relative to the root of the repository
33+
sarif_file: results.sarif
34+
govulncheck:
35+
name: Govulncheck
36+
runs-on: ubuntu-22.04
37+
steps:
38+
- id: govulncheck
39+
uses: golang/govulncheck-action@master
40+
with:
41+
go-version-file: go.mod

main.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"net/http"
88
"os"
9+
"time"
910

1011
"github.com/elnormous/contenttype"
1112
)
@@ -20,10 +21,13 @@ func main() {
2021
doHealthcheck(ctx)
2122
}
2223

23-
addr := getAddr()
24+
server := &http.Server{
25+
Addr: getAddr(),
26+
ReadHeaderTimeout: 3 * time.Second,
27+
}
2428

2529
http.HandleFunc("/", handler)
26-
err := http.ListenAndServe(addr, nil)
30+
err := server.ListenAndServe()
2731
if err != nil {
2832
fmt.Print(err)
2933
}

0 commit comments

Comments
 (0)