Skip to content
tracyhatemicePublic

About

A tiny Go webserver that returns client IP, handles DDNS updates and emits events via webhooks.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

166 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

who

Build and Push Container Image

Lightweight, self-hosted Go HTTP service for client IP reflection, name → IP mapping, DDNS updates, webhook triggers, and touch-file mirroring — backed by embedded pure-Go SQLite and an OIDC-authenticated Admin Web UI.

Runs as a single compressed static binary inside a minimal FROM scratch container alongside Traefik.

Deployment with Traefik

Assume Traefik is already configured with the Docker provider on an external Docker network named traefik.

Mount a persistent /data volume for the SQLite database (who.db), optionally mount an existing config.json read-only for one-time first-boot import, and configure OIDC environment variables to unlock the Admin UI.

When sharing a public domain where only specific path prefixes should be routed to who, set --base-path=/admin (or WHO_BASE_PATH=/admin) so the Admin UI, /auth/*, and /api/v1/* live under /admin while public /whoami, /whois, and /iam endpoints remain at /:

services:
  who:
    image: ghcr.io/tracyhatemice/who:latest
    container_name: 'who'
    networks:
      - traefik
    volumes:
      - ./data:/data
      - ./config.json:/config.json:ro # optional: imported once when /data/who.db is empty
    environment:
      WHO_BASE_PATH: /admin
      WHO_OIDC_ISSUER: https://id.example.org
      WHO_OIDC_CLIENT_ID: who-admin
      WHO_OIDC_CLIENT_SECRET: change-me
      WHO_OIDC_ALLOWED_EMAILS: admin@example.org
    labels:
      traefik.enable: true
      traefik.docker.network: traefik
      traefik.http.routers.who.entrypoints: https
      traefik.http.routers.who.tls: true
      traefik.http.routers.who.rule: >-
        HostRegexp(`^((ipv4|ipv6)\.)*example\.org$`) && (
          PathPrefix(`/whoami`) ||
          PathPrefix(`/whois`) ||
          PathPrefix(`/iam`) ||
          PathPrefix(`/admin`)
        )
      traefik.http.routers.who.tls.certresolver: le
    restart: 'unless-stopped'
    command:
      - --port=80
      - --verbose
      - --data-dir=/data
      - --config=/config.json

Dedicated subdomain option: If who has its own hostname (e.g. Host(\who.example.org`)), omit WHO_BASE_PATH/--base-pathand route the entire host towho— the Admin UI will be served directly at/`.

CLI Flags & Environment Variables

Every CLI flag has a matching WHO_* environment variable (CLI flags take precedence when explicitly provided):

Flag Environment Variable Default Description
--port WHO_PORT 80 TCP port number to listen on
--verbose WHO_VERBOSE false Enable verbose HTTP request logging (true, 1, yes, on)
--data-dir WHO_DATA_DIR ./data (/data in Docker) Directory holding the who.db SQLite database
--config WHO_CONFIG (empty) Optional seed config.json imported once when who.db is empty
--base-path WHO_BASE_PATH / Sub-path prefix for Admin UI, /auth/*, and /api/v1/* (e.g. /admin)
--ddns-endpoint WHO_DDNS_ENDPOINT (empty) Optional DDNS provider endpoint override (defaults to AWS Route53; used for local/E2E mock endpoints)
--oidc-issuer WHO_OIDC_ISSUER (empty) OIDC provider issuer URL (e.g. Pocket ID, Authelia, Authentik, Keycloak)
--oidc-client-id WHO_OIDC_CLIENT_ID (empty) OIDC relying-party client ID
--oidc-client-secret WHO_OIDC_CLIENT_SECRET (empty) OIDC client secret (optional for public PKCE clients)
--oidc-redirect-url WHO_OIDC_REDIRECT_URL (derived) Explicit OIDC callback URL override (defaults to <scheme>://<host><base-path>/auth/oidc/callback)
--oidc-allowed-emails WHO_OIDC_ALLOWED_EMAILS (empty) Comma-separated allowlist of verified OIDC email claims
--oidc-allowed-subs WHO_OIDC_ALLOWED_SUBS (empty) Comma-separated allowlist of OIDC sub (subject) claims

Public Usage & Endpoints

# Get your IP (extracted from X-Forwarded-For -> X-Real-Ip -> RemoteAddr)
$ curl -H "X-Real-Ip: 203.0.113.50" http://localhost:8080/whoami
203.0.113.50

# Inspect sorted request headers seen by who
$ curl -H "X-Real-Ip: 203.0.113.50" http://localhost:8080/whoami/headers
Accept: */*
User-Agent: curl/8.7.1
X-Real-Ip: 203.0.113.50

