Commit Graph

102 Commits

Author SHA1 Message Date
Fimeg
584311c3b6 fix: Remove last scan_updates reference\n\n- Line 833 in ChatTimeline still had scan_updates\n- Updated to check platform-specific scans (apt, dnf, winget, windows)\n- Verifying: no scan_updates references remain in frontend 2025-12-20 18:54:16 -05:00
Fimeg
1582a4c270 fix: Remove remaining scan_updates reference\n\n- Remove scan_updates from getActionIcon switch\n- Add platform-specific scan cases (apt, dnf, winget, windows)\n- All scan types now properly use platform-specific handlers 2025-12-20 17:40:51 -05:00
Fimeg
d255f91e82 fix: Remove deprecated scan_updates references\n\n- scan_updates removed following FINAL_Issue3 design\n- Platform-specific scans only (Windows: scan_winget + scan_windows, Linux: scan_apt/scan_dnf)\n- Updated command naming service to include platform-specific scans\n- All subsystem handlers properly isolated per design spec 2025-12-20 17:39:59 -05:00
Fimeg
294aa6be4b fix: Complete ChatTimeline integration with command naming\n\n- Replace all .replace() calls with formatCommandAction\n- Replace hard-coded scan conditionals with dynamic naming\n- All command display now uses centralized service\n\nCommand naming service now fully integrated for ETHOS compliance. 2025-12-20 17:27:19 -05:00
Fimeg
db1fd28afb feat: Command naming service integrated (ETHOS compliant)\n\n- Create ETHOS-compliant command naming service\n- Add imports to ChatTimeline\n- Replace .replace() calls with formatCommandAction\n- Partial scan conditional replacement\n\nStatus: Command naming service exists and is imported, full integration in progress 2025-12-20 17:14:08 -05:00
Fimeg
a95a4238de fix: Add missing command import to main.go 2025-12-20 16:47:05 -05:00
Fimeg
9ea147eafd 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
1a7abe7004 fix: Remove unused errors import from factory.go 2025-12-20 16:42:33 -05:00
Fimeg
b614cdb612 fix: Set IdempotencyKey before validation in CreateWithIdempotency 2025-12-20 16:32:23 -05:00
Fimeg
d226536c76 feat: Integrate factory with SubsystemHandler for idempotency support\n\n- Add commandFactory field to SubsystemHandler\n- Update NewSubsystemHandler to accept factory\n- Modify TriggerSubsystem to use CreateWithIdempotency\n- Update main.go to pass factory to handler\n\nNow all subsystem commands use idempotency keys, preventing duplicates from rapid clicks. 2025-12-20 16:15:53 -05:00
Fimeg
6e6ad053d4 feat: Add CreateWithIdempotency and idempotency_key support\n\n- Add CreateWithIdempotency method to command factory\n- Add GetCommandByIdempotencyKey to command queries\n- Update CreateCommand to handle idempotency_key field\n- Fix system command list to match actual usage\n\nThis enables proper idempotency for rapid-click prevention. 2025-12-20 15:59:56 -05:00
Fimeg
c0d6ece30f 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
642eec5d44 Fix zero UUID and storage metrics issues\n\n- Add ID generation in signAndCreateCommand to prevent zero UUIDs\n- Fix storage metrics metadata field (remove pq.Array)\n- Add IdempotencyKey field to AgentCommand model\n\nThese issues were causing duplicate key violations and storage page errors. 2025-12-20 14:26:55 -05:00
Fimeg
e7a8cc90dd 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
62697df112 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
54c554ac7c 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
2da93e442e 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
6b3ab6d6fc 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
a90692f1d8 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
9effa967a1 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
0fff047cb5 Implement proper storage metrics (P0-009)\n\n- Add dedicated storage_metrics table\n- Create StorageMetricReport models with proper field names\n- Add ReportStorageMetrics to agent client\n- Update storage scanner to use new method\n- Implement server-side handlers and queries\n- Register new routes and update UI\n- Remove legacy Scan() method\n- Follow ETHOS principles: honest naming, clean architecture 2025-12-17 17:00:05 -05:00
Fimeg
f7c8d23c5d WIP: Save current state - security subsystems, migrations, logging 2025-12-16 14:19:59 -05:00
Fimeg
f792ab23c7 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
Fimeg
40598c2203 Update install scripts to use registration token instead of API calls
Simplified install script approach based on architecture analysis:
- Fresh installs: Create minimal config with registration_token only
- Agent handles registration on first start (leverages existing agent logic)
- Upgrades: Preserve existing config, agent handles migration
- Removed complex credential preservation logic from Windows script

