Skip to content

safekeys/encrypted-folder [built] ​

A Safekeys folder is the transport unit: an ordinary directory (or object prefix) holding ciphertext blobs, a manifest, and an agent-readable README with no secrets. Folders can be copied, synced, or passed between agents freely — copying increases no cryptographic exposure, and only a live token plus a reachable sidecar and key authority allow use.

Status: built

Why this exists ​

Secrets need to move the way artefacts move — through git, object stores, artefacts folders, and agent handoffs — without each hop being a new exposure. Making the transport unit an inert ciphertext container means the risky part of the journey (copying) carries no risk at all, and the only sensitive operation (resolve) is gated by a token and a privileged process.

Design decisions ​

ordinary-directory [accepted] ​

Decision: Use an ordinary directory or object prefix rather than a custom container format.

Rationale: Any filesystem, object store, or artefact system can carry it with no adapter, and tooling (diff, sync, tar) works unchanged. The security comes from the contents being ciphertext, not from the container.

aes-gcm-or-chacha [accepted] ​

Decision: Encrypt objects with AES-256-GCM or ChaCha20-Poly1305.

Rationale: Both are AEAD constructions with wide hardware acceleration and mature library support, giving confidentiality and integrity without bespoke crypto.

readme-is-a-feature [accepted] ​

Decision: Ship a README.safekeys in every folder, designed to be model-readable.

Rationale: Agents will encounter folders; a clear, secret-free explanation prevents an agent from attempting to extract values or misusing the folder, and keeps the folder self-describing in handoffs.

manifest-is-metadata-only [accepted] ​

Decision: The manifest may hold a wrapped DEK but never plaintext, an unwrapped DEK, or a KEK, enforced structurally via additionalProperties: false.

Rationale: Envelope-wrapped keys are useless without the KEK, which never leaves the key store, so permitting them lets the folder be a self-contained transport unit while granting nothing on its own. Forbidding everything else means a manifest can be leaked in full without exposing a secret. Schema-level rejection is stronger than a documented rule because it cannot be misconfigured.

Consequences: An implementation that encounters an unwrapped DEK in a manifest must refuse and log a security event, since it indicates a compromised writer. Conformance vectors assert the negative cases.

Date: 2026-09-22

objects-path-constraint [accepted] ​

Decision: Require every object path to match ^objects/[A-Za-z0-9][A-Za-z0-9._-]*.enc$.

Rationale: A path constraint prevents two failure modes at once: an unencrypted file masquerading as ciphertext, and path traversal escaping the folder. Both are structural, so the schema can reject them before any code runs.

Consequences: Folders must keep ciphertext strictly under objects/ with an .enc suffix. Enforced by the path-traversal and unencrypted-object-path conformance vectors.

Date: 2026-09-22

How it works ​

Build an encrypted folder (build-folder) ​

Ciphertext objects plus a manifest are written to a directory or object prefix.

  1. Generate — For each secret, generate a random DEK and encrypt the plaintext into objects/<id>.enc.
  2. Generate — Write manifest.json — object ids, content-type hints, token references, wrapping key ids, and hashes.
  3. Generate — Write README.safekeys describing the folder for humans and agents, containing no secrets.
  4. Observe — The folder is now inert; it can be copied or committed without further protection.

Transport a folder (copy-folder) ​

A folder is moved between environments or agents with no unwrap occurring.

  1. Receive — Destination receives the folder or object prefix verbatim.
  2. Observe — No unwrap is attempted; no key material is required to hold the copy.
  3. Observe — Cryptographic exposure is unchanged by the copy.

Guarantees ​

folder-is-inert ​

A folder on its own must be useless without a live token and a reachable key authority.

Acceptance criteria:

  • [ ] Only ciphertext objects, a manifest, and a no-secret README are present
  • [ ] No key material, DEK, or KEK is stored in the folder
  • [ ] Copying the folder does not increase cryptographic exposure

manifest-is-metadata-only ​

The manifest describes structure and references but never values.

Acceptance criteria:

  • [ ] Object ids, content-type hints, token references, wrapping key ids, and hashes only
  • [ ] No plaintext, no recoverable key bytes
  • [ ] A manifest leaking entirely must not yield any secret

readme-is-agent-safe ​

The README is deliberately readable by humans and models.

Acceptance criteria:

  • [ ] Explains what the folder is and how to use it
  • [ ] Contains no secrets and no key material
  • [ ] Safe to surface in an agent's context

Test specifications ​

folder-copy-yields-nothing ​

Given:

  • folder_with_secrets: true

When: copy-folder

Then:

  • assertion: the copied folder contains no plaintext
  • assertion: reading every file in the folder without a sidecar yields no secret

Contracts verified: folder-is-inert

manifest-leak-yields-nothing ​

Given:

  • manifest_only: true

When: build-folder

Then:

  • assertion: no secret is recoverable from manifest.json alone
  • assertion: wrapping key ids are identifiers, not key material

Contracts verified: manifest-is-metadata-only

readme-safe-for-model-context ​

When: build-folder

Then:

  • assertion: README.safekeys contains no secret values
  • assertion: pasting README.safekeys into a model context exposes nothing sensitive

Contracts verified: readme-is-agent-safe

Implementation ​

  • Primary: pkg/protocol/folder.go
  • Test code: pkg/protocol/protocol_test.go
  • Test code status: manual

See Also ​

  • safekeys/envelope-encryption
  • safekeys/secret-transport
  • safekeys/capability-token
  • safekeys/control-plane-db