Watch
1
0
Fork
You've already forked RedFlag
0
Commit graph

479 commits

Author SHA1 Message Date
jpetree331
737cd7a337 fix(identity): D-1 machine ID deduplication fixes
- Remove unhashed 'unknown-' fallback from registration (F-D1-1)
  Registration aborts if GetMachineID() fails (no bad data)
- Add POST /admin/agents/:id/rebind-machine-id endpoint (F-D1-2)
  Admin can update stored machine ID after hardware change
- Delete dead example_integration.go with wrong usage (F-D1-3)
- Remove redundant Windows machineid.ID() retry (F-D1-4)
- Replace fmt.Printf with log.Printf in client.go (F-D1-5)

Operator note: agents registered with 'unknown-' machine IDs
must be rebound before upgrading. See D1_Fix_Implementation.md.

All tests pass. No regressions.
2026-03-29 09:53:43 -04:00
jpetree331
2668b9f102 test(machineid): D-1 pre-fix tests for machine ID duplication bugs
Pre-fix tests for 5 machine ID findings. Tests FAIL where they
assert correct post-fix behavior, PASS where they document bugs.

Tests added:
- F-D1-1 HIGH: Registration fallback unhashed format (4 tests)
- F-D1-1: Hash function and format consistency (3 tests)
- F-D1-2 MEDIUM: No machine ID recovery path (2 tests)
- F-D1-3 LOW: Dead example_integration.go code (2 tests)
- F-D1-4 LOW: Windows redundant machineid.ID() retry (2 tests)
- F-D1-5 LOW: client.go fmt.Printf for errors (2 tests)

Current state: 6 FAIL, 9 PASS. All prior tests pass.
2026-03-29 09:41:25 -04:00
jpetree331
ae54573c12 docs: D-1 machine ID duplication audit
Comprehensive audit of machine ID implementations across the
agent codebase. Identified 3 production call sites with 1 critical
divergence.

Key findings:
- F-D1-1 HIGH: Registration fallback "unknown-"+hostname is unhashed,
  mismatches runtime SHA256 hash, causes permanent agent lockout
  when GetMachineID() transiently fails then recovers
- F-D1-2 MEDIUM: No recovery path from machine ID mismatch
- F-D1-3 LOW: example_integration.go is dead code calling
  machineid.ID() directly (bypasses canonical hashing)
- F-D1-4 LOW: Windows redundant machineid.ID() retry
- F-D1-5 LOW: client.go uses fmt.Printf for machine ID error

6 findings total. See docs/D1_MachineID_Audit.md for details.
2026-03-29 09:34:04 -04:00
jpetree331
7a995c8ced refactor: C-series cleanup and TODO documentation
- Delete install.sh.deprecated (dead code)
- Add TODO(DEV-031) for ghost update scanner-side prevention
- Add TODO(DEV-030) with specific missing service cycles
- ETHOS sweep: zero banned words, emojis, or fmt.Printf
- All tests pass, Linux builds clean
2026-03-29 09:29:12 -04:00
jpetree331
0248ffeb74 verify: C-1 Windows bug fixes verified
All 8 C-1 fixes verified. Linux builds clean on AMD64 and ARM64.
98 tests pass (19 scanner + 4 internal + 14 crypto + 3 circuit +
58 server), 1 skip (pre-existing). No regressions.

DEV-030: polling loop parity (not deduplication) — gaps documented.
DEV-031: ghost update fix is detection-only, not prevention.
2026-03-29 09:21:16 -04:00
jpetree331
466d46ad05 fix(windows): C-1 Windows-specific bug fixes
- Apply B-2 jitter and backoff fixes to Windows service (F-C1-5)
  Proportional jitter and exponential backoff now in service polling loop
- Add known winget install location search for SYSTEM account (F-C1-1)
  Checks PATH then system-wide WindowsApps locations
- Fix winget text parser for package names with spaces (F-C1-2)
  Column-position parsing from header keywords replaces whitespace split
- Add ghost update post-install state verification (F-C1-3)
  RebootRequired flag on InstallResult marks pending reboot
