Skip to content

Fleet (osquery) Executor

Category: Asset Inventory and Network Management Script: fleet_osquery.py Integration: REST API Faraday Plugin: Raw JSON Website: https://fleetdm.com

Description

Imports the host inventory and the saved osquery queries from a Fleet server into Faraday. Each managed host becomes a Faraday host with its IP, hostnames, MAC and OS, and each saved query becomes a separate host. Every record carries one informational [ASSET-INVENTORY] vulnerability with its Fleet details.

Prerequisites

  • A Fleet server reachable from the agent
  • A Fleet API token (from My account > Get API token in the Fleet UI, or fleetctl login) with read access to hosts and queries
  • The Python requests package in the agent environment (checked with python3 -c 'import requests')

Configuration

Environment Variables (Setup)

Variable Required Description
FLEET_HOST Yes Fleet server URL (e.g., https://fleet.example.com). https:// is added if you omit the scheme.
FLEET_TOKEN Yes Fleet API token, sent as a Bearer token
FLEET_PAGES No Maximum number of pages of 100 records to read for hosts and for queries (default: 5, maximum: 50)

These variables are also accepted as execution arguments, so a single run can override them.

Execution Arguments

Parameter Type Mandatory Description
FLEET_TEAM_ID string No Import only the hosts and queries of this Fleet team ID (e.g., 3). If empty, imports all teams the token can see.
FLEET_LABEL_ID string No Import only the hosts with this Fleet label ID. It does not apply to saved queries.

YAML Configuration Example

executors:
  fleet_osquery:
    repo_executor: fleet_osquery.py
    max_size: 65536
    varenvs:
      FLEET_HOST: "https://fleet.example.com"
      FLEET_TOKEN: "<fleet_token>"
    params:
      FLEET_TEAM_ID:
        mandatory: false
        type: string
        base: string
      FLEET_LABEL_ID:
        mandatory: false
        type: string
        base: string

How It Works

  1. Authenticates every request with Authorization: Bearer <FLEET_TOKEN>
  2. Reads /api/v1/fleet/hosts (filtered by team_id and label_id) and /api/v1/fleet/queries (filtered by team_id), 100 records per page, up to FLEET_PAGES pages each
  3. Creates one Faraday host per Fleet host:
    • IP: the primary IP, or the first non-loopback IP of its network interfaces
    • Hostnames: hostname, computer name, display name and serial number
    • MAC and OS: the primary MAC, and the platform, OS version and hardware model
  4. Creates one Faraday host per saved query, named after the query, with the query SQL in the vulnerability description
  5. Adds one info vulnerability to each host, with Fleet ID, team, platform, status, last seen time and labels as references, plus any CVEs found in the software inventory

Notes

  • Hosts without a usable IP, and all saved queries, use the IP 0.0.0.0.
  • Severity is always info, because these records are inventory, not findings.
  • A 401 response stops the run. On 403, 429 or other errors the executor keeps what it has read so far.
  • The shared agent parameters (AGENT_CONFIG_* tags and severity filters) are not applied by this executor.