feat!: Urutau 2.0.0, ultralight probes and a single analysis hub
Each server runs an ultralight probe (scratch image, ~7 MiB RSS) that tails the logs, ships raw lines to the hub over HTTPS with an on-disk spool, and applies enforce decisions locally. The hub keeps one node per probe (primary node = the 1.x data dir, unchanged), does all analysis and serves the UI. Peer federation is removed. 'urutau import' brings 1.x data dirs in with hash and count verification. UI: probes page, host qualified incidents, IPs never wrap, egress heatmap labels, live and replay globes no longer auto-rotate, replay repeat, live traffic metrics. BREAKING CHANGE: URUTAU_PEERS, URUTAU_PEER_* and /api/v1/peer/* are gone; log path variables move from the hub to the probe. See docs/migration-2.0.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
23a7a5963a
commit
8546d14cef
130 files changed
+9396
-3311
No files matched your search
+85
-167
@@ -14,34 +14,31 @@ import (
|
||||
"time"
|
||||
|
||||
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/core"
|
||||
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/fed"
|
||||
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/store"
|
||||
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/wire"
|
||||
)
|
||||
|
||||
// Config is the runtime configuration of `urutau serve` and `urutau doctor`.
|
||||
type Config struct {
|
||||
Bind string
|
||||
Name string
|
||||
DataDir string
|
||||
Bind string
|
||||
Name string
|
||||
DataDir string
|
||||
// Log paths: the hub no longer reads files (the probes do); these fields
|
||||
// only serve tests and the file based Runner, they have no flag.
|
||||
TraefikLog string
|
||||
AuthLog string
|
||||
Fail2banLog string
|
||||
ProbeLog string // kernel log of new connections to unserved ports
|
||||
Ignore string // networks whose events are dropped (--ignore, alias of --trusted)
|
||||
Trusted string // trusted sources, e.g. the servers themselves (--trusted)
|
||||
MonitorUA string // regex of monitoring User-Agents
|
||||
MonitorFrom string // networks monitors come from (empty: any source)
|
||||
Domains string // optional allowlist of analytics domains
|
||||
AdminUsers string // SSH users whose logins grant admin immunity (empty: any user)
|
||||
PeerTokens []string // tokens accepted by /api/v1/peer/export
|
||||
PeerTokenFor map[string]string // per peer name (upper case) token used by the hub
|
||||
GeoDir string // directory of the geo databases (default <data-dir>/geo)
|
||||
ProbeLog string
|
||||
Ignore string // networks whose events are dropped (--ignore, alias of --trusted)
|
||||
Trusted string // trusted sources, e.g. the servers themselves (--trusted)
|
||||
MonitorUA string // regex of monitoring User-Agents
|
||||
MonitorFrom string // networks monitors come from (empty: any source)
|
||||
Domains string // optional allowlist of analytics domains
|
||||
AdminUsers string // SSH users whose logins grant admin immunity (empty: any user)
|
||||
GeoDir string // directory of the geo databases (default <data-dir>/geo)
|
||||
GeoUpdate time.Duration
|
||||
Peers []string
|
||||
PeerToken string
|
||||
Location string // "lat,lon" or "lat,lon,label" (--location)
|
||||
Location string // "lat,lon" or "lat,lon,label" (--location): default location of the primary probe
|
||||
PeerBlocklist string // "on" (default) or "off"
|
||||
PeerAllow string // CIDRs allowed to call /api/v1/peer/export (empty: any source with the token)
|
||||
TrustedProxy string // proxies whose X-Forwarded-For is believed
|
||||
Retention time.Duration
|
||||
TorAuto string // on (default) or off: download the official Tor lists every 6 h
|
||||
@@ -50,18 +47,19 @@ type Config struct {
|
||||
NoAuth bool
|
||||
// Second firewall (see internal/enforce).
|
||||
Enforce string // off (default), observe or on
|
||||
EnforceLog string // decision file read by the host fail2ban
|
||||
EnforceUnbanLog string // unban requests (UI button) read by the host; default: unban.log next to --enforce-log
|
||||
EnforceShare string // off (default) or on: exchange decisions with peers
|
||||
EnforceLog string // decision file (tests only: in the hub decisions go to the probe)
|
||||
EnforceUnbanLog string // unban file (tests only)
|
||||
EnforceShare string // off (default) or on: a decision of one probe also reaches the others
|
||||
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
|
||||
EgressLog string // kernel log of new outbound connections (tests only)
|
||||
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
|
||||
EgressContainers string // "<ip> <container>" map (tests only)
|
||||
EgressAllow string // URUTAU_EGRESS_ALLOW: default for the primary probe
|
||||
}
|
||||
|
||||
// DefaultEventsMax is the default size cap of the event registry.
|
||||
@@ -146,14 +144,9 @@ func ParseFlags(name string, args []string) (Config, error) {
|
||||
fs := flag.NewFlagSet(name, flag.ContinueOnError)
|
||||
var c Config
|
||||
host, _ := os.Hostname()
|
||||
var peers listFlag
|
||||
fs.StringVar(&c.Bind, "bind", env("URUTAU_BIND", "0.0.0.0:8790"), "listen address (URUTAU_BIND)")
|
||||
fs.StringVar(&c.Name, "name", env("URUTAU_NAME", host), "name of this instance (URUTAU_NAME)")
|
||||
fs.StringVar(&c.DataDir, "data-dir", env("URUTAU_DATA_DIR", "/data"), "snapshot directory (URUTAU_DATA_DIR)")
|
||||
fs.StringVar(&c.TraefikLog, "traefik-log", env("URUTAU_TRAEFIK_LOG", "/data/coolify/proxy/access.log"), "Traefik JSON access log, empty disables (URUTAU_TRAEFIK_LOG)")
|
||||
fs.StringVar(&c.AuthLog, "auth-log", env("URUTAU_AUTH_LOG", "/var/log/auth.log"), "sshd auth log, empty disables (URUTAU_AUTH_LOG)")
|
||||
fs.StringVar(&c.ProbeLog, "probe-log", env("URUTAU_PROBE_LOG", "/logs/host/probe.log"), "kernel log of network probes (unserved ports) written by the host kit, empty disables (URUTAU_PROBE_LOG)")
|
||||
fs.StringVar(&c.Fail2banLog, "fail2ban-log", env("URUTAU_FAIL2BAN_LOG", "/var/log/fail2ban.log"), "fail2ban log, empty disables (URUTAU_FAIL2BAN_LOG)")
|
||||
ign := &csvFlag{val: env("URUTAU_IGNORE", DefaultIgnore)}
|
||||
trusted := &csvFlag{val: env("URUTAU_TRUSTED", "")}
|
||||
fs.Var(ign, "ignore", "CIDRs/IPs whose events are dropped, repeatable or comma separated (URUTAU_IGNORE)")
|
||||
@@ -167,28 +160,21 @@ func ParseFlags(name string, args []string) (Config, error) {
|
||||
fs.StringVar(&c.GeoDir, "geo-dir", env("URUTAU_GEO_DIR", ""), "geo database directory, default <data-dir>/geo (URUTAU_GEO_DIR)")
|
||||
fs.DurationVar(&c.GeoUpdate, "geo-update", 24*time.Hour, "how often the geo database is refreshed, 0 disables downloads (URUTAU_GEO_UPDATE)")
|
||||
fs.StringVar(&c.MonitorUA, "monitor-ua", env("URUTAU_MONITOR_UA", DefaultMonitorUA), "regex of monitoring User-Agents; benign hits are counted apart, empty disables (URUTAU_MONITOR_UA)")
|
||||
fs.Var(&peers, "peer", "peer instance name=https://url, repeatable (URUTAU_PEERS, comma separated)")
|
||||
fs.StringVar(&c.PeerToken, "peer-token", "", "bearer token shared with peers; prefer URUTAU_PEER_TOKEN or URUTAU_PEER_TOKEN_FILE")
|
||||
allow := &csvFlag{val: env("URUTAU_PEER_ALLOW", "")}
|
||||
tproxy := &csvFlag{val: env("URUTAU_TRUSTED_PROXY", DefaultTrustedProxy)}
|
||||
fs.Var(allow, "peer-allow", "CIDRs allowed to call /api/v1/peer/export, empty allows any source with the token (URUTAU_PEER_ALLOW)")
|
||||
fs.Var(tproxy, "trusted-proxy", "reverse proxies whose X-Forwarded-For is trusted for the real client IP (URUTAU_TRUSTED_PROXY)")
|
||||
fs.StringVar(&c.Location, "location", env("URUTAU_LOCATION", ""), `where this instance lives, "lat,lon" or "lat,lon,label"; shown as the destination of live arcs (URUTAU_LOCATION)`)
|
||||
fs.StringVar(&c.PeerBlocklist, "peer-blocklist", env("URUTAU_PEER_BLOCKLIST", "on"), "on: the blocklist also lists strong hostile IPs seen only by peers; off: local IPs only (URUTAU_PEER_BLOCKLIST)")
|
||||
fs.StringVar(&c.PeerBlocklist, "blocklist-scope", "on", "on: the blocklist lists the strong hostile IPs of every probe; off: the primary probe only")
|
||||
fs.DurationVar(&c.Retention, "retention", store.DefaultRetention, "how long data is kept, at most 720h (URUTAU_RETENTION)")
|
||||
fs.StringVar(&c.TorAuto, "tor-auto", env("URUTAU_TOR_AUTO", "on"), "download the official Tor exit and relay lists every 6 h into <data-dir>/tor: on or off (URUTAU_TOR_AUTO)")
|
||||
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.EnforceUnbanLog, "enforce-unban-log", env("URUTAU_ENFORCE_UNBAN_LOG", ""), "unban request file written by the Unban button (URUTAU_ENFORCE_UNBAN_LOG); default unban.log next to --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.StringVar(&c.Enforce, "enforce", env("URUTAU_ENFORCE", "off"), "second firewall: off, observe (decide in memory only) or on (queue decisions for each probe's host fail2ban) (URUTAU_ENFORCE)")
|
||||
fs.StringVar(&c.EnforceShare, "enforce-share", env("URUTAU_ENFORCE_SHARE", "off"), "on: a decision of one probe also reaches the others, each 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)")
|
||||
c.EgressAllow = env("URUTAU_EGRESS_ALLOW", "")
|
||||
fs.StringVar(&c.EgressWorkloads, "egress-workloads", env("URUTAU_EGRESS_WORKLOADS", ""), "default workloads of the primary probe: \"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 != "" {
|
||||
@@ -204,33 +190,9 @@ func ParseFlags(name string, args []string) (Config, error) {
|
||||
if err := fs.Parse(args); err != nil {
|
||||
return c, err
|
||||
}
|
||||
c.Peers = peers
|
||||
c.Ignore, c.Trusted = ign.val, trusted.val
|
||||
c.PeerAllow, c.TrustedProxy = allow.val, tproxy.val
|
||||
c.TrustedProxy = tproxy.val
|
||||
c.MonitorFrom, c.Domains, c.AdminUsers = mfrom.val, doms.val, admins.val
|
||||
if c.PeerToken == "" {
|
||||
var err error
|
||||
if c.PeerToken, err = Secret("URUTAU_PEER_TOKEN"); err != nil {
|
||||
return c, err
|
||||
}
|
||||
}
|
||||
var err error
|
||||
if c.PeerTokenFor, err = perPeerTokens(); err != nil {
|
||||
return c, err
|
||||
}
|
||||
// Only the server token opens the local export. URUTAU_PEER_TOKEN_<NAME>
|
||||
// are client credentials sent to that peer: a compromised peer learns
|
||||
// them, so they must never open this instance's export.
|
||||
if c.PeerToken != "" {
|
||||
c.PeerTokens = append(c.PeerTokens, c.PeerToken)
|
||||
}
|
||||
if len(c.Peers) == 0 {
|
||||
for _, p := range strings.Split(os.Getenv("URUTAU_PEERS"), ",") {
|
||||
if p = strings.TrimSpace(p); p != "" {
|
||||
c.Peers = append(c.Peers, p)
|
||||
}
|
||||
}
|
||||
}
|
||||
if c.GeoDir == "" {
|
||||
c.GeoDir = filepath.Join(c.DataDir, "geo")
|
||||
}
|
||||
@@ -240,109 +202,104 @@ func ParseFlags(name string, args []string) (Config, error) {
|
||||
return c, nil
|
||||
}
|
||||
|
||||
// Validate checks the configuration and returns the parsed peers.
|
||||
func (c Config) Validate(token string) ([]fed.Peer, error) {
|
||||
// Validate checks the configuration.
|
||||
func (c Config) Validate(token string) error {
|
||||
if _, err := store.ParseLocation(c.Location); err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
if c.Name != "" && !wire.ValidName(c.Name) {
|
||||
return fmt.Errorf("--name %q must be lowercase letters, digits and dashes, at most 32 characters: it is the name of the primary probe", c.Name)
|
||||
}
|
||||
if v := strings.ToLower(c.PeerBlocklist); v != "" && v != "on" && v != "off" {
|
||||
return nil, fmt.Errorf("--peer-blocklist must be on or off")
|
||||
return fmt.Errorf("--blocklist-scope 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")
|
||||
return 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")
|
||||
return 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")
|
||||
return 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")
|
||||
return 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")
|
||||
}
|
||||
if c.EnforceUnbanLog == "" && c.EnforceLog != "" {
|
||||
c.EnforceUnbanLog = filepath.Join(filepath.Dir(c.EnforceLog), "unban.log")
|
||||
}
|
||||
var peers []fed.Peer
|
||||
seen := map[string]bool{}
|
||||
envSeen := map[string]string{}
|
||||
for _, s := range c.Peers {
|
||||
p, err := fed.ParsePeer(s)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if seen[p.Name] || p.Name == c.Name || p.Name == "all" {
|
||||
return nil, fmt.Errorf("peer name %q is duplicated or reserved", p.Name)
|
||||
}
|
||||
if other, dup := envSeen[tokenEnvName(p.Name)]; dup {
|
||||
return nil, fmt.Errorf("peer names %q and %q share the token variable URUTAU_PEER_TOKEN_%s", other, p.Name, tokenEnvName(p.Name))
|
||||
}
|
||||
envSeen[tokenEnvName(p.Name)] = p.Name
|
||||
seen[p.Name] = true
|
||||
peers = append(peers, p)
|
||||
return fmt.Errorf("--egress must be auto, on or off")
|
||||
}
|
||||
if _, err := core.ParseCIDRs(c.Ignore + "," + c.Trusted); err != nil {
|
||||
return nil, fmt.Errorf("--ignore/--trusted: %w", err)
|
||||
return fmt.Errorf("--ignore/--trusted: %w", err)
|
||||
}
|
||||
if c.MonitorUA != "" {
|
||||
if _, err := regexp.Compile(c.MonitorUA); err != nil {
|
||||
return nil, fmt.Errorf("--monitor-ua: %w", err)
|
||||
return fmt.Errorf("--monitor-ua: %w", err)
|
||||
}
|
||||
}
|
||||
if c.Retention < time.Hour || c.Retention > store.DefaultRetention {
|
||||
return nil, fmt.Errorf("--retention must be between 1h and 720h")
|
||||
return fmt.Errorf("--retention must be between 1h and 720h")
|
||||
}
|
||||
if c.EventsMax != "" {
|
||||
if _, err := ParseSize(c.EventsMax); err != nil {
|
||||
return nil, fmt.Errorf("--events-max: %w", err)
|
||||
return fmt.Errorf("--events-max: %w", err)
|
||||
}
|
||||
}
|
||||
if c.NoAuth {
|
||||
if !loopbackBind(c.Bind) {
|
||||
return nil, fmt.Errorf("--insecure-no-auth is only allowed on a loopback bind (got %q)", c.Bind)
|
||||
return fmt.Errorf("--insecure-no-auth is only allowed on a loopback bind (got %q)", c.Bind)
|
||||
}
|
||||
} else if err := checkToken("URUTAU_TOKEN", token); err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
all := append([]string(nil), c.PeerTokens...)
|
||||
if c.PeerToken != "" && !contains(all, c.PeerToken) {
|
||||
all = append(all, c.PeerToken)
|
||||
}
|
||||
for _, t := range c.PeerTokenFor {
|
||||
all = append(all, t)
|
||||
}
|
||||
for _, t := range all {
|
||||
if err := checkToken("URUTAU_PEER_TOKEN", t); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if t == token {
|
||||
return nil, fmt.Errorf("a peer token must differ from URUTAU_TOKEN")
|
||||
}
|
||||
}
|
||||
for i := range peers {
|
||||
peers[i].Token = c.PeerTokenFor[tokenEnvName(peers[i].Name)]
|
||||
if peers[i].Token == "" && c.PeerToken == "" {
|
||||
return nil, fmt.Errorf("peer %q has no token: set URUTAU_PEER_TOKEN or URUTAU_PEER_TOKEN_%s", peers[i].Name, tokenEnvName(peers[i].Name))
|
||||
}
|
||||
}
|
||||
for _, l := range []struct{ name, v string }{{"--peer-allow", c.PeerAllow}, {"--trusted-proxy", c.TrustedProxy}, {"--monitor-from", c.MonitorFrom}} {
|
||||
for _, l := range []struct{ name, v string }{{"--trusted-proxy", c.TrustedProxy}, {"--monitor-from", c.MonitorFrom}} {
|
||||
if _, err := core.ParseCIDRs(l.v); err != nil {
|
||||
return nil, fmt.Errorf("%s: %w", l.name, err)
|
||||
return fmt.Errorf("%s: %w", l.name, err)
|
||||
}
|
||||
}
|
||||
return peers, nil
|
||||
return nil
|
||||
}
|
||||
|
||||
// MigrationGuide is where the removed 1.x variables are explained.
|
||||
const MigrationGuide = "docs/migration-2.0.md"
|
||||
|
||||
// removedEnv are the 1.x variables that make the 2.0 hub refuse to start. The
|
||||
// log path variables moved to the probe (URUTAU_*_LOG there).
|
||||
var removedEnv = []string{"URUTAU_PEERS", "URUTAU_PEER_TOKEN", "URUTAU_PEER_TOKEN_FILE", "URUTAU_PEER_ALLOW", "URUTAU_PEER_BLOCKLIST",
|
||||
"URUTAU_TRAEFIK_LOG", "URUTAU_AUTH_LOG", "URUTAU_FAIL2BAN_LOG", "URUTAU_PROBE_LOG", "URUTAU_EGRESS_LOG", "URUTAU_EGRESS_CONTAINERS",
|
||||
"URUTAU_ENFORCE_LOG", "URUTAU_ENFORCE_UNBAN_LOG"}
|
||||
|
||||
// softEnv are set by the 1.x image: only a warning.
|
||||
var softEnv = map[string]bool{"URUTAU_TRAEFIK_LOG": true, "URUTAU_AUTH_LOG": true, "URUTAU_FAIL2BAN_LOG": true}
|
||||
|
||||
// CheckRemovedEnv returns an error naming the removed variables that are set
|
||||
// (the old image's TRAEFIK/AUTH/FAIL2BAN defaults only produce warnings).
|
||||
func CheckRemovedEnv(lookup func(string) (string, bool)) (warn []string, err error) {
|
||||
var bad []string
|
||||
for _, k := range removedEnv {
|
||||
if _, ok := lookup(k); ok {
|
||||
if softEnv[k] {
|
||||
warn = append(warn, k)
|
||||
} else {
|
||||
bad = append(bad, k)
|
||||
}
|
||||
}
|
||||
}
|
||||
// URUTAU_PEER_TOKEN_<NAME>[_FILE]
|
||||
for _, kv := range os.Environ() {
|
||||
if k, _, _ := strings.Cut(kv, "="); strings.HasPrefix(k, "URUTAU_PEER_TOKEN_") && !contains(bad, k) {
|
||||
bad = append(bad, k)
|
||||
}
|
||||
}
|
||||
if len(bad) > 0 {
|
||||
return warn, fmt.Errorf("these variables were removed in Urutau 2.0 (the federation and the log paths moved to probes): %s; see %s", strings.Join(bad, ", "), MigrationGuide)
|
||||
}
|
||||
return warn, nil
|
||||
}
|
||||
|
||||
func loopbackBind(bind string) bool {
|
||||
@@ -448,45 +405,6 @@ func Secret(name string) (string, error) {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
// tokenEnvName turns a peer name into its environment suffix: "hostinger" ->
|
||||
// "HOSTINGER", "my-peer" -> "MY_PEER".
|
||||
func tokenEnvName(name string) string {
|
||||
return strings.Map(func(r rune) rune {
|
||||
switch {
|
||||
case r >= 'a' && r <= 'z':
|
||||
return r - 32
|
||||
case r >= 'A' && r <= 'Z', r >= '0' && r <= '9':
|
||||
return r
|
||||
}
|
||||
return '_'
|
||||
}, name)
|
||||
}
|
||||
|
||||
// perPeerTokens collects URUTAU_PEER_TOKEN_<NAME> and URUTAU_PEER_TOKEN_<NAME>_FILE.
|
||||
func perPeerTokens() (map[string]string, error) {
|
||||
const prefix = "URUTAU_PEER_TOKEN_"
|
||||
out := map[string]string{}
|
||||
for _, kv := range os.Environ() {
|
||||
k, v, _ := strings.Cut(kv, "=")
|
||||
if !strings.HasPrefix(k, prefix) || k == prefix+"FILE" || v == "" {
|
||||
continue
|
||||
}
|
||||
name := strings.TrimPrefix(k, prefix)
|
||||
if strings.HasSuffix(name, "_FILE") {
|
||||
b, err := os.ReadFile(v)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%s: %w", k, err)
|
||||
}
|
||||
out[strings.TrimSuffix(name, "_FILE")] = strings.TrimSpace(string(b))
|
||||
continue
|
||||
}
|
||||
if _, set := out[name]; !set {
|
||||
out[name] = v
|
||||
}
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// AdminUserList splits --admin-users into names.
|
||||
func (c Config) AdminUserList() []string {
|
||||
var out []string
|
||||
|
||||
Reference in new issue
Block a user