- Replace fmt.Printf with log.Printf in winget scanner (F-C1-6)
- Remove emoji from Windows service log messages (F-C1-7)

GOOS=linux build: PASS. All tests pass, no regressions.
2026-03-29 09:13:21 -04:00
jpetree331
a35bcda26e test(windows): C-1 pre-fix tests for Windows-specific bugs
Pre-fix test suite for 7 Windows-specific findings. All tests
are SHARED (no build tags) — they compile and run on Linux
using source file inspection and direct function calls.

Tests added:
- F-C1-1 HIGH: Winget PATH-only search (2 tests)
- F-C1-2 MEDIUM: Winget text parser spaces bug (4 tests)
- F-C1-3 HIGH: Ghost updates — no post-install verification (3 tests)
- F-C1-4 RESOLVED: Service auto-restart already configured (1 test)
- F-C1-5 HIGH: Duplicated polling loop missing B-2 fixes (5 tests)
- F-C1-6 LOW: Winget uses fmt.Printf (2 tests)
- F-C1-7 LOW: Service has emojis in logs (2 tests)

Current state: 8 FAIL, 11 PASS. All prior tests pass.
2026-03-29 08:51:44 -04:00
jpetree331
a9443c346d docs: C-1 Windows-specific bugs audit
Comprehensive audit of Windows agent code: winget detection,
Windows Update ghost updates, service wrapper, HWID, and
vendored windowsupdate package.

Key findings:
- F-C1-1 HIGH: Winget not found as SYSTEM (PATH-only search)
- F-C1-3 HIGH: No post-install verification (ghost updates)
- F-C1-5 HIGH: Windows service has duplicated polling loop
  missing B-2 fixes (jitter cap, exponential backoff)
- F-C1-2 MEDIUM: Fragile winget text parser
- F-C1-4 MEDIUM: No service auto-restart on crash

9 findings total. See docs/C1_Windows_Audit.md for details.
2026-03-29 08:22:18 -04:00
jpetree331
a4c4c87ba4 fix(concurrency): wire retry_count increment for stuck command re-delivery (DEV-029)
retry_count column and filter existed but counter was never
incremented. Stuck commands always had retry_count=0 and
always passed the WHERE retry_count < 5 filter, making
the cap ineffective.

Fix: Added RedeliverStuckCommandTx that sets
retry_count = retry_count + 1 on stuck->sent re-delivery.
GetCommands handler now uses MarkCommandSentTx for new
commands (retry_count stays 0) and RedeliverStuckCommandTx
for stuck re-delivery (retry_count increments).

All 77 tests pass. DEV-029 resolved.
2026-03-29 08:16:12 -04:00
jpetree331
47db379757 verify: B-2 data integrity verification — fixes verified with 1 follow-up
All B-2 concurrency fixes verified:
- Registration transaction: atomic, no orphaned agents
- SELECT FOR UPDATE SKIP LOCKED: prevents duplicate delivery
- Token renewal: atomic validate + update
- GetCommands: rate limited with agent_checkin key
- Jitter: capped at min(pollingInterval/2, 30s)
- Exponential backoff: base=10s, cap=5min, reset on success

Finding: DEV-029 — retry_count column exists but never incremented.
Filter is in place but ineffective. Targeted fix needed.

77 tests pass. No regressions.
2026-03-29 08:09:35 -04:00
jpetree331
997f8b8069 fix(concurrency): B-2 data integrity and race condition fixes
- Wrap agent registration in DB transaction (F-B2-1/F-B2-8)
  All 4 ops atomic, manual DeleteAgent rollback removed
- Use SELECT FOR UPDATE SKIP LOCKED for atomic command delivery (F-B2-2)
  Concurrent requests get different commands, no duplicates
- Wrap token renewal in DB transaction (F-B2-9)
  Validate + update expiry atomic
- Add rate limit to GET /agents/:id/commands (F-B2-4)
  agent_checkin rate limiter applied
- Add retry_count column, cap stuck command retries at 5 (F-B2-10)
  Migration 029, GetStuckCommands filters retry_count < 5
