Alternera.Plugin.Provisional.SecretReads (alternera_plugin_sdk v0.9.0)

Copy Markdown View Source

Provisional: added for the Script step, and a change to it needs a changelog line but no new major (docs/USER_PLUGINS_DESIGN.md).

What a script run read from a store the tenant marked secret (Provisional.Store.secret?/2), and what that means for what the run shows. It is in the SDK so that every plugin that runs scripts against the tenant's stores keeps the same rules with the same code. A plain value the run's engine keeps beside its own state (Script in a Luerl private key), with no process: new/0 at the start of every run, note/4 with each value the run read from a store.

The rules:

  • A run that read from a secret store is marked (read?/1): it may have put the value anywhere it writes, so its step answers {:secret_read, result} and the proxy records every place the step wrote as a secret.
  • The text strings of such a value are collected (texts/1): the strings of at least 4 bytes at any depth, the keys of its objects (a map or a Jason.OrderedObject), not numbers or booleans. Shorter strings are left out, since a value of a letter or two would garble every word holding it. Past 1,000 texts the run keeps :overflow instead, so a run that reads a large secret store per record neither grows without bound nor leaks what it did not keep.
  • A failure's message is scrubbed of those texts (scrub/2): each is replaced by placeholder/0, the longest where two overlap. After an overflow the whole message is withheld. A value the script changed before it reached the message is not found.
  • A failure's error type is matched by name, so it cannot hold a placeholder: one that holds a collected text, or any after an overflow, becomes "failed" (scrub_type/2).
  • An error the language runtime raised after a secret read is withheld whole (withhold/2): the script may have put the value into it in any form (joined, encoded, quoted by the runtime's own formatting), which no replacement can find.

scrub/2 and scrub_type/2 take the value or what texts/1 took out of it, for a message scrubbed where the run's state is not at hand (a called pipeline's failure, scrubbed by the step's process).

Summary

Types

t()

A run's secret reads: whether it read one, and the texts collected.

What a run read from secret stores: the texts, or :overflow past 1000 of them.

Functions

A run that has read nothing from a secret store.

state after the run read value from a store already known to be marked secret: marked, with value's text strings collected (see the module doc).

state after the run read value from store of tenant_id: as it was when the store is not marked secret (Provisional.Store.secret?/2), else note/2. A read of several entries passes their keys with their values, since a key may hold the secret too.

What a value from a secret store is shown as: [secret store value].

Whether the run read a value from a store marked secret.

message with every collected text replaced by placeholder/0, the longest where two overlap; as it is when the run read none; a placeholder for the whole message after an overflow.

The error type a script failed with, or "failed" when the type holds a collected text or the run overflowed.

The texts the run read from secret stores, or :overflow.

The message of an error the language runtime raised: as given, or a fixed text saying it is withheld when the run read from a secret store.

Types

t()

@type t() :: %Alternera.Plugin.Provisional.SecretReads{
  read?: boolean(),
  texts: texts()
}

A run's secret reads: whether it read one, and the texts collected.

texts()

@type texts() :: MapSet.t(String.t()) | :overflow

What a run read from secret stores: the texts, or :overflow past 1000 of them.

Functions

new()

@spec new() :: t()

A run that has read nothing from a secret store.

note(state, value)

@spec note(t(), term()) :: t()

state after the run read value from a store already known to be marked secret: marked, with value's text strings collected (see the module doc).

note(state, tenant_id, store, value)

@spec note(t(), String.t(), String.t(), term()) :: t()

state after the run read value from store of tenant_id: as it was when the store is not marked secret (Provisional.Store.secret?/2), else note/2. A read of several entries passes their keys with their values, since a key may hold the secret too.

placeholder()

@spec placeholder() :: String.t()

What a value from a secret store is shown as: [secret store value].

read?(secret_reads)

@spec read?(t()) :: boolean()

Whether the run read a value from a store marked secret.

scrub(message, texts)

@spec scrub(String.t(), t() | texts()) :: String.t()

message with every collected text replaced by placeholder/0, the longest where two overlap; as it is when the run read none; a placeholder for the whole message after an overflow.

scrub_type(type, texts)

@spec scrub_type(String.t(), t() | texts()) :: String.t()

The error type a script failed with, or "failed" when the type holds a collected text or the run overflowed.

texts(secret_reads)

@spec texts(t()) :: texts()

The texts the run read from secret stores, or :overflow.

withhold(message, secret_reads)

@spec withhold(String.t(), t()) :: String.t()

The message of an error the language runtime raised: as given, or a fixed text saying it is withheld when the run read from a secret store.