> ## Documentation Index
> Fetch the complete documentation index at: https://docs.oasm.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Secrets and encryption

> How OASM protects the credentials it stores and hands to scanners: per-workspace envelope encryption, key rotation, sealed job secrets for workers, masking, redaction and an append-only audit trail

OASM holds credentials that are worth more than the data around them: cloud provider keys for asset sync, scanner licences, repository tokens, LLM API keys, SMTP passwords and webhook secrets. This page explains how those secrets are stored, how they travel to the worker that needs them, and how the platform keeps them out of logs, events and API responses.

Operating the keys — generating `ENCRYPTION_KEYS` and rotating them — is covered in [Deployment](https://docs.oasm.io/deployment.md#encryption-keys).

```mermaid theme={null}
flowchart LR
    KEK["KEK<br/>ENCRYPTION_KEYS (last = active)"] -->|wraps| DEK["Workspace DEK<br/>one per workspace"]
    DEK -->|"AES-256-GCM"| Store[("Secrets at rest<br/>integrations, connector profiles,<br/>job config, LLM keys")]
    Store -->|"decrypt at dispatch"| Core["Core API"]
    Core -->|"HPKE seal to the worker's key"| Worker["Worker"]
    Worker -->|"config in ExecuteJob"| Conn["Connector container"]
    Conn -->|"output masked: ***"| Worker
```

## Envelope encryption

Secrets are encrypted in two layers:

* **Key encryption keys (KEKs)** come from the `ENCRYPTION_KEYS` environment variable, a comma-separated list. The **last** key encrypts; earlier keys only decrypt. KEKs never touch the database.
* **Data encryption keys (DEKs)** are random 32-byte keys, one per workspace, generated when the workspace is created. Each DEK is stored in the workspace row **wrapped** (encrypted) by the active KEK.

Workspace secrets are encrypted with that workspace's DEK. A database dump alone therefore reveals nothing, and the secrets of one workspace are encrypted under a different key from every other workspace's. Platform-wide secrets that belong to no workspace, such as the SMTP password, are encrypted directly with the KEK.

Every ciphertext is **AES-256-GCM**, which is authenticated: a wrong key fails loudly instead of returning garbage. Each value is tagged with the id of the key that produced it (`v2:<keyId>:…` for KEK data, `v2:dek:…` for workspace data), so the right key is found again after keys are added or removed.

> [!NOTE]
>
> Outside development, the core API refuses to start unless the active key is random and at least 32 characters long. A default or example value is rejected.

### Key rotation

Rotation is additive. Append a new key to `ENCRYPTION_KEYS` and restart: on boot, an upgrade pass re-wraps every workspace DEK and rewrites every stored secret under the new active key, then logs how many values it changed and whether any value is still readable only with an older key. Only drop an old key once that log says nothing needs it. The pass runs under a distributed lock, so with several API replicas exactly one of them does the work.

## What is encrypted

| Secret | Where it lives | Key |
| - | - | - |
| Integration credentials (cloud provider, ticketing, notification, source-code) | integration config | workspace DEK |
| Connector configuration profiles (scanner API keys, licences, passwords) | tool config profiles | workspace DEK |
| Inline connector config stored on a job | job row | workspace DEK |
| LLM provider API keys and web-search provider keys | AI Studio settings | workspace DEK |
| SMTP password | system settings | KEK |

### Which fields count as secret

Integrations and connectors describe their configuration with a JSON Schema, so secrets are identified **by the schema**, not by hand-written code per tool. A field is sensitive when the schema renders it as a password widget, or when its name looks like a credential (`password`, `secret`, `token`, `api_key`, `access_key`, …). Sensitive fields are:

* encrypted before they are written,
* **masked** in every API response (`****` plus at most the last four characters),
* kept unchanged when a client sends the masked value back on update, so editing other fields of a form never overwrites a stored secret with its mask.

## Getting a secret to the scanner

A scan job may need the plaintext — a Nessus API key, a repository token — on a worker that may run on another network. Three controls apply on the way.

### Release policy

Before anything is decrypted for a worker, the core API checks that the worker is allowed to receive it:

* a **workspace worker** only receives jobs of its own workspace,
* a **provider worker** only receives jobs of its own tool,
* a **cloud worker** (operated by the platform) may receive any job.

A job that fails the check is marked failed and never leaves the core API. The worker's identity comes from its authenticated token, never from an id it sends.

### Sealed job secrets

On first start each worker generates an **HPKE** key pair (RFC 9180; DHKEM P-256, HKDF-SHA256, AES-256-GCM) and sends the public half when it joins. From then on, the core API seals each job's configuration and credential inputs to that key, binding the ciphertext to the job id and the worker id. Only the process holding the private key can open it, so a secret is not readable by anything that sits between the core API and the worker — a TLS-terminating proxy, a packet capture, or a message replayed to a different worker.

A registered key is never replaced on rejoin, so a stolen worker token cannot swap in an attacker's key. If a job cannot be sealed, it is failed rather than sent in the clear. See [Worker and connector runtime](https://docs.oasm.io/architecture/worker-runtime.md#identity-and-joining).

### Masking on the way back

Scanners sometimes echo their command line or configuration. The worker collects the secrets of each job and replaces them with `***` in container logs, raw results and error messages **before** anything is sent back to the core API. A tool that prints its own API key cannot leak it into the job registry, the console or a notification.

Repository credentials for Git organization targets are decrypted only at dispatch and never persisted on the job.

## Secrets in events

Every domain event passes through the [event bridge](https://docs.oasm.io/architecture/event-bridge.md), from which it may reach webhooks, Slack, Telegram and ticketing systems. Payloads are therefore **redacted once, at the producer**: fields whose name looks like a credential are dropped, and values that look like one (an `sk-` key, an `AKIA` access key, a PEM block, a long opaque token) are replaced with `***`. The audit table applies the same redaction again as defence in depth.

## Audit trail integrity

The [audit log](https://docs.oasm.io/audit-log.md) is **append-only in PostgreSQL itself**, not just in application code. A database trigger refuses every `UPDATE`, `DELETE` and `TRUNCATE` on the audit table, with two narrow exceptions that both require a dedicated maintenance role and a transaction-local flag:

* the retention job, which first archives expired rows to daily JSONL files and deletes only after the archive is complete,
* the personal-data sweep, which pseudonymizes the actor of a removed member.

Even an application bug or a compromised API process cannot quietly rewrite history. Exported CSV files neutralize spreadsheet formula injection.

## Related

> [card] [Tenancy and access control](https://docs.oasm.io/architecture/tenancy.md)
>
> How workspaces are kept apart

> [card] [Worker and connector runtime](https://docs.oasm.io/architecture/worker-runtime.md)
>
> Where sealed secrets are opened and how connector containers are isolated

> [card] [Event bridge](https://docs.oasm.io/architecture/event-bridge.md)
>
> Redaction at the producer and the lanes that consume events

> [card] [Deployment](https://docs.oasm.io/deployment.md#encryption-keys)
>
> Generating and rotating `ENCRYPTION_KEYS`


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.