Skip to content
Open
14 changes: 14 additions & 0 deletions changelog.d/8202-approval-seal-outage-row.security.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
- **An approval request whose seal Vault transit cannot check may now get a best-effort,
throttled audit row under the actor `system`.** Under `[store].cipher_provider =
"vault_transit"`, the approval gate's Outage at a request's seal check pages, logs and refuses
as before, and also tries an `approval.seal_check_unavailable` row, without the 503 waiting on
it. The row names the request, not who was refused, and may not be written: it is not tried after
an error that chains an `OSError` (at least a connection error, a timeout, a TLS handshake or
certificate-verification failure, a missing CA file, or a reply head the HTTP client could not
parse) or a gateway or server
timeout reply (HTTP 408 or 504), at most one is tried per request per interval, and the write can fail.
A row that is not tried after such an error, or that is tried and fails, is logged at ERROR and
paged as a lost audit row. A write cancelled when the engine's loop stops is logged at ERROR and
not paged, and a refusal the throttle skips logs and pages no row of its own. The page, log line and 503
text no longer say the request was refused, that nothing was done, or that Vault did not
answer. (`BACKLOG #8202`)
2 changes: 1 addition & 1 deletion docs/PHI.md

Large diffs are not rendered by default.

23 changes: 21 additions & 2 deletions docs/SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -3376,7 +3376,9 @@ least these paths. The alert is keyed `approval:<id>` and carries the row's acti
resolution's lost `approval.approver_provenance` row is keyed `approval:<id>:resolve` instead, so it
cannot fold into a lost release flag on the same request (vault BACKLOG #3438). A lost
`approval.standing_shown` row is keyed `approval:listing`, because it belongs to a listing rather
than to one request.
than to one request. A lost `approval.seal_check_unavailable` row is keyed
`approval:<id>:seal-check`, so it cannot fold into a lost request or outcome row on the same
request.

- a refusal's row, or an outcome row written alone after its status. The log line carries the
row's detail;
Expand All @@ -3391,7 +3393,24 @@ than to one request.
- an outcome whose status write found the row moved, where the read-back does not find this
write's row at its status and decision time, as below. The log line carries the row's detail;
on an interrupted or failed outcome its `recorded` or `compensated` field reads `false` where
another caller moved the row, and `unknown` where the read-back cannot tell.
another caller moved the row, and `unknown` where the read-back cannot tell;
- the best-effort `approval.seal_check_unavailable` row, below. The log line carries the row's
detail.

**Under `vault_transit`, a request whose seal Vault transit cannot check may get a best-effort,
throttled `approval.seal_check_unavailable` row under the actor `system` (vault BACKLOG #8202 item
146).** The gate pages `authority-seal-transit` and tries the row, naming the request whose seal
went unchecked, not who was refused, from where, or for which act. A route that meets it answers
**503** with `Retry-After`; the gate's own read-back after a failed write, and the restart
reconcile, meet the same check, try the row and answer nobody. The row is not tried when the check
met an error that chains an `OSError` (at least a connection error, a timeout, a TLS handshake or
certificate-verification failure, a missing CA file, or a reply head the HTTP client could not
parse) or a gateway or server
timeout reply (HTTP 408 or 504), so the refusal does not hold the store's writer lock for an audit MAC; that row is logged and paged as
lost. Where it is tried, the 503 does not wait on it.
Where it is tried it may still fail to write;
[ADR 0217](adr/0217-an-unverifiable-transit-row-seal-is-denied-like-a-failed-one-and-the-ad-reconciler-ends-sessions-rather-than-holding.md),
*Open audit gaps*, states how, and what stays open.

For some failed writes the gate logs at ERROR and pages nothing. At least this one: a restart
cannot move a leftover `executing` row to `interrupted`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,9 @@ give, or freeze a revocation a failed seal would not**. That is the test each an
A correction, added 2026-11-11: the Outage row's "the refused request itself is audited where the
audit append still works" does not hold for a request the approval gate refuses on an Outage, which
writes no row; that path and two others are named in *Open audit gaps, a correction added
2026-11-11*, in (c).
2026-11-11*, in (c). A later correction, added 2026-12-01: the approval gate's path is gap (3)
there, which that list now records as narrowed, not closed. At least gaps (1), (3), (4), (6) and
(7) there, with its extension, are paths where the Outage row's audit promise does not fully hold.

A correction, added 2026-11-11: the Unverifiable row's audit action and page do not hold on at
least gaps (1), (2), (5) and (6) of *Open audit gaps, a correction added 2026-11-11*, and its
Expand Down Expand Up @@ -1130,6 +1132,39 @@ session, approval, on SQLite, PostgreSQL and SQL Server):
writes no row. The owner ruled on 2026-11-11, in the Lander's session, that this ADR names them
as open and the build merges with them filed: "do it"
(https://github.com/MEFORORG/MessageFoundry/pull/2860#issuecomment-6785384065).
**A correction, added 2026-12-01:** gap (3) is narrowed, not closed (vault BACKLOG #8202 item
146). `_approval_seal_outage` now tries a best-effort, throttled
`approval.seal_check_unavailable` row under the actor `system` beside its page, an `approval.*`
action rather than `integrity.*`, since an Outage records no seal failure. What it records is
the approval row whose seal went unchecked: it does not name who was refused, from where, or for
which act. It is throttled per request on the gate's seal-report interval
(`SEAL_FAILURE_REPORT_INTERVAL_SECONDS`), in each gate and so in each engine process, not across
a cluster, and an attempt spends that interval whether or not it lands, so at least these
refusals write no row of their own: a second refusal on the same request inside the interval,
by any operator; one whose attempt fell in an interval a failed or untried write already spent,
though the append may work again by then; one whose slot the gate's own read-back after a failed
write spent, which tries the row though no caller was refused; and every one whose check met an
error that chains an `OSError` (at least a connection error, a timeout, a TLS handshake or
certificate-verification failure, a missing CA file, or a reply head the HTTP client could not
parse) or a gateway or server timeout reply (HTTP 408 or 504). Under
`vault_transit` the audit append's MAC goes through Transit too, under the store's writer lock,
so where the Outage's error is one of those (`TransitSealUnavailableError.unreachable`) the row
is not tried, so the
refusal does not hold the store's writer lock for an audit MAC; it is logged at ERROR and paged
as lost. Otherwise the row is tried, as a task the gate tracks
and its shutdown drain waits for, which the 503 does not wait on, so no caller drops it; it may
still fail, and a Vault that replies slowly with a failure, or stops replying between the check
and the append, can hold the store's writer lock for as long as the Transit call takes, which Transit's
timeout does not bound (`TRANSIT_REQUEST_TIMEOUT_S`), at most once per request per throttle
interval in each gate while that gate's throttle still remembers the request (it forgets the
oldest past `SEAL_FAILURE_TRACK_MAX` requests), so several refused requests can each hold it in
turn; before this change no append ran on this path. A failed or untried write
is logged and paged as the gate's other soft rows are, under the key `approval:<id>:seal-check`.
A write cancelled when the loop stops is logged at ERROR, not paged. Its page,
WARNING and 503 text no longer say the request was refused, that nothing was done, or that Vault
did not answer, as (c) item 4 requires (item 145), since the same check runs on the gate's
read-back after a write or a release. Gaps (1) and (2) are still open, and so is at least the
extension's list below.
- **Open audit gaps, extended 2026-11-11.** The three paths above are not the whole list. At least
these are open too, named here for filing on vault BACKLOG #8202, and each fails closed. (4) A
disable reads every account: `update_user` asks `is_last_enabled_admin`, which reads every
Expand Down
109 changes: 93 additions & 16 deletions messagefoundry/api/approvals.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
UserRecord,
approval_seal_ok_async,
)
from messagefoundry.transports.http_listener import TEMPORARY_REFUSAL_RETRY_AFTER_SECONDS

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -254,9 +255,12 @@ def _releasing_in_process(approval_id: str) -> bool:
#: files a second request.
REJOIN_SCAN_LIMIT = 1000

