aido-onyx/smb-connector/README.md
Naeem Dosh 26d3262cfb SMB connector: per-connector group access + standalone Docker mode
1. Optional Onyx group per connector. Set SMB_SOURCE_<N>_GROUPS (or
   "groups" in SMB_SOURCES JSON, or SMB_DEFAULT_GROUP_IDS as a fallback)
   to a list of Onyx user-group ids. The connector is then created
   PRIVATE and restricted to those groups; empty stays PUBLIC. Applied
   only at connector creation, as requested. Needs the Business licence.

2. Standalone deployment. New docker-compose.standalone.yml runs the
   connector as its own Compose project next to Onyx (no -f injection),
   joining Onyx's network (onyx_default, override via ONYX_NETWORK) to
   reach the API by service name. Suits Compose management tools that
   cannot handle multiple injected compose files. The legacy injected
   compose still works.

Verified: group-id parsing across all three source styles, the
private+groups vs public payload, standalone compose config, and the
full index/sync simulation (still green).
2026-09-24 14:20:39 +05:00

132 lines
6.7 KiB
Markdown

# AIDO SMB → Onyx Connector (Phase 1)
Syncs files from one or more **SMB/CIFS shares** into Onyx via the public
**Ingestion API**, with full production behaviour the POC was missing:
- **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 **connector
(cc_pair)** per source automatically; idempotent across restarts.
- **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.
It runs as a **sidecar container** and touches **no Onyx source code** — only the
public ingestion + admin APIs — so it survives Onyx upgrades.
> Phase 2 (separate) hides the broken file-preview for these SMB documents in the
> Onyx UI and shows the logical path instead, via the white-label overlay.
## 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
```bash
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.
```bash
cd smb-connector
docker compose -f docker-compose.standalone.yml up -d --build
docker compose -f docker-compose.standalone.yml logs -f
```
Onyx's compose has `name: onyx`, so its network is `onyx_default` (the default).
If your Onyx project uses another name, set `ONYX_NETWORK=<project>_default`.
**B. Injected into the Onyx compose (legacy).** Adds the service to the Onyx
project via a second compose file:
```bash
docker compose -f docker-compose.yml -f smb-connector/docker-compose.smb.yml up -d --build smb_connector
docker compose logs -f smb_connector
```
### 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
```
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 pdf,docx,txt,md,csv,xlsx,html) |
| `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 |
| `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** is the light set (PDF, DOCX, XLSX, CSV, TXT/MD, HTML). Legacy
`.doc`/`.xls` and scanned-image PDFs are skipped (no OCR) — Phase-1 scope.
- **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 (verified against v4.5.2): 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 logical path is stored for
display (Phase 2 surfaces it in the UI and hides the dead preview).