Skip to content
10 changes: 10 additions & 0 deletions changelog.d/8202-seal-refusal-audit.security.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
- **A Vault transit Outage at an approval request's seal check is audited, and the API answers
more seal refusal types.** Where the audit append still works, the approval gate writes an
`authority.seal_unavailable` audit row, not a seal failure, for a request an Outage refuses at
its seal check, at most once per report interval per request in each process, and pages each
such refusal; its page no longer says that nothing was done. The API's seal backstop now also
answers the Unverifiable and Outage refusal types that a route lets escape, with a 409 or a 503
and `Retry-After` in place of the generic 500. It logs each such refusal, and pages and audits
it, throttled per row, or per route where the refusal names no row. Limits are in
[ADR 0217](../docs/adr/0217-an-unverifiable-transit-row-seal-is-denied-like-a-failed-one-and-the-ad-reconciler-ends-sessions-rather-than-holding.md).
(`BACKLOG #8202`)
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). *(Note 2026-11-29, vault BACKLOG #8202 item 146: the gate now writes an
`authority.seal_unavailable` row each time an Outage refuses its check at
`ApprovalGate._verified`; gap (3)'s note says what that row records.)*

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 @@ -1127,7 +1129,14 @@ session, approval, on SQLite, PostgreSQL and SQL Server):
claim: an Unverifiable answer there goes to `ApprovalGate._store_fault`, which answers 503 and
pages `audit_write_failed`; no `integrity.authority_seal_unverifiable` row is written. (3) A
request refused by an Outage at `ApprovalGate._verified`: `_approval_seal_outage` pages and
writes no row. The owner ruled on 2026-11-11, in the Lander's session, that this ADR names them
writes no row. *(Note 2026-11-29, vault BACKLOG #8202 item 146: `_approval_seal_outage` now
also writes a soft `authority.seal_unavailable` row, not an `integrity.*` action, when an
Outage refuses a check at `ApprovalGate._verified`, the gate's own background reads included.
It writes at most one per report interval per request in each process, and only where the
audit append still works, which on a `vault_transit` store may itself need Transit. The row
names the request, with `system` as its actor and no client address, so it does not say who
was refused. Its reason no longer says the request was refused or that nothing was done
(item 145).)* 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).
- **Open audit gaps, extended 2026-11-11.** The three paths above are not the whole list. At least
Expand Down Expand Up @@ -1173,7 +1182,16 @@ session, approval, on SQLite, PostgreSQL and SQL Server):
page reaches no sink either. Beneath all of these, (c) item 2's catch census test,
(c) item 3's API backstop for both refusal types, and *The four answers*' "The API answers an
Outage with HTTP 503 and `Retry-After`" are not yet built on every path: a refusal no caller maps
reaches the engine's generic handler as a 500. The sign-in audit actions this ADR names,
reaches the engine's generic handler as a 500. *(Note 2026-11-29, vault BACKLOG #8202 item 161:
the API backstop in `api/auth_routes.py` is now registered for `RowSealError`,
`RowSealUnverifiableError`, `TransitSealUnverifiableError` and `TransitSealUnavailableError`.
It logs each refusal it answers, with the raising site. It pages and soft-audits throttled per
row where the refusal names one, else per route, within each process, so the Outage row's "the
refused request itself is audited" does not hold for every request it answers. A refusal of
those types that an HTTP route lets escape before its response starts no longer reaches the
generic 500. At least a refusal another type carries, such as the `ApprovalError` of item 155,
and one raised after a streamed response has started, still can, and the catch census test and
the CLI's handler are still not built.)* The sign-in audit actions this ADR names,
`auth.login_refused_unavailable` in the Outage row and in (e), `auth.login_refused_unverifiable`
in (e), and the audit rows (e)'s *Control kept* and *The refusal cache* promise a sign-in refusal
writes, are slice 2's sign-in refusals, which the 2026-11-08 build status line lists as not
Expand Down
63 changes: 47 additions & 16 deletions messagefoundry/api/approvals.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,12 @@
from messagefoundry.store.base import Store
from messagefoundry.store.row_seal import (
APPROVAL_KIND,
TRANSIT_OUTAGE_REFUSED_AUDIT_ACTION,
RowSealError,
SealFailureThrottle,
TransitSealUnavailableError,
TransitSealUnverifiableError,
seal_row_ref,
)
from messagefoundry.store.store import (
ANY_CLAIM_OWNER,
Expand All @@ -98,6 +100,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,10 +257,6 @@ 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

#: 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).
_READ_DEFECTS: tuple[type[Exception], ...] = (
Expand Down Expand Up @@ -707,6 +706,10 @@ 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 refused is audited again (vault BACKLOG #8202
# item 146): the queue reads on every page load, and on a vault_transit store the audit
# append may itself wait on Transit, so an unthrottled row would stall every load.
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 @@ -3260,13 +3263,15 @@ 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: refuse the request, record no seal failure, page, and audit
# the refused call itself (vault BACKLOG #8202 item 146). The Retry-After is the shared
# temporary-refusal value (item 153).
await self._approval_seal_outage(row.id)
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)},
"Vault transit could not check this approval request's integrity seal; try again"
" once it answers",
headers={"Retry-After": str(TEMPORARY_REFUSAL_RETRY_AFTER_SECONDS)},
) from exc
if held:
return row
Expand Down Expand Up @@ -3312,20 +3317,46 @@ 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."""
async def _approval_seal_outage(self, approval_id: str) -> 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, then a
soft :data:`~messagefoundry.store.row_seal.TRANSIT_OUTAGE_REFUSED_AUDIT_ACTION` row naming
the request (vault BACKLOG #8202 item 146), from any check this refuses, the gate's own
background reads included. Neither records a seal failure, so no ``integrity.*`` action is
written. The row is written where the audit append still works, at most once per
:data:`~messagefoundry.store.row_seal.SEAL_FAILURE_REPORT_INTERVAL_SECONDS` per request in
this process; its actor is ``system`` and it carries no client address, since this check is
not told who asked. A lost row pages ``audit_write_failed`` under a key of its own, so it
never folds into a lost row of the request's other actions. The WARNING is throttled, as
:meth:`_read` throttles a store fault's, since the queue reads on every page load.

The reason says only that the seal could not be made or checked (ADR 0217 (c) step 4,
item 145): this check also runs where an operation or a write may already have run, at
least in :meth:`_read_back_request`, so it never says that nothing was done."""
ref = seal_row_ref(APPROVAL_KIND, approval_id)
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 made or checked through"
f" Vault transit (approval {ref})"
)
if self._read_faults_reported.due("transit-outage"):
log.warning("%s", reason)
# The page first, so an audit write that raises a defect cannot skip it.
pager = getattr(self._store, "seal_pager", None)
if callable(pager):
pager().outage(reason)
if not self._seal_outage_reported.due(approval_id):
return
await self._record_audit_soft(
ref,
TRANSIT_OUTAGE_REFUSED_AUDIT_ACTION,
actor="system",
detail=json.dumps(
{"kind": APPROVAL_KIND, "approval_id": approval_id, "during": "approval"}
),
client=None,
context="a request's integrity seal could not be made or checked through Vault transit",
alert_key=f"approval:{ref}:seal_unavailable",
)

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
Loading
Loading