Skip to content
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
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,24 @@
Notable changes to this service, newest first, per release. This file is written for whoever
runs the service or integrates against it.

## v0.2.0

The service now runs on **Go 1.27.4** and **azugo v0.50.2**. Nothing about the API or the
configuration changes.

### Changed

- **Go 1.27.4** (was 1.27.2), both in `go.mod` and as the image's default build toolchain
(`ARG GO_VERSION` in the `Dockerfile`). Rebuild the image to pick it up.
- **Libraries:** azugo → v0.50.2 (core v0.50.1), `go-authbyte` → v0.46.0, `go-platform-kit` →
v1.13.0, `go-sec-events` → v1.3.0, `go-gdpr-audit` → v1.2.0, `go-web-eid` → v0.16.0.
- **Request bodies are held to the framework's limit:** a body over `SERVER_MAX_REQUEST_BODY_SIZE`
(4 MiB when unset) is refused with 413. No route of this service sets a limit of its own; its
bodies are small.
- **Audit:** if a request body cannot be read when the audit step looks for the certificate's
subject, the response the caller already received is unchanged, the personal-data access record
for that request is skipped, and a warning is logged without any body content.

## v0.1.2

A security release. **The service now builds with Go 1.27.2**, and its libraries move to their Go
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG GO_VERSION=1.27.2
ARG GO_VERSION=1.27.4

FROM golang:${GO_VERSION} AS build
WORKDIR /src
Expand Down
69 changes: 69 additions & 0 deletions audit/audit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package audit

