Skip to content

feat(notifications, github, backups): WS-N + WS-G + WS-1 foundation - #382

Merged
vsilent merged 12 commits into
devfrom
feature/notifications
Nov 25, 2026
Merged

vsilent merged 12 commits into
devfrom
feature/notifications

Conversation

@vsilent

@vsilent vsilent commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

Summary

Three workstreams (Dokploy-inspired), with pure logic extracted into leaf crates under crates/ and DB/Vault/routes glue kept in the monolith.

WS-N Notifications (complete)

  • Schema notification_channel, notification_dispatch + casbin rules.
  • REST /api/v1/notifications/* (channels CRUD, test, dispatch list) — owner-gated; global admin channels (project_id NULL) restricted to root/group_admin.
  • Adapters: slack / discord / telegram / email / webhook (HMAC X-Stacker-Signature).
  • Edge-triggered event bus (deploy transitions, container.down); email via RabbitMQ → notify.
  • CLI stacker notify {add,test,list}. Secrets live only in Vault; responses carry a masked targetHint only.

WS-G GitHub (complete)

  • Schema github_installation, github_repo, github_webhook_delivery + casbin.
  • POST /api/v1/github/webhook: HMAC X-Hub-Signature-256 (constant-time via verify_slice), anti-replay on X-GitHub-Delivery (DB PK), event normalization.
  • Watch paths (glob + ! exclusions), Repo Connect API /api/v1/github/repos (CRUD, owner-gated), autodeploy switch.
  • Auto-deploy of matched pushes via redeploy_saved_project (redeploys onto the existing server; never provisions a new VM).

WS-1 Backups — foundation (step 1.1 + crate)

  • Migration create_backup_tables (backup_destination, backup_job, backup_run).
  • Crate crates/backup-core: typed execution plans (DumpPlan/RestorePlan = process argv + upload/download target) — no shell-command strings, no embedded credentials; the agent runs the process and streams to storage with its native HTTP client. Pluggable, vendor-neutral storage backend. Retention policy 7 daily + 4 weekly.

Module layout

Pure logic in leaf crates (notification-core, github-events, backup-core) — unit-tested without building the monolith. Integration (Vault, sqlx, routes) in the monolith.

Testing

  • cargo test --lib: 2382 passed / 0 failed / 6 ignored
  • Leaf crates: notification-core 10/10, github-events 7/7, backup-core 12/12
  • notification_channels 9/9, github_webhook 9/9
  • cargo fmt / cargo clippy clean on the new crates

Review notes

  • SQL uses bind params only (no string-formatted SQL).
  • Secrets (webhook secret, channel tokens, device credentials) stored only in Vault; never serialized to responses or logged.
  • Casbin rules match the registered routes under the keyMatch2 matcher; new migrations only.
  • Webhook signature comparison is constant-time; delivery replay blocked by primary key.

Docs are in English and vendor-neutral (the backup storage backend is pluggable — could be restic or another client later).

- schema: notification_channel + notification_dispatch (migration
  20261124111150); casbin rules for /api/v1/notifications/*
  (migration 20261124111654)
- REST: create/list/update/delete/test channels, list dispatches
- adapters: slack, discord, telegram, webhook (HMAC X-Stacker-Signature);
  email delivery deferred to N4 via the notify service
- secrets live only in Vault (notification_secret_path); responses carry a
  masked targetHint; errors are redacted recursively before storing
- delivery is at-least-once: retry x3 with backoff on 429/5xx, shared
  reqwest client with a 10s timeout
- project events go to that project's channels only; global channels
  require root/group_admin (code-review B1) and are reserved for
  organization-level events
- unauthorized channel access answers 404 (no existence leak)
- tests: 8 integration (tests/notification_channels.rs) + unit tests for
  masking/redaction; reviewed by code-reviewer + migration-checker
  2026-11-24 (B1/M1/M2 fixed, M3 accepted as convention deviation)
- contracts and BDD fixtures live in config/shared-fixtures (notifications-*)
… N3)

- deploy status transitions notify project channels (edge-triggered:
  completed->deploy.succeeded, failed/error->deploy.failed) from the MQ
  listener and force-complete; best-effort, never breaks the deploy flow
- pure logic moved to the leaf crate crates/notification-core (events,
  channel payloads, masking, redaction, retry/backoff, HTTP delivery);
  its 10 unit tests run in ~10ms without building the service - the
  agreed crate/module strategy for fast compilation going forward
- services/notification.rs keeps orchestration only (Vault, dispatch rows,
  project fan-out with per-channel events filter)
- tests: notification-core 10/10, notification_channels 9/9 (new fan-out
  and dispatch-log cases), lib 2382 passed / 6 skipped (pre-existing)
…S-N N4)

- email channels deliver through RabbitMQ -> notify (routing key
  notify.start.email.notification.all, NotifyEmailMessage shape), recorded
  in notification_dispatch like every other channel
- container.down: edge-detect running->exited/dead between aggregate health
  reports in the agent report path and fan out the contract event to the
  project's channels (best-effort, never fails the report)
- CLI: stacker notify add/test/list over /api/v1/notifications/*
  (secrets are write-only and never echoed back)
- crates/TODO.md: Slack/Telegram/Discord targets shipped, Teams stays open
- tests: notification-core 10/10, notification_channels 9/9, lib
  2382 passed / 6 skipped (pre-existing)

Closes WS-N (N1-N4).
…h paths (WS-G G1-G3)

- schema: github_installation, github_repo (branch, watch_paths, autodeploy,
  project binding), github_webhook_delivery replay guard
  (migration 20261124131026); casbin-anonymous webhook rule
  (migration 20261124131027, precedent: payout webhook)
- POST /api/v1/github/webhook: X-Hub-Signature-256 HMAC (constant-time),
  one processing per X-GitHub-Delivery, webhook secret only in Vault
- pure logic in the leaf crate crates/github-events: signature verify,
  push/pull_request/installation normalization, watch-path matching
  (globs with ! exclusions); tests run in ~10ms standalone
- push handling answers the matched repos seam for the G5 deploy trigger
- tests: github-events 7/7, github_webhook 4/4, notification_channels 9/9
  (regression), lib 2382 passed / 6 skipped (pre-existing)
- /api/v1/github/repos CRUD (create/list/update/delete), owner-gated:
  touching another user's project answers 404, duplicate repo+branch 409
- casbin rules for the new endpoints (migration 20261124135149)
- installation / installation_repositories webhooks are recorded in
  github_installation
- auto-deploy switch lives on github_repo.autodeploy; the stale catalog
  form field autodeploy is marked as superseded (forms/project/app.rs)
- tests: github_webhook 7/7 (CRUD roundtrip, ownership, installation
  recording), github-events 7/7, notification_channels 9/9, lib
  2382 passed / 6 skipped (pre-existing)

G5 (redeploy_saved_project primitive) is designed in the plan and follows.
- src/services/redeploy.rs: redeploy_saved_project rebuilds the Deploy form
  from the project's recorded request plus its saved server/cloud rows and
  pins server.server_id, so a push redeploys onto the existing server and
  never provisions a new VM (deploy.rs:1720 reuse path)
- webhook response grows 'triggered': per-repo outcome
  (queued|skipped|failed) with the reason (e.g. no saved server yet)
- acting user for webhook deploys is the connected repo's owner
- tests: github_webhook 9/9 including the G5 seam (skip without a saved
  server, deployment row created with one), github-events 7/7,
  notification_channels 9/9, lib 2382 passed / 6 skipped

Closes WS-G (G1-G5).
- schema: backup_destination, backup_job (source postgres/mysql/mongo/volume,
  cron schedule, retention 7 daily + 4 weekly), backup_run lifecycle
  (migration 20261124142356)
- crates/backup-core: dump/restore command building for the agent exec queue
  (single shell commands, per-run token via $BACKUP_TOKEN, never embedded)
  and the retention policy (B2); 9 unit tests in ~10ms
- docs/BACKUPS_SYNCOPIA.md: decisions B1-B3, architecture

Contracts and fixtures: config/shared-fixtures (backups-syncopia.json,
backups.feature).
Header names for the backup upload/download leg are now passed in
(BackupSpec.extra_headers) and rendered generically - nothing
vendor-specific is hardcoded in the crate. The service layer will supply
them from configuration per destination. Tests updated (10/10).
…tral

- backup-core no longer builds curl/shell command strings. It now emits
  typed DumpPlan/RestorePlan (process argv + upload/download target); the
  agent runs the process and streams to storage with its native HTTP client.
  Per-run token via environment only. Retention policy unchanged (12/12 tests).
- Docs rewritten in English (NOTIFICATIONS, GITHUB_INTEGRATION, BACKUPS).
- BACKUPS_SYNCOPIA.md renamed to BACKUPS.md; no vendor/product names in
  code or docs - the backup storage backend is pluggable and unnamed.
…ty matrix

The route matrix requires every registered route to be classified
(every_route_is_classified) and every {id} route to carry a sweep request
for the live IDOR check. Added the WS-N and WS-G routes:

- Own: list/create (channels, dispatches, repos)
- Sweep: {id} routes (channel update/delete/test, repo update/delete)
  with fixtures (channel, repo) and sweep requests - the live test confirms
  another user gets 404 identical to a missing resource with no data change.
- Token: the GitHub webhook (authenticated by signature, not a session).
…lable

The two-user harness (spawn_app_two_users_with_configuration) does not
resolve PG* env overrides, so it is unreachable in CI jobs without a
postgres service on localhost. The tests now skip (let Some(..) else
return) instead of panicking on a failed spawn - matching how the security
route matrix handles the same harness. They run for real wherever a test
database is provided (9/9 locally).
@vsilent
vsilent merged commit 30856c5 into dev Nov 25, 2026
11 checks passed
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.

2 participants