# kubescape/node-agent architecture

> Architecture diagram of the GitHub repository kubescape/node-agent, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kubescape/node-agent
- Repository: https://github.com/kubescape/node-agent

## Overview

##### Main Components

a. Core Components:
- Node Agent Core (Central Controller)
- eBPF Tracers/Gadgets
- Rule Engine
- Event Processors
- Storage System
- Exporters

b. External Integrations:
- Kubernetes API Server
- ClamAV Malware Scanner
- Prometheus Metrics
- Alert Manager
- Storage Backend

##### Component Relationships

**Top Layer: External Systems**
- Kubernetes API Server
- Prometheus
- Alert Manager

**Middle Layer: Core Components**
- Node Agent Core
- Container Watcher
- Process Manager
- Network Manager
- Application Profile Manager

- Security Components
- Rule Engine
- Rule Binding Manager
- Malware Manager (ClamAV)

- Event Processing
- Event Reporters
- Exporters (HTTP/Syslog/CSV)

**Bottom Layer: System Level**
- eBPF Gadgets
- HTTP Tracer
- SSH Tracer
- Ptrace Detector
- Hardlink Tracer
- RandomX Detector
- System Resources

##### Data Flow Indicators

- eBPF data collection flow from system to tracers
- Event processing flow through the system
- Alert and metric reporting paths
- Configuration and rule updates from Kubernetes

##### Key Elements to Highlight

a. Security Features:
- Malware scanning capabilities
- Runtime security monitoring
- Network traffic analysis
- File system monitoring

b. Integration Points:
- Kubernetes integration
- Monitoring system connections
- Alert routing

##### Implementation Details

- eBPF-based monitoring architecture
- Real-time security scanning capabilities
- Event processing pipeline
- Rule evaluation system
- Multiple exporter options

##### Technical Notes

Annotations for:
- CO-RE (Compile Once Run Everywhere) requirement
- Kernel version dependencies
- Security permissions needed
- Configuration requirements (NODE_NAME, KUBECONFIG)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles
    classDef external fill:#FFA500,stroke:#000
    classDef core fill:#4169E1,stroke:#000
    classDef security fill:#32CD32,stroke:#000
    classDef ebpf fill:#9370DB,stroke:#000
    classDef system fill:#808080,stroke:#000

    %% External Systems Layer
    subgraph ExternalSystems
        K8S["Kubernetes API Server"]:::external
        PROM["Prometheus"]:::external
        ALERT["Alert Manager"]:::external
    end

    %% Core Components Layer
    subgraph CoreComponents
        %% Node Agent Core
        NAC["Node Agent Core"]:::core
        CW["Container Watcher"]:::core
        PM["Process Manager"]:::core
        NM["Network Manager"]:::core
        APM["Application Profile Manager"]:::core
        
        %% Security Components
        RE["Rule Engine"]:::security
        RBM["Rule Binding Manager"]:::security
        MM["Malware Manager"]:::security
        CLAM["ClamAV Integration"]:::security
        
        %% Event Processing
        ER["Event Reporters"]:::core
        EX["Exporters"]:::core
    end

    %% System Level Layer
    subgraph SystemLevel
        %% eBPF Gadgets
        subgraph Gadgets
            HTTP["HTTP Tracer"]:::ebpf
            SSH["SSH Tracer"]:::ebpf
            PTR["Ptrace Detector"]:::ebpf
            HLT["Hardlink Tracer"]:::ebpf
            RXD["RandomX Detector"]:::ebpf
        end
        
        SR["System Resources"]:::system
    end

    %% Relationships
    SR --> Gadgets
    Gadgets --> NAC
    NAC --> CW & PM & NM & APM
    NAC --> RE
    RE --> RBM
    RE --> MM
    MM --> CLAM
    NAC --> ER
    ER --> EX
    EX --> PROM
    EX --> ALERT
    K8S --> NAC

    %% Click Events
    click NAC "https://github.com/kubescape/node-agent/blob/main/pkg/containerwatcher/v1/container_watcher.go"
    click RE "https://github.com/kubescape/node-agent/tree/main/pkg/ruleengine/"
    click EX "https://github.com/kubescape/node-agent/tree/main/pkg/exporters/"
    click RBM "https://github.com/kubescape/node-agent/tree/main/pkg/rulebindingmanager/"
    click MM "https://github.com/kubescape/node-agent/tree/main/pkg/malwaremanager/"
    click PM "https://github.com/kubescape/node-agent/tree/main/pkg/processmanager/"
    click NM "https://github.com/kubescape/node-agent/tree/main/pkg/networkmanager/"
    click APM "https://github.com/kubescape/node-agent/tree/main/pkg/applicationprofilemanager/"
    click CW "https://github.com/kubescape/node-agent/tree/main/pkg/containerwatcher/"
    click HTTP "https://github.com/kubescape/node-agent/tree/main/pkg/ebpf/gadgets/http/"
    click SSH "https://github.com/kubescape/node-agent/tree/main/pkg/ebpf/gadgets/ssh/"
    click PTR "https://github.com/kubescape/node-agent/tree/main/pkg/ebpf/gadgets/ptrace/"
    click HLT "https://github.com/kubescape/node-agent/tree/main/pkg/ebpf/gadgets/hardlink/"
    click RXD "https://github.com/kubescape/node-agent/tree/main/pkg/ebpf/gadgets/randomx/"
    click CLAM "https://github.com/kubescape/node-agent/tree/main/pkg/malwaremanager/v1/clamav/"

    %% Legend
    subgraph Legend
        L1["External Systems"]:::external
        L2["Core Components"]:::core
        L3["Security Components"]:::security
        L4["eBPF Components"]:::ebpf
        L5["System Components"]:::system
    end
```
