Skip to content

Commit f5e0a84

Browse files
authored
Release/0.8.8 (#125)
* Fix schema update bug in API mode * Bump up APIFW ver to v0.8.8 * Bump up Go version up to v1.23.6 * Dependencies upgrade
1 parent 1e062c7 commit f5e0a84

File tree

16 files changed

+249
-92
lines changed

16 files changed

+249
-92
lines changed

.github/workflows/binaries.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151
needs:
5252
- draft-release
5353
env:
54-
X_GO_DISTRIBUTION: "https://go.dev/dl/go1.22.12.linux-amd64.tar.gz"
54+
X_GO_DISTRIBUTION: "https://go.dev/dl/go1.23.6.linux-amd64.tar.gz"
5555
APIFIREWALL_NAMESPACE: "github.com/wallarm/api-firewall"
5656
strategy:
5757
matrix:
@@ -162,7 +162,7 @@ jobs:
162162
needs:
163163
- draft-release
164164
env:
165-
X_GO_VERSION: "1.22.12"
165+
X_GO_VERSION: "1.23.6"
166166
APIFIREWALL_NAMESPACE: "github.com/wallarm/api-firewall"
167167
strategy:
168168
matrix:
@@ -272,19 +272,19 @@ jobs:
272272
include:
273273
- arch: armv6
274274
distro: bullseye
275-
go_distribution: https://go.dev/dl/go1.22.12.linux-armv6l.tar.gz
275+
go_distribution: https://go.dev/dl/go1.23.6.linux-armv6l.tar.gz
276276
artifact: armv6-libc
277277
- arch: aarch64
278278
distro: bullseye
279-
go_distribution: https://go.dev/dl/go1.22.12.linux-arm64.tar.gz
279+
go_distribution: https://go.dev/dl/go1.23.6.linux-arm64.tar.gz
280280
artifact: arm64-libc
281281
- arch: armv6
282282
distro: alpine_latest
283-
go_distribution: https://go.dev/dl/go1.22.12.linux-armv6l.tar.gz
283+
go_distribution: https://go.dev/dl/go1.23.6.linux-armv6l.tar.gz
284284
artifact: armv6-musl
285285
- arch: aarch64
286286
distro: alpine_latest
287-
go_distribution: https://go.dev/dl/go1.22.12.linux-arm64.tar.gz
287+
go_distribution: https://go.dev/dl/go1.23.6.linux-arm64.tar.gz
288288
artifact: arm64-musl
289289
steps:
290290
- uses: actions/[email protected]

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.22-alpine3.21 AS build
1+
FROM golang:1.23-alpine3.21 AS build
22

33
ARG APIFIREWALL_NAMESPACE
44
ARG APIFIREWALL_VERSION

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION := 0.8.7
1+
VERSION := 0.8.8
22
NAMESPACE := github.com/wallarm/api-firewall
33

44
.DEFAULT_GOAL := build

cmd/api-firewall/internal/handlers/api/updater.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ func (s *Specification) Run() {
106106
}
107107
s.lock.Unlock()
108108

109+
s.logger.Debugf("%s: OpenAPI specifications have been updated", logPrefix)
110+
109111
continue
110112
}
111113

