Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release - log more error detail #82

Merged
merged 14 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* @silinternational/developers
*.tf @silinternational/tf-devs
*.go @silinternational/go-devs
go.* @silinternational/go-devs
32 changes: 29 additions & 3 deletions .github/workflows/test-deploy-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ on:
paths-ignore:
- 'terraform/**'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false

jobs:
tests:
name: Tests
Expand All @@ -23,11 +27,33 @@ jobs:
- name: Test
run: docker compose -f actions-services.yml run --rm test ./scripts/test.sh

lint:
name: Lint and Vulnerability Scan
runs-on: ubuntu-latest
timeout-minutes: ${{ fromJSON(vars.DEFAULT_JOB_TIMEOUT_MINUTES) }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
check-latest: true
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: latest
- name: govulncheck
run: |
go install golang.org/x/vuln/cmd/govulncheck@latest
govulncheck ./...

deploy:
name: Deploy to AWS Lambda
needs: tests
needs: [ 'tests', 'lint' ]
if: github.ref_name == 'main' || github.ref_name == 'develop'
runs-on: ubuntu-latest
concurrency:
group: deploy-${{ github.ref }}-${{ matrix.region }}
cancel-in-progress: false
strategy:
matrix:
region: [ us-east-1, us-west-2 ]
Expand All @@ -52,7 +78,7 @@ jobs:

build-and-publish:
name: Build and Publish
needs: tests
needs: [ 'tests', 'lint' ]
runs-on: ubuntu-latest
steps:
- name: Checkout code
Expand All @@ -77,7 +103,7 @@ jobs:
with:
images: |
${{ vars.IMAGE_NAME }}
ghcr.io/${{ github.repository_owner }}/${{ vars.IMAGE_NAME }}
ghcr.io/${{ github.repository }}
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
Expand Down
19 changes: 19 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
run:
timeout: 2m
linters:
disable-all: true
enable:
# - errcheck
# - gosimple
# - govet
# - ineffassign
# - staticcheck
# - unused
- bodyclose
- gocheckcompilerdirectives
- godox
# - gofmt
# - goimports
# - gosec
# - whitespace
# - usestdlibvars
25 changes: 14 additions & 11 deletions user.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,20 +284,13 @@ func (u *DynamoUser) FinishRegistration(r *http.Request) (string, error) {
br := fixEncoding(body)
parsedResponse, err := protocol.ParseCredentialCreationResponseBody(br)
if err != nil {
var protocolError *protocol.Error
if errors.As(err, &protocolError) {
log.Printf("unable to parse body: %s", body)
log.Printf("ProtocolError: %s, DevInfo: %s", protocolError.Details, protocolError.DevInfo)
}
logProtocolError("unable to parse body", err)
return "", fmt.Errorf("unable to parse credential creation response body: %w", err)
}

credential, err := u.WebAuthnClient.CreateCredential(u, u.SessionData, parsedResponse)
if err != nil {
var protocolError *protocol.Error
if errors.As(err, &protocolError) {
log.Printf("ProtocolError: %s, DevInfo: %s", protocolError.Details, protocolError.DevInfo)
}
logProtocolError("unable to create credential", err)
return "", fmt.Errorf("unable to create credential: %w", err)
}

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

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

credential, err := u.WebAuthnClient.ValidateLogin(u, u.SessionData, parsedResponse)
if err != nil {
log.Printf("failed to validate login: %s", err)
logProtocolError("failed to validate login", err)
return &webauthn.Credential{}, fmt.Errorf("failed to validate login: %s", err)
}

Expand Down Expand Up @@ -488,3 +481,13 @@ func hashAndEncodeKeyHandle(id []byte) string {
hash := sha256.Sum256(id)
return base64.RawURLEncoding.EncodeToString(hash[:])
}

// logProtocolError logs a detailed message if the given error is an Error from go-webauthn/webauthn/protocol
func logProtocolError(msg string, err error) {
var protocolError *protocol.Error
if errors.As(err, &protocolError) {
log.Printf("%s, ProtocolError: %s, DevInfo: %s", msg, protocolError.Details, protocolError.DevInfo)
} else {
log.Printf("%s, Error: %s", msg, err)
}
}