import (
"fmt"
"strings"
"sync"
"testing"
"time"
Expand Down Expand Up @@ -200,3 +201,71 @@ func TestMiddlewareDispatch(t *testing.T) {
qt.Check(t, qt.Equals(sign.EventType, eventSigningCertificate))
qt.Check(t, qt.Equals(sign.Outcome, broker.OutcomeFailure))
}

// reqCertSubject runs after the handler has answered. A body the framework will
// not read (over the request size limit) or one that is not a JSON object gives
// an empty subject and leaves the response and the security event as they are.
func TestReqCertSubjectBodyCases(t *testing.T) {
const limit = 64

tests := []struct {
name string
body []byte
}{
{"over the limit", []byte(`{"certificate":"` + strings.Repeat("A", 4*limit) + `"}`)},
{"malformed", []byte(`{"certificate":`)},
{"not an object", []byte(`[1,2,3]`)},
{"empty", nil},
{"no certificate field", []byte(`{"other":"x"}`)},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
sink := &captureSink{}
rec := New(secevents.NewEmitter(sink), nil, nil, zap.NewNop())

var subject string
var seen bool

app := azugo.NewTestApp()
app.Use(func(next azugo.RequestHandler) azugo.RequestHandler {
return func(ctx *azugo.Context) {
ctx.SetMaxBodySize(limit)
next(ctx)
}
})
app.Use(rec.Middleware())
app.Post("/sign/certificate", func(ctx *azugo.Context) {
ctx.StatusCode(fasthttp.StatusOK)
ctx.Text("done")
})
// The recorder acts on the same path; read the subject the way it does.
app.Post("/sign/finalize", func(ctx *azugo.Context) {
subject = reqCertSubject(ctx, "certificate")
seen = true
ctx.StatusCode(fasthttp.StatusOK)
ctx.Text("done")
})
app.Start(t)
defer app.Stop()
tc := app.TestClient()

resp, err := tc.Post("/sign/certificate", tt.body)
qt.Assert(t, qt.IsNil(err))
qt.Check(t, qt.Equals(resp.StatusCode(), fasthttp.StatusOK))
fasthttp.ReleaseResponse(resp)

ev := sink.last()
qt.Assert(t, qt.IsNotNil(ev))
qt.Check(t, qt.Equals(ev.EventType, eventSigningCertificate))
qt.Check(t, qt.Equals(ev.Outcome, broker.OutcomeSuccess))

resp2, err := tc.Post("/sign/finalize", tt.body)
qt.Assert(t, qt.IsNil(err))
qt.Check(t, qt.Equals(resp2.StatusCode(), fasthttp.StatusOK))
fasthttp.ReleaseResponse(resp2)
qt.Check(t, qt.IsTrue(seen))
qt.Check(t, qt.Equals(subject, ""))
})
}
}
12 changes: 10 additions & 2 deletions audit/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,17 @@ func authorizedID(ctx *azugo.Context) string {
// reqCertSubject extracts the eID national identifier from the first present
// base64-DER certificate field in the request body, or "" when none can be
// parsed. The raw id is returned for pseudonymization by the caller; it is never
// logged itself.
// logged itself. The handler has already answered when this runs, so a body
// that cannot be read (over the request size limit) leaves the response as it
// is: the subject is "" and a warning without any body content is logged.
func reqCertSubject(ctx *azugo.Context, fields ...string) string {
body := ctx.Body.Bytes()
body, err := ctx.Body.Bytes()
if err != nil {
ctx.Log().Warn("audit: request body unreadable, certificate subject not recorded")

return ""
}

if len(body) == 0 {
return ""
}
Expand Down
58 changes: 29 additions & 29 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,55 +1,55 @@
module github.com/go-make-bytes/web-eid

go 1.27.2
go 1.27.4

require (
azugo.io/azugo v0.40.0
azugo.io/core v0.40.0
github.com/gmb-lib/go-authbyte v0.29.1
github.com/gmb-lib/go-gdpr-audit v1.1.6
github.com/gmb-lib/go-platform-kit v1.11.4
github.com/gmb-lib/go-sec-events v1.2.2
github.com/gmb-lib/go-web-eid v0.15.5
azugo.io/azugo v0.50.2
azugo.io/core v0.50.1
github.com/gmb-lib/go-authbyte v0.46.0
github.com/gmb-lib/go-gdpr-audit v1.2.0
github.com/gmb-lib/go-platform-kit v1.13.0
github.com/gmb-lib/go-sec-events v1.3.0
github.com/gmb-lib/go-web-eid v0.16.0
github.com/go-quicktest/qt v1.102.0
github.com/spf13/cobra v1.10.2
github.com/spf13/viper v1.21.0
github.com/valyala/fasthttp v1.75.0
github.com/valyala/fasthttp v1.79.0
go.uber.org/zap v1.28.0
)

require (
azugo.io/opentelemetry v0.40.0 // indirect
github.com/VictoriaMetrics/metrics v1.44.1 // indirect
azugo.io/opentelemetry v0.50.0 // indirect
github.com/VictoriaMetrics/metrics v1.45.0 // indirect
github.com/cenkalti/backoff/v5 v5.0.3 // indirect
github.com/cenkalti/backoff/v7 v7.0.1 // indirect
github.com/cenkalti/backoff/v7 v7.0.3 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/dgraph-io/ristretto/v2 v2.4.2 // indirect
github.com/dustin/go-humanize v1.1.0 // indirect
github.com/felixge/httpsnoop v1.1.0 // indirect
github.com/fsnotify/fsnotify v1.10.1 // indirect
github.com/gabriel-vasile/mimetype v1.4.15 // indirect
github.com/go-jose/go-jose/v4 v4.1.5 // indirect
github.com/gabriel-vasile/mimetype v1.4.16 // indirect
github.com/go-jose/go-jose/v4 v4.1.9 // indirect
github.com/go-logr/logr v1.4.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-playground/locales v0.14.2 // indirect
github.com/go-playground/universal-translator v0.18.2 // indirect
github.com/go-playground/validator/v10 v10.30.5 // indirect
github.com/go-playground/validator/v10 v10.30.6 // indirect
github.com/go-viper/mapstructure/v2 v2.5.0 // indirect
github.com/goccy/go-json v0.11.2 // indirect
github.com/goccy/go-json v0.12.0 // indirect
github.com/golang-jwt/jwt/v5 v5.3.1 // indirect
github.com/google/go-cmp v0.7.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.31.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.34.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/klauspost/compress v1.20.1 // indirect
github.com/klauspost/compress v1.20.4 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/lafriks/http2 v0.6.1 // indirect
github.com/lafriks/pkcs8 v1.2.4 // indirect
github.com/leodido/go-urn v1.5.0 // indirect
github.com/mattn/go-colorable v0.1.16 // indirect
github.com/mattn/go-isatty v0.0.24 // indirect
github.com/molecule-man/go-brrr v1.2.0 // indirect
github.com/molecule-man/go-brrr v1.3.1 // indirect
github.com/oklog/ulid/v2 v2.1.2 // indirect
github.com/pelletier/go-toml/v2 v2.4.3 // indirect
github.com/pkg/errors v0.9.1 // indirect
Expand All @@ -58,9 +58,9 @@ require (
github.com/sagikazarmark/locafero v0.12.0 // indirect
github.com/spf13/afero v1.15.0 // indirect
github.com/spf13/cast v1.10.0 // indirect
github.com/spf13/pflag v1.0.10 // indirect
github.com/spf13/pflag v1.1.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/valkey-io/valkey-go v1.0.78 // indirect
github.com/valkey-io/valkey-go v1.0.80 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fastrand v1.1.0 // indirect
github.com/valyala/histogram v1.2.0 // indirect
Expand All @@ -84,13 +84,13 @@ require (
go.opentelemetry.io/proto/otlp v1.11.1 // indirect
go.uber.org/atomic v1.12.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.yaml.in/yaml/v3 v3.0.5 // indirect
golang.org/x/crypto v0.58.0 // indirect
golang.org/x/net v0.61.0 // indirect
golang.org/x/sys v0.49.0 // indirect
golang.org/x/text v0.43.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20261005182115-fad411399dd8 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20261005182115-fad411399dd8 // indirect
google.golang.org/grpc v1.84.0 // indirect
go.yaml.in/yaml/v3 v3.0.6 // indirect
golang.org/x/crypto v0.59.0 // indirect
golang.org/x/net v0.62.0 // indirect
golang.org/x/sys v0.50.0 // indirect
golang.org/x/text v0.44.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20261116203732-fd2c7689a808 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20261116203732-fd2c7689a808 // indirect
google.golang.org/grpc v1.85.0 // indirect
google.golang.org/protobuf v1.36.12 // indirect
)
Loading
Loading