Skip to content

Commit 2d0d0bf

Browse files
committed
fix(policy): use the new logger for config validation messages
Signed-off-by: Xe Iaso <me@xeiaso.net>
1 parent d3b72e3 commit 2d0d0bf

2 files changed

Lines changed: 50 additions & 30 deletions

File tree

docs/docs/CHANGELOG.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2727

2828
### Deprecate `report_as` in challenge configuration
2929

30-
Previously Anubis let you lie to users about the difficulty of a challenge to interfere with operators of malicious scrapers as a psyops attack:
30+
Previously Anubis let you lie to users about the difficulty of a challenge to interfere with operators of malicious scrapers as a psychological attack:
3131

3232
```yaml
3333
bots:
@@ -42,9 +42,24 @@ bots:
4242
algorithm: slow # intentionally waste CPU cycles and time
4343
```
4444
45-
This has turned out to be a bad idea and has been removed.
45+
This has turned out to be a bad idea because it has caused massive user experience problems and has been removed. If you are using this setting, you will get a warning in your logs like this:
46+
47+
```json
48+
{
49+
"time": "2025-11-25T23:10:31.092201549-05:00",
50+
"level": "WARN",
51+
"source": {
52+
"function": "github.com/TecharoHQ/anubis/lib/policy.ParseConfig",
53+
"file": "TecharoHQ/anubis/lib/policy/policy.go",
54+
"line": 201
55+
},
56+
"msg": "use of deprecated report_as setting detected, please remove this from your policy file when possible",
57+
"at": "config-validate",
58+
"name": "mild-suspicion"
59+
}
60+
```
4661

47-
If you are using this setting, you will get a warning in your logs. To remove this warning, remove this setting from your policy file.
62+
To remove this warning, remove this setting from your policy file.
4863

4964
### Logging customization
5065

