SaltDns.Certificates.Store behaviour (Salt v1.0.0)

Where the private keys and chains of certificate versions are kept: one immutable object per version, certificates/<certificate id>/<serial>, written once and never overwritten. Salt DNS encrypts every object itself (SaltDns.Certificates.StoreCrypto) before it reaches the backend, so the backend only ever holds ciphertext. Postgres holds the facts about a version, never its private key.

Two backends implement this behaviour: SaltDns.Certificates.Store.S3 (any S3-compatible service, Garage is the target) and SaltDns.Certificates.Store.Local (a directory, for development and tests). Choose with config :salt_dns, SaltDns.Certificates, store: :s3 | :local.

The only objects that are ever deleted are the short-lived ones holding the key of an order that has not yielded a certificate yet (pending/...).

Summary

Callbacks

Writes the object only if it does not exist yet: {:error, :exists} otherwise.

Functions

The configured backend module.

Deletes an object (only for pending_key/2 objects).

The object key of the key of an order that has no certificate yet.

Reads and decrypts the object at key.

The id of the store key an existing object was encrypted with.

The object key of a version.

Encrypts plaintext and writes it at key. Returns the id of the store key used. An existing object is an error ({:error, :exists}).

Types

key()

@type key() :: String.t()

Callbacks

delete(key)

@callback delete(key()) :: :ok | {:error, term()}

get(key)

@callback get(key()) :: {:ok, binary()} | {:error, :not_found | term()}

put(key, binary)

@callback put(key(), binary()) :: :ok | {:error, :exists | term()}

Writes the object only if it does not exist yet: {:error, :exists} otherwise.

Functions

backend()

@spec backend() :: module()

The configured backend module.

delete(key)

@spec delete(key()) :: :ok | {:error, term()}

Deletes an object (only for pending_key/2 objects).

pending_key(certificate_id, order_id)

@spec pending_key(integer(), integer()) :: key()

The object key of the key of an order that has no certificate yet.

read(key)

@spec read(key()) :: {:ok, binary()} | {:error, :not_found | :undecryptable | term()}

Reads and decrypts the object at key.

stored_key_id(key)

@spec stored_key_id(key()) :: {:ok, String.t()} | {:error, term()}

The id of the store key an existing object was encrypted with.

version_key(certificate_id, serial)

@spec version_key(integer(), String.t()) :: key()

The object key of a version.

write(key, plaintext)

@spec write(key(), binary()) :: {:ok, String.t()} | {:error, term()}

Encrypts plaintext and writes it at key. Returns the id of the store key used. An existing object is an error ({:error, :exists}).