@@ -140,8 +142,8 @@ func (s *Specification) Shutdown() error {
140142
// Load function reads DB file and returns it
141143
func (s *Specification) Load() (storage.DBOpenAPILoader, error) {
142144

143-
// Load specification
144-
return storage.NewOpenAPIDB(s.cfg.PathToSpecDB, s.cfg.DBVersion)
145+
// Load specification only (without after load actions)
146+
return storage.LoadOpenAPIDB(s.cfg.PathToSpecDB, s.cfg.DBVersion)
145147
}
146148

147149
// Find function searches for the handler by path and method

cmd/api-firewall/tests/updater_v2_test.go

+106
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,24 @@ paths:
4444
content: {}
4545
`
4646

47+
const testUpdatedYamlSpecification = `openapi: 3.0.1
48+
info:
49+
title: Service
50+
version: 1.1.1
51+
servers:
52+
- url: /
53+
paths:
54+
/test/updated:
55+
get:
56+
tags:
57+
- Redirects
58+
summary: Absolutely 302 Redirects n times.
59+
responses:
60+
''200'':
61+
description: A redirection.
62+
content: {}
63+
`
64+
4765
var currentDBPath = "./wallarm_api2_update.db"
4866

4967
var cfgV2 = config.APIMode{
@@ -95,6 +113,39 @@ func insertSpecV2(dbFilePath, newSpec, state string) (*EntryV2, error) {
95113
return &entry, nil
96114
}
97115

116+
func updateSpecV2(dbFilePath string, schemaID int, newState string, newSchema string) (*EntryV2, error) {
117+
118+
db, err := sql.Open("sqlite3", dbFilePath)
119+
if err != nil {
120+
return nil, err
121+
}
122+
defer db.Close()
123+
124+
q := fmt.Sprintf("UPDATE openapi_schemas SET status = '%s', schema_content='%s' WHERE schema_id == %d", newState, newSchema, schemaID)
125+
_, err = db.Exec(q)
126+
if err != nil {
127+
return nil, err
128+
}
129+
130+
// entry of the V2
131+
entry := EntryV2{}
132+
133+
rows, err := db.Query(fmt.Sprintf("SELECT * FROM openapi_schemas WHERE schema_id == %d", schemaID))
134+
if err != nil {
135+
return nil, err
136+
}
137+
defer rows.Close()
138+
139+
for rows.Next() {
140+
err = rows.Scan(&entry.SchemaID, &entry.SchemaVersion, &entry.SchemaFormat, &entry.SchemaContent, &entry.Status)
141+
if err != nil {
142+
return nil, err
143+
}
144+
}
145+
146+
return &entry, nil
147+
}
148+
98149
// check that row is applied and delete this row
99150
func cleanSpecV2(dbFilePath string, schemaID int) error {
100151

@@ -388,6 +439,61 @@ func TestUpdaterBasicV2(t *testing.T) {
388439
}
389440
}
390441

442+
// update the current entry state
443+
_, err = updateSpecV2(currentDBPath, entry.SchemaID, "new", testUpdatedYamlSpecification)
444+
if err != nil {
445+
t.Fatal(err)
446+
}
447+
448+
// start updater second time.
449+
updNewSpecErrors := make(chan error, 1)
450+
updater = handlersAPI.NewHandlerUpdater(&lock, logger, specStorage, &cfgV2, &api, shutdown, &health, nil, nil)
451+
go func() {
452+
t.Logf("starting specification regular update process every %.0f seconds", cfg.SpecificationUpdatePeriod.Seconds())
453+
updNewSpecErrors <- updater.Start()
454+
}()
455+
456+
time.Sleep(3 * time.Second)
457+
458+
if err := updater.Shutdown(); err != nil {
459+
t.Fatal(err)
460+
}
461+
462+
// valid route in the updated spec
463+
req = fasthttp.AcquireRequest()
464+
req.SetRequestURI("/test/updated")
465+
req.Header.SetMethod("GET")
466+
req.Header.Add(web.XWallarmSchemaIDHeader, fmt.Sprintf("%d", entry.SchemaID))
467+
468+
reqCtx = fasthttp.RequestCtx{
469+
Request: *req,
470+
}
471+
472+
lock.RLock()
473+
api.Handler(&reqCtx)
474+
lock.RUnlock()
475+
476+
if reqCtx.Response.StatusCode() != 200 {
477+
t.Errorf("Incorrect response status code. Expected: 200 and got %d",
478+
reqCtx.Response.StatusCode())
479+
}
480+
481+
apifwResponse = validator.ValidationResponse{}
482+
if err := json.Unmarshal(reqCtx.Response.Body(), &apifwResponse); err != nil {
483+
t.Errorf("Error while JSON response parsing: %v", err)
484+
}
485+
486+
if len(apifwResponse.Summary) > 0 {
487+
if *apifwResponse.Summary[0].SchemaID != entry.SchemaID {
488+
t.Errorf("Incorrect error code. Expected: %d and got %d",
489+
entry.SchemaID, *apifwResponse.Summary[0].SchemaID)
490+
}
491+
if *apifwResponse.Summary[0].StatusCode != fasthttp.StatusOK {
492+
t.Errorf("Incorrect result status. Expected: %d and got %d",
493+
fasthttp.StatusOK, *apifwResponse.Summary[0].StatusCode)
494+
}
495+
}
496+
391497
}
392498

393499
func TestUpdaterFromEmptyDBV2(t *testing.T) {
0 Bytes
Binary file not shown.

demo/docker-compose/OWASP_CoreRuleSet/docker-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: "3.8"
22
services:
33
api-firewall:
44
container_name: api-firewall
5-
image: wallarm/api-firewall:v0.8.7
5+
image: wallarm/api-firewall:v0.8.8
66
restart: on-failure
77
environment:
88
APIFW_URL: "http://0.0.0.0:8080"

demo/docker-compose/docker-compose-api-mode.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: '3.8'
22
services:
33
api-firewall:
44
container_name: api-firewall
5-
image: wallarm/api-firewall:v0.8.7
5+
image: wallarm/api-firewall:v0.8.8
66
restart: on-failure
77
environment:
88
APIFW_MODE: "api"

demo/docker-compose/docker-compose-graphql-mode.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: '3.8'
22
services:
33
api-firewall:
44
container_name: api-firewall
5-
image: wallarm/api-firewall:v0.8.7
5+
image: wallarm/api-firewall:v0.8.8
66
restart: on-failure
77
environment:
88
APIFW_MODE: "graphql"

demo/docker-compose/docker-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: "3.8"
22
services:
33
api-firewall:
44
container_name: api-firewall
5-
image: wallarm/api-firewall:v0.8.7
5+
image: wallarm/api-firewall:v0.8.8
66
restart: on-failure
77
environment:
88
APIFW_URL: "http://0.0.0.0:8080"

docs/release-notes.md

+11
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22

33
This page describes new releases of Wallarm API Firewall.
44

5+
## v0.8.8 (2025-02-27)
6+
7+
* Dependency upgrade
8+
* Fix schema update bug in API mode
9+
* Update the Go version up to v1.23.6
10+
11+
## v0.8.7 (2025-02-21)
12+
13+
* Fix the high CPU load issue
14+
* Update the Go version up to v1.22.12
15+
516
## v0.8.6 (2024-12-20)
617

718
* Dependency upgrade

go.mod

+26-22
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,35 @@
11
module github.com/wallarm/api-firewall
22

3-
go 1.22.12
3+
go 1.23.0
4+
5+
toolchain go1.23.6
46

57
require (
68
github.com/andybalholm/brotli v1.1.1
79
github.com/ardanlabs/conf v1.5.0
810
github.com/clbanning/mxj/v2 v2.7.0
9-
github.com/corazawaf/coraza/v3 v3.2.1
11+
github.com/corazawaf/coraza/v3 v3.3.2
1012
github.com/dgraph-io/ristretto v0.2.0
11-
github.com/fasthttp/websocket v1.5.11
13+
github.com/fasthttp/websocket v1.5.12
1214
github.com/foxcpp/go-mockdns v1.1.0
13-
github.com/gabriel-vasile/mimetype v1.4.7
15+
github.com/gabriel-vasile/mimetype v1.4.8
1416
github.com/getkin/kin-openapi v0.124.0
1517
github.com/go-playground/validator v9.31.0+incompatible
1618
github.com/golang-jwt/jwt v3.2.2+incompatible
1719
github.com/golang/mock v1.6.0
1820
github.com/google/uuid v1.6.0
1921
github.com/karlseguin/ccache/v2 v2.0.8
20-
github.com/klauspost/compress v1.17.11
21-
github.com/mattn/go-sqlite3 v1.14.23
22+
github.com/klauspost/compress v1.18.0
23+
github.com/mattn/go-sqlite3 v1.14.24
2224
github.com/pkg/errors v0.9.1
2325
github.com/savsgio/gotils v0.0.0-20240704082632-aef3928b8a38
2426
github.com/sirupsen/logrus v1.9.3
2527
github.com/stretchr/testify v1.10.0
26-
github.com/valyala/fasthttp v1.58.0
28+
github.com/valyala/fasthttp v1.59.0
2729
github.com/valyala/fastjson v1.6.4
2830
github.com/wundergraph/graphql-go-tools v1.67.4
29-
golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67
30-
golang.org/x/sync v0.10.0
31+
golang.org/x/exp v0.0.0-20250218142911-aa4b98e5adaa
32+
golang.org/x/sync v0.11.0
3133
gopkg.in/yaml.v3 v3.0.1
3234
)
3335

@@ -37,8 +39,8 @@ require (
3739
github.com/Masterminds/sprig v2.22.0+incompatible // indirect
3840
github.com/buger/jsonparser v1.1.1 // indirect
3941
github.com/cespare/xxhash/v2 v2.3.0 // indirect
40-
github.com/corazawaf/libinjection-go v0.2.1 // indirect
41-
github.com/davecgh/go-spew v1.1.1 // indirect
42+
github.com/corazawaf/libinjection-go v0.2.2 // indirect
43+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
4244
github.com/dustin/go-humanize v1.0.1 // indirect
4345
github.com/eclipse/paho.mqtt.golang v1.2.0 // indirect
4446
github.com/go-openapi/jsonpointer v0.21.0 // indirect
@@ -55,9 +57,9 @@ require (
5557
github.com/jensneuse/pipeline v0.0.0-20200117120358-9fb4de085cd6 // indirect
5658
github.com/josharian/intern v1.0.0 // indirect
5759
github.com/leodido/go-urn v1.2.0 // indirect
58-
github.com/magefile/mage v1.15.0 // indirect
59-
github.com/mailru/easyjson v0.7.7 // indirect
60-
github.com/miekg/dns v1.1.62 // indirect
60+
github.com/magefile/mage v1.15.1-0.20241126214340-bdc92f694516 // indirect
61+
github.com/mailru/easyjson v0.9.0 // indirect
62+
github.com/miekg/dns v1.1.63 // indirect
6163
github.com/mitchellh/copystructure v1.0.0 // indirect
6264
github.com/mitchellh/reflectwalk v1.0.0 // indirect
6365
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
@@ -66,21 +68,23 @@ require (
6668
github.com/nats-io/nuid v1.0.1 // indirect
6769
github.com/perimeterx/marshmallow v1.1.5 // indirect
6870
github.com/petar-dambovaliev/aho-corasick v0.0.0-20240411101913-e07a1f0e8eb4 // indirect
69-
github.com/pmezard/go-difflib v1.0.0 // indirect
70-
github.com/r3labs/sse/v2 v2.8.1 // indirect
71+
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
72+
github.com/r3labs/sse/v2 v2.10.0 // indirect
7173
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 // indirect
72-
github.com/tidwall/gjson v1.17.1 // indirect
74+
github.com/tidwall/gjson v1.18.0 // indirect
7375
github.com/tidwall/match v1.1.1 // indirect
7476
github.com/tidwall/pretty v1.2.1 // indirect
7577
github.com/tidwall/sjson v1.2.5 // indirect
78+
github.com/valllabh/ocsf-schema-golang v1.0.3 // indirect
7679
github.com/valyala/bytebufferpool v1.0.0 // indirect
7780
go.uber.org/multierr v1.11.0 // indirect
7881
go.uber.org/zap v1.27.0 // indirect
79-
golang.org/x/crypto v0.31.0 // indirect
80-
golang.org/x/mod v0.22.0 // indirect
81-
golang.org/x/net v0.33.0 // indirect
82-
golang.org/x/sys v0.28.0 // indirect
83-
golang.org/x/tools v0.28.0 // indirect
82+
golang.org/x/crypto v0.35.0 // indirect
83+
golang.org/x/mod v0.23.0 // indirect
84+
golang.org/x/net v0.35.0 // indirect
85+
golang.org/x/sys v0.30.0 // indirect
86+
golang.org/x/tools v0.30.0 // indirect
87+
google.golang.org/protobuf v1.34.2 // indirect
8488
gopkg.in/cenkalti/backoff.v1 v1.1.0 // indirect
8589
gopkg.in/go-playground/assert.v1 v1.2.1 // indirect
8690
nhooyr.io/websocket v1.8.17 // indirect

0 commit comments

Comments
 (0)