- Cap polling jitter at current interval (fixes rapid mode) (F-B2-5)
  maxJitter = min(pollingInterval/2, 30s)
- Add exponential backoff with full jitter on reconnection (F-B2-7)
  calculateBackoff: base=10s, cap=5min, reset on success

All tests pass. No regressions from A-series or B-1.
2026-03-29 08:00:36 -04:00
jpetree331
925c65e2e1 test(concurrency): B-2 pre-fix tests for data integrity and concurrency bugs
Pre-fix test suite documenting 7 data integrity and concurrency
bugs. Tests FAIL where they assert correct post-fix behavior,
PASS where they document current buggy state.

Tests added:
- F-B2-1/8 HIGH: Registration not transactional (3 tests)
- F-B2-2 MEDIUM: Command delivery race condition (3 tests)
- F-B2-9 MEDIUM: Token renewal not transactional (2 tests)
- F-B2-4 MEDIUM: No rate limit on GetCommands (3 tests)
- F-B2-5 LOW: Jitter negates rapid mode (2 tests)
- F-B2-10 LOW: No max retry for stuck commands (2 tests)
- F-B2-7 MEDIUM: No exponential backoff on reconnection (2 tests)

Current state: 7 FAIL, 10 PASS. No A/B-1 regressions.
See docs/B2_PreFix_Tests.md for full inventory.
2026-03-29 07:45:16 -04:00
jpetree331
fc2f5c5e15 docs: B-2 data integrity and concurrency audit
Comprehensive audit of registration token races, command queue
concurrency, rapid mode risks, agent staleness, transaction
safety, and deadlock risks.

Key findings:
- F-B2-1 HIGH: Registration flow not transactional (4 separate ops)
- F-B2-8 HIGH: Same as F-B2-1 (crash leaves orphaned agent)
- F-B2-2 MEDIUM: Duplicate command delivery on concurrent requests
- F-B2-4 MEDIUM: No cap on concurrent rapid-mode agents
- F-B2-7 MEDIUM: No staggered reconnection after server restart
- F-B2-9 MEDIUM: Token renewal not transactional (self-healing)

10 findings total. See docs/B2_Data_Integrity_Audit.md for details.
2026-03-29 07:26:02 -04:00
jpetree331
14df497d8e verify: B-1 schema integrity verification — all fixes verified
- Migration sequence: 30 files, no duplicates, monotonically ordered
- Migration 024: self-insert removed, bad column fixed, idempotent
- Server aborts on migration failure (log.Fatalf)
- Scanner config migration renumbered to 027 with correct suffix
- All migrations idempotent (TestAllMigrationsAreIdempotent passes)
- N+1 replaced with GetAllUpdateStats aggregate query
- Stuck commands index (028) and background cleanup verified
- 55 tests pass (41 server + 14 agent), zero regressions
2026-03-29 07:12:50 -04:00
jpetree331
c28b2ed446 fix(database): B-1 schema integrity and migration fixes
- Fix migration 024 self-insert and bad column reference (F-B1-1, F-B1-2)
  Uses existing enabled/auto_run columns instead of non-existent deprecated
- Abort server on migration failure instead of warning (F-B1-11)
  main.go now calls log.Fatalf, prints [INFO] only on success
- Fix migration 018 scanner_config filename suffix (F-B1-3)
  Renumbered to 027 with .up.sql suffix
- Remove GRANT to non-existent role in scanner_config (F-B1-4)
- Resolve duplicate migration numbers 009 and 012 (F-B1-13)
  Renamed to 009b and 012b for unique lexical sorting
- Add IF NOT EXISTS to all non-idempotent migrations (F-B1-15)
  Fixed: 011, 012, 017, 023, 023a
- Replace N+1 dashboard stats loop with GetAllUpdateStats (F-B1-6)
  Single aggregate query replaces per-agent loop
- Add composite index on agent_commands(status, sent_at) (F-B1-5)
  New migration 028 with partial index for timeout service
- Add background refresh token cleanup goroutine (F-B1-10)
  24-hour ticker calls CleanupExpiredTokens