lib/policy/policy.go

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,29 @@ func ParseConfig(ctx context.Context, fin io.Reader, fname string, defaultDiffic
6666
result := newParsedConfig(c)
6767
result.DefaultDifficulty = defaultDifficulty
6868

69+
if c.Logging.Level != nil {
70+
logLevel = c.Logging.Level.String()
71+
}
72+
73+
switch c.Logging.Sink {
74+
case config.LogSinkStdio:
75+
result.Logger = internal.InitSlog(logLevel, os.Stderr)
76+
case config.LogSinkFile:
77+
out := &logrotate.Logger{
78+
Filename: c.Logging.Parameters.Filename,
79+
FilenameTimeFormat: time.RFC3339,
80+
MaxBytes: c.Logging.Parameters.MaxBytes,
81+
MaxAge: c.Logging.Parameters.MaxAge,
82+
MaxBackups: c.Logging.Parameters.MaxBackups,
83+
LocalTime: c.Logging.Parameters.UseLocalTime,
84+
Compress: c.Logging.Parameters.Compress,
85+
}
86+
87+
result.Logger = internal.InitSlog(logLevel, out)
88+
}
89+
90+
lg := result.Logger.With("at", "config-validate")
91+
6992
for _, b := range c.Bots {
7093
if berr := b.Valid(); berr != nil {
7194
validationErrs = append(validationErrs, berr)
@@ -126,7 +149,7 @@ func ParseConfig(ctx context.Context, fin io.Reader, fname string, defaultDiffic
126149

127150
if b.ASNs != nil {
128151
if !hasThothClient {
129-
slog.Warn("You have specified a Thoth specific check but you have no Thoth client configured. Please read https://anubis.techaro.lol/docs/admin/thoth for more information", "check", "asn", "settings", b.ASNs)
152+
lg.Warn("You have specified a Thoth specific check but you have no Thoth client configured. Please read https://anubis.techaro.lol/docs/admin/thoth for more information", "check", "asn", "settings", b.ASNs)
130153
continue
131154
}
132155

@@ -135,7 +158,7 @@ func ParseConfig(ctx context.Context, fin io.Reader, fname string, defaultDiffic
135158

136159
if b.GeoIP != nil {
137160
if !hasThothClient {
138-
slog.Warn("You have specified a Thoth specific check but you have no Thoth client configured. Please read https://anubis.techaro.lol/docs/admin/thoth for more information", "check", "geoip", "settings", b.GeoIP)
161+
lg.Warn("You have specified a Thoth specific check but you have no Thoth client configured. Please read https://anubis.techaro.lol/docs/admin/thoth for more information", "check", "geoip", "settings", b.GeoIP)
139162
continue
140163
}
141164

@@ -154,7 +177,7 @@ func ParseConfig(ctx context.Context, fin io.Reader, fname string, defaultDiffic
154177
}
155178

156179
if parsedBot.Challenge.Algorithm == "slow" {
157-
slog.Warn("use of deprecated algorithm \"slow\" detected, please update this to \"fast\" when possible", "name", parsedBot.Name)
180+
lg.Warn("use of deprecated algorithm \"slow\" detected, please update this to \"fast\" when possible", "name", parsedBot.Name)
158181
}
159182
}
160183

@@ -171,17 +194,20 @@ func ParseConfig(ctx context.Context, fin io.Reader, fname string, defaultDiffic
171194

172195
for _, t := range c.Thresholds {
173196
if t.Challenge != nil && t.Challenge.Algorithm == "slow" {
174-
slog.Warn("use of deprecated algorithm \"slow\" detected, please update this to \"fast\" when possible", "name", t.Name)
197+
lg.Warn("use of deprecated algorithm \"slow\" detected, please update this to \"fast\" when possible", "name", t.Name)
198+
}
199+
200+
if t.Challenge != nil && t.Challenge.ReportAs != 0 {
201+
lg.Warn("use of deprecated report_as setting detected, please remove this from your policy file when possible", "name", t.Name)
175202
}
176203

177204
if t.Name == "legacy-anubis-behaviour" && t.Expression.String() == "true" {
178205
if !warnedAboutThresholds.Load() {
179-
slog.Warn("configuration file does not contain thresholds, see docs for details on how to upgrade", "fname", fname, "docs_url", "https://anubis.techaro.lol/docs/admin/configuration/thresholds/")
206+
lg.Warn("configuration file does not contain thresholds, see docs for details on how to upgrade", "fname", fname, "docs_url", "https://anubis.techaro.lol/docs/admin/configuration/thresholds/")
180207
warnedAboutThresholds.Store(true)
181208
}
182209

183210
t.Challenge.Difficulty = defaultDifficulty
184-
t.Challenge.ReportAs = defaultDifficulty
185211
}
186212

187213
threshold, err := ParsedThresholdFromConfig(t)
@@ -206,27 +232,6 @@ func ParseConfig(ctx context.Context, fin io.Reader, fname string, defaultDiffic
206232
validationErrs = append(validationErrs, config.ErrUnknownStoreBackend)
207233
}
208234

209-
if c.Logging.Level != nil {
210-
logLevel = c.Logging.Level.String()
211-
}
212-
213-
switch c.Logging.Sink {
214-
case config.LogSinkStdio:
215-
result.Logger = internal.InitSlog(logLevel, os.Stderr)
216-
case config.LogSinkFile:
217-
out := &logrotate.Logger{
218-
Filename: c.Logging.Parameters.Filename,
219-
FilenameTimeFormat: time.RFC3339,
220-
MaxBytes: c.Logging.Parameters.MaxBytes,
221-
MaxAge: c.Logging.Parameters.MaxAge,
222-
MaxBackups: c.Logging.Parameters.MaxBackups,
223-
LocalTime: c.Logging.Parameters.UseLocalTime,
224-
Compress: c.Logging.Parameters.Compress,
225-
}
226-
227-
result.Logger = internal.InitSlog(logLevel, out)
228-
}
229-
230235
if len(validationErrs) > 0 {
231236
return nil, fmt.Errorf("errors validating policy config JSON %s: %w", fname, errors.Join(validationErrs...))
232237
}

0 commit comments

Comments
 (0)