aido-smb-connector/README.md
2026-11-25 16:14:48 +01:00

8.1 KiB

AIDO SMB → Onyx Connector

Syncs files from one or more SMB/CIFS shares into Onyx via the public Ingestion API:

  • Update & delete sync — changed files are re-indexed in place; files removed from a share are deleted from Onyx (reconciled every cycle).
  • Self-provisioning — creates/reuses the Onyx API key and one File connector (cc_pair) per source automatically; idempotent across restarts. Documents are pushed in as the file source, so they are searchable in Default Chat and appear in the source filters like any other connector.
  • Multi-source via Docker config — any number of shares, defined purely in env.
  • Logical path mapping — each document is labelled with the path users recognise (\\company\share\…), mapped from the local mount via config.
  • Per-source index document — an optional table-of-contents document per share so the assistant is aware of the full document set (see SMB_WRITE_INDEX).
  • Per-connector group access — restrict a connector to Onyx user groups (see SMB_SOURCE_<N>_GROUPS).

It runs as its own container and touches no Onyx source code — only the public ingestion + admin APIs — so it survives Onyx upgrades.

A small white-label UI overlay (branding/smb/smb-ui.patch) improves how these documents behave in the Onyx UI: the citation shows the short file name, and a click copies the full network path to the clipboard instead of opening a dead preview (SMB files have no browsable link). This applies to both the chat citation view and the licensed Search view.

How it works

 SMB share ──(read-only mount)──▶  smb_connector  ──ingestion API──▶  Onyx
                                       │
                        manifest.json (path → document_id + content hash)

Each cycle, per source:

  1. Walk the share, hash each eligible file.
  2. new / changed (hash differs) → POST /onyx-api/ingestion (upsert by stable id).
  3. gone (in manifest, not on disk) → DELETE /onyx-api/ingestion/{id}.
  4. Reconcile against Onyx's own doc list so deletes still happen if the manifest is lost.

Document ids are stable (smb::<source>::<hash of relative path>), so re-indexing a changed file updates it rather than duplicating.

Setup

cd smb-connector
cp .env.example .env
#   set ONYX_API_KEY (or ONYX_ADMIN_EMAIL/PASSWORD to auto-create one)
#   define your shares in SMB_SOURCES (JSON) or SMB_SOURCE_1_* vars

Then bring it up. Two deployment modes:

A. Standalone (recommended) — its own Compose project next to Onyx. No -f injection, so a Compose management tool can handle it on its own. It joins Onyx's network to reach the API by service name.

cd aido-smb-connector
docker compose up -d --build
docker compose logs -f

SMB mount — two modes

A. In-container mount (recommended, no host mount). The connector mounts each CIFS share itself; you just give it the share + credentials via env:

SMB_SOURCE_1_NAME=Finance
SMB_SOURCE_1_UNC=//nas.company.local/finance     # or _SERVER + _SHARE
SMB_SOURCE_1_MOUNT=/mnt/smb/finance              # where to mount it in the container
SMB_SOURCE_1_LOGICAL=\\company\finance           # path shown in Onyx
SMB_SOURCE_1_USERNAME=svc_onyx
SMB_SOURCE_1_PASSWORD=…                           # kept in a 0600 creds file, never in the process list
SMB_SOURCE_1_DOMAIN=COMPANY                       # optional
# SMB_SOURCE_1_VERS=3.0                           # SMB dialect, default 3.0
# SMB_SOURCE_1_MODIFIED_AFTER=2024-01-01   (inclusive)
# SMB_SOURCE_1_MODIFIED_BEFORE=2025-01-01  (exclusive)

This needs two Linux capabilities on the container (already set in docker-compose.smb.yml): cap_add: [SYS_ADMIN, DAC_READ_SEARCH] + security_opt: [apparmor:unconfined] (or privileged: true if your host is stricter). The host kernel must have the cifs module (standard on Linux). The share is mounted read-only and unmounted cleanly on container stop.

B. Host mount (legacy). Mount the share on the host and bind-mount it into the container, and omit the _UNC/_SERVER vars for that source so it isn't CIFS-mounted a second time — _MOUNT then just points at the bind-mounted path.