- ETHOS log format in migration runner (no emojis)

All 55 tests pass (41 server + 14 agent). No regressions.
See docs/B1_Fix_Implementation.md and DEV-025 through DEV-028.
2026-03-29 07:03:35 -04:00
jpetree331
96000c359d test(database): B-1 pre-fix tests for migration and schema bugs
Pre-fix test suite documenting 9 database migration and schema
integrity bugs. Tests FAIL where they assert correct post-fix
behavior, PASS where they document current buggy state.

Tests added:
- F-B1-11 P0: main.go swallows migration errors (3 tests)
- F-B1-13: Duplicate migration numbers 009/012 (2 tests)
- F-B1-1: Migration 024 self-insert into schema_migrations (2 tests)
- F-B1-2: Migration 024 references non-existent column (2 tests)
- F-B1-3: Migration 018 wrong file suffix (2 tests)
- F-B1-4: Migration 018 GRANT to wrong role (1 test)
- F-B1-15: 7+ migrations not idempotent (2 tests)
- F-B1-5: Missing agent_commands sent_at index (2 tests)
- F-B1-6: N+1 query in GetDashboardStats (2 tests)
- F-B1-10: No background refresh token cleanup (2 tests)

Current state: 10 PASS, 10 FAIL, 0 SKIP.
All A-series tests continue to pass (no regressions).
See docs/B1_PreFix_Tests.md for full inventory.
2026-03-29 06:42:19 -04:00
jpetree331
0af5ef478c docs: B-1 database migration and schema integrity audit
Comprehensive audit of the custom migration runner, all 26 migrations,
query patterns, foreign keys, and schema state management.

Critical findings:
- F-B1-11 P0: Server starts with incomplete schema after migration
  failure, prints [OK] — main.go swallows migration errors
- F-B1-1: Migration 024 self-inserts into schema_migrations
- F-B1-2: Migration 024 references non-existent deprecated column
- F-B1-3: Migration 018 scanner_config has wrong file extension
- F-B1-6: N+1 query in GetDashboardStats (1 query per agent)

15 findings total across P0/CRITICAL/HIGH/MEDIUM/LOW.
See docs/B1_Database_Audit.md for full analysis.
2026-03-29 06:28:59 -04:00
jpetree331
6328e8e442 verify: A-series refactor verification — all tests pass
All pre-existing tests pass after dead code cleanup.
No regressions from A-1, A-2, or A-3 fix rounds.
41 tests pass, 1 skip (pre-existing). Zero new failures.
Ready to proceed to B-series database audit.
2026-03-29 06:21:05 -04:00
jpetree331
4bc0bfb36c refactor: A-series dead code cleanup and ETHOS compliance sweep
- Remove dead queries.RetryCommand function (DEV-019, 31 lines)
- Remove security_settings.go.broken leftover from A-3
- Remove 5 compiled test binaries from aggregator-agent/ (~61MB)
- Remove config_builder.go.restored from repo root
- Remove test_disk_detection.go and test_disk.go (throwaway test files)
- Fix 6 banned word violations (production-ready, enhanced, robust, seamlessly)
- Add .gitignore rules for compiled agent binaries
- Document machine ID duplication for D-1 fix prompt
- Document 30+ pre-existing emoji violations for D-2 pass

No behavior changes. All 41 tests pass.
2026-03-29 06:17:12 -04:00
jpetree331
07077c99ef docs: A-3 verification report — all fixes verified
All 9 auth middleware fixes confirmed correct:
- F-A3-11: JWT secret leak removed, ETHOS log format
- F-A3-7: Config download protected (WebAuthMiddleware)
- F-A3-6: Update download protected (AuthMiddleware)
- F-A3-10: Scheduler stats on WebAuthMiddleware
- F-A3-13: RequireAdmin implemented, 7 routes re-enabled
- F-A3-12: JWT issuer claims with backward compat grace period
- F-A3-2: /auth/verify endpoint fixed
- F-A3-9: Agent unregister rate-limited
- F-A3-14: CORS origin configurable

