fix(probe): dedicated urutau-probe binary for the probe image; CI shellcheck via docker cp
CI / Format and vet (pull_request) Successful in 1m9s
CI / Dependency audit (pull_request) Successful in 32s
CI / Tests (Linux, race detector) (pull_request) Successful in 2m2s
CI / Docker images (build and smoke test) (pull_request) Successful in 50s
Release / Build probe image (arm64) (push) Failing after 21s
Release / Plan (reuse the published image?) (push) Successful in 5s
Release / ci (push) Successful in 2m15s
Release / Build hub image (arm64) (push) Successful in 24s
CI / Format and vet (push) Successful in 1m3s
CI / Tests (Linux, race detector) (push) Successful in 1m46s
CI / Dependency audit (push) Successful in 29s
CI / Docker images (build and smoke test) (push) Skipped
Release / Build hub image (amd64) (push) Successful in 21s
Release / Build probe image (amd64) (push) Failing after 20s
Release / Publish tags (hub) (push) Skipped
Release / Publish tags (probe) (push) Skipped
Release / Gitea release (push) Skipped

The probe image linked the whole hub (24 MB uncompressed, over the 15 MB
limit). cmd/urutau-probe links only probeagent, tail and wire (6.8 MB);
'urutau probe' still works and shares probeagent.Main. The shellcheck step
bind-mounted the workspace, which the runner's DinD daemon cannot see.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Lucas RayanandClaude Opus 5.5 committed 2026-11-15 22:30:18 -03:00
1 parent 8546d14cef
commit 0895e43693
5 files changed
+212 -106

No files matched your search

