Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5ceef3edf3 |
@@ -213,8 +213,7 @@ effective settings are logged at start.
|
|||||||
the name every log line and alert gives as `instance`, and every metric
|
the name every log line and alert gives as `instance`, and every metric
|
||||||
carries as its label `instance` (see "Metrics" below). Set it, for example to
|
carries as its label `instance` (see "Metrics" below). Set it, for example to
|
||||||
`fsn1app1/gitea`, for a name that stays the same when a deploy replaces the
|
`fsn1app1/gitea`, for a name that stays the same when a deploy replaces the
|
||||||
container, and that tells instances apart when several log to one place. A
|
container, and that tells instances apart when several log to one place.
|
||||||
name that is not valid UTF-8, such as one saved in Latin-1, stops the start.
|
|
||||||
- `SWWAF_MODE` (default `enforce`): `enforce`, or `observe` to pass on the
|
- `SWWAF_MODE` (default `enforce`): `enforce`, or `observe` to pass on the
|
||||||
requests `smallwebwaf` would refuse and log what it would have done (see "What
|
requests `smallwebwaf` would refuse and log what it would have done (see "What
|
||||||
it does so far" above).
|
it does so far" above).
|
||||||
|
|||||||
@@ -268,7 +268,6 @@ var (
|
|||||||
"is not ban, permanent_ban, waf_block, anomaly, reputation_hit, " +
|
"is not ban, permanent_ban, waf_block, anomaly, reputation_hit, " +
|
||||||
"source_failure or file_error")
|
"source_failure or file_error")
|
||||||
errNotNumberOrOff = errors.New("is not a whole number above zero, such as 60, or off")
|
errNotNumberOrOff = errors.New("is not a whole number above zero, such as 60, or off")
|
||||||
errNotUTF8 = errors.New("is not valid UTF-8")
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// FromEnvironment reads the settings with lookupEnv, normally
|
// FromEnvironment reads the settings with lookupEnv, normally
|
||||||
@@ -671,17 +670,11 @@ func (e *environment) facility(name, defaultValue string) int {
|
|||||||
return number
|
return number
|
||||||
}
|
}
|
||||||
|
|
||||||
// instanceName reads SWWAF_INSTANCE_NAME, by default the host's name. It
|
// instanceName reads SWWAF_INSTANCE_NAME, by default the host's name.
|
||||||
// must be valid UTF-8: the metrics library panics on a label that is not.
|
|
||||||
func (e *environment) instanceName() string {
|
func (e *environment) instanceName() string {
|
||||||
hostname, _ := os.Hostname() // "" when the host has no name to give
|
hostname, _ := os.Hostname() // "" when the host has no name to give
|
||||||
|
|
||||||
value := e.value("SWWAF_INSTANCE_NAME", hostname)
|
return e.value("SWWAF_INSTANCE_NAME", hostname)
|
||||||
if !utf8.ValidString(value) {
|
|
||||||
e.check("SWWAF_INSTANCE_NAME", fmt.Errorf("%q %w", value, errNotUTF8))
|
|
||||||
}
|
|
||||||
|
|
||||||
return value
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// appName reads the setting that is the APP-NAME of the records the log
|
// appName reads the setting that is the APP-NAME of the records the log
|
||||||
|
|||||||
@@ -737,25 +737,6 @@ func TestInstanceNameWithAControlCharacterStopsTheStartOnlyWithNtfySet(t *testin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInstanceNameNotUTF8StopsTheStart(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
// café saved in Latin-1.
|
|
||||||
const latin1 = "caf\xe9"
|
|
||||||
|
|
||||||
for name, env := range map[string]environment{
|
|
||||||
"set": {instanceName: latin1},
|
|
||||||
"in a file": {instanceName + "_FILE": writeFile(t, latin1+"\n")},
|
|
||||||
} {
|
|
||||||
_, err := config.FromEnvironment(env.lookupEnv)
|
|
||||||
|
|
||||||
want := instanceName + `: "caf\xe9" is not valid UTF-8`
|
|
||||||
if err == nil || err.Error() != want {
|
|
||||||
t.Errorf("%s: error %v, want %s", name, err, want)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestCodeOnBothCountryListsStopsTheStart(t *testing.T) {
|
func TestCodeOnBothCountryListsStopsTheStart(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
|||||||
@@ -597,13 +597,6 @@ func TestStalledRemoteLogEndpointHoldsUpNoRequest(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
out.line(t, "type", "request")
|
out.line(t, "type", "request")
|
||||||
|
|
||||||
// While the lines are sent, the process's lines give the instance name
|
|
||||||
// too.
|
|
||||||
line := out.line(t, "msg", "starting")
|
|
||||||
if line["instance"] != instance {
|
|
||||||
t.Errorf("start logged with instance %v, want %s", line["instance"], instance)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBanIsAlertedAndAnAlertNotSentIsKeptAcrossARestart(t *testing.T) {
|
func TestBanIsAlertedAndAnAlertNotSentIsKeptAcrossARestart(t *testing.T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user