41 tests pass (27 server + 14 agent). No regressions.
Zero issues found during verification.
2026-03-29 06:07:57 -04:00
jpetree331
c86c548e0d fix(security): A-3 auth middleware coverage fixes
Fixes 9 auth middleware findings from the A-3 recon audit.

F-A3-11 CRITICAL: Removed JWT secret from WebAuthMiddleware log output.
  Replaced emoji-prefixed fmt.Printf with ETHOS-compliant log.Printf.
  No secret values in any log output.

F-A3-7 CRITICAL: Config download now requires WebAuthMiddleware.
  GET /downloads/config/:agent_id is admin-only (agents never call it).

F-A3-6 HIGH: Update package download now requires AuthMiddleware.
  GET /downloads/updates/:package_id requires valid agent JWT.

F-A3-10 HIGH: Scheduler stats changed from AuthMiddleware to
  WebAuthMiddleware. Agent JWTs can no longer view scheduler internals.

F-A3-13 LOW: RequireAdmin() middleware implemented. 7 security settings
  routes re-enabled (GET/PUT/POST under /security/settings).
  security_settings.go.broken renamed to .go, API mismatches fixed.

F-A3-12 MEDIUM: JWT issuer claims added for token type separation.
  Agent tokens: issuer=redflag-agent, Web tokens: issuer=redflag-web.
  AuthMiddleware rejects tokens with wrong issuer.
  Grace period: tokens with no issuer still accepted (backward compat).

F-A3-2 MEDIUM: /auth/verify now has WebAuthMiddleware applied.
  Endpoint returns 200 with valid=true for valid admin tokens.

F-A3-9 MEDIUM: Agent self-unregister (DELETE /:id) now rate-limited
  using the same agent_reports rate limiter as other agent routes.

F-A3-14 LOW: CORS origin configurable via REDFLAG_CORS_ORIGIN env var.
  Defaults to http://localhost:3000 for development.
  Added PATCH method and agent-specific headers to CORS config.

All 27 server tests pass. All 14 agent tests pass. No regressions.
See docs/A3_Fix_Implementation.md and docs/Deviations_Report.md
(DEV-020 through DEV-022).
2026-03-28 22:17:40 -04:00
jpetree331
bb6449b845 test(security): A-3 pre-fix tests for auth middleware coverage bugs
Pre-fix test suite documenting 8 auth middleware bugs found during
the A-3 recon audit. Tests are written to FAIL where they assert
correct post-fix behavior, and PASS where they document current
buggy behavior. No bugs are fixed in this commit.

Tests added:
- F-A3-11 CRITICAL: WebAuthMiddleware leaks JWT secret to stdout
  (3 tests: secret in output, emoji in output, ETHOS format)
- F-A3-7 CRITICAL: Config download requires no auth (2 tests)
- F-A3-6 HIGH: Update package download requires no auth (2 tests)
- F-A3-10 HIGH: Scheduler stats accepts agent JWT (2 tests)
- F-A3-12 MEDIUM: Cross-type JWT token confusion (2 tests)
- F-A3-2 MEDIUM: /auth/verify dead endpoint (2 tests)
- F-A3-13 LOW: RequireAdmin middleware missing (1 test + 1 build-tagged)
- F-A3-9 MEDIUM: Agent self-unregister no rate limit (2 tests)

Current state: 10 FAIL, 7 PASS, 1 SKIP (build-tagged), 1 unchanged
See docs/A3_PreFix_Tests.md for full inventory.
2026-03-28 21:54:48 -04:00
jpetree331
acbf29d598 feat(security): A-1 Ed25519 key rotation + A-2 replay attack fixes
Complete RedFlag codebase with two major security audit implementations.

== A-1: Ed25519 Key Rotation Support ==

Server:
- SignCommand sets SignedAt timestamp and KeyID on every signature
- signing_keys database table (migration 020) for multi-key rotation
- InitializePrimaryKey registers active key at startup
- /api/v1/public-keys endpoint for rotation-aware agents
- SigningKeyQueries for key lifecycle management

