Skip to content

feat: Grafana integration — fleet-wide auth dashboard - #26

Merged
anhtuank7c merged 7 commits into
mainfrom
feat/grafana-integration
May 27, 2026
Merged

anhtuank7c merged 7 commits into
mainfrom
feat/grafana-integration

Conversation

@anhtuank7c

Copy link
Copy Markdown
Owner

Closes #25.

Summary

Ships examples/grafana/ — a complete Loki/Alloy/Grafana integration that
turns the ECS-shaped events PAMSignal already writes via sd_journal_send()
into a fleet-wide auth dashboard. No daemon changes.

Dashboard

Operator deliverable: install Alloy on each host, point it at Loki, import
one dashboard JSON, attach four alert rules to a contact point. Target
time-to-working-dashboard for a Loki newcomer: under 30 minutes.

What's in the box

File Role
alloy.river Production journald scraper. Promotes app/host/service/event_action to Loki labels (~30 × fleet_size streams); keeps SOURCE_IP/USER_NAME/… in the JSON body for query-time parsing.
dashboards/pamsignal-v1.json 12 panels across 6 rows: stat row, outcome/service time-series, per-host volume, top-IP + top-username tables, recent brute-force + root-login logs, live event stream. Multi-select variables for host/service/action.
alerts.yaml Four Grafana-native rules: brute-force detected (critical), root SSH login (high), ≥10 fails from one IP in 5 min (high, safety net), host silent >10 min (medium).
docker-compose.yml Loki + Grafana + Alloy + image renderer + Python synthetic producer. Single command, no Linux fleet required.
verify.sh One-shot pipeline health check with five distinct exit codes that pinpoint the broken step.
README.md Deploy-for-real guide, architecture, troubleshooting, tuning notes.

Design rationale (schema, label cardinality plan, panel rationale) lives in
docs/grafana-integration.md.

Commits

  • 8a5f127 docs: add Grafana integration design
  • fe48590 feat(grafana): add Loki/Alloy/Grafana integration with try-it stack
  • 67e500c docs: surface Grafana integration from main README and CHANGELOG
  • c8454cd ci: validate Grafana integration on every PR

What was validated live before push

  • All 12 panel queries return non-empty results against the synthetic dataset
  • verify.sh --loki-only exits 0
  • Both Alloy configs pass alloy fmt --test
  • Dashboard JSON parses and provisions into Grafana
  • alerts.yaml parses
  • Screenshot rendered via the image renderer (the PNG in this PR)

Test plan

  • CI green on grafana-integration workflow (validates configs, brings up stack, asserts panels return data, uploads dashboard screenshot artifact)
  • cd examples/grafana && docker compose up -d → http://localhost:3000 shows the PAMSignal dashboard with synthetic events flowing in
  • ./examples/grafana/verify.sh --loki-only exits 0 against the running stack
  • Trigger the synthetic brute-force burst (auto-fires every ~25s) → "Brute-force alerts" stat flips red within ~30s
  • On a real Linux host: install Alloy, drop in alloy.river, restart pamsignal → events appear in Loki with the four expected labels
  • Import alerts.yaml into Grafana, wire to a contact point, confirm at least one rule fires against the synthetic stack
  • docker compose down -v cleans up without orphans

Follow-ups (manual, post-merge)

  • Submit dashboards/pamsignal-v1.json to https://grafana.com/grafana/dashboards/ with tags pamsignal pam auth ssh brute-force fleet loki
  • Launch posts: r/selfhosted, r/sysadmin, r/grafana, Show HN

🤖 Generated with Claude Code

anhtuank7c and others added 7 commits May 27, 2026 23:55
Locks the panel layout, label-cardinality plan, LogQL patterns, and
alert thresholds for the fleet-wide auth dashboard before any
implementation work lands. Sourced from the schema PAMSignal already
emits via sd_journal_send() — no daemon changes required.

Refs #25.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Ships everything an operator with a Linux fleet needs to surface
PAMSignal events in a fleet-wide auth dashboard, with no daemon
changes.

- alloy.river — production journald scraper. Filters
  SYSLOG_IDENTIFIER=pamsignal and promotes four low-cardinality
  fields (app, host, service, event_action) to Loki labels.
  Everything else stays in the JSON body, parsed at query time.
  Total streams stay at ~30 × fleet_size — safe to thousands
  of hosts.