This is more reliable and aligns with the agent's built-in migration system.

Changes:
- Linux: Populate registration_token in config template, keep backup logic
- Windows: Simplified - removed 100+ lines of credential extraction/restoration
- Both: Fresh installs get minimal template, upgrades preserve existing config

NOTE: This commit modified the 'sacred scripts' (install templates) significantly.
Casey found this highly suspect and it may need investigation, but proceeding for now
to test the approach. The changes should be reviewed carefully before v0.1.x release.
2025-12-13 10:53:16 -05:00
Fimeg
9c69246116 Add registration token parameter to downloads handler and template service
- Pass registration token from URL query parameter to install script generation
- Update RenderInstallScriptFromBuild to accept registration token
- Add RegistrationToken field to template data structure

This lays groundwork for fixing agent registration - install scripts will be able
to call the registration API with the provided token.
2025-12-13 10:44:05 -05:00
Fimeg
8b9a314200 ui: improve Agent Health layout and fix misaligned controls
- Move Update Agent button to Subsystem Configuration header
- Remove duplicate Compact Summary box with misaligned refresh
- Reduce visual separation between sections (same card styling)
- Make security status details visible instead of hidden in tooltips
- Fix enforced status colors (blue instead of red)
- Consolidate enabled/auto-run counts in header
- Reduce spacing between sections for cohesive interface

