Skip to main content

SecOps Brain RAG

RAG sécurisé sur corpus markdown (second brain) : filtrage RBAC avant recherche, redaction des secrets avant envoi au LLM, citations obligatoires [Source: path], et évaluation (recall@k, MRR, violations RBAC).

Aucun appel réseau au import ni dans les tests. Le mode --offline répond sans réseau.

Arborescence

secops-brain-rag/
├── pyproject.toml
├── README.md / .env.example
├── src/secops_rag/
│   ├── ingestion.py   # parse markdown, sensibilité, chunks, index
│   ├── security.py    # RBAC, redaction secrets, audit
│   ├── retrieval.py   # BM25 + TF-IDF/SVD, fusion RRF
│   ├── generator.py   # prompt cité, clients LLM
│   ├── evals.py       # recall@k, MRR, run_eval
│   └── cli.py         # index, query, eval, audit-rbac
└── tests/             # conftest + 6 modules + eval_dataset.json

Installation

cd secops-brain-rag
pip install -e .        # dépendances : pydantic, typer, rich, numpy,
                        # scikit-learn, httpx, openai, pyyaml, pytest
cp .env.example .env    # optionnel : FREELMAPI_API_KEY, RAG_MODEL

Usage

# 1. Indexer le corpus
secops-rag index ./docs -o index.json

# 2. Interroger (rôle viewer par défaut, offline sans réseau)
# Timeout global fail-closed: --timeout 30 (défaut). Timeout => DENY verdict explicite.
secops-rag query "Quel est le protocole de travail ?" --role viewer --offline --index index.json

# 3. Évaluer
secops-rag eval tests/eval_dataset.json --index index.json --role viewer

# 4. Auditer le RBAC (chunks par sensibilité + matrice rôles + verdict PASS/FAIL)
secops-rag audit-rbac index.json

Injection de secret (portable)

Ne jamais utiliser export ni passer une clé en env VAR=... (fuite via ps, historique shell, CI logs). Recommandation générique :

  • utiliser un gestionnaire de secrets (Vault, 1Password CLI, variables chiffrées du CI, systemd LoadCredential, Docker secrets, etc.) qui expose la clé uniquement au processus enfant ;
  • ou un fichier secret en mode 0600 (ou 0400), jamais commité, chargé à l'exécution sans l'écrire dans l'historique shell.

Le secret ne doit jamais apparaître en clair dans l'historique shell, ni être committé dans le dépôt. Exemple de principe (avec votre outil d'injection) :

# fichier secret 0600 contenant : FREELMAPI_API_KEY=...
# votre outil d'injection expose FREELMAPI_API_KEY uniquement à secops-rag, puis :
secops-rag query "..." --role viewer --index index.json

Sécurité (RBAC)

Rôle Voit public Voit internal Voit restricted
viewer yes no no
member yes yes no
admin yes yes yes

Sensibilité déduite dans l'ordre : frontmatter (sensitivity/classification) → tags (restricted, confidentiel, secret) → chemin (credentials, secret, prive) → défaut public.

Secrets masqués (security.redact_secrets) : clés OpenAI sk-…, ghp_…, xoxb-…, AKIA…, api_key=…, password=…, mot de passe=…, Bearer …, clés privées PEM. Remplacement par [REDACTED:TYPE].

Retrieval

  • BM25 maison (k1=1.5, b=0.6), tokenisation fr/en (accents inclus).
  • TF-IDF sklearn (max_features=2048) + TruncatedSVD si dim > 64, similarité cosinus.
  • Fusion RRF : score = somme 1/(k + rang), k=60 par défaut.

Évaluation

run_eval filtre les chunks par rôle avant la recherche, puis calcule par cas : recall@k, MRR, fuites RBAC, must_not_contain. Le résumé impose rbac_violations == 0 et reporte citation_groundedness.

Télémétrie

  • Traces JSONL locales (SECOPS_RAG_TRACES, défaut ~/.local/state/secops_rag/traces.jsonl) : append-only, sanitization secrets, allowlist de clés.
  • Export OTLP fail-open (jamais bloquant) : SECOPS_RAG_OTLP_ENDPOINT ou OTEL_EXPORTER_OTLP_TRACES_ENDPOINT (défaut http://127.0.0.1:4318/v1/traces). Si opentelemetry/collecteur absent ou en erreur, la query continue et le verdict reste explicite.
  • Aucune raw query exportée en OTLP (seulement longueur/métadonnées).

Tests

cd secops-brain-rag
PYTHONPATH=src python -m pytest tests -q

Metadata

Release files for secops-brain-rag 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for secops-brain-rag 0.1.0
File Size Uploaded Provenance Actions
secops_brain_rag-0.1.0.tar.gz 26.5 kB With provenance Details for secops_brain_rag-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for secops-brain-rag 0.1.0
File Interpreter ABI Platform Actions
secops_brain_rag-0.1.0-py3-none-any.whl Python 3 none any Details for secops_brain_rag-0.1.0-py3-none-any.whl

Total release size: 49.6 kB

Release files / secops_brain_rag-0.1.0.tar.gz

Download URL secops_brain_rag-0.1.0.tar.gz
Size 26.5 kB
Tags Source
SHA-256 checksum
How to use checksums
2359f07c785f616b5a2447cc7aa4c7462269025c7d751565bd97e64a305051c1
BLAKE2b-256 checksum
How to use checksums
5b50bcff5c738f28dea2851ea6da5f4daeca99e5ce036a027a2031939d95350f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 2, 2026.

Transparency log

Release files / secops_brain_rag-0.1.0-py3-none-any.whl

Download URL secops_brain_rag-0.1.0-py3-none-any.whl
Size 23.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c85c484ecb132657dba09ef25aa229b569ca9014d75145f04f46120dbcbc6965
BLAKE2b-256 checksum
How to use checksums
266e7a5e571ec01cd5ee541b39ae2073968e9282f9b2738397f6835c4c3e4d02
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 2, 2026.

Transparency log

Security for secops-brain-rag 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for secops_brain_rag-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 2, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page