#: The ``Retry-After`` seconds on the 503 :meth:`ApprovalGate._verified` raises when a Vault transit
#: Outage leaves a request's seal unchecked (ADR 0217: an Outage answers 503 with ``Retry-After``).
_TRANSIT_OUTAGE_RETRY_AFTER_SECONDS = 5
#: The audit action of the best-effort, throttled row, under the actor ``system``, that the gate
#: writes when a Vault transit Outage leaves a request's seal unchecked (ADR 0217, the Outage row).
#: It names the request, not who was refused; it is not tried after a connection error, a timeout,
#: or a gateway or server timeout reply (HTTP 408 or 504), and may fail to write when it is tried.
#: Not ``integrity.*``: an Outage records no seal failure.
APPROVAL_SEAL_CHECK_UNAVAILABLE_ACTION = "approval.seal_check_unavailable"

#: Faults :meth:`ApprovalGate._read` raises as they are, because they name a defect in the read
#: path, not a store that is down: a 503 inviting a retry would never clear (BACKLOG #3157).
Expand Down Expand Up @@ -707,6 +711,8 @@ def __init__(
self._seal_failures_reported = SealFailureThrottle()
# When each request whose seal Vault transit cannot verify is reported again (ADR 0217).
self._seal_unverifiable_reported = SealFailureThrottle()
# When each request a Vault transit Outage left unchecked is audited again (ADR 0217).
self._seal_outage_reported = SealFailureThrottle()
# When the queue warns again about a request whose params are unreadable (BACKLOG #3252).
self._unreadable_params_reported = SealFailureThrottle()
# When a failed store read of each kind is logged again (BACKLOG #3157): the queue page
Expand Down Expand Up @@ -3245,7 +3251,9 @@ async def _verified(self, found: Any, *, report: bool = True) -> ApprovalRow | N
"""``found`` as a checked :class:`ApprovalRow`, or ``None`` when its seal fails, which is
reported unless ``report`` is False. Its params and requester id are what a release acts on
and what the self-approval refusal compares, so a row changed outside the store acts on
nothing."""
nothing. A Vault transit Outage raises a 503 :class:`ApprovalError` instead, reported by
:meth:`_approval_seal_outage` whatever ``report`` says: a page, and a best-effort,
throttled audit row under the actor ``system``, which may not be written."""
try:
row = ApprovalRow.from_mapping(found)
except RowSealError:
Expand All @@ -3260,13 +3268,17 @@ async def _verified(self, found: Any, *, report: bool = True) -> ApprovalRow | N
await self._approval_seal_unverifiable(row.id, exc)
return None
except TransitSealUnavailableError as exc:
# ADR 0217, the Outage row: refuse the request, record no seal failure, page.
self._approval_seal_outage()
# ADR 0217, the Outage row: record no seal failure, page, start a best-effort,
# throttled system row unless the check was unreachable, and answer 503 without
# waiting on that row. A read-back after a write
# or a release meets this too, so the text says only what was not checked, never what
# was not done.
self._approval_seal_outage(row.id, unreachable=exc.unreachable)
raise ApprovalError(
503,
"Vault transit could not check this approval request's integrity seal, so "
"nothing was done; try again once it answers",
headers={"Retry-After": str(_TRANSIT_OUTAGE_RETRY_AFTER_SECONDS)},
"an approval request's integrity seal could not be checked through Vault "
"transit; try again later",
headers={"Retry-After": str(TEMPORARY_REFUSAL_RETRY_AFTER_SECONDS)},
) from exc
if held:
return row
Expand Down Expand Up @@ -3312,20 +3324,85 @@ async def _approval_seal_unverifiable(
context="a request's integrity seal could not be verified",
)

def _approval_seal_outage(self) -> None:
"""Page a Vault transit Outage met checking a request's seal under the shared
``authority-seal-transit`` subject (ADR 0217, *The four answers*), with no audit row: an
Outage records no seal failure. The WARNING is throttled, as :meth:`_read` throttles a
store fault's, since the queue reads on every page load."""
def _approval_seal_outage(self, approval_id: str, *, unreachable: bool) -> None:
"""Report a Vault transit Outage met checking request ``approval_id``'s seal (ADR 0217,
*The four answers*): a page under the shared ``authority-seal-transit`` subject, every
time; a WARNING, throttled as :meth:`_read` throttles a store fault's, since the queue reads
on every page load; and a best-effort, throttled
:data:`APPROVAL_SEAL_CHECK_UNAVAILABLE_ACTION` row under the actor ``system``, which records
no seal failure. The row names the request whose seal went unchecked, not who was refused
or for what act, and is throttled per request: an attempt spends the slot whether or not it
lands, so a Vault that stays down is not asked for an audit MAC on every page load. A
failed audit write is logged and paged under its own key, not raised: during an Outage the
append may fail too, and the 503 still stands.

When ``unreachable`` (a connection error, a timeout, or a gateway or server timeout reply
(HTTP 408 or 504), :attr:`TransitSealUnavailableError.unreachable`) the row is not tried,
and is logged and paged as lost, so this refusal does not wait on an audit append or hold
the store's writer lock for its MAC; its pages may still make Transit calls of their own
(see :meth:`_alert_lost_audit`). Otherwise the write is started as a task the gate tracks
in ``_inflight``, which :meth:`drain` waits for, and is not awaited: the 503 does not wait
on it, and no caller, cancelled or not, can drop it with no record.

The text names what was not checked and no outcome, and never says Vault did not answer:
this check also runs on the gate's read-back after a write or a release
(:meth:`_read_back_request`), where an operation may have run, and Vault may have answered
with a refusal the probe could not clear (ADR 0217 (c) item 4)."""
reason = (
f"an {APPROVAL_KIND} request's integrity seal could not be checked because Vault"
" transit was unavailable; the request was refused and nothing was done"
f"an {APPROVAL_KIND} request's integrity seal could not be checked through Vault"
" transit, so nothing this check read from it is acted on"
)
if self._read_faults_reported.due("transit-outage"):
log.warning("%s", reason)
pager = getattr(self._store, "seal_pager", None)
if callable(pager):
pager().outage(reason)
if not self._seal_outage_reported.due(approval_id):
return
ref = scrub_log_argument(approval_id)
detail = json.dumps({"kind": APPROVAL_KIND, "approval_id": approval_id})
context = "a request's integrity seal could not be checked through Vault transit"
# Its own key, so a lost row of this best-effort kind cannot fold into, and throttle, the
# page for a lost approval.requested or outcome row on the same request, which a read-back
# after a failed write raises next (as approval:<id>:resolve is kept apart).
alert_key = f"approval:{ref}:seal-check"
if unreachable:
# Under vault_transit the append's audit MAC is a Transit call made under the store's
# writer lock, so against a Vault that the check could not reach it would hold that
# lock until the same timeout again. The row is not tried: it is lost, and reported as
# the gate reports any lost row.
log.error(
"approval %s: %s, but its %s audit row was not tried, since the Transit call "
"failed at the connection level or timed out and the audit append's MAC goes "
"through Transit. Lost detail: %s",
ref,
context,
APPROVAL_SEAL_CHECK_UNAVAILABLE_ACTION,
scrub_log_argument(detail),
)
self._alert_lost_audit(ref, APPROVAL_SEAL_CHECK_UNAVAILABLE_ACTION, key=alert_key)
return
# Started, not awaited, so the 503 does not wait on the append (on the restart reconcile's
# path that wait would sit under _owner_lock). Tracked in _inflight, as _shielded tracks
# its writes, so drain() waits for it and the loop's weak reference cannot drop it: the
# write lands, or its failure is logged and paged by _record_audit_soft, or a cancel or
# an escaped error is logged by _log_orphaned_write.
task = asyncio.ensure_future(
self._record_audit_soft(
ref,
APPROVAL_SEAL_CHECK_UNAVAILABLE_ACTION,
actor="system",
detail=detail,
client=None,
context=context,
alert_key=alert_key,
)
)
# The scrubbed id, as every log line here uses: drain() and the orphan log print it, and
# it comes from a row whose seal went unchecked.
self._inflight[task] = ref
task.add_done_callback(self._forget)
task.add_done_callback(lambda t: _log_orphaned_write(t, ref))

async def _approval_seal_failed(self, approval_id: str) -> None:
"""Report a request whose row failed its integrity seal (BACKLOG #2592): a WARNING, an
Expand Down
3 changes: 2 additions & 1 deletion messagefoundry/pipeline/alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,8 @@ def audit_write_failed(self, name: str, *, action: str) -> None:
id>``, the key :meth:`approval_too_early` uses, ``approval:<approval id>:resolve`` for a
resolution's lost provenance row (vault BACKLOG #3438), and ``approval:listing`` for a lost
``approval.standing_shown`` row, which belongs to a listing rather than to one request
(vault BACKLOG #3747). ``POST /config/reload`` uses
(vault BACKLOG #3747), and ``approval:<approval id>:seal-check`` for a lost
``approval.seal_check_unavailable`` row (vault BACKLOG #8202). ``POST /config/reload`` uses
``config_reload:inline`` when it loses the ``config_reload_attempted`` row it writes before
an ungated reload, and then refuses the reload with 503 (vault BACKLOG #2254). The IdP
step-up return's audit budget uses ``step_up_return:audit_budget:<action>`` when its
Expand Down
Loading
Loading