- dashboards/pamsignal-v1.json — 12-panel dashboard. Stats row,
  outcome/service time-series, per-host volume, top-IP and
  top-username tables, recent brute-force + root-login logs,
  live event stream. Multi-select variables for host, service,
  event_action.
- alerts.yaml — four Grafana-native rules: brute-force detected
  (critical), successful root SSH login (high), ≥10 failed
  logins from one IP in 5 min (high, safety net), host stopped
  reporting for >10 min (medium).
- docker-compose.yml — single-command local stack with Loki,
  Grafana, Alloy, image renderer, and a Python synthetic event
  producer that generates realistic event mix + periodic
  brute-force bursts. Lets operators see the dashboard before
  committing to deploy.
- verify.sh — one-shot pipeline health check with five distinct
  exit codes that pinpoint the broken step.
- README.md — deploy-for-real guide for Loki newcomers, plus
  troubleshooting and tuning notes.
- alloy/demo.alloy — file-source variant for the docker-compose
  stack, mirrors the production label set.
- synthetic/, config/, provisioning/ — supporting scaffolding.

assets/grafana-dashboard.png is the rendered v1 dashboard against
the synthetic dataset (12 hosts, ~30 min of traffic).

Refs #25.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Adds a top-level "Fleet view in Grafana" section to the README with
the dashboard screenshot and a one-liner for the local try-it stack,
plus a link from the documentation index. CHANGELOG entry under
Unreleased summarizes the integration's deliverables, design
rationale, and the two manual launch tasks left for the maintainer.

Refs #25.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
New workflow triggers on paths under examples/grafana/ and the
design doc. On each run it:

- alloy fmt --test on both alloy.river and alloy/demo.alloy
- json.tool on dashboards/pamsignal-v1.json
- yaml.safe_load on alerts.yaml
- docker compose up -d, waits for Loki + Grafana healthy
- 30s soak for synthetic events to accumulate
- Asserts the 8 representative panel queries return non-empty
  results against Loki
- Confirms the dashboard is provisioned with the expected title
- Runs verify.sh --loki-only
- Renders the dashboard PNG via grafana-image-renderer and
  uploads it as an artifact (14-day retention)

Designed to finish in under two minutes so the maintainer doesn't
avoid editing the dashboard for fear of slow CI.

Refs #25.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
setup-python doesn't ship PyYAML; the validate step was failing
with ModuleNotFoundError. Add an inline pip install.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Grafana 11.4 cold-boots in 60–90s on GitHub Actions runners due to
database migrations, exceeding the original 60s wait. Bump the
timeout to 180s and switch the readiness check from a piped grep
(can drop exit code under set -e) to a case match on the captured
response body.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
grafana.com (and Grafana's UI Import) reject dashboards with
hardcoded datasource UIDs, with the error "Old dashboard JSON
format. Read about Importing & Sharing with Grafana 2.x or 3.0."
The marketplace expects the "shared externally" format: a
${DS_LOKI} placeholder for the Loki datasource plus __inputs,
__elements and __requires metadata so the importer can pick their
own datasource at import time.

This commit:

- adds dashboards/pamsignal-v1.grafana-com.json with the
  marketplace format. All 16 datasource refs (12 panels + 3
  template variables + 1 annotation) use the ${DS_LOKI}
  placeholder. __requires declares grafana>=11.0.0, loki>=1.0.0,
  and the four panel plugin types (stat, timeseries, table, logs)
  the dashboard uses.
- keeps dashboards/pamsignal-v1.json as the provisioning-ready
  version (hardcoded uid="loki" matches the bundled provisioning
  file) — both files stay in sync because the marketplace one is
  derived from it.
- updates examples/grafana/README.md to point operators at the
  right file for the right path: provisioning vs. grafana.com /
  UI import.
- extends CI to JSON-validate the marketplace file and assert
  it has no hardcoded "loki" uid leaks plus a __inputs block.

Verified locally by importing the marketplace JSON into Grafana
11.4 via /api/dashboards/import with the DS_LOKI input bound to
the local datasource — dashboard renders identically.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@anhtuank7c
anhtuank7c merged commit ebe33ef into main May 27, 2026
6 checks passed
@anhtuank7c
anhtuank7c deleted the feat/grafana-integration branch May 27, 2026 17:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Grafana integration — agent-side artifacts for fleet-scale PAM monitoring

1 participant