Anubis module for Caddy

wa

Changed files
+11 -7
example
+10 -2
caddy_anubis.go
···
import (
"fmt"
+
"log/slog"
"net"
"net/http"
"strconv"
···
"github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile"
"github.com/caddyserver/caddy/v2/modules/caddyhttp"
"go.uber.org/zap"
+
"go.uber.org/zap/exp/zapslog"
)
func init() {
···
func (m *AnubisMiddleware) Provision(ctx caddy.Context) error {
m.log = ctx.Logger(m)
-
// slog.SetLogLoggerLevel(slog.LevelDebug) // TODO: customizable log level
+
// TODO: figure out a better level for this
+
zs := zapslog.NewHandler(m.log.Core(), zapslog.AddStacktraceAt(slog.LevelError + 1))
+
+
// TODO: don't set the global slog logger
+
// currently, anubis does not allow custom loggers (https://github.com/TecharoHQ/anubis/issues/864)
+
sl := slog.New(zs)
+
slog.SetDefault(sl)
m.log.Debug("loading anubis policies", zap.String("policy_file", m.PolicyFname), zap.Int("default_difficulty", m.DefaultDifficulty))
policy, err := libanubis.LoadPoliciesOrDefault(ctx, m.PolicyFname, m.DefaultDifficulty)
···
m.DefaultDifficulty = anubis.DefaultDifficulty
m.Options.CookieExpiration = anubis.CookieDefaultExpirationTime
-
m.Options.CookieSecure = true // TODO: temporary
+
m.Options.CookieSecure = true // TODO: set this only on https upstreams
for nesting := d.Nesting(); d.NextBlock(nesting); {
var err error
-4
example/Caddyfile
···
localhost {
-
log {
-
level debug
-
}
-
@anubis {
# This matcher allows you to select specific paths for Anubis to handle.
# If you want to handle all paths, remove this block and use `anubis {...}` instead!
+1 -1
go.mod
···
go.uber.org/automaxprocs v1.6.0 // indirect
go.uber.org/mock v0.5.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
-
go.uber.org/zap/exp v0.3.0 // indirect
+
go.uber.org/zap/exp v0.3.0
go.yaml.in/yaml/v2 v2.4.2 // indirect
golang.org/x/crypto v0.40.0 // indirect
golang.org/x/crypto/x509roots/fallback v0.0.0-20250305170421-49bf5b80c810 // indirect