+8 -1
View File
@@ -44,7 +44,14 @@ jobs:
docker compose config --quiet docker compose config --quiet
URUTAU_HUB=https://hub.example.org URUTAU_PROBE_NAME=ci docker compose -f deploy/probe/docker-compose.yml config --quiet URUTAU_HUB=https://hub.example.org URUTAU_PROBE_NAME=ci docker compose -f deploy/probe/docker-compose.yml config --quiet
- name: shellcheck (host kit) - name: shellcheck (host kit)
run: docker run --rm -v "$PWD:/mnt:ro" koalaman/shellcheck:v0.10.0 deploy/host/install.sh # The job workspace is not visible to the runner's Docker daemon (DinD):
# copy the file into the container instead of bind mounting it.
run: |
cid=$(docker create -w /mnt koalaman/shellcheck:v0.10.0 install.sh)
docker cp deploy/host/install.sh "$cid:/mnt/install.sh"
docker start -a "$cid"; status=$?
docker rm "$cid" >/dev/null
exit "$status"
- name: gofmt - name: gofmt
run: test -z "$(gofmt -l .)" run: test -z "$(gofmt -l .)"
- run: go vet ./... - run: go vet ./...
+8 -5
View File
@@ -1,8 +1,9 @@
# syntax=docker/dockerfile:1 # syntax=docker/dockerfile:1
# #
# Urutau 2: one static binary (no CGO, standard library only), two images. # Urutau 2: static binaries (no CGO, standard library only), two images.
# --target hub the hub: dashboard, API, probe ingestion (Alpine) # --target hub the hub: dashboard, API, probe ingestion (Alpine), cmd/urutau
# --target probe the probe: `urutau probe` only (FROM scratch, a few MB) # --target probe the probe only (FROM scratch), cmd/urutau-probe: links just the
# probe agent, the tailer and the wire protocol (~7 MB binary)
# The default (last) stage is the hub, so a plain `docker build .` is the hub. # The default (last) stage is the hub, so a plain `docker build .` is the hub.
# Build stage. # Build stage.
@@ -11,7 +12,9 @@ WORKDIR /src
COPY go.mod ./ COPY go.mod ./
COPY cmd cmd COPY cmd cmd
COPY internal internal COPY internal internal
RUN CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o /out/urutau ./cmd/urutau RUN CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o /out/urutau ./cmd/urutau \
&& v=$(sed -n 's/^var Version = "\(.*\)"/\1/p' internal/app/version.go) \
&& CGO_ENABLED=0 go build -trimpath -ldflags="-s -w -X main.version=$v" -o /out/urutau-probe ./cmd/urutau-probe
# Files the scratch image needs: CA certificates (HTTPS to the hub), zoneinfo # Files the scratch image needs: CA certificates (HTTPS to the hub), zoneinfo
# (TZ must match the host's fail2ban log) and an owned empty /state. # (TZ must match the host's fail2ban log) and an owned empty /state.
@@ -30,7 +33,7 @@ FROM scratch AS probe
COPY --from=probe-files /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt COPY --from=probe-files /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY --from=probe-files /usr/share/zoneinfo /usr/share/zoneinfo COPY --from=probe-files /usr/share/zoneinfo /usr/share/zoneinfo
COPY --from=probe-files --chown=10001:10001 /rootfs/state /state COPY --from=probe-files --chown=10001:10001 /rootfs/state /state
COPY --from=build /out/urutau /urutau COPY --from=build /out/urutau-probe /urutau
LABEL org.opencontainers.image.title="Urutau probe" \ LABEL org.opencontainers.image.title="Urutau probe" \
org.opencontainers.image.description="Ultra-light Urutau probe: ships host logs to an Urutau hub" \ org.opencontainers.image.description="Ultra-light Urutau probe: ships host logs to an Urutau hub" \
org.opencontainers.image.source="https://git.lucasrguerra.dev.br/ciberfauna/urutau" \ org.opencontainers.image.source="https://git.lucasrguerra.dev.br/ciberfauna/urutau" \
+17
View File
@@ -0,0 +1,17 @@
// Command urutau-probe is the ultralight Urutau probe on its own: only the
// probe agent, the tailer and the wire protocol are linked in (no geo, store,
// analysis or UI), which keeps the probe image and its memory small.
// `urutau-probe --hub ...` and `urutau-probe probe --hub ...` are equivalent
// to `urutau probe --hub ...`.
package main
import (
"os"
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/probeagent"
)
// version is set at build time (-ldflags "-X main.version=...").
var version = "dev"
func main() { os.Exit(probeagent.Main(os.Args[1:], version)) }
+1 -100
View File
@@ -2,27 +2,20 @@ package main
import ( import (
"bytes" "bytes"
"context"
"encoding/json" "encoding/json"
"errors"
"flag" "flag"
"fmt" "fmt"
"io" "io"
"log/slog"
"net/http" "net/http"
"os" "os"
"os/signal"
"path/filepath" "path/filepath"
"strconv" "strconv"
"strings" "strings"
"syscall"
"time" "time"
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/app" "git.lucasrguerra.dev.br/ciberfauna/urutau/internal/app"
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/hub" "git.lucasrguerra.dev.br/ciberfauna/urutau/internal/hub"
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/probeagent" "git.lucasrguerra.dev.br/ciberfauna/urutau/internal/probeagent"
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/store"
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/wire"
) )
func envOr(k, def string) string { func envOr(k, def string) string {
@@ -32,99 +25,7 @@ func envOr(k, def string) string {
return def return def
} }
func runProbe(args []string) int { func runProbe(args []string) int { return probeagent.Main(args, app.Version) }
fs := flag.NewFlagSet("probe", flag.ContinueOnError)
var c probeagent.Config
var tokenFile, spool, loc string
check := fs.Bool("check", false, "exit 0 when the probe in --state-dir is alive (container HEALTHCHECK)")
fs.StringVar(&c.Hub, "hub", envOr("URUTAU_HUB", ""), "hub URL (URUTAU_HUB)")
fs.StringVar(&c.Name, "name", envOr("URUTAU_PROBE_NAME", ""), "probe name (URUTAU_PROBE_NAME)")
fs.StringVar(&c.Token, "token", "", "probe token; prefer URUTAU_PROBE_TOKEN or URUTAU_PROBE_TOKEN_FILE")
fs.StringVar(&tokenFile, "token-file", envOr("URUTAU_PROBE_TOKEN_FILE", ""), "file with the probe token (URUTAU_PROBE_TOKEN_FILE)")
fs.StringVar(&c.StateDir, "state-dir", envOr("URUTAU_STATE_DIR", "/state"), "spool and state directory (URUTAU_STATE_DIR)")
paths := map[string]*string{}
for _, p := range []struct{ src, env, def, help string }{
{wire.SrcTraefik, "URUTAU_TRAEFIK_LOG", "", "Traefik JSON access log"},
{wire.SrcAuth, "URUTAU_AUTH_LOG", "", "sshd auth log"},
{wire.SrcFail2ban, "URUTAU_FAIL2BAN_LOG", "", "fail2ban log"},
{wire.SrcProbe, "URUTAU_PROBE_LOG", "", "kernel log of network probes"},
{wire.SrcEgress, "URUTAU_EGRESS_LOG", "", "kernel log of outbound connections"},
} {
v := new(string)
paths[p.src] = v
fs.StringVar(v, p.src+"-log", envOr(p.env, p.def), p.help+", empty disables ("+p.env+")")
}
fs.StringVar(&c.Containers, "egress-containers", envOr("URUTAU_EGRESS_CONTAINERS", ""), "containers.map written by the host kit (URUTAU_EGRESS_CONTAINERS)")
fs.StringVar(&c.Resolv, "resolv", envOr("URUTAU_RESOLV", "/etc/resolv.conf"), "resolv.conf of the host (URUTAU_RESOLV)")
fs.StringVar(&c.DecisionsLog, "enforce-log", envOr("URUTAU_ENFORCE_LOG", ""), "decisions file the host fail2ban reads, empty ignores decisions (URUTAU_ENFORCE_LOG)")
fs.StringVar(&c.UnbanLog, "enforce-unban-log", envOr("URUTAU_ENFORCE_UNBAN_LOG", ""), "unban requests file, empty ignores unbans (URUTAU_ENFORCE_UNBAN_LOG)")
fs.StringVar(&spool, "spool-max", envOr("URUTAU_PROBE_SPOOL_MAX", "64MiB"), "spool size cap (URUTAU_PROBE_SPOOL_MAX)")
fs.StringVar(&loc, "location", envOr("URUTAU_LOCATION", ""), `"lat,lon[,label]"; the hub configuration wins (URUTAU_LOCATION)`)
if err := fs.Parse(args); err != nil {
if errors.Is(err, flag.ErrHelp) {
return 0
}
return 2
}
if *check {
if err := probeagent.Check(c.StateDir); err != nil {
fmt.Fprintln(os.Stderr, "urutau probe:", err)
return 1
}
return 0
}
fail := func(m string) int { fmt.Fprintln(os.Stderr, "urutau probe:", m); return 2 }
if c.Hub == "" || c.Name == "" {
return fail("URUTAU_HUB and URUTAU_PROBE_NAME are required")
}
if !wire.ValidName(c.Name) {
return fail("invalid probe name")
}
if _, err := wire.CheckHubURL(c.Hub); err != nil {
return fail(err.Error())
}
if c.Token == "" {
c.Token = os.Getenv("URUTAU_PROBE_TOKEN")
}
if c.Token == "" && tokenFile != "" {
b, err := os.ReadFile(tokenFile)
if err != nil {
return fail("URUTAU_PROBE_TOKEN_FILE: " + err.Error())
}
c.Token = strings.TrimSpace(string(b))
}
if c.Token == "" {
return fail("URUTAU_PROBE_TOKEN or URUTAU_PROBE_TOKEN_FILE is required")
}
n, err := app.ParseSize(spool)
if err != nil {
return fail("--spool-max: " + err.Error())
}
c.SpoolMax = n
if l, err := store.ParseLocation(loc); err != nil {
return fail(err.Error())
} else if l != nil {
c.Location = &wire.Location{Lat: l.Lat, Lon: l.Lon, Label: l.Label}
}
c.Paths = map[string]string{}
for src, p := range paths {
if *p != "" {
c.Paths[src] = *p
}
}
c.Version = app.Version
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGTERM, syscall.SIGINT)
defer stop()
if err := probeagent.Run(ctx, c, slog.New(slog.NewTextHandler(os.Stderr, nil))); err != nil &&
!errors.Is(err, context.Canceled) {
fmt.Fprintln(os.Stderr, "urutau probe:", err)
if errors.Is(err, probeagent.ErrUnauthorized) || errors.Is(err, probeagent.ErrIncompatible) {
return 3
}
return 1
}
return 0
}
// runProbes manages probes: directly on <data-dir>/probes.json (hub stopped or // runProbes manages probes: directly on <data-dir>/probes.json (hub stopped or
// not, the file is replaced atomically) or through the API with --url. // not, the file is replaced atomically) or through the API with --url.
+178
View File
@@ -0,0 +1,178 @@
package probeagent
import (
"context"
"errors"
"flag"
"fmt"
"log/slog"
"math"
"os"
"os/signal"
"strconv"
"strings"
"syscall"
"unicode"
"unicode/utf8"
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/wire"
)
func envOr(k, def string) string {
if v, ok := os.LookupEnv(k); ok {
return v
}
return def
}
// Main is the `urutau probe` command line (also the whole urutau-probe
// binary): flags with URUTAU_* environment defaults, then Run. It returns the
// process exit code. A leading "probe" argument is accepted and skipped.
func Main(args []string, version string) int {
if len(args) > 0 && args[0] == "probe" {
args = args[1:]
}
fs := flag.NewFlagSet("probe", flag.ContinueOnError)
var c Config
var tokenFile, spool, loc string
check := fs.Bool("check", false, "exit 0 when the probe in --state-dir is alive (container HEALTHCHECK)")
fs.StringVar(&c.Hub, "hub", envOr("URUTAU_HUB", ""), "hub URL (URUTAU_HUB)")
fs.StringVar(&c.Name, "name", envOr("URUTAU_PROBE_NAME", ""), "probe name (URUTAU_PROBE_NAME)")
fs.StringVar(&c.Token, "token", "", "probe token; prefer URUTAU_PROBE_TOKEN or URUTAU_PROBE_TOKEN_FILE")
fs.StringVar(&tokenFile, "token-file", envOr("URUTAU_PROBE_TOKEN_FILE", ""), "file with the probe token (URUTAU_PROBE_TOKEN_FILE)")
fs.StringVar(&c.StateDir, "state-dir", envOr("URUTAU_STATE_DIR", "/state"), "spool and state directory (URUTAU_STATE_DIR)")
paths := map[string]*string{}
for _, p := range []struct{ src, env, def, help string }{
{wire.SrcTraefik, "URUTAU_TRAEFIK_LOG", "", "Traefik JSON access log"},
{wire.SrcAuth, "URUTAU_AUTH_LOG", "", "sshd auth log"},
{wire.SrcFail2ban, "URUTAU_FAIL2BAN_LOG", "", "fail2ban log"},
{wire.SrcProbe, "URUTAU_PROBE_LOG", "", "kernel log of network probes"},
{wire.SrcEgress, "URUTAU_EGRESS_LOG", "", "kernel log of outbound connections"},
} {
v := new(string)
paths[p.src] = v
fs.StringVar(v, p.src+"-log", envOr(p.env, p.def), p.help+", empty disables ("+p.env+")")
}
fs.StringVar(&c.Containers, "egress-containers", envOr("URUTAU_EGRESS_CONTAINERS", ""), "containers.map written by the host kit (URUTAU_EGRESS_CONTAINERS)")
fs.StringVar(&c.Resolv, "resolv", envOr("URUTAU_RESOLV", "/etc/resolv.conf"), "resolv.conf of the host (URUTAU_RESOLV)")
fs.StringVar(&c.DecisionsLog, "enforce-log", envOr("URUTAU_ENFORCE_LOG", ""), "decisions file the host fail2ban reads, empty ignores decisions (URUTAU_ENFORCE_LOG)")
fs.StringVar(&c.UnbanLog, "enforce-unban-log", envOr("URUTAU_ENFORCE_UNBAN_LOG", ""), "unban requests file, empty ignores unbans (URUTAU_ENFORCE_UNBAN_LOG)")
fs.StringVar(&spool, "spool-max", envOr("URUTAU_PROBE_SPOOL_MAX", "64MiB"), "spool size cap (URUTAU_PROBE_SPOOL_MAX)")
fs.StringVar(&loc, "location", envOr("URUTAU_LOCATION", ""), `"lat,lon[,label]"; the hub configuration wins (URUTAU_LOCATION)`)
if err := fs.Parse(args); err != nil {
if errors.Is(err, flag.ErrHelp) {
return 0
}
return 2
}
if *check {
if err := Check(c.StateDir); err != nil {
fmt.Fprintln(os.Stderr, "urutau probe:", err)
return 1
}
return 0
}
fail := func(m string) int { fmt.Fprintln(os.Stderr, "urutau probe:", m); return 2 }
if c.Hub == "" || c.Name == "" {
return fail("URUTAU_HUB and URUTAU_PROBE_NAME are required")
}
if !wire.ValidName(c.Name) {
return fail("invalid probe name")
}
if _, err := wire.CheckHubURL(c.Hub); err != nil {
return fail(err.Error())
}
if c.Token == "" {
c.Token = os.Getenv("URUTAU_PROBE_TOKEN")
}
if c.Token == "" && tokenFile != "" {
b, err := os.ReadFile(tokenFile)
if err != nil {
return fail("URUTAU_PROBE_TOKEN_FILE: " + err.Error())
}
c.Token = strings.TrimSpace(string(b))
}
if c.Token == "" {
return fail("URUTAU_PROBE_TOKEN or URUTAU_PROBE_TOKEN_FILE is required")
}
n, err := parseSize(spool)
if err != nil {
return fail("--spool-max: " + err.Error())
}
c.SpoolMax = n
if l, err := parseLocation(loc); err != nil {
return fail(err.Error())
} else if l != nil {
c.Location = l
}
c.Paths = map[string]string{}
for src, p := range paths {
if *p != "" {
c.Paths[src] = *p
}
}
c.Version = version
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGTERM, syscall.SIGINT)
defer stop()
if err := Run(ctx, c, slog.New(slog.NewTextHandler(os.Stderr, nil))); err != nil &&
!errors.Is(err, context.Canceled) {
fmt.Fprintln(os.Stderr, "urutau probe:", err)
if errors.Is(err, ErrUnauthorized) || errors.Is(err, ErrIncompatible) {
return 3
}
return 1
}
return 0
}
// parseSize reads sizes such as "64MiB", "512k" or "1g" (same rules as the hub).
func parseSize(v string) (int64, error) {
v = strings.TrimSpace(strings.ToLower(v))
if v == "" {
return 0, errors.New("empty size")
}
mult := int64(1)
for _, u := range []struct {
suf string
m int64
}{{"gib", 1 << 30}, {"mib", 1 << 20}, {"kib", 1 << 10}, {"gb", 1 << 30}, {"mb", 1 << 20}, {"kb", 1 << 10}, {"g", 1 << 30}, {"m", 1 << 20}, {"k", 1 << 10}, {"b", 1}} {
if strings.HasSuffix(v, u.suf) {
mult, v = u.m, strings.TrimSpace(strings.TrimSuffix(v, u.suf))
break
}
}
n, err := strconv.ParseFloat(v, 64)
if err != nil || n < 0 || n > 1<<40 {
return 0, fmt.Errorf("invalid size %q", v)
}
return int64(n * float64(mult)), nil
}
// parseLocation reads "lat,lon[,label]" (same rules as the hub).
func parseLocation(s string) (*wire.Location, error) {
s = strings.TrimSpace(s)
if s == "" {
return nil, nil
}
p := strings.SplitN(s, ",", 3)
if len(p) < 2 {
return nil, errors.New("location: expected lat,lon or lat,lon,label")
}
lat, e1 := strconv.ParseFloat(strings.TrimSpace(p[0]), 64)
lon, e2 := strconv.ParseFloat(strings.TrimSpace(p[1]), 64)
if e1 != nil || e2 != nil || math.IsNaN(lat) || math.IsNaN(lon) || lat < -90 || lat > 90 || lon < -180 || lon > 180 {
return nil, errors.New("location: lat must be within [-90,90] and lon within [-180,180]")
}
l := &wire.Location{Lat: lat, Lon: lon}
if len(p) == 3 {
l.Label = strings.TrimSpace(p[2])
bad := utf8.RuneCountInString(l.Label) > 64 || !utf8.ValidString(l.Label)
for _, r := range l.Label {
bad = bad || unicode.IsControl(r)
}
if bad {
return nil, errors.New("location: label must have at most 64 characters and no control characters")
}
}
return l, nil
}