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>
99 lines
2.6 KiB
Go
99 lines
2.6 KiB
Go
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
|
|
}
|