Remove every reference to our own servers (closes #396)
check / check (push) Failing after 4m36s
check / check (push) Failing after 4m36s
script/publish no longer defaults DOCKER_HOST to an SSH target on one of our servers or PUBLISH_IMAGE to the registry. Both are required, and an unset one stops it with a message naming it. The README says so. The instance name in docs and tests was our server's name; it is now host1/waf in the docs and host1/blog in the tests. Model: opus-5-5
This commit is contained in:
1 parent
0a2b2d809f
commit
1f985e8230
13 files changed
+62
-57
No files matched your search
@@ -304,7 +304,7 @@ Every setting the code reads, with its default:
|
|||||||
| `SWW_RPROXY_MAX_REQUEST_TIME_MS` | `60000` | Two time limits, each this long, in milliseconds or `off`: one for the visitor to send its request line and headers, then one for the whole request to reach the app. |
|
| `SWW_RPROXY_MAX_REQUEST_TIME_MS` | `60000` | Two time limits, each this long, in milliseconds or `off`: one for the visitor to send its request line and headers, then one for the whole request to reach the app. |
|
||||||
| `SWW_RPROXY_MAX_RESPONSE_TIME_MS` | `1800000` | How long the answer may take, from the end of the request to its last byte reaching the visitor, in milliseconds or `off`. |
|
| `SWW_RPROXY_MAX_RESPONSE_TIME_MS` | `1800000` | How long the answer may take, from the end of the request to its last byte reaching the visitor, in milliseconds or `off`. |
|
||||||
| `SWW_WAF_LISTEN_ADDR` | `:8080` | Where `waf` listens; leave the host part empty. |
|
| `SWW_WAF_LISTEN_ADDR` | `:8080` | Where `waf` listens; leave the host part empty. |
|
||||||
| `SWW_WAF_INSTANCE_NAME` | the container's host name | The name in every line `waf` logs, and in every alert and metric, such as `fsn1/waf`. |
|
| `SWW_WAF_INSTANCE_NAME` | the container's host name | The name in every line `waf` logs, and in every alert and metric, such as `host1/waf`. |
|
||||||
| `SWW_WAF_MODE` | `enforce` | `observe` refuses nothing and makes no ban; each log line says what `enforce` would have done. |
|
| `SWW_WAF_MODE` | `enforce` | `observe` refuses nothing and makes no ban; each log line says what `enforce` would have done. |
|
||||||
| `SWW_WAF_IPV6_GROUP_PREFIX` | `64` | The prefix length of the IPv6 netblock that counts as one client, from 32 to 128. |
|
| `SWW_WAF_IPV6_GROUP_PREFIX` | `64` | The prefix length of the IPv6 netblock that counts as one client, from 32 to 128. |
|
||||||
| `SWW_WAF_MAX_TRACKED_CLIENTS` | `20000` | The most clients kept, in memory and in `clients.json`; the least recently seen is dropped first. |
|
| `SWW_WAF_MAX_TRACKED_CLIENTS` | `20000` | The most clients kept, in memory and in `clients.json`; the least recently seen is dropped first. |
|
||||||
@@ -530,7 +530,7 @@ services:
|
|||||||
image: smallwebwaf
|
image: smallwebwaf
|
||||||
environment:
|
environment:
|
||||||
SWW_COMMAND: waf
|
SWW_COMMAND: waf
|
||||||
SWW_WAF_INSTANCE_NAME: fsn1/waf
|
SWW_WAF_INSTANCE_NAME: host1/waf
|
||||||
# Refuse nothing yet; log what enforce mode would have done.
|
# Refuse nothing yet; log what enforce mode would have done.
|
||||||
SWW_WAF_MODE: observe
|
SWW_WAF_MODE: observe
|
||||||
# Look addresses up in a local IPinfo Lite database, never GeoJS.
|
# Look addresses up in a local IPinfo Lite database, never GeoJS.
|
||||||
@@ -817,11 +817,10 @@ on the host.
|
|||||||
`make check`.
|
`make check`.
|
||||||
- `script/docker`: builds the image, whose build runs the tests and the linter
|
- `script/docker`: builds the image, whose build runs the tests and the linter
|
||||||
first. `make docker`.
|
first. `make docker`.
|
||||||
- `script/publish`: runs `script/docker`, whose build happens on the Docker host
|
- `script/publish`: runs `script/docker` on the Docker host named by
|
||||||
named by `DOCKER_HOST` (`ssh://root@fsn1app1` unless set). It then pushes the
|
`DOCKER_HOST`, then pushes the image to `PUBLISH_IMAGE`, such as
|
||||||
image to `PUBLISH_IMAGE` (`git.eeqj.de/sneak/smallwebwaf` unless set). It
|
`registry.example.com/smallwebwaf`. Both variables are required. It refuses a
|
||||||
refuses a working tree with uncommitted changes. `make publish`. It pushes
|
working tree with uncommitted changes. `make publish`. It pushes four tags:
|
||||||
four tags:
|
|
||||||
- the UTC date as `YYYY-MM-DD`;
|
- the UTC date as `YYYY-MM-DD`;
|
||||||
- the short commit hash;
|
- the short commit hash;
|
||||||
- the branch name;
|
- the branch name;
|
||||||
|
|||||||
+2
-2
@@ -34,7 +34,7 @@ on one line:
|
|||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"instance": "fsn1/waf",
|
"instance": "host1/waf",
|
||||||
"time": "2026-10-06T12:00:50.123461Z",
|
"time": "2026-10-06T12:00:50.123461Z",
|
||||||
"event": "ban",
|
"event": "ban",
|
||||||
"host": "app.example",
|
"host": "app.example",
|
||||||
@@ -109,7 +109,7 @@ on one line:
|
|||||||
## Slack and ntfy
|
## Slack and ntfy
|
||||||
|
|
||||||
Slack and ntfy get a message with a title and a text. The title is the instance
|
Slack and ntfy get a message with a title and a text. The title is the instance
|
||||||
and the event, such as `fsn1/waf: ban`. The text is the `reason`, then one line
|
and the event, such as `host1/waf: ban`. The text is the `reason`, then one line
|
||||||
for each of these that the alert has:
|
for each of these that the alert has:
|
||||||
|
|
||||||
- the host, the client, the netblock and the country;
|
- the host, the client, the netblock and the country;
|
||||||
|
|||||||
+1
-1
@@ -26,7 +26,7 @@ These questions write no line:
|
|||||||
A `report` line:
|
A `report` line:
|
||||||
|
|
||||||
```
|
```
|
||||||
{"type":"request","waf_line":"report","time":"2026-10-03T12:00:00.123Z","instance":"fsn1/waf","client_ip":"203.0.113.9","method":"GET","scheme":"https","host":"app.example","path":"/","query":"","protocol":"HTTP/1.1","status":200,"request_bytes":0,"response_bytes":5120,"referer":"","user_agent":"curl/8.9.1","request_id":"7Q2NHZ4KJ3VXW5YB6R3MEFTD2A","peer_ip":"172.18.0.2","forwarded_for":"203.0.113.9","client_group":"203.0.113.9/32","asn":"AS64496","as_name":"Example Net","country":"DE","request_headers":{"accept":"*/*"},"action":"forward","counts":{"minute":1,"hour":12,"day":40,"minute_bytes":5120,"hour_bytes":61440,"day_bytes":204800},"core_rule_set_score":0,"duration_total_ms":3.217,"duration_checks_ms":0.041,"duration_core_rule_set_ms":0.029,"duration_upstream_total_ms":3.104}
|
{"type":"request","waf_line":"report","time":"2026-10-03T12:00:00.123Z","instance":"host1/waf","client_ip":"203.0.113.9","method":"GET","scheme":"https","host":"app.example","path":"/","query":"","protocol":"HTTP/1.1","status":200,"request_bytes":0,"response_bytes":5120,"referer":"","user_agent":"curl/8.9.1","request_id":"7Q2NHZ4KJ3VXW5YB6R3MEFTD2A","peer_ip":"172.18.0.2","forwarded_for":"203.0.113.9","client_group":"203.0.113.9/32","asn":"AS64496","as_name":"Example Net","country":"DE","request_headers":{"accept":"*/*"},"action":"forward","counts":{"minute":1,"hour":12,"day":40,"minute_bytes":5120,"hour_bytes":61440,"day_bytes":204800},"core_rule_set_score":0,"duration_total_ms":3.217,"duration_checks_ms":0.041,"duration_core_rule_set_ms":0.029,"duration_upstream_total_ms":3.104}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Every line
|
### Every line
|
||||||
|
|||||||
+1
-1
@@ -34,7 +34,7 @@ chooses between the two (see "The image's command" below).
|
|||||||
such as `:9000`. Leave the host out (see "Ports" in [`SPEC.md`](../SPEC.md)).
|
such as `:9000`. Leave the host out (see "Ports" in [`SPEC.md`](../SPEC.md)).
|
||||||
- `SWW_WAF_INSTANCE_NAME` (default: the container's host name): the `instance`
|
- `SWW_WAF_INSTANCE_NAME` (default: the container's host name): the `instance`
|
||||||
name in each line `waf` logs, and in each alert and metric, such as
|
name in each line `waf` logs, and in each alert and metric, such as
|
||||||
`fsn1/waf`. Valid UTF-8. No control character while `SWW_WAF_ALERT_NTFY_URL`
|
`host1/waf`. Valid UTF-8. No control character while `SWW_WAF_ALERT_NTFY_URL`
|
||||||
is set. 1 to 48 printable ASCII characters without a space while
|
is set. 1 to 48 printable ASCII characters without a space while
|
||||||
`SWW_WAF_LOG_REMOTE_URL` is set and `SWW_WAF_LOG_REMOTE_APP_NAME` is not.
|
`SWW_WAF_LOG_REMOTE_URL` is set and `SWW_WAF_LOG_REMOTE_APP_NAME` is not.
|
||||||
- `SWW_WAF_MODE` (default `enforce`): `enforce` or `observe`.
|
- `SWW_WAF_MODE` (default `enforce`): `enforce` or `observe`.
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ const (
|
|||||||
ntfyURL = "https://ntfy.example/sww-alerts"
|
ntfyURL = "https://ntfy.example/sww-alerts"
|
||||||
ntfyToken = "tk_0123456789abcdefghijklmnopq"
|
ntfyToken = "tk_0123456789abcdefghijklmnopq"
|
||||||
// instance is the instance name every alert gives.
|
// instance is the instance name every alert gives.
|
||||||
instance = "fsn1app1/blog"
|
instance = "host1/blog"
|
||||||
// started is when each test starts, as an alert gives it, and
|
// started is when each test starts, as an alert gives it, and
|
||||||
// anHourOn an hour later.
|
// anHourOn an hour later.
|
||||||
started = "2000-01-01T00:00:00Z"
|
started = "2000-01-01T00:00:00Z"
|
||||||
@@ -1160,8 +1160,8 @@ func TestEachDestinationIsSentOnlyTheAlertsWaitingForIt(t *testing.T) {
|
|||||||
synctest.Wait()
|
synctest.Wait()
|
||||||
|
|
||||||
wantBodies(t, standIns[alerts.DestinationSlack],
|
wantBodies(t, standIns[alerts.DestinationSlack],
|
||||||
`{"text":"*fsn1app1/blog: file_error*\nsecond"}`,
|
`{"text":"*host1/blog: file_error*\nsecond"}`,
|
||||||
`{"text":"*fsn1app1/blog: file_error*\nthird"}`)
|
`{"text":"*host1/blog: file_error*\nthird"}`)
|
||||||
wantBodies(t, standIns[alerts.DestinationNtfy], "fourth")
|
wantBodies(t, standIns[alerts.DestinationNtfy], "fourth")
|
||||||
|
|
||||||
// alerts.json then lists Slack and ntfy alone, with no alert waiting.
|
// alerts.json then lists Slack and ntfy alone, with no alert waiting.
|
||||||
@@ -1477,7 +1477,7 @@ func anAlertForEachEvent() []eventMessage {
|
|||||||
Reason: "requests per hour over the limit of 10000",
|
Reason: "requests per hour over the limit of 10000",
|
||||||
Detail: map[string]any{"mode": "observe"},
|
Detail: map[string]any{"mode": "observe"},
|
||||||
},
|
},
|
||||||
"fsn1app1/blog: ban", "default no_entry",
|
"host1/blog: ban", "default no_entry",
|
||||||
"requests per hour over the limit of 10000\nclient: 203.0.113.9\n" +
|
"requests per hour over the limit of 10000\nclient: 203.0.113.9\n" +
|
||||||
"netblock: 203.0.113.0/24\ncountry: DE\nmode: observe",
|
"netblock: 203.0.113.0/24\ncountry: DE\nmode: observe",
|
||||||
},
|
},
|
||||||
@@ -1489,7 +1489,7 @@ func anAlertForEachEvent() []eventMessage {
|
|||||||
), Country: "FR",
|
), Country: "FR",
|
||||||
Reason: "matched the rule env-file",
|
Reason: "matched the rule env-file",
|
||||||
},
|
},
|
||||||
"fsn1app1/blog: permanent_ban", "high no_entry",
|
"host1/blog: permanent_ban", "high no_entry",
|
||||||
"matched the rule env-file\nclient: 198.51.100.7\n" +
|
"matched the rule env-file\nclient: 198.51.100.7\n" +
|
||||||
"netblock: 198.51.100.7/32\ncountry: FR",
|
"netblock: 198.51.100.7/32\ncountry: FR",
|
||||||
},
|
},
|
||||||
@@ -1500,7 +1500,7 @@ func anAlertForEachEvent() []eventMessage {
|
|||||||
Reason: "refused by the Core Rule Set",
|
Reason: "refused by the Core Rule Set",
|
||||||
Host: "app.example",
|
Host: "app.example",
|
||||||
},
|
},
|
||||||
"fsn1app1/blog: core_rule_set_match", "default shield",
|
"host1/blog: core_rule_set_match", "default shield",
|
||||||
"refused by the Core Rule Set\nhost: app.example\nclient: 192.0.2.1\n" +
|
"refused by the Core Rule Set\nhost: app.example\nclient: 192.0.2.1\n" +
|
||||||
"netblock: 192.0.2.1/32",
|
"netblock: 192.0.2.1/32",
|
||||||
},
|
},
|
||||||
@@ -1509,7 +1509,7 @@ func anAlertForEachEvent() []eventMessage {
|
|||||||
Event: alerts.EventAnomaly, Netblock: netip.MustParsePrefix("192.0.2.0/24"),
|
Event: alerts.EventAnomaly, Netblock: netip.MustParsePrefix("192.0.2.0/24"),
|
||||||
Reason: "requests per minute over the threshold of 5000",
|
Reason: "requests per minute over the threshold of 5000",
|
||||||
},
|
},
|
||||||
"fsn1app1/blog: anomaly", "high chart_with_upwards_trend",
|
"host1/blog: anomaly", "high chart_with_upwards_trend",
|
||||||
"requests per minute over the threshold of 5000\nnetblock: 192.0.2.0/24",
|
"requests per minute over the threshold of 5000\nnetblock: 192.0.2.0/24",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -1518,7 +1518,7 @@ func anAlertForEachEvent() []eventMessage {
|
|||||||
Netblock: netip.MustParsePrefix("192.0.2.2/32"),
|
Netblock: netip.MustParsePrefix("192.0.2.2/32"),
|
||||||
Reason: "listed by a DNS blocklist",
|
Reason: "listed by a DNS blocklist",
|
||||||
},
|
},
|
||||||
"fsn1app1/blog: reputation_hit", "low label",
|
"host1/blog: reputation_hit", "low label",
|
||||||
"listed by a DNS blocklist\nclient: 192.0.2.2\nnetblock: 192.0.2.2/32",
|
"listed by a DNS blocklist\nclient: 192.0.2.2\nnetblock: 192.0.2.2/32",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -1526,7 +1526,7 @@ func anAlertForEachEvent() []eventMessage {
|
|||||||
Event: alerts.EventSourceFailure, Reason: "asking GeoJS failed",
|
Event: alerts.EventSourceFailure, Reason: "asking GeoJS failed",
|
||||||
Detail: map[string]any{"source": "geojs"},
|
Detail: map[string]any{"source": "geojs"},
|
||||||
},
|
},
|
||||||
"fsn1app1/blog: source_failure", "high warning",
|
"host1/blog: source_failure", "high warning",
|
||||||
"asking GeoJS failed\nsource: geojs",
|
"asking GeoJS failed\nsource: geojs",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -1537,7 +1537,7 @@ func anAlertForEachEvent() []eventMessage {
|
|||||||
"file": "/etc/sww/rules.d/50-app.rules", "error": "line 2: no action",
|
"file": "/etc/sww/rules.d/50-app.rules", "error": "line 2: no action",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"fsn1app1/blog: file_error", "high warning",
|
"host1/blog: file_error", "high warning",
|
||||||
"a rule file has an error, and the rules stay as they were\n" +
|
"a rule file has an error, and the rules stay as they were\n" +
|
||||||
"file: /etc/sww/rules.d/50-app.rules\nerror: line 2: no action",
|
"file: /etc/sww/rules.d/50-app.rules\nerror: line 2: no action",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -218,7 +218,7 @@ const (
|
|||||||
// instance is an SWW_WAF_INSTANCE_NAME that is a valid app name too, and
|
// instance is an SWW_WAF_INSTANCE_NAME that is a valid app name too, and
|
||||||
// remoteURL an SWW_WAF_LOG_REMOTE_URL, for the tests that send the lines.
|
// remoteURL an SWW_WAF_LOG_REMOTE_URL, for the tests that send the lines.
|
||||||
const (
|
const (
|
||||||
instance = "fsn1app1/blog"
|
instance = "host1/blog"
|
||||||
remoteURL = "syslog+udp://192.0.2.1:514"
|
remoteURL = "syslog+udp://192.0.2.1:514"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -847,11 +847,11 @@ func TestInstanceNameAndLoggedHeadersAsSet(t *testing.T) {
|
|||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
cfg := wafFromEnvironment(t, environment{
|
cfg := wafFromEnvironment(t, environment{
|
||||||
instanceName: "fsn1app1/blog",
|
instanceName: "host1/blog",
|
||||||
logRequestHeaders: " Accept , X-Custom",
|
logRequestHeaders: " Accept , X-Custom",
|
||||||
})
|
})
|
||||||
|
|
||||||
if cfg.InstanceName != "fsn1app1/blog" ||
|
if cfg.InstanceName != "host1/blog" ||
|
||||||
!slices.Equal(
|
!slices.Equal(
|
||||||
cfg.LogRequestHeaders,
|
cfg.LogRequestHeaders,
|
||||||
[]string{"accept", "x-custom"},
|
[]string{"accept", "x-custom"},
|
||||||
@@ -1024,14 +1024,14 @@ func TestInstanceNameNotAnAppNameStopsTheStartOnlyWhileSending(
|
|||||||
) {
|
) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
const spaced = "fsn1 app1"
|
const spaced = "host1 blog"
|
||||||
|
|
||||||
sending := environment{logRemoteURL: remoteURL, instanceName: spaced}
|
sending := environment{logRemoteURL: remoteURL, instanceName: spaced}
|
||||||
|
|
||||||
_, err := config.WAFFromEnvironment(sending.viper())
|
_, err := config.WAFFromEnvironment(sending.viper())
|
||||||
|
|
||||||
want := logRemoteAppName + `: is unset, and ` + instanceName +
|
want := logRemoteAppName + `: is unset, and ` + instanceName +
|
||||||
` "fsn1 app1", its default, is not 1 to 48 printable ASCII characters ` +
|
` "host1 blog", its default, is not 1 to 48 printable ASCII characters ` +
|
||||||
`without a space, such as blog`
|
`without a space, such as blog`
|
||||||
if err == nil || err.Error() != want {
|
if err == nil || err.Error() != want {
|
||||||
t.Errorf("error %v, want %s", err, want)
|
t.Errorf("error %v, want %s", err, want)
|
||||||
@@ -1333,13 +1333,13 @@ func TestInstanceNameWithAControlCharacterStopsTheStartOnlyWithNtfySet(
|
|||||||
) {
|
) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
const name = "fsn1app1\r"
|
const name = "host1\r"
|
||||||
|
|
||||||
_, err := config.WAFFromEnvironment(environment{
|
_, err := config.WAFFromEnvironment(environment{
|
||||||
instanceName: name, alertNtfyURL: "https://ntfy.example/sww-alerts",
|
instanceName: name, alertNtfyURL: "https://ntfy.example/sww-alerts",
|
||||||
}.viper())
|
}.viper())
|
||||||
|
|
||||||
want := instanceName + `: "fsn1app1\r" holds a control character, such as the ` +
|
want := instanceName + `: "host1\r" holds a control character, such as the ` +
|
||||||
`carriage return of a Windows line end, and is sent to ntfy in a header ` +
|
`carriage return of a Windows line end, and is sent to ntfy in a header ` +
|
||||||
`while ` + alertNtfyURL + ` is set`
|
`while ` + alertNtfyURL + ` is set`
|
||||||
if err == nil || err.Error() != want {
|
if err == nil || err.Error() != want {
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ import (
|
|||||||
const (
|
const (
|
||||||
// started is the time a record made as a test starts gives.
|
// started is the time a record made as a test starts gives.
|
||||||
started = "2000-01-01T00:00:00.000Z"
|
started = "2000-01-01T00:00:00.000Z"
|
||||||
appName = "fsn1app1/blog"
|
appName = "host1/blog"
|
||||||
// local0 is the number of the default facility, and local0Info the
|
// local0 is the number of the default facility, and local0Info the
|
||||||
// priority of its records.
|
// priority of its records.
|
||||||
local0 = 16
|
local0 = 16
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ func TestProcessLinesAreMarkedProcessAndGiveTheInstance(t *testing.T) {
|
|||||||
|
|
||||||
var out bytes.Buffer
|
var out bytes.Buffer
|
||||||
|
|
||||||
requestlog.NewProcessLogger(&out, "fsn1app1/blog", slog.LevelInfo).
|
requestlog.NewProcessLogger(&out, "host1/blog", slog.LevelInfo).
|
||||||
Info("starting",
|
Info("starting",
|
||||||
"version", "v1")
|
"version", "v1")
|
||||||
|
|
||||||
@@ -152,7 +152,7 @@ func TestProcessLinesAreMarkedProcessAndGiveTheInstance(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if fields["type"] != "process" ||
|
if fields["type"] != "process" ||
|
||||||
fields["instance"] != "fsn1app1/blog" ||
|
fields["instance"] != "host1/blog" ||
|
||||||
fields["msg"] != "starting" ||
|
fields["msg"] != "starting" ||
|
||||||
fields["level"] != "INFO" ||
|
fields["level"] != "INFO" ||
|
||||||
fields["version"] != "v1" {
|
fields["version"] != "v1" {
|
||||||
@@ -187,7 +187,7 @@ func TestProcessLoggerWritesTheMessagesAtItsLevelOrMoreSevere(t *testing.T) {
|
|||||||
|
|
||||||
processLog := requestlog.NewProcessLogger(
|
processLog := requestlog.NewProcessLogger(
|
||||||
&out,
|
&out,
|
||||||
"fsn1app1/blog",
|
"host1/blog",
|
||||||
level,
|
level,
|
||||||
)
|
)
|
||||||
for _, at := range levels {
|
for _, at := range levels {
|
||||||
|
|||||||
@@ -159,7 +159,7 @@ const filledAlertsJSON = `{
|
|||||||
"waiting": {
|
"waiting": {
|
||||||
"webhook": [
|
"webhook": [
|
||||||
{
|
{
|
||||||
"instance": "fsn1app1/blog",
|
"instance": "host1/blog",
|
||||||
"time": "2026-10-06T00:00:00Z",
|
"time": "2026-10-06T00:00:00Z",
|
||||||
"event": "ban",
|
"event": "ban",
|
||||||
"client": "203.0.113.9",
|
"client": "203.0.113.9",
|
||||||
@@ -174,7 +174,7 @@ const filledAlertsJSON = `{
|
|||||||
"suppressed_repeats": 0
|
"suppressed_repeats": 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"instance": "fsn1app1/blog",
|
"instance": "host1/blog",
|
||||||
"time": "2026-10-06T00:00:00Z",
|
"time": "2026-10-06T00:00:00Z",
|
||||||
"event": "file_error",
|
"event": "file_error",
|
||||||
"client": "",
|
"client": "",
|
||||||
@@ -2398,7 +2398,7 @@ func newParams(dir string) state.Params {
|
|||||||
Events: alerts.Events(),
|
Events: alerts.Events(),
|
||||||
Cooldown: 15 * time.Minute,
|
Cooldown: 15 * time.Minute,
|
||||||
MaxPerHour: 2,
|
MaxPerHour: 2,
|
||||||
Instance: "fsn1app1/blog",
|
Instance: "host1/blog",
|
||||||
Now: midnight,
|
Now: midnight,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
+14
-14
@@ -52,7 +52,7 @@ const (
|
|||||||
adminSecret = "fedcba9876543210fedcba9876543210"
|
adminSecret = "fedcba9876543210fedcba9876543210"
|
||||||
// instance is the SWW_WAF_INSTANCE_NAME the tests set where they look at
|
// instance is the SWW_WAF_INSTANCE_NAME the tests set where they look at
|
||||||
// it.
|
// it.
|
||||||
instance = "fsn1app1/blog"
|
instance = "host1/blog"
|
||||||
// greeting is what the tests' app answers.
|
// greeting is what the tests' app answers.
|
||||||
greeting = "hello from the app"
|
greeting = "hello from the app"
|
||||||
// placed is the client the tests' lookup databases place.
|
// placed is the client the tests' lookup databases place.
|
||||||
@@ -386,8 +386,8 @@ func TestEveryLogLineAndMetricCarriesTheInstanceName(t *testing.T) {
|
|||||||
// the comments.
|
// the comments.
|
||||||
for line := range strings.Lines(metrics) {
|
for line := range strings.Lines(metrics) {
|
||||||
if !strings.HasPrefix(line, "#") &&
|
if !strings.HasPrefix(line, "#") &&
|
||||||
!strings.Contains(line, `instance="fsn1app1/blog"`) {
|
!strings.Contains(line, `instance="host1/blog"`) {
|
||||||
t.Errorf("series %q, without instance=\"fsn1app1/blog\"", line)
|
t.Errorf("series %q, without instance=\"host1/blog\"", line)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -734,12 +734,12 @@ func TestLookupDatabaseReplacedWhileRunningTakesEffect(t *testing.T) {
|
|||||||
t,
|
t,
|
||||||
url+"_sww/metrics",
|
url+"_sww/metrics",
|
||||||
token,
|
token,
|
||||||
`sww_lookup_database_read_failures_total{instance="fsn1app1/blog"} 1`,
|
`sww_lookup_database_read_failures_total{instance="host1/blog"} 1`,
|
||||||
)
|
)
|
||||||
lastRead = seriesValue(
|
lastRead = seriesValue(
|
||||||
t,
|
t,
|
||||||
metrics,
|
metrics,
|
||||||
`sww_lookup_database_last_read_timestamp_seconds{instance="fsn1app1/blog"}`,
|
`sww_lookup_database_last_read_timestamp_seconds{instance="host1/blog"}`,
|
||||||
)
|
)
|
||||||
|
|
||||||
wantStatus(t, url, placed, http.StatusOK)
|
wantStatus(t, url, placed, http.StatusOK)
|
||||||
@@ -801,7 +801,7 @@ func TestBlocklistTriesAndCopiesKeptInListsJSONAcrossRestarts(t *testing.T) {
|
|||||||
// too.
|
// too.
|
||||||
rateLimitExemptNets: placed + "," + localhost,
|
rateLimitExemptNets: placed + "," + localhost,
|
||||||
}
|
}
|
||||||
failures := `sww_reputation_failures_total{instance="fsn1app1/blog",` +
|
failures := `sww_reputation_failures_total{instance="host1/blog",` +
|
||||||
`source="` + torURL + `"} `
|
`source="` + torURL + `"} `
|
||||||
|
|
||||||
// tor.txt cannot be fetched at first, which is counted.
|
// tor.txt cannot be fetched at first, which is counted.
|
||||||
@@ -984,8 +984,8 @@ func TestStalledRemoteLogEndpointHoldsUpNoRequest(t *testing.T) {
|
|||||||
// last.
|
// last.
|
||||||
metrics := metricsText(t, url+"_sww/metrics", token)
|
metrics := metricsText(t, url+"_sww/metrics", token)
|
||||||
for _, series := range []string{
|
for _, series := range []string{
|
||||||
`sww_remote_log_lines_sent_total{instance="fsn1app1/blog"} 0`,
|
`sww_remote_log_lines_sent_total{instance="host1/blog"} 0`,
|
||||||
`sww_remote_log_lines_waiting{instance="fsn1app1/blog"} 1`,
|
`sww_remote_log_lines_waiting{instance="host1/blog"} 1`,
|
||||||
} {
|
} {
|
||||||
if !strings.Contains(metrics, "\n"+series+"\n") {
|
if !strings.Contains(metrics, "\n"+series+"\n") {
|
||||||
t.Errorf("no %q in the metrics:\n%s", series, metrics)
|
t.Errorf("no %q in the metrics:\n%s", series, metrics)
|
||||||
@@ -993,7 +993,7 @@ func TestStalledRemoteLogEndpointHoldsUpNoRequest(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const dropped = "\nsww_remote_log_lines_dropped_total" +
|
const dropped = "\nsww_remote_log_lines_dropped_total" +
|
||||||
`{instance="fsn1app1/blog"} `
|
`{instance="host1/blog"} `
|
||||||
if strings.Contains(metrics, dropped+"0\n") ||
|
if strings.Contains(metrics, dropped+"0\n") ||
|
||||||
!strings.Contains(metrics, dropped) {
|
!strings.Contains(metrics, dropped) {
|
||||||
t.Errorf("no line dropped in the metrics:\n%s", metrics)
|
t.Errorf("no line dropped in the metrics:\n%s", metrics)
|
||||||
@@ -1089,7 +1089,7 @@ func TestBanIsAlertedAndAnAlertNotSentIsKeptAcrossARestart(t *testing.T) {
|
|||||||
runUntilStopped(t, env, func(url string) {
|
runUntilStopped(t, env, func(url string) {
|
||||||
webhook.waitFor(t, "permanent_ban", true)
|
webhook.waitFor(t, "permanent_ban", true)
|
||||||
|
|
||||||
const ofWebhook = `{destination="webhook",instance="fsn1app1/blog"}`
|
const ofWebhook = `{destination="webhook",instance="host1/blog"}`
|
||||||
|
|
||||||
metrics := metricsWith(t, url+"_sww/metrics", token,
|
metrics := metricsWith(t, url+"_sww/metrics", token,
|
||||||
"\nsww_alerts_sent_total"+ofWebhook+" 1\n")
|
"\nsww_alerts_sent_total"+ofWebhook+" 1\n")
|
||||||
@@ -1176,13 +1176,13 @@ func TestBanIsAlertedToSlackAndNtfy(t *testing.T) {
|
|||||||
err := json.Unmarshal([]byte(slackPost.body), &message)
|
err := json.Unmarshal([]byte(slackPost.body), &message)
|
||||||
|
|
||||||
if err != nil ||
|
if err != nil ||
|
||||||
!strings.HasPrefix(message.Text, "*fsn1app1/blog: ban*\n") ||
|
!strings.HasPrefix(message.Text, "*host1/blog: ban*\n") ||
|
||||||
!strings.Contains(message.Text, "\nclient: "+client+"\n") {
|
!strings.Contains(message.Text, "\nclient: "+client+"\n") {
|
||||||
t.Errorf("Slack was sent %s", slackPost.body)
|
t.Errorf("Slack was sent %s", slackPost.body)
|
||||||
}
|
}
|
||||||
|
|
||||||
ntfyPost := ntfy.firstPost(t)
|
ntfyPost := ntfy.firstPost(t)
|
||||||
if ntfyPost.header.Get("Title") != "fsn1app1/blog: ban" ||
|
if ntfyPost.header.Get("Title") != "host1/blog: ban" ||
|
||||||
ntfyPost.header.Get("Authorization") != "Bearer "+ntfyToken ||
|
ntfyPost.header.Get("Authorization") != "Bearer "+ntfyToken ||
|
||||||
!strings.Contains(ntfyPost.body, "\nclient: "+client+"\n") {
|
!strings.Contains(ntfyPost.body, "\nclient: "+client+"\n") {
|
||||||
t.Errorf("ntfy was sent %s, with the headers %v", ntfyPost.body,
|
t.Errorf("ntfy was sent %s, with the headers %v", ntfyPost.body,
|
||||||
@@ -1194,9 +1194,9 @@ func TestBanIsAlertedToSlackAndNtfy(t *testing.T) {
|
|||||||
// test process cannot fail the test.
|
// test process cannot fail the test.
|
||||||
sent := []string{
|
sent := []string{
|
||||||
"\nsww_alerts_sent_total{destination=\"slack\"," +
|
"\nsww_alerts_sent_total{destination=\"slack\"," +
|
||||||
"instance=\"fsn1app1/blog\"} 1\n",
|
"instance=\"host1/blog\"} 1\n",
|
||||||
"\nsww_alerts_sent_total{destination=\"ntfy\"," +
|
"\nsww_alerts_sent_total{destination=\"ntfy\"," +
|
||||||
"instance=\"fsn1app1/blog\"} 1\n",
|
"instance=\"host1/blog\"} 1\n",
|
||||||
}
|
}
|
||||||
|
|
||||||
metrics := metricsWith(t, url+"_sww/metrics", token, sent...)
|
metrics := metricsWith(t, url+"_sww/metrics", token, sent...)
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ const (
|
|||||||
alertWebhookURL = "SWW_WAF_ALERT_WEBHOOK_URL"
|
alertWebhookURL = "SWW_WAF_ALERT_WEBHOOK_URL"
|
||||||
alertMaxPerHour = "SWW_WAF_ALERT_MAX_PER_HOUR"
|
alertMaxPerHour = "SWW_WAF_ALERT_MAX_PER_HOUR"
|
||||||
// alertInstance is the instance every alert of these tests gives.
|
// alertInstance is the instance every alert of these tests gives.
|
||||||
alertInstance = "fsn1app1/blog"
|
alertInstance = "host1/blog"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestBanForABrokenLimitRaisesABanAlertWithItsNotes(t *testing.T) {
|
func TestBanForABrokenLimitRaisesABanAlertWithItsNotes(t *testing.T) {
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ const (
|
|||||||
// requestIDHeader carries the request's id.
|
// requestIDHeader carries the request's id.
|
||||||
requestIDHeader = "X-Request-ID"
|
requestIDHeader = "X-Request-ID"
|
||||||
// instance is the SWW_WAF_INSTANCE_NAME a test sets.
|
// instance is the SWW_WAF_INSTANCE_NAME a test sets.
|
||||||
instance = "fsn1app1/blog"
|
instance = "host1/blog"
|
||||||
// ipv6Client is a client on IPv6, and ipv6Group the netblock the rate
|
// ipv6Client is a client on IPv6, and ipv6Group the netblock the rate
|
||||||
// limits count it as.
|
// limits count it as.
|
||||||
ipv6Client = "2001:db8::7"
|
ipv6Client = "2001:db8::7"
|
||||||
|
|||||||
+12
-6
@@ -2,8 +2,9 @@
|
|||||||
# script/publish: build the image on the Docker host and push it to the
|
# script/publish: build the image on the Docker host and push it to the
|
||||||
# registry under four tags: the UTC date (YYYY-MM-DD), the short commit
|
# registry under four tags: the UTC date (YYYY-MM-DD), the short commit
|
||||||
# hash, the branch name and latest. The build is script/docker's, so the
|
# hash, the branch name and latest. The build is script/docker's, so the
|
||||||
# tests and the linter run first. The host and the registry name are
|
# tests and the linter run first. DOCKER_HOST names the Docker host and
|
||||||
# environment variables with defaults, for running it against another.
|
# PUBLISH_IMAGE the image in the registry. Both must be set; neither has
|
||||||
|
# a default.
|
||||||
#
|
#
|
||||||
# The working tree must be clean: the hash tag names a commit, and an
|
# The working tree must be clean: the hash tag names a commit, and an
|
||||||
# image built from uncommitted changes would carry a hash that does not
|
# image built from uncommitted changes would carry a hash that does not
|
||||||
@@ -13,11 +14,16 @@ set -eu
|
|||||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd -P)"
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd -P)"
|
||||||
ROOT="$(cd "$SCRIPT_DIR/.." && pwd -P)"
|
ROOT="$(cd "$SCRIPT_DIR/.." && pwd -P)"
|
||||||
|
|
||||||
: "${DOCKER_HOST:=ssh://root@fsn1app1}"
|
|
||||||
: "${PUBLISH_IMAGE:=git.eeqj.de/sneak/smallwebwaf}"
|
|
||||||
export DOCKER_HOST
|
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
|
if [ -z "${DOCKER_HOST:-}" ]; then
|
||||||
|
echo "script/publish: DOCKER_HOST is not set; set it to the Docker host that builds the image, such as ssh://user@build.example.com" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if [ -z "${PUBLISH_IMAGE:-}" ]; then
|
||||||
|
echo "script/publish: PUBLISH_IMAGE is not set; set it to the image name in the registry, such as registry.example.com/smallwebwaf" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
cd "$ROOT"
|
cd "$ROOT"
|
||||||
|
|
||||||
# Own line: a failing command substitution inside an argument does
|
# Own line: a failing command substitution inside an argument does
|
||||||
|
|||||||
Reference in new issue
Block a user