From ae4c8d224c4052f707e006511e67278cad05c02b Mon Sep 17 00:00:00 2001 From: Xe Iaso Date: Tue, 25 Nov 2025 23:11:34 -0500 Subject: [PATCH] fix(policy): use the new logger for config validation messages Signed-off-by: Xe Iaso --- docs/docs/CHANGELOG.md | 21 ++++++++++++--- lib/policy/policy.go | 59 +++++++++++++++++++++++------------------- 2 files changed, 50 insertions(+), 30 deletions(-) diff --git a/docs/docs/CHANGELOG.md b/docs/docs/CHANGELOG.md index c2484e22..e5ef4180 100644 --- a/docs/docs/CHANGELOG.md +++ b/docs/docs/CHANGELOG.md @@ -27,7 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Deprecate `report_as` in challenge configuration -Previously Anubis let you lie to users about the difficulty of a challenge to interfere with operators of malicious scrapers as a psyops attack: +Previously Anubis let you lie to users about the difficulty of a challenge to interfere with operators of malicious scrapers as a psychological attack: ```yaml bots: @@ -42,9 +42,24 @@ bots: algorithm: slow # intentionally waste CPU cycles and time ``` -This has turned out to be a bad idea and has been removed. +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: -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. +```json +{ + "time": "2025-11-25T23:10:31.092201549-05:00", + "level": "WARN", + "source": { + "function": "github.com/TecharoHQ/anubis/lib/policy.ParseConfig", + "file": "/home/xe/code/TecharoHQ/anubis/lib/policy/policy.go", + "line": 201 + }, + "msg": "use of deprecated report_as setting detected, please remove this from your policy file when possible", + "at": "config-validate", + "name": "mild-suspicion" +} +``` + +To remove this warning, remove this setting from your policy file. ### Logging customization diff --git a/lib/policy/policy.go b/lib/policy/policy.go index 639bbe59..afb9b77e 100644 --- a/lib/policy/policy.go +++ b/lib/policy/policy.go @@ -66,6 +66,29 @@ func ParseConfig(ctx context.Context, fin io.Reader, fname string, defaultDiffic result := newParsedConfig(c) result.DefaultDifficulty = defaultDifficulty + if c.Logging.Level != nil { + logLevel = c.Logging.Level.String() + } + + switch c.Logging.Sink { + case config.LogSinkStdio: + result.Logger = internal.InitSlog(logLevel, os.Stderr) + case config.LogSinkFile: + out := &logrotate.Logger{ + Filename: c.Logging.Parameters.Filename, + FilenameTimeFormat: time.RFC3339, + MaxBytes: c.Logging.Parameters.MaxBytes, + MaxAge: c.Logging.Parameters.MaxAge, + MaxBackups: c.Logging.Parameters.MaxBackups, + LocalTime: c.Logging.Parameters.UseLocalTime, + Compress: c.Logging.Parameters.Compress, + } + + result.Logger = internal.InitSlog(logLevel, out) + } + + lg := result.Logger.With("at", "config-validate") + for _, b := range c.Bots { if berr := b.Valid(); berr != nil { validationErrs = append(validationErrs, berr) @@ -126,7 +149,7 @@ func ParseConfig(ctx context.Context, fin io.Reader, fname string, defaultDiffic if b.ASNs != nil { if !hasThothClient { - 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) + 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) continue } @@ -135,7 +158,7 @@ func ParseConfig(ctx context.Context, fin io.Reader, fname string, defaultDiffic if b.GeoIP != nil { if !hasThothClient { - 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) + 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) continue } @@ -154,7 +177,7 @@ func ParseConfig(ctx context.Context, fin io.Reader, fname string, defaultDiffic } if parsedBot.Challenge.Algorithm == "slow" { - slog.Warn("use of deprecated algorithm \"slow\" detected, please update this to \"fast\" when possible", "name", parsedBot.Name) + lg.Warn("use of deprecated algorithm \"slow\" detected, please update this to \"fast\" when possible", "name", parsedBot.Name) } } @@ -171,17 +194,20 @@ func ParseConfig(ctx context.Context, fin io.Reader, fname string, defaultDiffic for _, t := range c.Thresholds { if t.Challenge != nil && t.Challenge.Algorithm == "slow" { - slog.Warn("use of deprecated algorithm \"slow\" detected, please update this to \"fast\" when possible", "name", t.Name) + lg.Warn("use of deprecated algorithm \"slow\" detected, please update this to \"fast\" when possible", "name", t.Name) + } + + if t.Challenge != nil && t.Challenge.ReportAs != 0 { + lg.Warn("use of deprecated report_as setting detected, please remove this from your policy file when possible", "name", t.Name) } if t.Name == "legacy-anubis-behaviour" && t.Expression.String() == "true" { if !warnedAboutThresholds.Load() { - 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/") + 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/") warnedAboutThresholds.Store(true) } t.Challenge.Difficulty = defaultDifficulty - t.Challenge.ReportAs = defaultDifficulty } threshold, err := ParsedThresholdFromConfig(t) @@ -206,27 +232,6 @@ func ParseConfig(ctx context.Context, fin io.Reader, fname string, defaultDiffic validationErrs = append(validationErrs, config.ErrUnknownStoreBackend) } - if c.Logging.Level != nil { - logLevel = c.Logging.Level.String() - } - - switch c.Logging.Sink { - case config.LogSinkStdio: - result.Logger = internal.InitSlog(logLevel, os.Stderr) - case config.LogSinkFile: - out := &logrotate.Logger{ - Filename: c.Logging.Parameters.Filename, - FilenameTimeFormat: time.RFC3339, - MaxBytes: c.Logging.Parameters.MaxBytes, - MaxAge: c.Logging.Parameters.MaxAge, - MaxBackups: c.Logging.Parameters.MaxBackups, - LocalTime: c.Logging.Parameters.UseLocalTime, - Compress: c.Logging.Parameters.Compress, - } - - result.Logger = internal.InitSlog(logLevel, out) - } - if len(validationErrs) > 0 { return nil, fmt.Errorf("errors validating policy config JSON %s: %w", fname, errors.Join(validationErrs...)) }