Skip to content

feat: agent-based distributed scanning#52

Open
hojmark wants to merge 69 commits intomainfrom
feat/agent
Open

feat: agent-based distributed scanning#52
hojmark wants to merge 69 commits intomainfrom
feat/agent

Conversation

@hojmark
Copy link
Owner

@hojmark hojmark commented Oct 17, 2025

No description provided.

@hojmark hojmark force-pushed the feat/agent branch 2 times, most recently from cc03943 to 7a4c18d Compare October 28, 2025 22:52
@hojmark hojmark force-pushed the feat/agent branch 5 times, most recently from a4fedd7 to 6fa5385 Compare November 10, 2025 22:07
@hojmark hojmark force-pushed the feat/agent branch 3 times, most recently from 3219be4 to fb2baab Compare December 3, 2025 19:50
@hojmark hojmark added the enhancement New feature or request label Feb 4, 2026
@hojmark hojmark added this to the 1.0.0 milestone Feb 13, 2026
@hojmark hojmark force-pushed the feat/agent branch 2 times, most recently from 8381ec4 to 5294ed8 Compare February 18, 2026 13:44
hojmark added 13 commits March 3, 2026 20:54
Enhanced DistributedNetworkScanner to provide clear visibility into
scan failures without requiring TUI changes. The existing log window
will automatically display these warnings:

- Enhanced BuildFinalResult to log different messages based on success:
  - Success: Normal info log with scan statistics
  - Partial failure: Warning log listing failed subnet count and CIDRs

- Improved error handling in ScanSingleSubnetViaAgentAsync:
  - Separate handling for cancellation vs other exceptions
  - More detailed error messages including the error reason
  - Clear indication that partial results are being returned

These warnings will appear in:
- TUI mode: Displayed in the log window
- Non-TUI mode: Written to console/log output
- All modes: Captured in structured logs for monitoring

No TUI changes needed - minimal invasive approach using existing
logging infrastructure.
Created comprehensive containerlab topology and test infrastructure to
validate the distributed scanning MVP in a realistic multi-segment
network environment.

Topology design:
- Management network (10.0.0.0/24) connecting CLI and all agents
- Segment A (192.168.10.0/24) isolated from CLI, accessible to agent1 and agent3
- Segment B (192.168.20.0/24) isolated from CLI, accessible to agent2 and agent3
- 4 target devices (2 per segment) for discovery validation
- Multi-homed agent3 to test overlapping subnet handling

Test coverage:
- Agent identity persistence across restarts
- Subnet discovery from multiple agents
- Distributed scanning with source-based assignment
- Overlapping subnet detection and result merging
- Retry logic with simulated agent failures
- Warning logs for partial results
- Device deduplication across scans

Files added:
- distributed-scan-mvp.clab.yaml: Main topology definition
- test-inventory.yaml: Agent configuration for tests
- test-integration.sh: Automated test script with validation
- README.md: Documentation with manual testing instructions

The test script validates all MVP requirements end-to-end and can be
integrated into CI/CD pipelines.
- Update image references from localhost/hojmark/drift:latest to localhost:5000/drift:dev
- Simplify distributed-scan-mvp topology by removing explicit bridge nodes (not supported in containerlab without OVS)
- Use direct point-to-point links for segment networks
- Add simple-test.clab.yaml for basic functionality testing
- Fix container entry points and commands for proper agent startup

Note: The distributed topology needs further work to properly create switched networks
with multiple nodes on the same segment, but basic functionality is now testable.
Change agent to bind to 0.0.0.0 instead of 127.0.0.1 to enable
connections from remote CLI instances in containerized environments.
This is essential for distributed scanning across network segments.
Extract common agent services (execution environment, subnet provider,
network scanner) into ConfigureAgentCoreServices() method to avoid
duplication between CLI and agent setup. This provides a cleaner
separation of concerns and makes it easier to maintain agent
dependencies.
- Remove manual 'agentid_' prefix addition in AgentSubnetProvider since AgentId already includes it
- Update DistributedNetworkScanner to compare full agent IDs with prefix (use agentId.Value)
- Fix Cluster peer stream creation to not add redundant prefix (2 locations)

This resolves agent lookup failures caused by doubled prefixes like 'agentid_agentid_...'
… cooperation-test

Introduces a structured containerlab integration test target (TestContainerlab)
with two passing test cases:
- simple-test: 1 agent + CLI + 1 target, verifies basic distributed scan
- cooperation-test: 3 agents + CLI + 5 targets, verifies multi-agent coordination
  and result merging (4/4 scan operations: local + 3 agents)

Fixes rootless Podman + pasta networking incompatibility by pre-creating the
'clab' management network before each deploy, so containerlab reuses it instead
of failing on the kernel bridge lookup it performs after creating a new network.

Also cleans up stale prototype topology files and adds hidden --id flag on
agent start for deterministic agent identity in tests.
- Fix MissingOption exit code: catch ArgumentException in CommandBase and return GeneralError
- Fix RemoteScan tests: update test agent IDs to use required 'agentid_' prefix
- Fix MergeOverlappingSubnetResults: dedup by Device ID (GetDeviceId().ToString()) and union addresses on merge
- Fix local scanner MAC resolution: fall back to local interface MAC for own IPs missing from ARP cache
- Add subnet-isolation containerlab topology and integration test assertions
- Update all affected Verifier snapshots
- Add WarnAgentPreview() extension method on IOutputManager that fans out
  to all outputs via CompoundLogger; covers both agent hosting and
  distributed scanning contexts
- Call WarnAgentPreview() at agent startup and before distributed scans
- Upgrade AgentSubnetProvider failure log from Information to Warning so
  excluded agents are visible
- Replace Console.WriteLine in PeerStream.DisposeAsync with structured
  LogTrace
- Update test snapshots to reflect new warning messages
hojmark added 14 commits March 3, 2026 21:16
…or annotations

Containerlab writes all its output to stderr by design. Nuke's default
logger maps stderr to Log.Error, which GH Actions annotates as errors.
Pass a custom logger to Clab() that logs both stdout and stderr at the
Information level.
@hojmark hojmark changed the title feat: agent feat: distributed network scanning Mar 10, 2026
@hojmark hojmark changed the title feat: distributed network scanning feat: agent-based distributed scanning Mar 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant