USB Device Handler

October 31, 2025 · View on GitHub

The USB Device Handler is a KubeArmor module that provides audit and enforcement capabilities for USB devices at the host level. It allows administrators to define fine-grained host security policies that control USB device access based on their class, subclass, protocol, and level.

To enable USB device enforcement, use the enableUSBDeviceHandler flag.

Note that the USB Device Handler requires host policies to be enabled as well. It operates only with KubeArmor host policies.

You can define policies that enforce actions on specific USB devices by their hardware classification. See the policy spec here.

Working

The USB Device Handler works by:

  1. Listening to kernel uevents via a Netlink socket for USB device attachments and removals.
  2. When a USB device is attached, it matches the device against the currently applied host policies.
  3. The most specific matching policy is selected and its action (Allow, Audit, or Block) is enforced.
  4. Enforcement is achieved through sysfs-based USB authorization, by modifying the device configuration under /sys/bus/usb/devices/.

Policy Handling

The handler maintains an ordered list of rules, sorted by their specificity. Specificity is determined by the number of defined fields among:

  • class
  • subclass
  • protocol
  • level

Specificity Rules

  • Each defined property increases the rule’s specificity.
  • Rules are sorted in decreasing order of specificity.
  • If multiple rules have the same specificity, action priority decides which one is used: Block > Audit > Allow

For example, consider these three host policies:

#ClassSub ClassProtocolLevelAction
186802Allow
286802Block
386-2Audit

After evaluation, the handler will generate the following internal rules:

#Class (100)Sub Class (10)Protocol (1)Level (100)ActionSpecificity
186802Block211
286-2Audit210

Note that the Allow rule (policy #1) was replaced by the Block rule (policy #2) because they target the same device attributes and Block has higher priority.

Enforcement Mode

If there is at least one Allow rule, the handler operates in Allowlist Mode. Devices not matching any policy will have their behavior decided by the host default device posture. It can be audit or block (default is audit).

You can configure this using the hostDefaultDevicePosture flag.

Supported USB Classes

DecimalHexClass NameDescription
10x01AUDIOAudio devices
20x02COMMUNICATION-CDCCommunications & CDC Control
30x03HIDHuman Interface Devices (keyboard, mouse etc.)
50x05PHYSICALPhysical devices
60x06IMAGECameras, scanners
70x07PRINTERPrinters
80x08MASS-STORAGEStorage devices (flash drives, external HDDs, etc.)
90x09HUBHubs
100x0ACDC-DATACDC Data interface
110x0BSMART-CARDSmart Card readers
130x0DCONTENT-SECURITYContent security devices
140x0EVIDEOVideo devices (Webcams, capture cards)
150x0FPERSONAL-HEALTHCAREHealthcare/medical devices
160x10AUDIO/VIDEOAudio/Video devices
170x11BILLBOARDBillboard devices
180x12TYPE-C-BRIDGEType-C bridge devices
190x13BULK-DISPLAYBulk Display Protocol devices
200x14MCTPMCTP over USB protocol endpoint
600x3CI3CI3C over USB devices
2200xDCDIAGNOSTICDiagnostic devices
2240xE0WIRELESS-CONTROLLERWireless controllers (Bluetooth, WiFi adapters)
2390xEFMISCELLANEOUSMiscellaneous devices
2540xFEAPPLICATION-SPECIFICApplication-defined class
2550xFFVENDOR-SPECIFICVendor-defined proprietary class

As defined by usb.org.

Policy examples

  • Keyboard

    apiVersion: security.kubearmor.com/v1
    kind: KubeArmorHostPolicy
    metadata:
      name: hsp-block-keybd
    spec:
      nodeSelector:
        matchLabels:
          kubernetes.io/hostname: aryan
      severity: 5
      device:
        matchDevice:
        - class: HID
          subClass: 1
          protocol: 1
      action: Block
    

    The above policy will block USB keyboards attached at any level to the host with hostname aryan

  • Mouse

    apiVersion: security.kubearmor.com/v1
    kind: KubeArmorHostPolicy
    metadata:
    name: hsp-audit-mouse
    spec:
    nodeSelector:
        matchLabels:
        kubernetes.io/hostname: aryan
    severity: 5
    device:
        matchDevice:
        - class: "0x3"
        subClass: 1
        protocol: 2
        level: 1
    action: Audit
    

    The above policy will audit USB mice attached directly to the host with hostname aryan


Known Limitation: Composite USB Devices (Mouse + Keyboard)

When a composite USB device that controls both mouse and keyboard is connected, and a KubeArmor policy is applied to block either one of them (for example, the mouse or the keyboard interface), both stop functioning. In sysfs although, only the targeted interface is deauthorized according to the policy. But the entire composite device becomes unavailable to the system.