feat: 1.4.0 second firewall, egress analysis and HTML report
CI / Docker image (build and smoke test) (push) Skipped
CI / Format and vet (push) Successful in 28s
CI / Dependency audit (push) Successful in 16s
CI / Tests (Linux, race detector) (push) Successful in 1m3s
Release / Plan (reuse the published image?) (push) Successful in 4s
Release / ci (push) Skipped
Release / Build image (amd64) (push) Skipped
Release / Build image (arm64) (push) Skipped
Release / Publish tags (push) Successful in 13s
Release / Gitea release (push) Successful in 3s
CI / Docker image (build and smoke test) (push) Skipped
CI / Format and vet (push) Successful in 28s
CI / Dependency audit (push) Successful in 16s
CI / Tests (Linux, race detector) (push) Successful in 1m3s
Release / Plan (reuse the published image?) (push) Successful in 4s
Release / ci (push) Skipped
Release / Build image (amd64) (push) Skipped
Release / Build image (arm64) (push) Skipped
Release / Publish tags (push) Successful in 13s
Release / Gitea release (push) Successful in 3s
Optional second firewall (URUTAU_ENFORCE off/observe/on) through the host fail2ban, outbound traffic analysis (beaconing, mining, spam, DNS bypass, unauthorised scans) with authorised scanner workloads, host kit in deploy/host and a printable HTML report. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3adaa007ec
commit
c33cca22e3
59 files changed
+7364
-24
No files matched your search
@@ -46,6 +46,19 @@ type Config struct {
|
||||
TorExits string // file with Tor exit addresses, one per line; empty disables the check
|
||||
EventsMax string // size cap of the event registry ("512MB", "0" disables it)
|
||||
NoAuth bool
|
||||
// Second firewall (see internal/enforce).
|
||||
Enforce string // off (default), observe or on
|
||||
EnforceLog string // decision file read by the host fail2ban
|
||||
EnforceShare string // off (default) or on: exchange decisions with peers
|
||||
EnforceThreshold int // attack events in 10 minutes that justify a ban
|
||||
EnforceMaxPerMin int // decisions per minute; the excess is dropped
|
||||
|
||||
// Egress analysis (see internal/egress).
|
||||
Egress string // auto (default: on when the log exists), on or off
|
||||
EgressLog string // kernel log of new outbound connections
|
||||
EgressWorkloads string // "name=CIDR|name:<prefix>[,...][:role];..."
|
||||
EgressResolvers string // DNS resolvers allowed (empty: the usual public ones)
|
||||
EgressContainers string // "<ip> <container>" map written by the host kit
|
||||
}
|
||||
|
||||
// DefaultEventsMax is the default size cap of the event registry.
|
||||
@@ -86,6 +99,15 @@ func env(key, def string) string {
|
||||
return def
|
||||
}
|
||||
|
||||
func envInt(key string, def int) int {
|
||||
if v, ok := os.LookupEnv(key); ok {
|
||||
if n, err := strconv.Atoi(strings.TrimSpace(v)); err == nil {
|
||||
return n
|
||||
}
|
||||
}
|
||||
return def
|
||||
}
|
||||
|
||||
// csvFlag accumulates comma separated values; the first use replaces the default.
|
||||
type csvFlag struct {
|
||||
val string
|
||||
@@ -152,6 +174,16 @@ func ParseFlags(name string, args []string) (Config, error) {
|
||||
fs.DurationVar(&c.Retention, "retention", store.DefaultRetention, "how long data is kept, at most 720h (URUTAU_RETENTION)")
|
||||
fs.StringVar(&c.TorExits, "tor-exits", env("URUTAU_TOR_EXITS", ""), "file with Tor exit node addresses, one per line, reloaded every 24 h when it changes; empty disables (URUTAU_TOR_EXITS)")
|
||||
fs.StringVar(&c.EventsMax, "events-max", env("URUTAU_EVENTS_MAX", DefaultEventsMax), "size cap of the event registry in <data-dir>/events, 0 disables it (URUTAU_EVENTS_MAX)")
|
||||
fs.StringVar(&c.Enforce, "enforce", env("URUTAU_ENFORCE", "off"), "second firewall: off, observe (decide in memory only) or on (write decisions for the host fail2ban) (URUTAU_ENFORCE)")
|
||||
fs.StringVar(&c.EnforceLog, "enforce-log", env("URUTAU_ENFORCE_LOG", "/logs/enforce/decisions.log"), "decision file appended in --enforce=on (URUTAU_ENFORCE_LOG)")
|
||||
fs.StringVar(&c.EnforceShare, "enforce-share", env("URUTAU_ENFORCE_SHARE", "off"), "on: exchange decisions with peers, each side applies its own exclusions (URUTAU_ENFORCE_SHARE)")
|
||||
fs.IntVar(&c.EnforceThreshold, "enforce-threshold", envInt("URUTAU_ENFORCE_THRESHOLD", 5), "attack events in 10 minutes that justify a ban (URUTAU_ENFORCE_THRESHOLD)")
|
||||
fs.StringVar(&c.Egress, "egress", env("URUTAU_EGRESS", "auto"), "egress analysis: auto (on when --egress-log exists), on or off (URUTAU_EGRESS)")
|
||||
fs.StringVar(&c.EgressLog, "egress-log", env("URUTAU_EGRESS_LOG", "/logs/host/egress.log"), "kernel log of new outbound connections written by the host kit (URUTAU_EGRESS_LOG)")
|
||||
fs.StringVar(&c.EgressWorkloads, "egress-workloads", env("URUTAU_EGRESS_WORKLOADS", ""), "workloads: \"ciberlab=name:<container prefix>:scanner;mail=10.0.7.0/24:mail\" (URUTAU_EGRESS_WORKLOADS)")
|
||||
fs.StringVar(&c.EgressResolvers, "egress-resolvers", env("URUTAU_EGRESS_RESOLVERS", ""), "DNS resolvers allowed, comma separated; empty: the usual public ones (URUTAU_EGRESS_RESOLVERS)")
|
||||
fs.StringVar(&c.EgressContainers, "egress-containers", env("URUTAU_EGRESS_CONTAINERS", "/logs/host/containers.map"), "\"<ip> <container>\" map written by the host kit (URUTAU_EGRESS_CONTAINERS)")
|
||||
fs.IntVar(&c.EnforceMaxPerMin, "enforce-max-per-min", envInt("URUTAU_ENFORCE_MAX_PER_MIN", 60), "most decisions per minute, the excess is dropped and counted (URUTAU_ENFORCE_MAX_PER_MIN)")
|
||||
fs.BoolVar(&c.NoAuth, "insecure-no-auth", false, "disable authentication; only allowed on a loopback bind")
|
||||
if v := os.Getenv("URUTAU_GEO_UPDATE"); v != "" {
|
||||
if d, err := time.ParseDuration(v); err == nil {
|
||||
@@ -210,6 +242,30 @@ func (c Config) Validate(token string) ([]fed.Peer, error) {
|
||||
if v := strings.ToLower(c.PeerBlocklist); v != "" && v != "on" && v != "off" {
|
||||
return nil, fmt.Errorf("--peer-blocklist must be on or off")
|
||||
}
|
||||
if c.Enforce != "" || c.EnforceShare != "" { // a Config built by hand may leave them unset
|
||||
switch strings.ToLower(c.Enforce) {
|
||||
case "", "off", "observe", "on":
|
||||
default:
|
||||
return nil, fmt.Errorf("--enforce must be off, observe or on")
|
||||
}
|
||||
if v := strings.ToLower(c.EnforceShare); v != "" && v != "off" && v != "on" {
|
||||
return nil, fmt.Errorf("--enforce-share must be on or off")
|
||||
}
|
||||
if c.EnforceThreshold < 1 || c.EnforceThreshold > 1000 {
|
||||
return nil, fmt.Errorf("--enforce-threshold must be between 1 and 1000")
|
||||
}
|
||||
if c.EnforceMaxPerMin < 1 || c.EnforceMaxPerMin > 10000 {
|
||||
return nil, fmt.Errorf("--enforce-max-per-min must be between 1 and 10000")
|
||||
}
|
||||
}
|
||||
switch strings.ToLower(c.Egress) {
|
||||
case "", "auto", "on", "off":
|
||||
default:
|
||||
return nil, fmt.Errorf("--egress must be auto, on or off")
|
||||
}
|
||||
if strings.EqualFold(c.Enforce, "on") && c.EnforceLog == "" {
|
||||
return nil, fmt.Errorf("--enforce=on needs --enforce-log")
|
||||
}
|
||||
var peers []fed.Peer
|
||||
seen := map[string]bool{}
|
||||
envSeen := map[string]string{}
|
||||
|
||||
@@ -56,6 +56,7 @@ func Doctor(c Config, w io.Writer, asJSON bool) bool {
|
||||
os.Remove(f.Name())
|
||||
add("data-dir", "ok", fmt.Sprintf("%s writable", filepath.Clean(c.DataDir)))
|
||||
}
|
||||
doctorEnforce(c, add)
|
||||
geoInfo := doctorGeo(c, add)
|
||||
stateInfo := doctorState(c, add)
|
||||
ok := true
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"net/netip"
|
||||
"net/url"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/core"
|
||||
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/egress"
|
||||
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/fed"
|
||||
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/intel"
|
||||
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/server"
|
||||
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/store"
|
||||
)
|
||||
|
||||
// newEgress builds the egress analysis, or returns nil when it is off (or in
|
||||
// auto mode without the host log).
|
||||
func newEgress(c Config, st *store.Store, log *slog.Logger) (*egress.Source, error) {
|
||||
mode := strings.ToLower(c.Egress)
|
||||
if mode == "off" || c.EgressLog == "" {
|
||||
return nil, nil
|
||||
}
|
||||
if mode == "" || mode == "auto" {
|
||||
if _, err := os.Stat(c.EgressLog); err != nil {
|
||||
return nil, nil
|
||||
}
|
||||
}
|
||||
var allow []netip.Prefix
|
||||
if nets, err := core.ParseCIDRs(c.Trusted); err == nil {
|
||||
for _, n := range nets {
|
||||
if p, err := netip.ParsePrefix(n.String()); err == nil {
|
||||
allow = append(allow, p)
|
||||
}
|
||||
}
|
||||
}
|
||||
allow = append(allow, egressExtraAllow(c)...)
|
||||
eng, err := egress.New(egress.Config{
|
||||
Workloads: c.EgressWorkloads,
|
||||
Resolvers: c.EgressResolvers,
|
||||
Allow: allow,
|
||||
Containers: c.EgressContainers,
|
||||
Geo: func(ip string) (string, string, string) {
|
||||
g := st.GeoOf(ip)
|
||||
asn := ""
|
||||
if g.ASN != 0 {
|
||||
asn = "AS" + strconv.FormatUint(uint64(g.ASN), 10)
|
||||
}
|
||||
return g.CC, asn, g.ASOrg
|
||||
},
|
||||
BadDst: func(a netip.Addr) (bool, string) {
|
||||
if intel.IsTorExit(a) {
|
||||
return true, "tor-exit"
|
||||
}
|
||||
if st.KnownHostile(a.String()) {
|
||||
return true, "attacked-us"
|
||||
}
|
||||
return false, ""
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
server.SetEgress(eng)
|
||||
log.Info("egress analysis on", "log", c.EgressLog)
|
||||
return egress.NewSource(c.EgressLog, eng, log), nil
|
||||
}
|
||||
|
||||
// egressExtraAllow adds to the egress Allow list the addresses of the peers and
|
||||
// the CIDRs of URUTAU_EGRESS_ALLOW (legitimate periodic pollers).
|
||||
func egressExtraAllow(c Config) []netip.Prefix {
|
||||
var out []netip.Prefix
|
||||
for _, ps := range c.Peers {
|
||||
p, err := fed.ParsePeer(ps)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if u, err := url.Parse(p.URL); err == nil && u.Hostname() != "" {
|
||||
for _, a := range resolveHost(u.Hostname()) {
|
||||
out = append(out, netip.PrefixFrom(a, a.BitLen()))
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, s := range strings.Split(os.Getenv("URUTAU_EGRESS_ALLOW"), ",") {
|
||||
if s = strings.TrimSpace(s); s == "" {
|
||||
continue
|
||||
}
|
||||
if p, err := netip.ParsePrefix(s); err == nil {
|
||||
out = append(out, p.Masked())
|
||||
} else if a, err := netip.ParseAddr(s); err == nil {
|
||||
a = a.Unmap()
|
||||
out = append(out, netip.PrefixFrom(a, a.BitLen()))
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"log/slog"
|
||||
"net"
|
||||
"net/netip"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/core"
|
||||
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/enforce"
|
||||
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/fed"
|
||||
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/store"
|
||||
)
|
||||
|
||||
// newEnforce builds the second firewall and hooks it into the store; nil when off.
|
||||
func newEnforce(c Config, st *store.Store, peers []fed.Peer, en enricher) *enforce.Engine {
|
||||
mode := strings.ToLower(c.Enforce)
|
||||
if mode != enforce.ModeObserve && mode != enforce.ModeOn {
|
||||
return nil
|
||||
}
|
||||
trusted, _ := core.ParseCIDRs(c.Ignore + "," + c.Trusted)
|
||||
var hosts []string
|
||||
for _, p := range peers {
|
||||
if u, err := url.Parse(p.URL); err == nil && u.Hostname() != "" {
|
||||
hosts = append(hosts, u.Hostname())
|
||||
}
|
||||
}
|
||||
e := enforce.New(enforce.Config{
|
||||
Mode: mode, Path: c.EnforceLog, StatePath: filepath.Join(c.DataDir, "enforce.json"), Host: c.Name,
|
||||
Threshold: c.EnforceThreshold, MaxPerMin: c.EnforceMaxPerMin, Share: strings.EqualFold(c.EnforceShare, "on"),
|
||||
Trusted: trusted, PeerHosts: hosts, InfraHosts: hosts, Resolve: resolveHost,
|
||||
Crawler: func(ip string, uas []string) bool { v := st.FCrDNS(ip, uas); return v != nil && *v },
|
||||
Geo: func(ip string) (string, uint32, string) {
|
||||
if en.g == nil {
|
||||
return "", 0, ""
|
||||
}
|
||||
g := en.Geo(ip)
|
||||
return g.CC, g.ASN, g.ASOrg
|
||||
},
|
||||
})
|
||||
st.SetIngestHook(e.Observe)
|
||||
return e
|
||||
}
|
||||
|
||||
func resolveHost(h string) []netip.Addr {
|
||||
if a, err := netip.ParseAddr(h); err == nil {
|
||||
return []netip.Addr{a.Unmap()}
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||
defer cancel()
|
||||
ips, err := net.DefaultResolver.LookupNetIP(ctx, "ip", h)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
for i := range ips {
|
||||
ips[i] = ips[i].Unmap()
|
||||
}
|
||||
return ips
|
||||
}
|
||||
|
||||
// shareDecisions pulls the decisions of every peer and pushes the local ones, every 30 s.
|
||||
func shareDecisions(ctx context.Context, hub *fed.Hub, e *enforce.Engine, log *slog.Logger) {
|
||||
pulled := map[string]int64{}
|
||||
pushed := map[string]int64{}
|
||||
t := time.NewTicker(30 * time.Second)
|
||||
defer t.Stop()
|
||||
for {
|
||||
for _, p := range hub.Peers {
|
||||
start := time.Now().Unix()
|
||||
var in struct {
|
||||
Decisions []enforce.Wire `json:"decisions"`
|
||||
}
|
||||
if err := hub.Get(ctx, p, fmt.Sprintf("/api/v1/peer/decisions?since=%d", pulled[p.Name]), &in); err == nil {
|
||||
e.AcceptPeer(p.Name, in.Decisions)
|
||||
pulled[p.Name] = start - 5
|
||||
} else if ctx.Err() == nil {
|
||||
log.Debug("enforce: pull failed", "peer", p.Name, "err", err)
|
||||
}
|
||||
if mine := e.LocalSince(pushed[p.Name]); len(mine) > 0 {
|
||||
if err := hub.PostJSON(ctx, p, "/api/v1/peer/decisions?from="+url.QueryEscape(e.Host()), map[string]any{"decisions": mine}); err == nil {
|
||||
pushed[p.Name] = start
|
||||
} else if ctx.Err() == nil {
|
||||
log.Debug("enforce: push failed", "peer", p.Name, "err", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case <-t.C:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// doctorEnforce reports the mode of the second firewall and its file.
|
||||
func doctorEnforce(c Config, add func(name, status, detail string)) {
|
||||
mode := strings.ToLower(c.Enforce)
|
||||
if mode == "" || mode == "off" {
|
||||
add("enforce", "off", "disabled (--enforce=off)")
|
||||
return
|
||||
}
|
||||
w := enforce.Writable(c.EnforceLog)
|
||||
detail := fmt.Sprintf("mode=%s share=%s threshold=%d file=%s writable=%v", mode, strings.ToLower(orDefault(c.EnforceShare, "off")), c.EnforceThreshold, c.EnforceLog, w)
|
||||
switch {
|
||||
case mode == "on" && !w:
|
||||
add("enforce", "fail", detail)
|
||||
case !w:
|
||||
add("enforce", "warn", detail)
|
||||
default:
|
||||
add("enforce", "ok", detail)
|
||||
}
|
||||
if mode == "on" {
|
||||
if n, tot := cloudflareClients(c.TraefikLog); n > 0 {
|
||||
add("enforce-cdn", "warn", fmt.Sprintf("%d of the last %d requests in %s come from Cloudflare addresses: Traefik is not "+
|
||||
"restoring the real client IP (set entryPoints.*.forwardedHeaders.trustedIPs to the Cloudflare ranges); "+
|
||||
"Cloudflare is never banned, but the real attackers stay invisible", n, tot, c.TraefikLog))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// cloudflareClients counts, in the tail of the Traefik JSON access log, the
|
||||
// requests whose ClientHost is a Cloudflare address.
|
||||
func cloudflareClients(path string) (cf, total int) {
|
||||
if path == "" {
|
||||
return 0, 0
|
||||
}
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
return 0, 0
|
||||
}
|
||||
defer f.Close()
|
||||
const tail = 512 << 10
|
||||
if fi, err := f.Stat(); err == nil && fi.Size() > tail {
|
||||
f.Seek(fi.Size()-tail, io.SeekStart)
|
||||
}
|
||||
sc := bufio.NewScanner(f)
|
||||
sc.Buffer(make([]byte, 0, 64<<10), 1<<20)
|
||||
for sc.Scan() {
|
||||
var l struct {
|
||||
ClientHost string `json:"ClientHost"`
|
||||
}
|
||||
if json.Unmarshal(sc.Bytes(), &l) != nil || l.ClientHost == "" {
|
||||
continue
|
||||
}
|
||||
a, err := netip.ParseAddr(l.ClientHost)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
total++
|
||||
if enforce.IsCloudflare(a) {
|
||||
cf++
|
||||
}
|
||||
}
|
||||
return cf, total
|
||||
}
|
||||
@@ -98,6 +98,18 @@ func Serve(c Config) error {
|
||||
bindHost, _, _ := net.SplitHostPort(c.Bind)
|
||||
h := server.New(server.Options{Token: token, PeerTokens: c.PeerTokens, PeerAllow: allow, TrustedProxy: tproxy, Ignore: ign,
|
||||
AllowHosts: []string{bindHost}, NoAuth: c.NoAuth, LocalBlocklist: strings.EqualFold(c.PeerBlocklist, "off"), Version: Version, Store: st, Hub: hub})
|
||||
egressSrc, err := newEgress(c, st, log)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if egressSrc != nil {
|
||||
extra := runner.Extra
|
||||
runner.Extra = func() []store.SourceStatus { return append(extra(), egressSrc.Status()) }
|
||||
}
|
||||
eng := newEnforce(c, st, peers, en)
|
||||
if eng != nil {
|
||||
server.SetEnforce(eng)
|
||||
}
|
||||
ln, err := net.Listen("tcp", c.Bind)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -110,6 +122,9 @@ func Serve(c Config) error {
|
||||
go func() { defer wg.Done(); elog.Run(ctx) }()
|
||||
}
|
||||
runner.Start(ctx, offsets, &wg)
|
||||
if egressSrc != nil {
|
||||
egressSrc.Start(ctx, &wg)
|
||||
}
|
||||
wg.Add(2)
|
||||
go func() { defer wg.Done(); rd.Run(ctx) }()
|
||||
go func() {
|
||||
@@ -140,6 +155,14 @@ func Serve(c Config) error {
|
||||
wg.Add(1)
|
||||
go func() { defer wg.Done(); hub.Run(ctx) }()
|
||||
}
|
||||
if eng != nil {
|
||||
wg.Add(1)
|
||||
go func() { defer wg.Done(); eng.Run(ctx) }()
|
||||
if hub != nil && eng.Share() {
|
||||
wg.Add(1)
|
||||
go func() { defer wg.Done(); shareDecisions(ctx, hub, eng, log) }()
|
||||
}
|
||||
}
|
||||
log.Info("urutau started", "version", Version, "name", c.Name, "bind", ln.Addr().String(), "peers", len(peers), "auth", !c.NoAuth)
|
||||
errc := make(chan error, 1)
|
||||
go func() { errc <- srv.Serve(ln) }()
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -195,3 +196,64 @@ func TestIPDetailConsistentOnSyntheticLogs(t *testing.T) {
|
||||
t.Skip("synthetic data sets not available")
|
||||
}
|
||||
}
|
||||
|
||||
func TestEnforceConfig(t *testing.T) {
|
||||
c, err := ParseFlags("x", []string{"--insecure-no-auth", "--bind", "127.0.0.1:1"})
|
||||
if err != nil || c.Enforce != "off" || c.EnforceLog != "/logs/enforce/decisions.log" || c.EnforceShare != "off" || c.EnforceThreshold != 5 || c.EnforceMaxPerMin != 60 {
|
||||
t.Fatalf("%+v %v", c, err)
|
||||
}
|
||||
for _, bad := range [][]string{{"--enforce=maybe"}, {"--enforce-share=x"}, {"--enforce-threshold=0"}, {"--enforce-max-per-min=0"}} {
|
||||
c, err := ParseFlags("x", append([]string{"--insecure-no-auth", "--bind", "127.0.0.1:1", "--data-dir", t.TempDir()}, bad...))
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if _, err := c.Validate(""); err == nil {
|
||||
t.Errorf("%v accepted", bad)
|
||||
}
|
||||
}
|
||||
t.Setenv("URUTAU_ENFORCE", "observe")
|
||||
t.Setenv("URUTAU_ENFORCE_THRESHOLD", "9")
|
||||
c, _ = ParseFlags("x", nil)
|
||||
if c.Enforce != "observe" || c.EnforceThreshold != 9 {
|
||||
t.Fatalf("env %+v", c)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDoctorEnforce(t *testing.T) {
|
||||
var got []Check
|
||||
add := func(n, s, d string) { got = append(got, Check{n, s, d}) }
|
||||
doctorEnforce(Config{Enforce: "on", EnforceLog: t.TempDir() + "/x/d.log", EnforceThreshold: 5}, add)
|
||||
doctorEnforce(Config{Enforce: "on", EnforceLog: "/proc/nope/d.log"}, add)
|
||||
doctorEnforce(Config{Enforce: "off"}, add)
|
||||
if got[0].Status != "ok" || !strings.Contains(got[0].Detail, "mode=on") || got[1].Status != "fail" || got[2].Status != "off" {
|
||||
t.Fatalf("%+v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDoctorEnforceCloudflare(t *testing.T) {
|
||||
lg := filepath.Join(t.TempDir(), "access.log")
|
||||
os.WriteFile(lg, []byte(`{"ClientHost":"104.16.1.1"}`+"\n"+`{"ClientHost":"203.0.114.5"}`+"\n"), 0o600)
|
||||
var got []Check
|
||||
add := func(n, s, d string) { got = append(got, Check{n, s, d}) }
|
||||
doctorEnforce(Config{Enforce: "on", EnforceLog: t.TempDir() + "/x/d.log", TraefikLog: lg}, add)
|
||||
if len(got) != 2 || got[1].Name != "enforce-cdn" || got[1].Status != "warn" {
|
||||
t.Fatalf("%+v", got)
|
||||
}
|
||||
got = nil
|
||||
doctorEnforce(Config{Enforce: "observe", EnforceLog: t.TempDir() + "/x/d.log", TraefikLog: lg}, add)
|
||||
if len(got) != 1 {
|
||||
t.Fatalf("%+v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEgressExtraAllow(t *testing.T) {
|
||||
t.Setenv("URUTAU_EGRESS_ALLOW", "203.0.113.0/24, 198.51.100.7 ,bad")
|
||||
got := egressExtraAllow(Config{Peers: []string{"p=https://192.0.2.9:8443"}})
|
||||
var s []string
|
||||
for _, p := range got {
|
||||
s = append(s, p.String())
|
||||
}
|
||||
if strings.Join(s, " ") != "192.0.2.9/32 203.0.113.0/24 198.51.100.7/32" {
|
||||
t.Fatalf("%v", s)
|
||||
}
|
||||
}
|
||||
@@ -2,4 +2,4 @@ package app
|
||||
|
||||
// Version is the release version (SemVer). Release builds may override it with
|
||||
// -ldflags "-X .../internal/app.Version=...".
|
||||
var Version = "1.3.0"
|
||||
var Version = "1.4.0"
|
||||
Reference in new issue
Block a user