Circuit Breaker

repository·main·Indexed 41 days ago

https://github.com/blkleg/circuitbreaker

A self-hosted infrastructure discovery, monitoring, and interactive topology visualization platform for homelabs and private networks. Version 0.4.2 features a FastAPI backend and a React frontend to map hardware, services, networks, and clusters using live telemetry.

Tokens
277.8K
Snippets
580
Records
1.2K
Agent score
50%

What's inside Circuit Breaker

  1. Overview of Approved UI Implementation Plans

    main

    The docs/design/approved-ui/ directory contains the official implementation plans for the Circuit Breaker user interface. These plans serve as the record of design decisions and visual baselines for the ten core UI workflows.

    Key architectural decisions include:

    • Unified Navigator: A single overlay that replaces both the top-right Routes dropdown and the existing command palette, providing a unified keyboard/search experience.
    • Theme Awareness: All approved surfaces must be theme-aware (e.g., supporting Gruvbox or other palettes) while preserving composition, density, and semantic status distinctions.
    • Service Integration: New UI workflows must use existing services and components. Speculative frameworks or generic workflow engines are prohibited.
    • Access Tokens: The redesign reuses the INC-14 admin API and route, focusing on presentation, search, risk framing, and HTTP auditing rather than creating a new credential subsystem.
  2. Overview of Circuit Breaker features

    main

    Circuit Breaker provides several key capabilities for infrastructure management:

    • Auto-Discovery (Beta): Scan network ranges and merge approved items into your inventory.
    • cb-agent: A Linux daemon for remote telemetry collection, monitor probes, and internal network discovery.
    • Monitoring: Native ICMP, TCP, HTTP, and DNS checks with uptime and latency history. Includes threshold alert rules for hardware gauges.
    • Notifications: Webhook-based routing to notification sinks.
    • Parked Messages: A mechanism to recover or abandon undelivered internal message bus messages via Logs -> Parked Messages.
    • Backup & Restore: Export and restore inventory snapshots.
    • Authentication: Supports local auth, OAuth/OIDC, and MFA.
  3. Production-Readiness Requirements for cb-agent

    main

    The cb-agent production-readiness specification defines the criteria for a signed agent to be considered stable for deployment. Key operational requirements include:

    Lifecycle Operations

    An agent must be capable of being installed, enrolled, operated, upgraded, rolled back, revoked, and removed across supported host and network matrices.

    Network and Scope Safety

    • Network Scope Accuracy: The agent must respect network boundaries (multi-NIC, VLAN, bridge, VPN, Docker, IPv4/IPv6). Disallowed scopes must never be scanned or probed.
    • Remote Site Resilience: The agent must function behind NAT (no inbound ports) using realistic DNS/TLS, handling packet loss, latency, DHCP changes, reboots, and intermittent WAN connectivity.

    Resource Constraints

    Agents must enforce ceilings for:

    • Idle CPU/RAM
    • Discovery load
    • Disconnected-spool disk usage (must fail gracefully at bounds).

    Operator Safety and UI

    • State Visibility: The UI must clearly communicate last-seen freshness, clock skew, offline/revoked/disabled status, stale telemetry, pending config/updates, and degraded capability states.
    • Actionable Errors: Installation and enrollment errors must be actionable without exposing sensitive keys or protocol internals.
    • Explicit Confirmation: High-risk operations such as revocation, uninstallation, scope expansion, remote-probe/discovery grants, and update dispatch require explicit confirmation and audited records.
  4. Understand the Circuit Breaker repository layout

    main

    The project is organized as a modular monolith with the following primary directory structure:

    • apps/backend/: FastAPI + SQLAlchemy + Pydantic (Python 3.12). Contains src/app/ (api, services, db, core, workers, schemas, integrations, middleware, jobs), tests/ (pytest), and migrations/ (Alembic).
    • apps/frontend/: React + Vite + Tailwind (JSX/JS). Contains src/ (pages, components, hooks, api, lib, context, utils, __tests__).
    • apps/agent/: Go cb-agent (cmd/, internal/, e2e/).
    • docker/: Mono image, nginx, entrypoint, and supervisord configurations.
    • tests/: Integration, build (repo-policy), and unit tests.
    • docs/: User and ops documentation (MkDocs), design, and evidence.
    • specs/: 1.0.0 release-control ledger and dated design specs.
    • plans/: Indexed implementation plans.
    • scripts/: CI tiers, install helpers, and version parity.
    • packaging/: nfpm, native bundle, and rollback logic.
    • .github/: CI workflows, CODEOWNERS, and PR/bug templates.
    • SECURITY_REPORTS/ & SECURITY_PATCHES/: Historical audits.

    Runtime Stack: PostgreSQL, Redis, NATS, and nginx. Deployment is via a mono container or native systemd using install.sh or the cb command.

  5. Codebase layout and component locations

    main

    The project is organized into three main areas:

    Go Agent (apps/agent/)

    • Entrypoint: cmd/cb-agent/main.go
    • Core Logic: internal/{frame,link,capability,spool,netscope,hostinfo,status,tlsdial,update}
    • Collection: internal/collect/{collect.go,payload.go,host/,probe/}

    Backend (apps/backend/src/app/)

    • Discovery Services: services/{discovery_service,discovery_profiles_service,discovery_scheduler,discovery_import_service,discovery_merge}.py
    • Agent Services: services/{agent_link,agent_registry,agent_capabilities,agent_probe,agent_telemetry}.py
    • Monitoring: services/monitoring/{probe_eligibility,probe_reconcile}.py and workers/monitor_probe_dispatch.py
    • API & Schemas: api/ and schemas/ directories for discovery, agents, and agent frames.
    • Core & DB: core/ (scope, ACL, scheduler, locks) and db/models.py.

    Frontend (apps/frontend/src/)

    • Pages: pages/{AgentDetailPage,AgentsPage,DiscoveryPage,DiscoveryHistoryPage}.jsx
    • Components: components/agents/* and components/discovery/{ScanProfileForm,ScanDetailPanel,NewScanPage}.jsx
    • Hooks & API: hooks/useDiscoveryStream.js and api/{agents.js,discovery.js}
  6. Understand the cbi-agent Cohesion Hardening Plan

    main

    The cbi-agent Cohesion Hardening plan (Slices 1-2) is a series of 21 test-first tasks designed to consolidate contracts and fix defects in the agent, backend, and frontend. This plan is a prerequisite for Slice 3 (probe.result) and Slice 4 (discovery.finding) because it establishes the core architectural patterns and data contracts they depend on.

    Key objectives include:

    • Normalizer Consolidation: Moving from multiple hand-rolled copies to a single shared normalizer function used by probe.result projections.
    • Conformance Harness: Using a cross-language conformance corpus (JSON fixtures) as a mandatory gate for shipping new frame types.
    • Testability Patterns: Implementing injected clocks and dialers (collector test seams) to allow for reliable testing of collectors.
    • Readiness & Capability Semantics: Defining how capabilities report health and how per-capability grant isolation works.
    • Data Observability: Ensuring bounded history, spool visibility, and complete Agent Detail views to support end-to-end testing of future slices.
  7. Understand the Security and Trust implementation roadmap

    main

    The security architecture of Circuit Breaker is implemented through discrete 'Sprint Implementation Slices' (SEC-1 through SEC-6). These slices define the progression from tenant boundary enforcement and endpoint authorization to authentication hardening, outbound safety, and audit/content security.

    Developers should note that the implementation path diverges at SEC-2:

    • SEC-2A is followed if multi-tenancy is supported (enforcing tenant boundaries via RLS and request context).
    • SEC-2B is followed if multi-tenancy is unsupported (removing/disabling tenant management features).

    Each slice is designed to be verified against specific requirements and produces artifacts (migrations, tests, and documentation) required for release candidates.

  8. Understand the Circuit Breaker 1.0.0 Production-Readiness Specifications

    main

    The specs/1.0.0/ directory contains the formal product and release specifications for the 1.0.0 version of Circuit Breaker. These documents translate audit requirements into testable outcomes and evidence.

    Each specification is paired with an implementation file that breaks the work into manageable slices. A requirement is only considered 'Done' when it meets the following criteria:

    1. Normative acceptance criteria pass against the exact release-candidate commit.
    2. Behavior is tested from the signed artifact (not just a source checkout).
    3. Evidence (location, environment, owner, date, result) is recorded in the release ledger.
    4. All failures, skips, or warnings are resolved or approved under RC-08.
    5. User-facing contracts and operational documentation are updated.
    6. The release owner confirms no superseding changes have invalidated the evidence.
  9. Understand the cbi-agent Slice 2 Host Telemetry Plan

    main

    The cbi-agent Slice 2 plan defines the implementation requirements for host telemetry within the cb-agent. This includes protocol upgrades (schema v2), structured capability configuration, a new collector framework, and enhanced telemetry persistence.

    Key architectural shifts include:

    • Schema Negotiation: Agents use hello.capability_schema to negotiate between legacy (boolean) and structured ({enabled, config}) capability grants. A value of 2 indicates the new schema.
    • Telemetry Types: Introduction of telemetry.host payloads and capability.readiness control frames.
    • Persistence: New data structures for agent_host_samples (raw payloads) and agent_host_sample_hourly (7–30 day rollups).
    • Collector Framework: A new internal framework for non-overlapping, cancellable scheduling of collectors (Core, Filesystem, Disk, Network, Thermal, and Docker).
  10. Understand the cb-agent architecture and foundation

    main

    The cb-agent is a Go-based daemon designed to enroll against a Circuit Breaker instance via an end-to-end-encrypted channel. It operates as an outbound-only agent, reporting heartbeats and appearing in the Circuit Breaker UI for administrator approval.

    Core Components

    • apps/agent/ (Go module): Implements key generation, Noise IK handshakes, a bounded data spool, and a capability gate.
    • Backend Control Plane: A Python/FastAPI subsystem that terminates the Noise channel, manages agent state, and handles enrollment. It includes modules for crypto, registry, and link management.
    • Frontend Agents Surface: A React-based UI following the MonitorsPage pattern for managing and viewing agent status.

    Technical Specifications

    • Encryption: Noise IK pattern using X25519 DH, ChaCha20-Poly1305 cipher, and SHA-256. Rekeying occurs every 15 minutes.
    • Communication: Outbound-only frames via WSS (WebSockets). No network relay or tunneling is supported in the foundation version.
    • Data Spooling: Uses /var/lib/cb-agent/spool/ with a default 64 MB cap. Only data frames are spooled; control frames are never spooled. When draining, the agent interleaves spooled frames with live traffic at a ratio of 1 spooled frame per 4 live frames.
  11. Server Contract Implementation Plan Overview

    main

    The Server Contract Implementation Plan aims to align the server's operational contract with specific requirements (SRV-03, SRV-05, and SRV-06). The primary goals are to implement distinguishable health endpoints (liveness, readiness, and startup), introduce a configuration validator, and unify the divergent cb CLI tools into a single command-line interface.

    Key Architectural Changes

    • Health Probes: Health is split into three distinct endpoints backed by a shared probe function. This allows orchestrators (like systemd or Docker) to differentiate between a wedged process (requiring a restart) and a process waiting on a dependency (requiring a wait).
    • Config Validation: Reuses the app.core.startup_validation module, exposed via a new app.cli entrypoint.
    • CLI Unification: The two existing cb scripts will converge into a single CLI using mode dispatch.

    Tech Stack

    • FastAPI
    • Python 3.12
    • Bash
    • systemd
    • Docker HEALTHCHECK