Agent:
- Key-ID-aware verification via CheckKeyRotation
- FetchAndCacheAllActiveKeys for rotation pre-caching
- Cache metadata with TTL and staleness fallback
- SecurityLogger events for key rotation and command signing

== A-2: Replay Attack Fixes (F-1 through F-7) ==

F-5 CRITICAL - RetryCommand now signs via signAndCreateCommand
F-1 HIGH     - v3 format: "{agent_id}:{cmd_id}:{type}:{hash}:{ts}"
F-7 HIGH     - Migration 026: expires_at column with partial index
F-6 HIGH     - GetPendingCommands/GetStuckCommands filter by expires_at
F-2 HIGH     - Agent-side executedIDs dedup map with cleanup
F-4 HIGH     - commandMaxAge reduced from 24h to 4h
F-3 CRITICAL - Old-format commands rejected after 48h via CreatedAt

Verification fixes: migration idempotency (ETHOS #4), log format
compliance (ETHOS #1), stale comments updated.

All 24 tests passing. Docker --no-cache build verified.
See docs/ for full audit reports and deviation log (DEV-001 to DEV-019).
2026-03-28 21:25:47 -04:00
Fimeg
d0e0afc331 Add docs and project files - force for Culurien 2026-03-28 20:46:24 -04:00
Fimeg
d3a2e9ef27 force for Culurien 2026-03-28 20:30:54 -04:00
Fimeg
3cddb7437f force for Culurien 2026-03-28 20:27:49 -04:00
Fimeg
421be35bcd fix: Heartbeat UI refresh - smart polling implementation 2025-12-20 20:22:43 -05:00
Fimeg
34664f7d93 fix: Remove last scan_updates reference
- Line 833 in ChatTimeline still had scan_updates
- Updated to check platform-specific scans (apt, dnf, winget, windows)
- Verifying: no scan_updates references remain in frontend
2025-12-20 18:54:16 -05:00
Fimeg
ea3b5fb741 fix: Remove remaining scan_updates reference
- Remove scan_updates from getActionIcon switch
- Add platform-specific scan cases (apt, dnf, winget, windows)
- All scan types now properly use platform-specific handlers
2025-12-20 17:40:51 -05:00
Fimeg
ee25ba28c6 fix: Remove deprecated scan_updates references
- scan_updates removed following FINAL_Issue3 design
- Platform-specific scans only (Windows: scan_winget + scan_windows, Linux: scan_apt/scan_dnf)
- Updated command naming service to include platform-specific scans
- All subsystem handlers properly isolated per design spec
2025-12-20 17:39:59 -05:00
Fimeg
eaf4c45a02 fix: Complete ChatTimeline integration with command naming
- Replace all .replace() calls with formatCommandAction
- Replace hard-coded scan conditionals with dynamic naming
- All command display now uses centralized service

Command naming service now fully integrated for ETHOS compliance.
2025-12-20 17:27:19 -05:00
Fimeg
01ee92dfbe feat: Command naming service integrated (ETHOS compliant)
- Create ETHOS-compliant command naming service
- Add imports to ChatTimeline
- Replace .replace() calls with formatCommandAction
- Partial scan conditional replacement

Status: Command naming service exists and is imported, full integration in progress
2025-12-20 17:14:08 -05:00
Fimeg
286831e285 fix: Add missing command import to main.go 2025-12-20 16:47:05 -05:00
Fimeg
061ec6c77d feat: Factory integration complete with UI updates
- Command factory with CreateWithIdempotency support
- SubsystemHandler uses factory for all scan commands
- Idempotency prevents duplicate commands from rapid clicks
- UI updates for AgentStorage and heartbeat
- Includes previous factory, queries, and main.go changes

Now all command creation goes through factory for consistent validation and UUID generation.
2025-12-20 16:43:28 -05:00
Fimeg
5abd370cee fix: Remove unused errors import from factory.go 2025-12-20 16:42:33 -05:00
Fimeg
9a524dc265 fix: Set IdempotencyKey before validation in CreateWithIdempotency 2025-12-20 16:32:23 -05:00
Fimeg
6ac15d404e feat: Integrate factory with SubsystemHandler for idempotency support
- Add commandFactory field to SubsystemHandler
- Update NewSubsystemHandler to accept factory
- Modify TriggerSubsystem to use CreateWithIdempotency
- Update main.go to pass factory to handler

Now all subsystem commands use idempotency keys, preventing duplicates from rapid clicks.
2025-12-20 16:15:53 -05:00
Fimeg
8decdc12ff feat: Add CreateWithIdempotency and idempotency_key support
- Add CreateWithIdempotency method to command factory
- Add GetCommandByIdempotencyKey to command queries
- Update CreateCommand to handle idempotency_key field
- Fix system command list to match actual usage

This enables proper idempotency for rapid-click prevention.
2025-12-20 15:59:56 -05:00
Fimeg
bb7a009e1f cleanup: Remove unused files and fix ETHOS violations
Remove unused generation scripts (not referenced):
- scripts/generate-keypair.go (unused manual utility)
- cmd/tools/keygen/ (unused utility, clutters cmd structure)

Remove root-level dev files (clutter):
- restart_and_fix.sh (dangerous: wipes database)
- test_install_commands.sh (development only)
- test-binary (compiled artifact)
- sudo (third-party tool)
- scanning_ux_summary.txt (dev notes)

Fix ETHOS violations in build-secure-agent.sh:
- Remove emojis (🔨, , ℹ️)
- Replace with proper format: [INFO] [build] ...

Cleanup based on definitive code forensics.

Impact: Cleaner repository, ETHOS-compliant, no functional loss.
2025-12-20 15:23:13 -05:00
Fimeg
5dd938e225 Fix zero UUID and storage metrics issues
- Add ID generation in signAndCreateCommand to prevent zero UUIDs
- Fix storage metrics metadata field (remove pq.Array)
- Add IdempotencyKey field to AgentCommand model

These issues were causing duplicate key violations and storage page errors.
2025-12-20 14:26:55 -05:00
Fimeg
09d7bd3139 fix: Update .gitignore and remove dev files from repository
Remove development and investigation files that shouldn't be in repo:
- Kate editor swap files (*.swp, *.kate-swp)
- Discord development folder (contains credentials)
- Development investigation scripts (db_investigation.sh, etc.)
- Configuration files (docker-compose.dev.yml)

Note: Files removed from git but kept locally (rm --cached)
Files are still present in working directory but won't be tracked
2025-12-20 14:12:11 -05:00
Fimeg
480dd53f42 v0.1.27 release: Complete implementation
Features:
- Error logging system with ETHOS #1 compliance
- Command factory pattern with UUID generation
- Hardware binding with machine fingerprint validation
- Ed25519 cryptographic signing for updates
- Deduplication and idempotency for commands
- Circuit breakers and retry logic
- Frontend error logging integration

Bug Fixes:
- Version display using compile-time injection
- Migration 017 CONCURRENTLY issue resolved
- Docker build context fixes
- Rate limiting implementation verified

Documentation:
- README updated to reflect actual implementation
- v0.1.27 inventory analysis added
2025-12-20 13:47:36 -05:00
Fimeg
c70f1ef7aa fix: Remove misleading TODO comment from handleUpdateAgent
The TODO claimed update system was a "placeholder" but the code that
follows implements complete functionality:
- downloadUpdatePackage() downloads the package
- computeSHA256() verifies checksum
- verifyBinarySignature() with ed25519.Verify() checks signature
- installNewBinary() performs atomic installation
- Full rollback/cleanup with defer on failure

The comment was incorrect and misleading about the code quality.
2025-12-19 22:30:19 -05:00
Fimeg
7efa1f38b1 fix: migration runner and scan logging fixes
- Fix migration conflicts and duplicate key errors
- Remove duplicate scan logging from agents
- Fix AgentHealth UI and Storage page triggers
- Prevent scans from appearing on wrong pages

Fixes duplicate key violations on fresh installs and
storage scans appearing on Updates page.
2025-12-19 20:59:12 -05:00
Fimeg
b6561118c9 fix: Remove duplicate scan logging to prevent storage/system scans on Updates page
BREAKING CHANGE: Storage and system scans no longer create entries in update_logs

**Problem**
- Storage scans were appearing on Updates page (mixed with package updates)
- System scans were appearing on Updates page (mixed with package updates)
- Duplicate "Scan All" entries from collective + individual logging

**Root Cause**
Scan handlers were calling both ReportLog() and dedicated endpoints:
- reportLogWithAck → POST /api/v1/agents/:id/logs → update_logs table
- This caused storage/system metrics to appear alongside package updates

**Fix**
Removed ALL ReportLog() calls from scan handlers:
1. handleScanUpdatesV2 (lines 44-46): Removed collective logging
2. handleScanStorage (lines 103-105): Use only ReportStorageMetrics
3. handleScanSystem (lines 189-191): Use only ReportMetrics
4. handleScanDocker (lines 269-271): Use only ReportDockerImages

**Verification**
- All 4 handlers have working dedicated endpoints (verified via subagent)
- Routes already registered: POST /storage-metrics, POST /metrics, etc.
- Frontend queries correct endpoints (verified)
- No data loss: dedicated endpoints store in proper tables

**Result**
- Storage scans → storage_metrics table → Storage page only 
- System scans → system reporting → System page only 
- Package updates → update_logs table → Updates page only 
- No duplicate "Scan All" entries 

**Files Changed**
- aggregator-agent/cmd/agent/subsystem_handlers.go: Removed 20 lines of ReportLog calls
- internal/api/handlers/agents.go: Command recovery enhancements
- internal/api/handlers/updates.go: Subsystem extraction logic
- internal/database/queries/commands.go: GetStuckCommands query
2025-12-19 15:11:32 -05:00
Fimeg
13010910ef fix: Complete AgentHealth improvements and build fixes
- Update Update scanner default from 15min to 12 hours (backend)
- Add 1 week and 2 week frequency options (frontend)
- Rename AgentScanners to AgentHealth component
- Add OS-aware package manager badges (APT, DNF, Windows/Winget, Docker)
- Fix all build errors (types, imports, storage metrics)
- Add useMemo optimization for enabled/auto-run counts
2025-12-17 21:30:10 -05:00
Fimeg
5061e4eca1 feat: AgentHealth scanner improvements with extended defaults and OS-aware badges
- Update scanner defaults from 15min to 12 hours
- Add 1 week and 2 week frequency options
- Rename AgentScanners to AgentHealth
- Add OS-aware package manager badges (APT, DNF, Windows/Winget, Docker)
- Fix useMemo import and usage
2025-12-17 21:07:43 -05:00
Fimeg
39a9baf491 Implement proper storage metrics (P0-009)
- Add dedicated storage_metrics table
- Create StorageMetricReport models with proper field names
- Add ReportStorageMetrics to agent client
- Update storage scanner to use new method
- Implement server-side handlers and queries
- Register new routes and update UI
- Remove legacy Scan() method
- Follow ETHOS principles: honest naming, clean architecture
2025-12-17 17:00:05 -05:00
Fimeg
7482b8642a WIP: Save current state - security subsystems, migrations, logging 2025-12-16 14:19:59 -05:00
Fimeg
5bba3d0d1e Fix version tracking deadlock - allow old agents to check in for updates
Problem: Version check middleware blocked old agents from checking in to receive
update commands, creating a deadlock where agents couldn't upgrade because they
were blocked from checking in.

Solution: Modified MachineBindingMiddleware to allow old agents checking in for
commands to proceed IF they have a pending update_agent command. This allows
agents to receive the update command even when below minimum version.

Changes:
- Added grace period logic in middleware for command endpoints
- Check if agent has pending update command before blocking
- If update pending, allow check-in and log it
- Added HasPendingUpdateCommand() to AgentQueries for checking pending updates
- Also added same method to CommandQueries for completeness

This prevents the version tracking deadlock while maintaining security for
agents without pending updates.

NOTE: Need to test that old agents can actually receive and execute update
commands when allowed through this path.
2025-12-13 10:55:11 -05:00