# Register a name with your client IP
$ curl -H "X-Real-Ip: 203.0.113.50" http://localhost:8080/iam/alice
203.0.113.50

# Register a token-protected name
$ curl -H "Authorization: Bearer <token>" -H "X-Real-Ip: 203.0.113.50" http://localhost:8080/iam/router
203.0.113.50

# Register a name with an explicit IPv4 or IPv6 address
$ curl http://localhost:8080/iam/bob/192.168.1.100
192.168.1.100

# Look up a registered name (or alias)
$ curl http://localhost:8080/whois/alice
203.0.113.50

# Looking up an unregistered name returns 404
$ curl -v http://localhost:8080/whois/unknown
< HTTP/1.1 404 Not Found

Public Endpoints

Public endpoints are always mounted at root (/) regardless of --base-path:

GET /whoami

Returns the client's IP address using the fallback chain X-Forwarded-For (last IP) → X-Real-Ip → RemoteAddr, or an empty body if no valid IP can be extracted.

GET /whoami/headers

Returns all incoming HTTP request headers sorted alphabetically (Name: Value, one per line, empty values skipped). Useful for verifying reverse-proxy forwarding headers.

GET /iam/{name}

Registers {name} with the detected client IP address.

  • Returns the stored IP address (200 OK)
  • Returns 400 Bad Request if {name} is an alias or no valid client IP can be extracted
  • Returns 401 Unauthorized if {name} has an /iam token configured and no matching token is supplied

GET /iam/{name}/{ip}

Registers {name} with a manually specified IPv4 or IPv6 address. If {ip} is not a valid IP literal, falls back to the detected client IP (GET /iam/{name} behavior).

GET /whois/{name}

Returns the IP address currently stored for {name}, or newline-separated resolved member IPs when {name} is an alias. Returns 404 Not Found if {name} is unknown or an alias has no members with known IPs.

GET /healthz

Returns ok (200 OK, text/plain) for container health/readiness checks without writing to the public access log.

OIDC Authentication & Admin Dashboard

OIDC Setup