The enabled/auto-run toggles now properly align with their
subsystems in the table, and critical security information
is immediately visible without hover interactions.
2025-11-10 23:08:17 -05:00
Fimeg
3f0838affc refactor: replace 899 lines of script generation with templates
Created InstallTemplateService with clean template-based script generation.
Added linux.sh.tmpl and windows.ps1.tmpl for install scripts.
Removed massive generateLinuxScript and generateWindowsScript functions.
Downloads handler now uses template service (1073 lines → 174 lines).
Templates easily maintainable without modifying Go code.
2025-11-10 22:41:47 -05:00
Fimeg
455bc75044 fix: ConfigService now reads subsystems from database
Critical regression fix - subsystems were hardcoded instead of reading user settings.
Added CreateDefaultSubsystems to queries/subsystems.go.
ConfigService now queries agent_subsystems table for actual user configuration.
AgentLifecycleService creates default subsystems when creating new agents.
Respects user-configured enabled/auto_run settings from UI.
2025-11-10 22:32:22 -05:00
Fimeg
e1173c9f3b refactor: consolidate config logic into ConfigService
Created centralized ConfigService for configuration management.
Added deprecation comments to ConfigBuilder and AgentBuilder.
Platform-specific defaults centralized in one place.
Removed placeholder ConfigService from agent_lifecycle.go.
2025-11-10 22:23:56 -05:00
Fimeg
52c9c1a45b refactor: add AgentLifecycleService for unified agent operations
Created centralized lifecycle service to handle new, upgrade, and rebuild operations.
Added deprecation notices to old handlers (agent_setup, build_orchestrator, agent_build).
Foundation for consolidating duplicate agent lifecycle logic.
2025-11-10 22:15:03 -05:00
Fimeg
4531ca34c5 refactor: consolidate AgentFile struct into common package
Created aggregator/pkg/common module with shared AgentFile type.
Removed duplicate definitions from migration and services packages.
Both agent and server now use common.AgentFile.
2025-11-10 22:03:43 -05:00
Fimeg
ddaa9ac637 fix: correct platform format in version detection
Created version package for semantic version comparison.
Fixed GetLatestVersionByTypeAndArch to use combined platform format.
Replaced inline version comparison with reusable version.Compare().
2025-11-10 21:50:46 -05:00
Fimeg
c95cc7d91f cleanup: remove 2,369 lines of dead code
Removed backup files and unused legacy scanner function.
All code verified as unreferenced.
2025-11-10 21:20:42 -05:00
Fimeg
1f2b1b7179 fix: repair version detection platform query format
- Fix GetLatestVersionByTypeAndArch to separate platform/architecture
- Query now correctly uses platform='linux' and architecture='amd64'
- Resolves UI showing 'no packages available' despite updates existing
2025-11-10 20:11:32 -05:00
Fimeg
e6ac0b1ec4 feat: implement agent migration system
- Fix config version inflation bug in main.go
- Add dynamic subsystem checking to prevent false change detection
- Implement migration detection and execution system
- Add directory migration from /etc/aggregator to /etc/redflag
- Update all path references across codebase to use new directories
- Add configuration schema versioning and automatic migration
- Implement backup and rollback capabilities
- Add security feature detection and hardening
- Update installation scripts and sudoers for new paths
- Complete Phase 1 migration system
2025-11-04 14:25:53 -05:00
Fimeg
253022cacd security: prevent discord bot code from being tracked
- Add discord/ to .gitignore to protect private bot configuration
- Discord bot contains API tokens and private implementation details
- Prevents accidental exposure of Discord credentials in repository history
2025-11-04 10:07:05 -05:00
Fimeg
95f70bd9bb feat: bump to v0.1.23 with security metrics and UI improvements
- Bump agent and server versions to 0.1.23
- Implement security metrics collection (bound agents, command processing, version compliance)
- Add dismiss button for timed out commands in agent status
- Add config sync endpoint for server->agent configuration updates
- Add ignored updates workflow in AgentUpdatesEnhanced (approve/reject workflow)
- Swap AgentScanners layout (subsystems top, security bottom)
- Replace placeholder security data with database metrics
- Add backpressure detection based on pending command ratios
2025-11-04 09:41:27 -05:00
Fimeg
38894f64d3 feat: add config sync endpoint and security UI updates
- Add GET /api/v1/agents/:id/config endpoint for server configuration
- Agent fetches config during check-in and applies updates
- Add version tracking to prevent unnecessary config applications
- Clean separation: config sync independent of commands
- Fix agent UI subsystem settings to actually control agent behavior
- Update Security Health UI with frosted glass styling and tooltips
2025-11-03 22:36:26 -05:00
Fimeg
eccc38d7c9 feat: separate data classification architecture
- Create separate scanner interfaces for storage, system, and docker data
- Add dedicated endpoints for metrics and docker images instead of misclassifying as updates
- Implement proper database tables for storage metrics and docker images
- Fix storage/system metrics appearing incorrectly as package updates
- Add scanner types with proper data structures for each subsystem
- Update agent handlers to use correct endpoints for each data type
2025-11-03 21:44:48 -05:00
Fimeg
57be3754c6 fix: agent acknowledgment recursion and subsystem UI improvements
- Fix recursive call in reportLogWithAck that caused infinite loop
- Add machine binding and security API endpoints
- Enhance AgentScanners component with security status display
- Update scheduler and timeout service reliability
- Remove deprecated install.sh script
- Add subsystem configuration and logging improvements
2025-11-03 21:02:57 -05:00
Fimeg
d0f13e5da7 bump: agent version 0.1.20 -> 0.1.22
v0.1.22 minimum version for security features
machine binding and version enforcement

agent now sends version during registration
no bootstrap gap
2025-11-02 14:00:55 -05:00
Fimeg
c1ad4283b0 fix: clean old config on agent reinstall
install script now removes old .env and config.json
prevents conflicts during reinstall/upgrade

