Skip to content

Commit fae7973

Browse files
authored
Merge pull request #82 from silinternational/develop
Release - log more error detail
2 parents 7e06bc0 + d9f6f3a commit fae7973

File tree

4 files changed

+59
-14
lines changed

4 files changed

+59
-14
lines changed

.github/CODEOWNERS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
* @silinternational/developers
2+
*.tf @silinternational/tf-devs
3+
*.go @silinternational/go-devs
4+
go.* @silinternational/go-devs

.github/workflows/test-deploy-publish.yml

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,28 @@ jobs:
2727
- name: Test
2828
run: docker compose -f actions-services.yml run --rm test ./scripts/test.sh
2929

30+
lint:
31+
name: Lint and Vulnerability Scan
32+
runs-on: ubuntu-latest
33+
timeout-minutes: ${{ fromJSON(vars.DEFAULT_JOB_TIMEOUT_MINUTES) }}
34+
steps:
35+
- uses: actions/checkout@v4
36+
- uses: actions/setup-go@v5
37+
with:
38+
go-version-file: 'go.mod'
39+
check-latest: true
40+
- name: golangci-lint
41+
uses: golangci/golangci-lint-action@v6
42+
with:
43+
version: latest
44+
- name: govulncheck
45+
run: |
46+
go install golang.org/x/vuln/cmd/govulncheck@latest
47+
govulncheck ./...
48+
3049
deploy:
3150
name: Deploy to AWS Lambda
32-
needs: tests
51+
needs: [ 'tests', 'lint' ]
3352
if: github.ref_name == 'main' || github.ref_name == 'develop'
3453
runs-on: ubuntu-latest
3554
concurrency:
@@ -59,7 +78,7 @@ jobs:
5978

6079
build-and-publish:
6180
name: Build and Publish
62-
needs: tests
81+
needs: [ 'tests', 'lint' ]
6382
runs-on: ubuntu-latest
6483
steps:
6584
- name: Checkout code
@@ -84,7 +103,7 @@ jobs:
84103
with:
85104
images: |
86105
${{ vars.IMAGE_NAME }}
87-
ghcr.io/${{ github.repository_owner }}/${{ vars.IMAGE_NAME }}
106+
ghcr.io/${{ github.repository }}
88107
tags: |
89108
type=ref,event=branch
90109
type=semver,pattern={{version}}

.golangci.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
run:
2+
timeout: 2m
3+
linters:
4+
disable-all: true
5+
enable:
6+
# - errcheck
7+
# - gosimple
8+
# - govet
9+
# - ineffassign
10+
# - staticcheck
11+
# - unused
12+
- bodyclose
13+
- gocheckcompilerdirectives
14+
- godox
15+
# - gofmt
16+
# - goimports
17+
# - gosec
18+
# - whitespace
19+
# - usestdlibvars

user.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -284,20 +284,13 @@ func (u *DynamoUser) FinishRegistration(r *http.Request) (string, error) {
284284
br := fixEncoding(body)
285285
parsedResponse, err := protocol.ParseCredentialCreationResponseBody(br)
286286
if err != nil {
287-
var protocolError *protocol.Error
288-
if errors.As(err, &protocolError) {
289-
log.Printf("unable to parse body: %s", body)
290-
log.Printf("ProtocolError: %s, DevInfo: %s", protocolError.Details, protocolError.DevInfo)
291-
}
287+
logProtocolError("unable to parse body", err)
292288
return "", fmt.Errorf("unable to parse credential creation response body: %w", err)
293289
}
294290

295291
credential, err := u.WebAuthnClient.CreateCredential(u, u.SessionData, parsedResponse)
296292
if err != nil {
297-
var protocolError *protocol.Error
298-
if errors.As(err, &protocolError) {
299-
log.Printf("ProtocolError: %s, DevInfo: %s", protocolError.Details, protocolError.DevInfo)
300-
}
293+
logProtocolError("unable to create credential", err)
301294
return "", fmt.Errorf("unable to create credential: %w", err)
302295
}
303296

@@ -349,7 +342,7 @@ func (u *DynamoUser) FinishLogin(r *http.Request) (*webauthn.Credential, error)
349342
br := fixEncoding(body)
350343
parsedResponse, err := protocol.ParseCredentialRequestResponseBody(br)
351344
if err != nil {
352-
log.Printf("failed to parse credential request response body: %s", err)
345+
logProtocolError(fmt.Sprintf("failed to parse credential request response body: %s", body), err)
353346
return &webauthn.Credential{}, fmt.Errorf("failed to parse credential request response body: %s", err)
354347
}
355348

@@ -378,7 +371,7 @@ func (u *DynamoUser) FinishLogin(r *http.Request) (*webauthn.Credential, error)
378371

379372
credential, err := u.WebAuthnClient.ValidateLogin(u, u.SessionData, parsedResponse)
380373
if err != nil {
381-
log.Printf("failed to validate login: %s", err)
374+
logProtocolError("failed to validate login", err)
382375
return &webauthn.Credential{}, fmt.Errorf("failed to validate login: %s", err)
383376
}
384377

@@ -488,3 +481,13 @@ func hashAndEncodeKeyHandle(id []byte) string {
488481
hash := sha256.Sum256(id)
489482
return base64.RawURLEncoding.EncodeToString(hash[:])
490483
}
484+
485+
// logProtocolError logs a detailed message if the given error is an Error from go-webauthn/webauthn/protocol
486+
func logProtocolError(msg string, err error) {
487+
var protocolError *protocol.Error
488+
if errors.As(err, &protocolError) {
489+
log.Printf("%s, ProtocolError: %s, DevInfo: %s", msg, protocolError.Details, protocolError.DevInfo)
490+
} else {
491+
log.Printf("%s, Error: %s", msg, err)
492+
}
493+
}

0 commit comments

Comments
 (0)