|
| 1 | +# Security |
| 2 | + |
| 3 | +Two independent protections, both on by default with zero configuration: where API |
| 4 | +keys live, and who on the local machine can read the files BuffData writes. |
| 5 | + |
| 6 | +## API keys: the OS keyring, not a plaintext file |
| 7 | + |
| 8 | +```bash |
| 9 | +buffdata auth set GEMINI_API_KEY |
| 10 | +# Value for GEMINI_API_KEY: [hidden input] |
| 11 | +# Repeat for confirmation: [hidden input] |
| 12 | +# Stored GEMINI_API_KEY in the OS keyring. |
| 13 | +``` |
| 14 | + |
| 15 | +Stores the key in the platform-native credential store -- Windows Credential Manager, |
| 16 | +macOS Keychain, or Linux Secret Service/KWallet, via the `keyring` package (a base |
| 17 | +dependency, not an extra: this is the default story for every `pip install buffdata` |
| 18 | +user, not an enterprise add-on). The prompt uses hidden input with a confirmation |
| 19 | +step, and the value is never written to any file, never echoed to the terminal, and |
| 20 | +never lands in shell history the way `export GEMINI_API_KEY=sk-...` would. |
| 21 | + |
| 22 | +Every command picks it up automatically afterward -- no `.env` file, no |
| 23 | +`BUFFDATA_SECRET_BACKEND` change. `EnvSecretResolver`, the default backend |
| 24 | +([`buffdata/engine/secrets.py`](../buffdata/engine/secrets.py)), checks the |
| 25 | +environment variable first (so CI/scripted use with real env vars is completely |
| 26 | +unaffected) and falls back to the OS keyring only when that's unset. It's the one |
| 27 | +backend that behaves this way; every other backend (`vault`, |
| 28 | +`aws_secrets_manager`, `gcp_secret_manager`, `azure_key_vault` -- see |
| 29 | +[providers.md](providers.md#secret-backends)) is explicit and doesn't fall back to |
| 30 | +anything, since those are deliberate infrastructure choices, not a smoothing default. |
| 31 | + |
| 32 | +```bash |
| 33 | +buffdata auth status # which known secrets resolve, and from where -- values never shown |
| 34 | +buffdata auth remove GEMINI_API_KEY |
| 35 | +``` |
| 36 | + |
| 37 | +``` |
| 38 | + Secret resolution status |
| 39 | +┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓ |
| 40 | +┃ Name ┃ Resolves from ┃ |
| 41 | +┡━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩ |
| 42 | +│ GEMINI_API_KEY │ not set │ |
| 43 | +│ GOOGLE_API_KEY │ not set │ |
| 44 | +│ OPENAI_API_KEY │ environment │ |
| 45 | +│ ANTHROPIC_API_KEY │ not set │ |
| 46 | +│ AZURE_OPENAI_API_KEY │ not set │ |
| 47 | +│ OPENAI_COMPATIBLE_API_KEY │ not set │ |
| 48 | +│ OLLAMA_API_KEY │ not set │ |
| 49 | +│ LMSTUDIO_API_KEY │ not set │ |
| 50 | +│ VLLM_API_KEY │ not set │ |
| 51 | +│ LLAMACPP_API_KEY │ not set │ |
| 52 | +└───────────────────────────┴───────────────┘ |
| 53 | +``` |
| 54 | + |
| 55 | +Set `BUFFDATA_KEYRING_SERVICE` to use a different keyring namespace than the default |
| 56 | +`buffdata` (multiple installs/profiles on one machine, for instance). |
| 57 | + |
| 58 | +Verified for real in |
| 59 | +[`tests/test_auth_keyring.py`](../tests/test_auth_keyring.py) -- genuine |
| 60 | +`keyring.set_password`/`get_password`/`delete_password` round trips (via a real, |
| 61 | +file-backed `keyrings.alt` backend in the test environment, since no OS-native |
| 62 | +credential store is available in headless CI; the platform-native ones are what |
| 63 | +production actually uses), the full `buffdata auth set/remove/status` CLI flow, and an |
| 64 | +end-to-end test confirming a key stored via `auth set` is what `create_llm_client` |
| 65 | +actually resolves and uses -- no gap between "stored" and "used." |
| 66 | + |
| 67 | +## Files at rest: owner-only permissions |
| 68 | + |
| 69 | +[`buffdata/security/permissions.py`](../buffdata/security/permissions.py)'s |
| 70 | +`restrict_to_owner()` sets `0600` (owner read/write only) on every locally-written file |
| 71 | +that can carry sensitive content, immediately after writing it: |
| 72 | + |
| 73 | +- **Pipeline checkpoints** (`.{output}.checkpoint.json`) -- can briefly hold |
| 74 | + pre-PII-redaction text, since the checkpoint after the `validate` stage is written |
| 75 | + before the `pii` stage runs (see [architecture.md](architecture.md)). |
| 76 | +- **`report.json`** -- record counts, provider/model, dataset-revealing file paths. |
| 77 | +- **The audit database** (`buffdata_audit.db` by default) -- every recorded run across |
| 78 | + a team, queryable by anyone who can read the file. |
| 79 | + |
| 80 | +A no-op on Windows (`os.chmod` doesn't express meaningful ACLs there, and NTFS's |
| 81 | +per-user-profile isolation already covers the common single-user-machine case) and |
| 82 | +never fails the write it's protecting -- this is defense in depth for a shared POSIX |
| 83 | +machine, not something the rest of the pipeline depends on for correctness. |
| 84 | + |
| 85 | +## What this doesn't cover |
| 86 | + |
| 87 | +- **Encryption at rest** for these same files was deliberately not built: without a |
| 88 | + passphrase or key-management story for a `pip install`ed CLI to draw from, an |
| 89 | + encryption key would have to be hardcoded (pointless) or become yet another secret |
| 90 | + the user has to manage (worse than the file-permission protection it would replace). |
| 91 | + File permissions are the standard mitigation for this exact scenario -- |
| 92 | + `~/.ssh/id_rsa` and `~/.aws/credentials` use the same approach, not encryption. |
| 93 | +- **The final output dataset** (`optimized.jsonl` and its `.rejected.jsonl`) is *not* |
| 94 | + permission-restricted -- it's the deliverable you explicitly asked BuffData to |
| 95 | + produce for downstream use (training, sharing, `buffdata push` to a Hub), and |
| 96 | + defaulting it to owner-only would just be friction for the common case of a build |
| 97 | + pipeline or teammate reading it under a different local user. |
| 98 | +- Redacting secrets from third-party SDK exception messages (if `openai`/`anthropic`/ |
| 99 | + `google-genai` ever included a raw key in an error string) is outside BuffData's |
| 100 | + control -- checked during this work and none of buffdata's own code paths do this |
| 101 | + (no client's `__repr__`, exception message, or anything written to `report.json`/the |
| 102 | + audit DB ever includes `self.api_key`), but a third-party library's own error |
| 103 | + formatting isn't something this codebase can guarantee. |
0 commit comments