E-04 Encryption Service
Brick E: Data, RAG, context, memory. French version: E-04-encryption-service
1. Role and responsibilities
Envelope application encryption with keys managed in OpenBao, backed by a KMS or HSM.
- Encrypt / decrypt
- Manage and rotate keys per tenant
- BYOK / HYOK via KMS/HSM
2. Position in the architecture and interactions
- Callers: Checkpoints, Object Storage, Token Vault, Media.
- Execution path: Synchronous.
- Every interaction goes through the Control Plane API v1 (
/v1) behind the API Gateway (D-14).
3. Open source component and developed part
- Open source: OpenBao, KMS cloud ou HSM PKCS#11
- Developed: API and key metadata.
- External integration through an adapter
eai/integrations/<system>.pywith an in-process fallback when the URL is not configured.
4. Data model
Tables (schema eai, tenant_id RLS):
eai.encryption_keys
Common columns: id uuid, tenant_id uuid NOT NULL, created_at, updated_at; RLS policy current_setting('app.tenant_id', true)::uuid.
5. Contract
- Applied contract: no manifest
- Key fields:
key_id, version, algorithm - Validation:
POST /v1/contracts/{name}/validate; manifest apply:POST /v1/manifests/apply.
6. API endpoints
POST /v1/encryption/encryptPOST /v1/encryption/decryptGET /v1/encryption/keysPOST /v1/encryption/keysPOST /v1/encryption/keys/{id}/rotate
Request POST /v1/encryption/encrypt:
{
"key": "key_tenant_main",
"plaintext_base64": "SGVsbG8="
}
Response:
{
"ciphertext": "vault:v3:Zm9v...",
"key_version": 3
}
7. SDK examples
Python:
from enterprise_ai import EnterpriseAI
client = EnterpriseAI(base_url="<control-plane-url>", api_key="eai_xxx_secret")
c = client.encryption.encrypt(b"Hello", key="key_tenant_main")
TypeScript:
import { EnterpriseAI } from "@enterprise-ai/sdk";
const client = new EnterpriseAI({ baseUrl: "<control-plane-url>", apiKey: process.env.EAI_API_KEY });
const c = await client.encryption.encrypt({ key: "key_tenant_main", plaintext_base64: "SGVsbG8=" });
Java:
EnterpriseAIClient client = EnterpriseAIClient.builder()
.baseUrl("<control-plane-url>")
.apiKey(System.getenv("EAI_API_KEY"))
.build();
JsonNode c = client.encryption().encrypt(Map.of("key", "key_tenant_main", "plaintext", "Hello"));
Go:
c, _ := eai.NewClient(eai.WithBaseURL("<control-plane-url>"), eai.WithAPIKey(os.Getenv("EAI_API_KEY")))
ct, _ := c.Encryption.Encrypt(ctx, "key_tenant_main", []byte("Hello"))
8. Configuration
- Environment variables:
EAI_OPENBAO_URL,EAI_OPENBAO_TRANSIT_MOUNT,EAI_DATABASE_URL - Helm values keys:
global.openbao,global.secretsMode
9. Security controls
- The key never leaves OpenBao/HSM
- Rotation restricted to security_officer
- Every request carries the tenant resolved from the credential; PostgreSQL RLS
- Every mutation and policy decision writes a hash-chained audit event
10. Observability
- Prometheus metrics:
eai_crypto_ops_total{op} - Traces: OpenTelemetry spans with GenAI semantic conventions (
gen_ai.operation.name,gen_ai.agent.id,gen_ai.tool.name), attributeseai.tenant_id,eai.run_id,traceparentpropagation. - Audit actions:
encryption.key.create,encryption.key.rotate,encryption.decrypt
11. FinOps units
- KMS/HSM operations.
- Emitted as Usage Event (
POST /v1/finops/usage) with tenant, project, agent and run.
12. Failure modes and resilience
- Old versions kept for decryption
- Normalized errors (error envelope, message_i18n en/fr)
13. Standalone adoption (client of a client)
- enterprise_ai.encryption + OpenBao.
- SDK:
enterprise_ai.privacy / dlp / knowledge_bases / memory / retention / lineage - Minimal deployment: Helm chart with
controlPlane.enabled=trueand PostgreSQL; disabled external components use their in-process fallback.
14. Acceptance tests
- Decryption after rotation works
- Cross-tenant access refused
- Error returned in fr with Accept-Language: fr
Governed RAG (kit L4)
eai.crypto.envelope: Tink envelope encryption (one AES256-GCM data key per message, wrapped by an OpenBao transit or local dev key encryption key), rotation, re-wrap without touching the payload, decryption with an old version until it is retired. Tests: tests/test_data_envelope_tink.py.