Configuration

Var Purpose
ONYX_API_URL Onyx API base (e.g. http://api_server:8080)
ONYX_API_KEY API key; if empty, auto-created from admin creds and cached
ONYX_ADMIN_EMAIL / ONYX_ADMIN_PASSWORD Bootstrap creds to auto-create the key + connectors
SMB_SOURCES JSON list of {name, mount, logical, cc_pair_id?}
SMB_SOURCE_<N>_NAME/_MOUNT/_LOGICAL/_CC_PAIR_ID Indexed alternative to SMB_SOURCES
SMB_SOURCE_<N>_UNC (or _SERVER+_SHARE) In-container CIFS mount: the share to mount at _MOUNT
SMB_SOURCE_<N>_USERNAME/_PASSWORD/_DOMAIN/_VERS CIFS credentials + dialect (default 3.0); omit user for guest
INGESTION_INTERVAL_SECONDS Reconcile interval (default 300)
INCLUDE_EXTENSIONS File types to ingest. Default covers office + web + many text/IT formats (pdf, docx, xlsx, csv, txt, md, html, plus yaml, json, xml, ini, conf, cfg, sh, bash, ps1, py, sql, log, dockerfile, properties, toml, rst, mjs, patch, tsx)
MAX_FILE_MB Skip files larger than this (default 50)
SMB_WRITE_INDEX Write a per-source index (table-of-contents) document listing every file, so the assistant is aware of the full set (default on; 0/false to disable)
SMB_SOURCE_<N>_GROUPS Onyx user-group ids (comma-separated) allowed to access this connector. Set → connector created private and restricted to those groups; empty → public. Applied only at connector creation. Needs the Onyx Business licence. In SMB_SOURCES JSON use "groups": [id, …].
SMB_DEFAULT_GROUP_IDS Fallback group ids for any source that has none set
SMB_SOURCE_<N>_MODIFIED_AFTER / _MODIFIED_BEFORE Optional modified-date filter per source (YYYY-MM-DD). Only files whose modified date is in range are indexed. Both optional: set both for a range, only _AFTER for everything newer than that date, only _BEFORE for everything older. _AFTER is inclusive, _BEFORE is exclusive (dates read as UTC). In SMB_SOURCES JSON use "modified_after" / "modified_before". A file that falls outside the range is removed from Onyx if it was indexed under an earlier range.
SMB_DEFAULT_MODIFIED_AFTER / _BEFORE Fallback date filter for any source that sets none
ONYX_NETWORK Standalone mode only: name of Onyx's Docker network (default onyx_default)

State (manifest + cached key/cc_pair) lives in the mounted /app/state volume.

Notes / scope

  • Extraction covers office, web, and common text/IT formats (see INCLUDE_EXTENSIONS). Legacy .doc/.xls and scanned-image PDFs are skipped (no OCR). Add or remove types via INCLUDE_EXTENSIONS.
  • Connector type: documents are ingested as the file source (a first-class, chat-searchable connector), so they appear in Default Chat and the source filters. The connector is created once, then documents are pushed via the Ingestion API (from_ingestion_api), not polled from a file location.
  • Auth for provisioning: creating the API key/connectors needs one admin credential the first time. At steady state only the cached API key is used.
  • API-key auto-creation requires LICENSE_ENFORCEMENT_ENABLED=false on the Onyx deployment: the /admin/api-key endpoint is EE-tier-gated and returns HTTP 402 when enforcement is on (the default). CE/white-label deployments run with it off, so this is fine — and if you'd rather not rely on it, just supply a pre-made ONYX_API_KEY. Connector/cc_pair creation and the ingestion API itself are not tier-gated and work on plain CE.
  • Document ids are URL-safe (smb_<source>_<hash>), matching how Onyx stores/returns them, so update and delete reconcile reliably (verified end-to-end).
  • smb:// links can't open from a browser; the full network path is stored in the document metadata, and the UI overlay copies it to the clipboard on click (see branding/smb/smb-ui.patch).