Skip to main content

Module withhold

Module withhold 

Source
Expand description

The values srv holds secret (its instance key, an agent’s token, a Vault value it handed to an agent’s process) are never written into an agent’s transcript, and never served to a paired device from one: a line that carries one is stored, and shown to a device, with the value replaced by MARK. A value is matched as it is and in its ordinary spellings (base64, URL-encoded, hex, as JSON holds it: vault::scrub::forms).

The values are registered where srv learns them (a token is minted or loaded, the instance key is made, a Vault value is handed to a process). The registry holds only what can still be used:

  • register keeps a value for the life of the process;
  • hold keeps a value for an owner, until its expiry, until the owner is released (its token revoked, its container removed, its device unpaired) or until the owner holds another value in its place;
  • hold_until keeps a value that works until a given time, and keeps it until then even when a renewed one follows it: the value that was replaced still works, so it stays hidden until it expires;
  • hold_kept keeps a value with no known expiry (a refresh token, an API key) and keeps the values an owner held before it, up to KEPT_PER_OWNER, oldest dropped first;
  • a batch of registrations (register_all) costs one rebuild of the matcher, made when a line next needs it.

The registry is bounded and never fails open. A value up to MAX_POOLED_LEN goes into the one pattern, and the registry holds at most MAX_TOTAL_BYTES of those; a larger value (a certificate bundle, a key file) is held apart and matched by an exact search, up to MAX_VALUE_LEN each and MAX_LARGE_BYTES in all. Within a budget the oldest values an owner holds make room first; a value that does not fit is refused, counted and logged. A pattern that cannot be built is replaced by an exact search over the same values, and if even that is over its limit every line is read as the mark (MARK) in place of its text. Either state is logged once with the counts and reported to the hook (set_alert).

Structs§

Health
The state of the registry, for a health read.

Constants§

KEPT_PER_OWNER
How many values with no known expiry an owner keeps with hold_kept.
MARK
What a withheld value is replaced by.
MAX_LARGE_BYTES
The most the values over MAX_POOLED_LEN hold in all (bytes). Each is kept in every spelling, about 15 times its size, so this bounds what the exact search holds.
MAX_POOLED_LEN
The longest value that goes into the one pattern; a longer one is held apart and matched by an exact search.
MAX_TOTAL_BYTES
The most the pattern’s values hold (bytes of values, not of spellings): past it the oldest values an owner holds make room.
MAX_TRUSTED_LIFE_MS
The longest a value is trusted to keep working (ms from now): an expiry beyond it is not believed, and the value is held as one with no known expiry (hold_kept).
MAX_VALUE_LEN
The longest value the registry takes (bytes): a longer one is refused.
MIN_LEN
Shorter values are not registered: matching them would mangle ordinary text.
UNTIL_PER_OWNER
How many values an owner holds with hold_until at once: past it the one that expires first is dropped (the value just held never is), so what one owner is given cannot crowd out the values of the others.

Functions§

health
The state of the registry now.
hold
Withholds value for owner, in place of what the owner held before, until expires_at (unix ms; None for no expiry) or until the owner is released. Holding the value the owner already holds changes nothing.
hold_kept
Withholds value for owner with no expiry, until the process ends or the owner is released. The values the owner kept before it stay withheld too, up to KEPT_PER_OWNER: past that the oldest is dropped. Keeping the same value again changes nothing.
hold_until
Withholds value for owner until expires_at (unix ms), when it stops working. A renewed value the owner holds next with hold_until does not take its place: the value that was replaced still works until its own expiry, so it stays withheld until then. Holding the same value and expiry again changes nothing.
holds
Whether text holds a registered value, in any of its spellings: the same matcher text replaces with. Always true when matching is closed.
in_place
text over each line, in place.
lines
text over transcript bytes (NDJSON lines); bytes that are not UTF-8 are left as they are, except when matching is closed: then every line is the mark.
register
Registers value to be withheld from now on, for the life of the process. A value shorter than MIN_LEN and one already registered change nothing.
register_all
register for each of values, under one lock: the matcher is built once for the lot, when a line next needs it.
release
Stops withholding what owner holds: its value no longer works.
release_all
release for what owner holds and what it holds with hold_until.
release_prefix
release_all for every owner whose name starts with prefix.
set_alert
Sets what is told when the registry refuses a value or degrades its matching: one line with the counts, never a value. Called outside the registry’s lock, so it may read or write the registry. The first call wins.
text
text with every registered value replaced by MARK; the text itself when it holds none. Never the text of a line when matching is closed: then every line is the mark.