addresses .env conflict errors reported in testing
2025-11-02 13:32:53 -05:00
Fimeg
0062e2acab feat: setup wizard key generation
added ed25519 keypair generation to setup endpoint
wired route for POST /api/setup/generate-keys

existing registration token system handles deployment
2025-11-02 10:04:31 -05:00
Fimeg
822f57bbdc feat: setup wizard and token management
added ed25519 key generation to setup endpoint
deployment handler for token CRUD with install commands
wired routes for /api/setup/generate-keys and /admin/deployment

setup generates keypair on demand
deployment endpoints provide one-liner install commands
ready for v0.1.22 testing
2025-11-02 09:32:37 -05:00
Fimeg
ec3ba88459 feat: machine binding and version enforcement
migration 017 adds machine_id to agents table
middleware validates X-Machine-ID header on authed routes
agent client sends machine ID with requests
MIN_AGENT_VERSION config defaults 0.1.22
version utils added for comparison

blocks config copying attacks via hardware fingerprint
old agents get 426 upgrade required
breaking: <0.1.22 agents rejected
2025-11-02 09:30:04 -05:00
Fimeg
99480f3fe3 fix: resolve frontend approval error and add invalid command handling
- Added missing approveMultiple function to updateApi
- Fixed API endpoint from /updates/bulk-approve to /updates/approve
- Enhanced invalid command handling in both Linux and Windows agents
- Agents now report unknown command types as failed commands back to server
2025-11-01 21:56:31 -04:00
Fimeg
3690472396 feat: granular subsystem commands with parallel scanner execution
Split monolithic scan_updates into individual subsystems (updates/storage/system/docker).
Scanners now run in parallel via goroutines - cuts scan time roughly in half, maybe more.

Agent changes:
- Orchestrator pattern for scanner management
- New scanners: storage (disk metrics), system (cpu/mem/processes)
- New commands: scan_storage, scan_system, scan_docker
- Wrapped existing scanners (APT/DNF/Docker/Windows/Winget) with common interface
- Version bump to 0.1.20

Server changes:
- Migration 015: agent_subsystems table with trigger for auto-init
- Subsystem CRUD: enable/disable, interval (5min-24hr), auto-run toggle
- API routes: /api/v1/agents/:id/subsystems/* (9 endpoints)
- Stats tracking per subsystem

Web UI changes:
- ChatTimeline shows subsystem-specific labels and icons
- AgentScanners got interactive toggles, interval dropdowns, manual trigger buttons
- TypeScript types added for subsystems

Backward compatible with legacy scan_updates - for now. Bugs probably exist somewhere.
2025-11-01 21:34:26 -04:00
Fimeg
bf4d46529f feat: add resilience and reliability features for agent subsystems
Added circuit breakers with configurable timeouts for all subsystems (APT, DNF, Docker, Windows, Winget, Storage). Replaces cron-based scheduler with priority queue that should scale beyond 1000+ agents if your homelab is that big.

Command acknowledgment system ensures results aren't lost on network failures or restarts. Agent tracks pending acknowledgments with persistent state and automatic retry.

- Circuit breakers: 3 failures in 1min opens circuit, 30s cooldown
- Per-subsystem timeouts: 30s-10min depending on scanner
- Priority queue scheduler: O(log n), worker pool, jitter, backpressure
- Acknowledgments: at-least-once delivery, max 10 retries over 24h
- All tests passing (26/26)
2025-11-01 18:42:41 -04:00
Fimeg
528848f476 docs: add v0.1.18 release notes and testing status 2025-11-01 09:48:19 -04:00
Fimeg
8b880b2d5a docs: update README with v0.1.18 and improve update/uninstall sections
- Bump version to 0.1.18
- Add simple update one-liner
- Organize nuclear option and uninstall into dropdowns
- Document agent config file locations
- Reference uninstall.sh script
2025-11-01 09:36:48 -04:00