The Admin UI and /api/v1/* management API are protected by OpenID Connect (Authorization Code Flow with S256 PKCE, nonce validation, HttpOnly/SameSite=Lax SQLite-backed session cookies, per-request allowlist re-verification, Sec-Fetch-Site: cross-site rejection, and X-Who-CSRF: 1 protection on mutating requests and GET /api/v1/backup/export).

Unauthenticated requests to the Admin UI root serve a minimal, self-contained HTML sign-in (or setup) page without loading the compiled Admin SPA bundle or exposing /api/v1/* routes, while unauthenticated requests to SPA assets return 401 Unauthorized.

  1. Create an OIDC client in your identity provider (Pocket ID, Authelia, Authentik, Keycloak, Google, etc.) with redirect URI:
    • https://<your-domain>/auth/oidc/callback (default root mount), or
    • https://<your-domain><base-path>/auth/oidc/callback when using --base-path (e.g. https://example.org/admin/auth/oidc/callback).
  2. Set WHO_OIDC_ISSUER and WHO_OIDC_CLIENT_ID (plus WHO_OIDC_CLIENT_SECRET for confidential clients).
  3. Restrict admin access via WHO_OIDC_ALLOWED_EMAILS (requires email_verified: true from the provider) and/or WHO_OIDC_ALLOWED_SUBS.

When OIDC is not configured, who runs normally for all public /whoami, /iam, and /whois traffic while serving the locked setup guide at the Admin UI root and returning 503 Service Unavailable on /api/v1/*.

Dashboard Views

  • Overview: 24-hour KPI summary (persisted/ephemeral/alias counts, IP changes, /iam, /whois, and /whoami request totals, delivery errors), stacked 24h traffic histogram, recent IP changes with delivery badges, and recent delivery failures.
  • Records: Tokenized key:value filtering (state:, type:, auth:, iam:, ip:, member: plus free-text search) and numbered pagination across persisted records, dynamic aliases, and in-memory ephemeral records; explicit Persisted / Ephemeral badges; aligned Sync, Edit, ⋯, and Delete actions (one-click persist to SQLite, /iam bearer token generation/rotation/clearing, manual syncs); and a paginated per-record DNS / IP History (old_ip → new_ip) drawer with child DDNS, webhook, and touch delivery outcomes.
  • DDNS: Standalone view to create, edit, enable/disable, filter (iam:, provider:, secret:, domain:, zone:, ip-version:, status:), paginate, and manually trigger (Sync) dynamic DNS rules. Rules reference reusable provider credential bundles managed under Settings → Provider Secrets, with sensitive values masked (••••••••) in API responses and preserved on edit unless explicitly replaced.
  • Webhooks: Standalone view to create, edit, enable/disable, filter (iam:, method:, url:, status:), paginate, and test outbound HTTP webhook notifications, with header values masked (••••••••) in API responses.
  • Touch Files: Filter (iam:, path:, ip:, status:), paginate, and manage JSON mirror file rules, preview the live flattened JSON payload ({"iam", "ip", "last_update"}), toggle rules on/off, and trigger immediate disk writes.
  • Access Log: Compact time-range picker (1h / 24h / 7d / 30d / All time / custom range + Refresh), interactive stacked traffic histogram with range brushing, tokenized autocomplete filter bar (endpoint:, iam:, method:, status:, ip:, changed:, user-agent: plus free-text search), and a List | Top toggle switching between a server-paginated request log (with slide-over inspection drawer) and SQL-aggregated ranked breakdown cards (Top Endpoints, Top IAMs, Top Client IPs, Top Status Codes, Top User-Agents) with click-to-filter drill-down.
  • Audit Log: Time-range picker (All time default plus 1h / 24h / 7d / 30d / custom range + Refresh), tokenized autocomplete filter bar (category:, action:, actor:, target:, ip: plus free-text search), and a List | Top toggle switching between a server-paginated security/audit trail and SQL-aggregated breakdown cards (Top Categories, Top Actions, Top Actors, Top Targets, Top IPs) with click-to-filter drill-down.
  • Settings:
    • Appearance: Switch between Light, Dark, and System color themes.
    • Provider Secrets: Manage and paginate reusable DDNS provider credential bundles.
    • Data & Retention: Configure automatic hourly pruning windows (access_logs default 30 days, audit_logs default 90 days, ip_history default 0 / keep forever), view live who.db disk usage, or run manual pruning.
    • Sign-In Sessions: Inspect and revoke active OIDC admin sessions.
    • Backup: Export the current configuration as a config.json-compatible JSON snapshot (via CSRF-protected fetch, optionally including secrets), or import a JSON backup in Merge (non-destructive upsert) or Replace mode.

Core Features

1. SQLite Storage & First-Boot config.json Import

Configuration, IP transition history, delivery outcomes, access logs, audit logs, and admin sessions are stored in a single pure-Go SQLite database (<data-dir>/who.db in WAL mode, /data/who.db inside the container).

  • Persisted vs. Ephemeral names: Names defined in SQLite (via the Admin UI or imported from config.json) persist their latest IP and last_update timestamp across restarts. Unconfigured names updated via /iam/{name} still work in memory as ephemeral records and can be persisted later from the UI.
  • First-boot config.json seeding: Passing --config=/path/to/config.json (or WHO_CONFIG) imports who, secrets, ddns, webhooks, and touch into who.db only when all five configuration tables are empty. On subsequent restarts, who.db is authoritative and config.json is left untouched (so it can safely be mounted :ro).
  • Last-change semantics: Re-registering the same IP address is a fast no-op — last_update is only bumped and side effects only fire when the IP actually changes (or when manually synced from the UI).

2. Optional /iam Bearer Tokens

Individual who records can optionally require a bearer token before /iam/{name} or /iam/{name}/{ip} accepts an update:

  1. Open Records in the Admin UI (or use POST /api/v1/records/{iam}/token) to generate or rotate a token.
  2. Copy the plaintext token when shown — only its SHA-256 hash is stored in SQLite and verified in constant time.
  3. Supply the token in updates via any of:
    • Authorization: Bearer <token> header (recommended)
    • X-Who-Token: <token> header
    • ?token=<token> query parameter (query strings are automatically stripped before writing access_logs or verbose stdout logs)

Records without a token remain open, preserving drop-in compatibility with existing scripts (such as scripts/openwrt/70-ddns-update).

3. DDNS & Reusable Provider Secrets

Automatic asynchronous DNS A/AAAA updates when a name's IP changes via /iam/{name} (or on manual sync/test from the Admin UI). Provider credentials live in a reusable secrets store so multiple DDNS rules can share and rotate keys in one place (route53 supported today; structured for additional providers such as Cloudflare):

{
  "secrets": [
    {
      "name": "aws-main",
      "provider": "route53",
      "credentials": {
        "access_key": "AKIAIOSFODNN7EXAMPLE",
        "secret_key": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
      }
    }
  ],
  "ddns": [
    {
      "provider": "route53",
      "secret": "aws-main",
      "domain": "julia.ddns.example.com",
      "ip_version": "ipv4",
      "zone_id": "Z3M3LMPEXAMPLE",
      "ttl": 300,
      "iam": "juliav4",
      "enabled": true
    }
  ]
}
Field Description
provider DNS provider (route53)
secret Name of the saved secrets entry supplying provider credentials
domain Record FQDN to update (e.g. sub.example.com, example.com, *.example.com)
ip_version ipv4 (A records), ipv6 (AAAA records), or empty to accept either
zone_id Hosted Zone ID (e.g. Route53 Hosted Zone ID)
ttl DNS record TTL in seconds (default: 300)
iam Record name that triggers this rule
enabled Optional boolean (true by default)

4. Webhook Notifications

Sends asynchronous HTTP JSON notifications when a name's IP changes — ideal for firewall allowlist reloads, cache invalidations, or home/lab automation.

{
  "webhooks": [
    {
      "iam": "juliav4",
      "url": "https://example.com/reload/allowlist",
      "method": "POST",
      "headers": {
        "Authorization": "Bearer token123"
      },
      "enabled": true
    }
  ]
}

Webhooks send Content-Type: application/json:

{
  "iam": "juliav4",
  "ip": "203.0.113.50",
  "timestamp": "2026-01-28T12:34:56Z"
}

5. Aliases

Aliases group multiple regular iam records under a single read-only name. Querying /whois/{alias} resolves current member IPs in alias-list order, one per line (omitting members without an IP, or returning 404 if none have IPs).

{
  "who": [
    { "iam": "juliav4", "ip": "111.111.111.111" },
    { "iam": "juliav6", "ip": "2001:db8::1" },
    { "iam": "julia", "alias": ["juliav4", "juliav6"] }
  ]
}

Aliases cannot be updated directly via /iam/{alias} and cannot reference other aliases.

6. Touch Files

Mirrors an iam record (or flattened alias) to an on-disk JSON file (0644) on startup and whenever a covered IP changes:

{
  "touch": [
    {
      "iam": "julia",
      "path": "/var/run/who/julia.json",
      "enabled": true
    }
  ]
}

Output format (ip is always [] when empty, never null; for aliases, last_update is the most recent member change):

{
  "iam": "julia",
  "ip": ["111.111.111.111", "2001:db8::1"],
  "last_update": 1752900000
}

Building from Source

Requires Go 1.26+ and Node.js 24+ with pnpm:

# Lint, test, build embedded Svelte UI, and compile static ./who binary
$ make

# Build container image locally
$ make image

End-to-End Testing (make e2e)

The e2e/ workspace runs full-stack browser and API verification with Playwright Chromium against a self-contained Docker Compose stack (e2e/docker-compose.yml):

  • Traefik (traefik:v3.6): TLS termination on https://app.who.localhost:18443 and https://auth.who.localhost:18443 using ephemerally generated CA and server certificates in e2e/.generated/.
  • GLAuth (ghcr.io/glauth/glauth:v2.5.4): Lightweight LDAP directory backing admin@who.localhost and denied@who.localhost.
  • Authelia (authelia/authelia:4.39): OIDC Identity Provider (Authorization Code + S256 PKCE + UserInfo) backed by GLAuth and generated RSA JWKS.
  • who (built from root Dockerfile): Configured with WHO_BASE_PATH=/who, WHO_OIDC_ALLOWED_EMAILS=admin@who.localhost, and WHO_DDNS_ENDPOINT=http://mock-sink:9999.
  • mock-sink (node:24-alpine): HTTP sink capturing outbound Route53 XML UPSERT requests and webhook deliveries on http://127.0.0.1:19999.
# One-time Playwright setup (installs e2e deps and Chromium browser binary)
$ pnpm --dir e2e install --frozen-lockfile
$ pnpm --dir e2e exec playwright install --with-deps chromium

# Cold-boot the full Compose stack, run all 5 Playwright projects, and tear down cleanly
$ make e2e

# Keep stack running while iterating on individual Playwright specs
$ make e2e-up
$ NODE_EXTRA_CA_CERTS="$PWD/e2e/.generated/certs/ca.crt" pnpm --dir e2e exec playwright test tests/mobile-layout.spec.mjs
$ make e2e-down

GitHub Actions (.github/workflows/docker-build.yml) runs both test (go test -race -v ./... and pnpm --dir ui run check) and e2e (bash e2e/scripts/run.sh, uploading e2e/playwright-report, e2e/test-results, and e2e/.generated/compose-logs.txt on failure) before build-and-push.

About

A tiny Go webserver that returns client IP, handles DDNS updates and emits events via webhooks.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Packages

Used by

Contributors

Languages