From 37f5c2b85f5a7e021cf5017ed300236bb18c5ca3 Mon Sep 17 00:00:00 2001 From: Scott Hall Date: Wed, 2 Dec 2026 17:23:56 -0600 Subject: [PATCH 1/5] A refused service-account bind pages as a configuration refusal A service-account bind the directory refuses with invalidCredentials (49) now reads as MISCONFIGURED to the AD session reconciler instead of UNAVAILABLE. LdapUnansweredError carries refused_bind, set by _unanswered for a bind refused with a code in _REFUSING_BIND_CODES, and configuration is true for it. The refusal's text now says the engine reads it as a fault in the configuration. The misconfigured alert's message names [auth].ad_bind_dn and its password first, inside the 200-character cut. Docs and a changelog fragment follow. BACKLOG #8161 item 1 (the owner's reserve build). Verified-by: tests --- .../refused-service-bind-pages.changed.md | 8 + docs/CONFIGURATION.md | 9 +- docs/SECURITY.md | 3 +- messagefoundry/auth/ldap.py | 44 +++-- messagefoundry/auth/reconcile.py | 6 +- messagefoundry/auth/service.py | 16 +- ...est_ldap_refused_service_bind_reconcile.py | 165 ++++++++++++++++++ tests/test_ldap_service_bind_and_release.py | 3 +- 8 files changed, 222 insertions(+), 32 deletions(-) create mode 100644 changelog.d/refused-service-bind-pages.changed.md create mode 100644 tests/test_ldap_refused_service_bind_reconcile.py diff --git a/changelog.d/refused-service-bind-pages.changed.md b/changelog.d/refused-service-bind-pages.changed.md new file mode 100644 index 0000000000..0544654ce4 --- /dev/null +++ b/changelog.d/refused-service-bind-pages.changed.md @@ -0,0 +1,8 @@ +- **A service-account bind the directory refuses with invalidCredentials now pages on every + reconcile pass.** The AD session reconciler read a wrong, locked or expired `[auth].ad_bind_dn` + password as a directory outage, which paged only once the outage lasted + `[auth].ad_reconcile_outage_passes` passes, although the refusal recurs until the password or the + account is fixed. It now reads as a configuration refusal, like a bind refused for its DN: each + such pass raises `ad_reconcile_aborted` with reason `directory_misconfigured` and audits + `auth.ad_reconcile_misconfigured`. Neither reading strikes or revokes an account. The alert's + message now names `[auth].ad_bind_dn` and its password first. diff --git a/docs/CONFIGURATION.md b/docs/CONFIGURATION.md index 33a9677946..c1ec1d625b 100644 --- a/docs/CONFIGURATION.md +++ b/docs/CONFIGURATION.md @@ -1023,10 +1023,11 @@ WARNING lines that name each faulting account stop. A configuration refusal opens its own `ad_reconcile_aborted` instance as well, with reason `directory_misconfigured` and source `directory-reconciler-misconfigured` (BACKLOG #3010). The reconciler raises it on every pass in which the directory refuses a search with noSuchObject, -invalidDNSyntax or insufficientAccessRights, as a deleted or moved search base does. Before #3010 -such a base read as "not found" for every account. Nothing resolves it automatically either. A -search base changes only on a restart, so resolve it by hand once the base is fixed and the ERROR -line naming the code stops. +invalidDNSyntax or insufficientAccessRights, as a deleted or moved search base does, or refuses the +service-account bind with one of those codes or invalidCredentials, as a wrong, locked or expired +`[auth].ad_bind_dn` password does. Before #3010 such a base read as "not found" for every account. +Nothing resolves it automatically either. A search base changes only on a restart, so resolve it by +hand once the base or the service account is fixed and the ERROR line naming the code stops. A paging refusal opens one `ad_reconcile_aborted` instance per account, under the source `directory-reconciler-paging:` (vault BACKLOG #3696). Nothing resolves it automatically. diff --git a/docs/SECURITY.md b/docs/SECURITY.md index cc0c0a8090..ba3ae84ffb 100644 --- a/docs/SECURITY.md +++ b/docs/SECURITY.md @@ -6813,7 +6813,8 @@ probe is refused, faulted or fails, at least one refused and none referred, the `directory_misconfigured`: it judges no account it asked about and revokes nothing, but it pages. Like the fault's, that alert has no inverse; an operator resolves it, and a pass with such a refusal marks no alert clear. A service-account bind the directory refuses with one of those codes -takes the same path, as a malformed `ad_bind_dn` does. **The cost:** while the +takes the same path, as a malformed `ad_bind_dn` does, and so does one it refuses with +invalidCredentials, as a wrong, locked or expired service password does. **The cost:** while the refusal lasts, the refused accounts' sessions are never revoked by the reconciler, so they run to the absolute cap. Other result codes that are not an answer, such as busy or unavailable, are an outage. A second-factor step-up and a passkey assertion, which probe the directory before they diff --git a/messagefoundry/auth/ldap.py b/messagefoundry/auth/ldap.py index 1cca7e89a3..c019c7e4ee 100644 --- a/messagefoundry/auth/ldap.py +++ b/messagefoundry/auth/ldap.py @@ -251,8 +251,10 @@ class LdapUnansweredError(LdapError): the engine's for the case, never text the directory sent. ``operation`` is the engine's own name for what was refused, such as ``service-account bind`` or ``user search``, or empty when the raiser named none, so a refused bind DN and a refused search base read apart. - All three default, so the exception survives a copy or a pickle, which rebuild it from its - message and then restore them from its ``__dict__``. + ``refused_bind`` says the directory refused a service-account bind with one of + :data:`_REFUSING_BIND_CODES` (:func:`_unanswered`). All four default, so the exception survives + a copy or a pickle, which rebuild it from its message and then restore them from its + ``__dict__``. """ def __init__( @@ -262,20 +264,24 @@ def __init__( code: int | None = None, code_name: str = "no code", operation: str = "", + refused_bind: bool = False, ) -> None: super().__init__(message) self.code = code self.code_name = code_name self.operation = operation + self.refused_bind = refused_bind @property def configuration(self) -> bool: - """Whether the code points at the configuration rather than at a passing load - (:data:`_CONFIGURATION_CODES`): noSuchObject (32), invalidDNSyntax (34) and - insufficientAccessRights (50). Such a code recurs on every attempt until the configuration - changes, so the session reconciler reads it as misconfigured, which alerts, and not as - unavailable, which pages only once an outage lasts (BACKLOG #3010, #3709).""" - return self.code in _CONFIGURATION_CODES + """Whether the refusal points at the configuration rather than at a passing load: a code in + :data:`_CONFIGURATION_CODES`, noSuchObject (32), invalidDNSyntax (34) or + insufficientAccessRights (50), or a bind the directory refused (:attr:`refused_bind`), such + as a service-account bind refused with invalidCredentials (49) for a wrong, locked or + expired service password. Such a refusal recurs on every attempt until the configuration + or the account changes, so the session reconciler reads it as misconfigured, which alerts, + and not as unavailable, which pages only once an outage lasts (BACKLOG #3010, #3709).""" + return self.refused_bind or self.code in _CONFIGURATION_CODES class LdapUndecodableError(LdapError): @@ -1029,9 +1035,9 @@ def _refuse_unanswered( read as absence it would read every account absent at once, which the reconciler's mass-revoke breaker does not stop at or under its floor. - **What each caller makes of it.** The session reconciler reads one of the configuration codes - (:attr:`LdapUnansweredError.configuration`) as misconfigured and any other as unavailable. - Neither strikes. A sign-in writes ``auth.login_error``; the nested group search raising means + **What each caller makes of it.** The session reconciler reads one of the configuration codes, + or a service-account bind the directory refused (:attr:`LdapUnansweredError.configuration`), + as misconfigured and any other as unavailable. Neither strikes. A sign-in writes ``auth.login_error``; the nested group search raising means no caller sees a shorter group list. **The cost, named.** Neither reading revokes, so a code that recurs on every pass, such as a @@ -1088,12 +1094,12 @@ def _unanswered(operation: str, code: int | None, *, bind: bool = False) -> Ldap # A configuration code is not read as the directory not answering: the session reconciler # reads it as a configuration refusal, which alerts (LdapUnansweredError.configuration). # A bind the directory refused, such as with invalidCredentials, is an answer, so it is - # called a refusal, not "not an answer" (BACKLOG #3017 L3). + # called a refusal, not "not an answer" (BACKLOG #3017 L3). It is read as a configuration + # refusal too: a wrong, locked or expired service password recurs on every pass until someone + # changes it, so read as an outage it would page only once the outage run grew long enough. refused = bind and code in _REFUSING_BIND_CODES - if code in _CONFIGURATION_CODES: + if code in _CONFIGURATION_CODES or refused: reading = "the engine reads it as a fault in the configuration" - elif refused: - reading = "the engine reads the directory as unavailable until it is fixed" else: reading = "the engine reads it as the directory not answering" verdict = "which refused the bind" if refused else "which is not an answer" @@ -1101,7 +1107,9 @@ def _unanswered(operation: str, code: int | None, *, bind: bool = False) -> Ldap # Keyed on ldap3's name, not the raw code: a directory chooses the code, and ldap3's table is # finite, so the set of warnings stays bounded. _warn_once(f"unanswered: {operation}: {name}", "%s Reported once per code.", message) - return LdapUnansweredError(message, code=code, code_name=name, operation=operation) + return LdapUnansweredError( + message, code=code, code_name=name, operation=operation, refused_bind=refused + ) #: The result codes that end a user bind without judging its password (BACKLOG #3169): busy (51), @@ -1704,7 +1712,9 @@ def _refuse_service_bind(conn: Any) -> NoReturn: :func:`_refuse_unanswered`, as a search's does: a referral is refused by name, so the reconciler reads it as referred and alerts (BACKLOG #2538), and any other code is named with ldap3's name for it and the hint for it, never the directory's diagnostic message, so an - operator still sees ``invalidCredentials`` for a wrong service password. A bind response + operator still sees ``invalidCredentials`` for a wrong service password. A code in + :data:`_REFUSING_BIND_CODES` the reconciler reads as misconfigured, which alerts on every pass + (:attr:`LdapUnansweredError.configuration`); any other as an outage. A bind response carrying the referral's hosts never reaches here: ldap3 cannot decode one, and :func:`_ldap3_call` refuses it first. A result that is not a dict, or one that reads success although the bind did not bind, still refuses, naming no code. diff --git a/messagefoundry/auth/reconcile.py b/messagefoundry/auth/reconcile.py index b04c1bdd07..e0df573c62 100644 --- a/messagefoundry/auth/reconcile.py +++ b/messagefoundry/auth/reconcile.py @@ -126,8 +126,10 @@ class ProbeOutcome(Enum): FAULT = "probe_fault" #: The directory refused the search with a result code that points at the configuration rather #: than at a passing load: noSuchObject, invalidDNSyntax or insufficientAccessRights - #: (``LdapUnansweredError.configuration``, BACKLOG #3010). A deleted or moved search base, or one - #: the service account may not read, answers so for every account. Contributes nothing for this + #: (``LdapUnansweredError.configuration``, BACKLOG #3010), or refused the service-account bind, + #: such as with invalidCredentials for a wrong, locked or expired service password. A deleted or + #: moved search base, or one the service account may not read, or a refused service bind, + #: answers so for every account. Contributes nothing for this #: account, like :attr:`UNAVAILABLE`: no strike, no revocation, no strike reset, no recorded #: outcome, and it never moves the ADR 0195 hold. Unlike it, it alerts, because it recurs on #: every pass until the configuration is fixed: read as unavailable, it would stop revocation diff --git a/messagefoundry/auth/service.py b/messagefoundry/auth/service.py index 973e0140ac..27f50451e0 100644 --- a/messagefoundry/auth/service.py +++ b/messagefoundry/auth/service.py @@ -10218,9 +10218,10 @@ async def _probe_principal(self, user: UserRecord) -> reconcile.Probe: except LdapError as exc: if isinstance(exc, LdapUnansweredError) and exc.configuration: # BACKLOG #3010. A deleted or moved search base, or one the service account may not - # read, refuses every probe on every pass. Read as UNAVAILABLE it would stop - # revocation without a page; MISCONFIGURED alerts instead, and never strikes or - # revokes this account. DEBUG here, as for a referral: the reconciler logs one + # read, refuses every probe on every pass, and so does a service-account bind the + # directory refused, such as for a wrong service password. Read as UNAVAILABLE it + # would stop revocation without a page; MISCONFIGURED alerts instead, and never + # strikes or revokes this account. DEBUG here, as for a referral: the reconciler logs one # ERROR per pass carrying the first refusal's text. That text is the engine's own, # naming the operation and the code, never the directory's diagnostic message. _log.debug("directory probe of %s was refused: %s", user.username, exc) @@ -12221,6 +12222,9 @@ async def _record_reconcile_misconfigured( BACKLOG #3010. A search that ends with noSuchObject, invalidDNSyntax or insufficientAccessRights says the configured base, or the service account's right to read it, is wrong, not that the account is gone (:attr:`~reconcile.ProbeOutcome.MISCONFIGURED`). + So does a service-account bind the directory refused, such as with invalidCredentials for a + wrong, locked or expired service password, which is why the message names + ``[auth].ad_bind_dn`` and its password first. It leaves that account unjudged: no strike and no revocation. A deleted or moved search base refuses every account on every pass, so while it lasts nothing is revoked and the sessions run to the absolute cap. Before #3010 such a search read as "not found", which tripped the @@ -12251,9 +12255,9 @@ async def _record_reconcile_misconfigured( # The settings to change come first: the store keeps only the first 200 characters of an # alert instance's reason, as `_record_reconcile_referral` says. self._reconcile_misconfigured_alert = ( - "LDAP configuration refused: check [auth].ad_user_search_base, " - "[auth].ad_group_search_base and the read rights of [auth].ad_bind_dn. A refused " - "account is never revoked while the refusal lasts. " + "LDAP configuration refused: check [auth].ad_bind_dn, its password and rights, " + "[auth].ad_user_search_base and [auth].ad_group_search_base. A refused account is " + "never revoked while the refusal lasts. " f"{len(plan.misconfigured)} of {plan.asked} signed-in directory account(s) asked were " f"refused for the configuration and left unjudged. {others} So a refused account's " "sessions run to [auth].session_absolute_hours. The ERROR log line for each such pass " diff --git a/tests/test_ldap_refused_service_bind_reconcile.py b/tests/test_ldap_refused_service_bind_reconcile.py new file mode 100644 index 0000000000..5cda904795 --- /dev/null +++ b/tests/test_ldap_refused_service_bind_reconcile.py @@ -0,0 +1,165 @@ +# SPDX-License-Identifier: AGPL-3.0-or-later +# Copyright (C) 2026 MessageFoundry Foundation, LLC and contributors +"""A service-account bind the directory refuses with invalidCredentials (49) is a configuration +refusal to the session reconciler, not an outage (BACKLOG #3010, #3017 L3). + +The refusal's own text tells the operator to fix ``[auth].ad_bind_dn`` and its password. Read as an +outage, the reconciler would page only once the run of outage passes reached +``[auth].ad_reconcile_outage_passes``, although a wrong, locked or expired service password recurs on +every pass until someone changes it. It now reads as ``MISCONFIGURED``, which alerts on every pass, +like a bind refused with a code that names its DN. Neither reading strikes or revokes. + +The controls: an outage code on the same bind, and 49 on an operation that is not a bind, still +read as the directory not answering. + +Synthetic data only; nothing here touches PHI. +""" + +from __future__ import annotations + +import copy +import pickle +from types import SimpleNamespace +from typing import Any + +import ldap3 +import pytest +from ldap3.core.results import ( + RESULT_BUSY, + RESULT_INVALID_CREDENTIALS, + RESULT_INVALID_DN_SYNTAX, + RESULT_UNAVAILABLE, +) + +from messagefoundry.auth import ldap as ldap_module +from messagefoundry.auth.ldap import LdapUnansweredError +from messagefoundry.auth.reconcile import MISCONFIGURED_ABORT, OUTAGE_ABORT, ProbeOutcome +from tests.test_ad_user_account_control import ( + _alive, + _audited, + _pass, + _settings, + _signed_in_estate, +) +from tests.test_approval_requester_recheck import _Sink + +#: The service account the estate's settings bind as. +_SERVICE_DN = _settings().ad_bind_dn + + +@pytest.fixture(autouse=True) +def _fresh_warnings(monkeypatch: pytest.MonkeyPatch) -> None: + """Each test sees its own once-per-process warnings.""" + monkeypatch.setattr(ldap_module, "_object_guid_shapes_warned", set()) + + +@pytest.mark.parametrize( + ("operation", "code", "bind", "configuration"), + [ + pytest.param("service-account bind", RESULT_INVALID_CREDENTIALS, True, True, id="bind-49"), + pytest.param("service-account bind", RESULT_INVALID_DN_SYNTAX, True, True, id="bind-34"), + # THE CONTROLS: a code that judged nothing, and 49 on an operation that is not a bind. + pytest.param("service-account bind", RESULT_UNAVAILABLE, True, False, id="bind-52"), + pytest.param("service-account bind", None, True, False, id="bind-no-code"), + pytest.param("user search", RESULT_INVALID_CREDENTIALS, False, False, id="search-49"), + pytest.param("user bind", RESULT_BUSY, False, False, id="user-bind-51"), + ], +) +def test_a_refused_bind_reads_as_a_configuration_refusal( + operation: str, code: int | None, bind: bool, configuration: bool +) -> None: + """RED before the fix for ``bind-49``: the refusal read as the directory being unavailable.""" + refusal = ldap_module._unanswered(operation, code, bind=bind) + assert refusal.configuration is configuration + reads_configuration = "the engine reads it as a fault in the configuration" in str(refusal) + assert reads_configuration is configuration, str(refusal) + + +def test_the_configuration_reading_survives_a_copy_and_a_pickle() -> None: + """``BaseException`` rebuilds from its message, then restores the attributes from its + ``__dict__``, so the reading must live there.""" + refusal = ldap_module._unanswered("service-account bind", RESULT_INVALID_CREDENTIALS, bind=True) + for clone in (copy.copy(refusal), pickle.loads(pickle.dumps(refusal))): + assert isinstance(clone, LdapUnansweredError) + assert clone.configuration is True + assert (str(clone), clone.code) == (str(refusal), RESULT_INVALID_CREDENTIALS) + + +def _refuse_the_service_bind(monkeypatch: pytest.MonkeyPatch, code: int) -> None: + """Over the estate's ldap3 double, end the service account's bind with ``code``, as ldap3 + leaves a refused bind: ``bind()`` answers ``False`` and the result carries the code.""" + base = ldap3.Connection + + class Refusing(base): # type: ignore[misc, valid-type] + def __init__(self, *args: Any, **kwargs: Any) -> None: + super().__init__(*args, **kwargs) + # A refused bind's socket is closed without an unbind; the estate's double has none. + self.strategy = SimpleNamespace(close=lambda: None) + + def bind(self) -> bool: + if self._bind_dn == _SERVICE_DN: + self.result = {"result": code, "description": "x", "type": "bindResponse"} + return False + return bool(super().bind()) + + monkeypatch.setattr(ldap3, "Connection", Refusing) + + +@pytest.mark.parametrize( + ("code", "misconfigured"), + [ + pytest.param(RESULT_INVALID_CREDENTIALS, True, id="49-invalidCredentials"), + # THE CONTROL: an outage code on the same bind is still an outage. + pytest.param(RESULT_UNAVAILABLE, False, id="52-unavailable"), + ], +) +async def test_a_refused_service_bind_pages_on_every_pass_and_never_revokes( + monkeypatch: pytest.MonkeyPatch, code: int, misconfigured: bool +) -> None: + """Through the real authenticator and the real reconciler. Three signed-in accounts, and a + service bind the directory refuses on every pass. + + RED before the fix for 49: each pass was a plain outage, which paged only once the run reached + ``[auth].ad_reconcile_outage_passes``.""" + names = ["user00", "user01", "user02"] + outage_passes = 2 + passes = 4 + async with _signed_in_estate(monkeypatch, names, ad_reconcile_outage_passes=outage_passes) as ( + _directory, + service, + store, + tokens, + ): + _refuse_the_service_bind(monkeypatch, code) + user = await store.get_user_by_username(names[0]) + assert user is not None + expected = ProbeOutcome.MISCONFIGURED if misconfigured else ProbeOutcome.UNAVAILABLE + assert (await service._probe_principal(user)).outcome is expected + + sink = _Sink() + for n in range(1, passes + 1): + plan = await _pass(service, sink) + assert plan.revocations == () + if misconfigured: + assert plan.aborted == MISCONFIGURED_ABORT + assert plan.outage_passes == 0 + else: + assert plan.directory_outage + assert plan.outage_passes == n + assert await _alive(service, tokens) == set(names) + assert await _audited(store, "auth.ad_session_revoked") == [] + refused = await _audited(store, "auth.ad_reconcile_misconfigured") + assert len(refused) == (passes if misconfigured else 0) + pages = [e[1] for e in sink.events if e[0] == "ad_reconcile_aborted"] + if misconfigured: + assert pages == ["directory-reconciler-misconfigured"] * passes + alert = service.directory_reconcile_misconfigured + assert alert is not None + # The setting a refused bind points at leads the message, inside the store's + # 200-character cut of an alert instance's reason. + assert "[auth].ad_bind_dn" in alert[:200] and "password" in alert[:200], alert + assert "never revoked while the refusal lasts" in alert[:200], alert + else: + outage = [e[2]["reason"] for e in sink.events if e[1] == "directory-reconciler-outage"] + assert pages == ["directory-reconciler-outage"] and outage == [OUTAGE_ABORT] + assert service.directory_reconcile_misconfigured is None diff --git a/tests/test_ldap_service_bind_and_release.py b/tests/test_ldap_service_bind_and_release.py index f53c41e913..ae4878782a 100644 --- a/tests/test_ldap_service_bind_and_release.py +++ b/tests/test_ldap_service_bind_and_release.py @@ -315,7 +315,6 @@ def test_any_other_service_bind_refusal_names_its_result_code() -> None: assert dc.searches == [] -_REFUSED = "which refused the bind; the engine reads the directory as unavailable until it is fixed" _CONFIGURATION = "which refused the bind; the engine reads it as a fault in the configuration" _NO_ANSWER = "which is not an answer; the engine reads it as the directory not answering" @@ -323,7 +322,7 @@ def test_any_other_service_bind_refusal_names_its_result_code() -> None: @pytest.mark.parametrize( ("operation", "code", "bind", "verdict"), [ - pytest.param("service-account bind", 49, True, _REFUSED, id="bind-49"), + pytest.param("service-account bind", 49, True, _CONFIGURATION, id="bind-49"), pytest.param("service-account bind", 34, True, _CONFIGURATION, id="bind-34"), pytest.param("service-account bind", 8, True, _NO_ANSWER, id="bind-8-judged-nothing"), pytest.param("service-account bind", 52, True, _NO_ANSWER, id="bind-52-outage"), From f155529c39540847c8d6cb3f3bf2e6a384f3e278 Mon Sep 17 00:00:00 2001 From: Scott Hall Date: Wed, 2 Dec 2026 17:45:38 -0600 Subject: [PATCH 2/5] Refused service bind: docs, restart and lockout notes, leak test Review round 1 repairs. The docstrings that still called every code outside the configuration set an outage now name a refused service-account bind. The wording no longer calls a lockout a password state or says it lasts until someone changes it. CONFIGURATION.md says a corrected service password takes effect only on a restart, and SECURITY.md that each probe sends its own service bind, so a refused password counts toward the account's lockout. The end-to-end test checks that the directory's diagnostic text reaches no audit row, page or log line, and the table gains the strongerAuthRequired control. BACKLOG #8161 item 1. Verified-by: tests --- .../refused-service-bind-pages.changed.md | 13 +++---- docs/CONFIGURATION.md | 11 +++--- docs/SECURITY.md | 4 ++- messagefoundry/auth/ldap.py | 35 +++++++++++-------- messagefoundry/auth/reconcile.py | 19 +++++----- messagefoundry/auth/service.py | 5 ++- ...est_ldap_refused_service_bind_reconcile.py | 33 ++++++++++++++--- 7 files changed, 77 insertions(+), 43 deletions(-) diff --git a/changelog.d/refused-service-bind-pages.changed.md b/changelog.d/refused-service-bind-pages.changed.md index 0544654ce4..de687328be 100644 --- a/changelog.d/refused-service-bind-pages.changed.md +++ b/changelog.d/refused-service-bind-pages.changed.md @@ -1,8 +1,9 @@ - **A service-account bind the directory refuses with invalidCredentials now pages on every - reconcile pass.** The AD session reconciler read a wrong, locked or expired `[auth].ad_bind_dn` - password as a directory outage, which paged only once the outage lasted - `[auth].ad_reconcile_outage_passes` passes, although the refusal recurs until the password or the - account is fixed. It now reads as a configuration refusal, like a bind refused for its DN: each - such pass raises `ad_reconcile_aborted` with reason `directory_misconfigured` and audits + reconcile pass.** The AD session reconciler read a wrong or expired `[auth].ad_bind_dn` password, + or a locked service account, as a directory outage, which paged only once the outage lasted + `[auth].ad_reconcile_outage_passes` passes, although the refusal recurs on every pass while it + lasts. It now reads as a configuration refusal, like a bind refused for its DN: each such pass + raises `ad_reconcile_aborted` with reason `directory_misconfigured` and audits `auth.ad_reconcile_misconfigured`. Neither reading strikes or revokes an account. The alert's - message now names `[auth].ad_bind_dn` and its password first. + message now names `[auth].ad_bind_dn` and its password first. A corrected service password + takes effect only after a restart. diff --git a/docs/CONFIGURATION.md b/docs/CONFIGURATION.md index c1ec1d625b..83311a1bee 100644 --- a/docs/CONFIGURATION.md +++ b/docs/CONFIGURATION.md @@ -1024,10 +1024,13 @@ A configuration refusal opens its own `ad_reconcile_aborted` instance as well, w `directory_misconfigured` and source `directory-reconciler-misconfigured` (BACKLOG #3010). The reconciler raises it on every pass in which the directory refuses a search with noSuchObject, invalidDNSyntax or insufficientAccessRights, as a deleted or moved search base does, or refuses the -service-account bind with one of those codes or invalidCredentials, as a wrong, locked or expired -`[auth].ad_bind_dn` password does. Before #3010 such a base read as "not found" for every account. -Nothing resolves it automatically either. A search base changes only on a restart, so resolve it by -hand once the base or the service account is fixed and the ERROR line naming the code stops. +service-account bind with one of those codes or invalidCredentials, as a wrong or expired +`[auth].ad_bind_dn` password or a locked service account does. Before #3010 such a base read as +"not found" for every account. Nothing resolves it automatically either. A search base changes only +on a restart, and so does the service password: the engine reads `[auth].ad_bind_password` or +`[auth].ad_bind_password_secret` once, at start. Resolve the alert by hand once the base or the +service account is fixed, the engine restarted where its settings changed, and the ERROR line +naming the code stops. A paging refusal opens one `ad_reconcile_aborted` instance per account, under the source `directory-reconciler-paging:` (vault BACKLOG #3696). Nothing resolves it automatically. diff --git a/docs/SECURITY.md b/docs/SECURITY.md index ba3ae84ffb..b2fb5b5ed8 100644 --- a/docs/SECURITY.md +++ b/docs/SECURITY.md @@ -6814,7 +6814,9 @@ probe is refused, faulted or fails, at least one refused and none referred, the Like the fault's, that alert has no inverse; an operator resolves it, and a pass with such a refusal marks no alert clear. A service-account bind the directory refuses with one of those codes takes the same path, as a malformed `ad_bind_dn` does, and so does one it refuses with -invalidCredentials, as a wrong, locked or expired service password does. **The cost:** while the +invalidCredentials, as a wrong or expired service password or a locked service account does. +Each probe still sends its own service bind, so a refused password is sent again for every +account a pass probes, and each try counts toward the service account's lockout. **The cost:** while the refusal lasts, the refused accounts' sessions are never revoked by the reconciler, so they run to the absolute cap. Other result codes that are not an answer, such as busy or unavailable, are an outage. A second-factor step-up and a passkey assertion, which probe the directory before they diff --git a/messagefoundry/auth/ldap.py b/messagefoundry/auth/ldap.py index c019c7e4ee..d0d29683c6 100644 --- a/messagefoundry/auth/ldap.py +++ b/messagefoundry/auth/ldap.py @@ -251,8 +251,10 @@ class LdapUnansweredError(LdapError): the engine's for the case, never text the directory sent. ``operation`` is the engine's own name for what was refused, such as ``service-account bind`` or ``user search``, or empty when the raiser named none, so a refused bind DN and a refused search base read apart. - ``refused_bind`` says the directory refused a service-account bind with one of - :data:`_REFUSING_BIND_CODES` (:func:`_unanswered`). All four default, so the exception survives + ``refused_bind`` says the directory refused a bind the raiser named a bind with one of + :data:`_REFUSING_BIND_CODES` (:func:`_unanswered`); the service-account bind is the only + caller that names one, and a user bind must not, since its refused password is no + configuration fault. All four default, so the exception survives a copy or a pickle, which rebuild it from its message and then restore them from its ``__dict__``. """ @@ -277,10 +279,10 @@ def configuration(self) -> bool: """Whether the refusal points at the configuration rather than at a passing load: a code in :data:`_CONFIGURATION_CODES`, noSuchObject (32), invalidDNSyntax (34) or insufficientAccessRights (50), or a bind the directory refused (:attr:`refused_bind`), such - as a service-account bind refused with invalidCredentials (49) for a wrong, locked or - expired service password. Such a refusal recurs on every attempt until the configuration - or the account changes, so the session reconciler reads it as misconfigured, which alerts, - and not as unavailable, which pages only once an outage lasts (BACKLOG #3010, #3709).""" + as a service-account bind refused with invalidCredentials (49) for a wrong or expired + service password or a locked service account. Such a refusal recurs on every attempt while + it lasts, so the session reconciler reads it as misconfigured, which alerts, and not as + unavailable, which pages only once an outage lasts (BACKLOG #3010, #3709).""" return self.refused_bind or self.code in _CONFIGURATION_CODES @@ -1004,8 +1006,9 @@ def _referral_error(operation: str, message: str) -> LdapReferralError: 50: " insufficientAccessRights means the service account may not read it.", } -#: The codes that point at the configuration rather than at a passing load -#: (:attr:`LdapUnansweredError.configuration`). Kept apart from the hints on purpose: a hint added +#: The codes that point at the configuration rather than at a passing load, on any operation +#: (:attr:`LdapUnansweredError.configuration`, which a refused bind also sets through +#: :data:`_REFUSING_BIND_CODES`). Kept apart from the hints on purpose: a hint added #: for a transient code must not make it page as a misconfiguration. _CONFIGURATION_CODES = frozenset({32, 34, 50}) @@ -1037,14 +1040,16 @@ def _refuse_unanswered( **What each caller makes of it.** The session reconciler reads one of the configuration codes, or a service-account bind the directory refused (:attr:`LdapUnansweredError.configuration`), - as misconfigured and any other as unavailable. Neither strikes. A sign-in writes ``auth.login_error``; the nested group search raising means - no caller sees a shorter group list. + as misconfigured and any other as unavailable. Neither strikes. A sign-in writes + ``auth.login_error``; the nested group search raising means no caller sees a shorter group + list. **The cost, named.** Neither reading revokes, so a code that recurs on every pass, such as a deleted search base, stops offboarding and the role re-diff for as long as it lasts. A - configuration code alerts on every pass it answers, and a pass where nothing else answered - aborts as ``directory_misconfigured``. Any other code reads as an outage, which pages only once - it lasts ``[auth].ad_reconcile_outage_passes`` passes (BACKLOG #3709). + configuration code, or a refused service-account bind, alerts on every pass it answers, and a + pass where nothing else answered aborts as ``directory_misconfigured``. Any other code reads as + an outage, which pages only once it lasts ``[auth].ad_reconcile_outage_passes`` passes + (BACKLOG #3709). This warns once per operation and code, and the text carries no directory text: the code, ldap3's name for it and the operation, never the diagnostic message the directory sent. @@ -1095,8 +1100,8 @@ def _unanswered(operation: str, code: int | None, *, bind: bool = False) -> Ldap # reads it as a configuration refusal, which alerts (LdapUnansweredError.configuration). # A bind the directory refused, such as with invalidCredentials, is an answer, so it is # called a refusal, not "not an answer" (BACKLOG #3017 L3). It is read as a configuration - # refusal too: a wrong, locked or expired service password recurs on every pass until someone - # changes it, so read as an outage it would page only once the outage run grew long enough. + # refusal too: a wrong or expired service password, or a locked service account, recurs on every + # pass while it lasts, so read as an outage it would page only once the outage run grew long. refused = bind and code in _REFUSING_BIND_CODES if code in _CONFIGURATION_CODES or refused: reading = "the engine reads it as a fault in the configuration" diff --git a/messagefoundry/auth/reconcile.py b/messagefoundry/auth/reconcile.py index e0df573c62..a993069200 100644 --- a/messagefoundry/auth/reconcile.py +++ b/messagefoundry/auth/reconcile.py @@ -49,7 +49,7 @@ It too still strikes an UNKEYED row (BACKLOG #3170). A search the directory refused for a reason that points at the configuration is not an outage -either (BACKLOG #3010). A :attr:`ProbeOutcome.MISCONFIGURED` account is left unjudged like an +either (BACKLOG #3010), nor is a service-account bind it refused. A :attr:`ProbeOutcome.MISCONFIGURED` account is left unjudged like an unreachable one, and unlike one it alerts on every pass that probes it. A pass whose only answers are those refusals, faults and failures, at least one such refusal and no referral, aborts as ``directory_misconfigured``, which judges no account it asked about, alerts, and still strikes an @@ -100,7 +100,8 @@ class ProbeOutcome(Enum): #: outcome whatever its account state, because it is not this account's entry. ABSENT = "absent" #: The directory could not be consulted (``LdapError`` — connectivity/bind/config — other than a - #: referral, a configuration code or a response ldap3 could not decode), or a network-class + #: referral, a configuration code, a service-account bind the directory refused or a response + #: ldap3 could not decode), or a network-class #: ``OSError`` escaped the directory layer (BACKLOG #3100). Contributes nothing: no strike, no #: revocation, no strike reset. UNAVAILABLE = "unavailable" @@ -127,13 +128,13 @@ class ProbeOutcome(Enum): #: The directory refused the search with a result code that points at the configuration rather #: than at a passing load: noSuchObject, invalidDNSyntax or insufficientAccessRights #: (``LdapUnansweredError.configuration``, BACKLOG #3010), or refused the service-account bind, - #: such as with invalidCredentials for a wrong, locked or expired service password. A deleted or - #: moved search base, or one the service account may not read, or a refused service bind, - #: answers so for every account. Contributes nothing for this - #: account, like :attr:`UNAVAILABLE`: no strike, no revocation, no strike reset, no recorded - #: outcome, and it never moves the ADR 0195 hold. Unlike it, it alerts, because it recurs on - #: every pass until the configuration is fixed: read as unavailable, it would stop revocation - #: without a page. Before BACKLOG #3010 such a search read as "not found", so a deleted base + #: such as with invalidCredentials for a wrong or expired service password or a locked service + #: account. A deleted or moved search base, one the service account may not read, or a refused + #: service bind answers so for every account. Contributes nothing for this account, like + #: :attr:`UNAVAILABLE`: no strike, no revocation, no strike reset, no recorded outcome, and it + #: never moves the ADR 0195 hold. Unlike it, it alerts, because it recurs on every pass while + #: the configuration or the service account stays wrong: read as unavailable, it would stop + #: revocation without a page. Before BACKLOG #3010 such a search read as "not found", so a deleted base #: struck every account and could trip the breaker. MISCONFIGURED = "misconfigured" #: The row carries no ``directory_object_id``, so it was NOT probed (BACKLOG #2434). A name diff --git a/messagefoundry/auth/service.py b/messagefoundry/auth/service.py index 27f50451e0..acf4f72d88 100644 --- a/messagefoundry/auth/service.py +++ b/messagefoundry/auth/service.py @@ -12223,9 +12223,8 @@ async def _record_reconcile_misconfigured( insufficientAccessRights says the configured base, or the service account's right to read it, is wrong, not that the account is gone (:attr:`~reconcile.ProbeOutcome.MISCONFIGURED`). So does a service-account bind the directory refused, such as with invalidCredentials for a - wrong, locked or expired service password, which is why the message names - ``[auth].ad_bind_dn`` and its password first. - It leaves that account unjudged: no strike and no revocation. A deleted or moved search base + wrong or expired service password or a locked service account, which is why the message + names ``[auth].ad_bind_dn`` and its password first. It leaves that account unjudged: no strike and no revocation. A deleted or moved search base refuses every account on every pass, so while it lasts nothing is revoked and the sessions run to the absolute cap. Before #3010 such a search read as "not found", which tripped the mass-revoke breaker on a large enough estate, and a plain outage would page nobody until diff --git a/tests/test_ldap_refused_service_bind_reconcile.py b/tests/test_ldap_refused_service_bind_reconcile.py index 5cda904795..eff2ef4384 100644 --- a/tests/test_ldap_refused_service_bind_reconcile.py +++ b/tests/test_ldap_refused_service_bind_reconcile.py @@ -5,8 +5,8 @@ The refusal's own text tells the operator to fix ``[auth].ad_bind_dn`` and its password. Read as an outage, the reconciler would page only once the run of outage passes reached -``[auth].ad_reconcile_outage_passes``, although a wrong, locked or expired service password recurs on -every pass until someone changes it. It now reads as ``MISCONFIGURED``, which alerts on every pass, +``[auth].ad_reconcile_outage_passes``, although a wrong or expired service password, or a locked +service account, recurs on every pass while it lasts. It now reads as ``MISCONFIGURED``, which alerts on every pass, like a bind refused with a code that names its DN. Neither reading strikes or revokes. The controls: an outage code on the same bind, and 49 on an operation that is not a bind, still @@ -18,6 +18,7 @@ from __future__ import annotations import copy +import logging import pickle from types import SimpleNamespace from typing import Any @@ -28,6 +29,7 @@ RESULT_BUSY, RESULT_INVALID_CREDENTIALS, RESULT_INVALID_DN_SYNTAX, + RESULT_STRONGER_AUTH_REQUIRED, RESULT_UNAVAILABLE, ) @@ -46,6 +48,10 @@ #: The service account the estate's settings bind as. _SERVICE_DN = _settings().ad_bind_dn +#: Stands for the diagnostic text a directory sends with a refused bind. It must never reach an +#: audit row, an alert or a log line. +_LEAK = "80090308: LdapErr: synthetic-leak-refused-bind" + @pytest.fixture(autouse=True) def _fresh_warnings(monkeypatch: pytest.MonkeyPatch) -> None: @@ -58,8 +64,11 @@ def _fresh_warnings(monkeypatch: pytest.MonkeyPatch) -> None: [ pytest.param("service-account bind", RESULT_INVALID_CREDENTIALS, True, True, id="bind-49"), pytest.param("service-account bind", RESULT_INVALID_DN_SYNTAX, True, True, id="bind-34"), - # THE CONTROLS: a code that judged nothing, and 49 on an operation that is not a bind. + # THE CONTROLS: codes that judged nothing, and 49 on an operation that is not a bind. pytest.param("service-account bind", RESULT_UNAVAILABLE, True, False, id="bind-52"), + pytest.param( + "service-account bind", RESULT_STRONGER_AUTH_REQUIRED, True, False, id="bind-8" + ), pytest.param("service-account bind", None, True, False, id="bind-no-code"), pytest.param("user search", RESULT_INVALID_CREDENTIALS, False, False, id="search-49"), pytest.param("user bind", RESULT_BUSY, False, False, id="user-bind-51"), @@ -98,7 +107,13 @@ def __init__(self, *args: Any, **kwargs: Any) -> None: def bind(self) -> bool: if self._bind_dn == _SERVICE_DN: - self.result = {"result": code, "description": "x", "type": "bindResponse"} + self.result = { + "result": code, + "description": "x", + "message": _LEAK, + "dn": _LEAK, + "type": "bindResponse", + } return False return bool(super().bind()) @@ -114,13 +129,17 @@ def bind(self) -> bool: ], ) async def test_a_refused_service_bind_pages_on_every_pass_and_never_revokes( - monkeypatch: pytest.MonkeyPatch, code: int, misconfigured: bool + monkeypatch: pytest.MonkeyPatch, + caplog: pytest.LogCaptureFixture, + code: int, + misconfigured: bool, ) -> None: """Through the real authenticator and the real reconciler. Three signed-in accounts, and a service bind the directory refuses on every pass. RED before the fix for 49: each pass was a plain outage, which paged only once the run reached ``[auth].ad_reconcile_outage_passes``.""" + caplog.set_level(logging.DEBUG, logger="messagefoundry") names = ["user00", "user01", "user02"] outage_passes = 2 passes = 4 @@ -150,6 +169,10 @@ async def test_a_refused_service_bind_pages_on_every_pass_and_never_revokes( assert await _audited(store, "auth.ad_session_revoked") == [] refused = await _audited(store, "auth.ad_reconcile_misconfigured") assert len(refused) == (passes if misconfigured else 0) + # The directory's diagnostic text reaches no row, page or log line. + assert all(_LEAK not in str(dict(r)["detail"]) for r in refused) + assert all(_LEAK not in str(e[2].get("detail", "")) for e in sink.events) + assert all(_LEAK not in r.getMessage() for r in caplog.records) pages = [e[1] for e in sink.events if e[0] == "ad_reconcile_aborted"] if misconfigured: assert pages == ["directory-reconciler-misconfigured"] * passes From 373fb950fd5a3b15cbdaec56dbbb903e32853150 Mon Sep 17 00:00:00 2001 From: Scott Hall Date: Wed, 2 Dec 2026 17:59:09 -0600 Subject: [PATCH 3/5] Refused service bind pages as a configuration refusal Review round 2 repairs. One helper, _reads_as_configuration, now decides both the refusal's wording and LdapUnansweredError.configuration. The bind parameter's docstrings say it marks the service-account bind and must never be passed for a user bind. The docstrings that still named only a search refusal as misconfigured now name the refused service bind too. SECURITY.md limits the lockout cost to a wrong password. CONFIGURATION.md and the changelog name the password settings rather than ad_bind_dn, and the changelog says the alert has no inverse, even after a lockout ends. The leak check reads the formatted log text, tracebacks included. Long lines are reflowed. Proposed PR title: A service-account bind refused with invalidCredentials pages as a configuration refusal BACKLOG #8161 item 1. Verified-by: tests --- .../refused-service-bind-pages.changed.md | 12 +++++---- docs/CONFIGURATION.md | 4 +-- docs/SECURITY.md | 3 ++- messagefoundry/api/app.py | 5 ++-- messagefoundry/auth/ldap.py | 27 ++++++++++++------- messagefoundry/auth/reconcile.py | 17 ++++++------ messagefoundry/auth/service.py | 13 +++++---- ...est_ldap_refused_service_bind_reconcile.py | 7 ++--- 8 files changed, 52 insertions(+), 36 deletions(-) diff --git a/changelog.d/refused-service-bind-pages.changed.md b/changelog.d/refused-service-bind-pages.changed.md index de687328be..338ff79a68 100644 --- a/changelog.d/refused-service-bind-pages.changed.md +++ b/changelog.d/refused-service-bind-pages.changed.md @@ -1,9 +1,11 @@ - **A service-account bind the directory refuses with invalidCredentials now pages on every - reconcile pass.** The AD session reconciler read a wrong or expired `[auth].ad_bind_dn` password, - or a locked service account, as a directory outage, which paged only once the outage lasted + reconcile pass.** The AD session reconciler read a wrong or expired service password + (`[auth].ad_bind_password` or `[auth].ad_bind_password_secret`), or a locked `[auth].ad_bind_dn` + account, as a directory outage, which paged only once the outage lasted `[auth].ad_reconcile_outage_passes` passes, although the refusal recurs on every pass while it lasts. It now reads as a configuration refusal, like a bind refused for its DN: each such pass raises `ad_reconcile_aborted` with reason `directory_misconfigured` and audits - `auth.ad_reconcile_misconfigured`. Neither reading strikes or revokes an account. The alert's - message now names `[auth].ad_bind_dn` and its password first. A corrected service password - takes effect only after a restart. + `auth.ad_reconcile_misconfigured`. Neither reading strikes or revokes an account. That alert has + no inverse, so resolve it by hand once the bind succeeds again, including after a lockout ends on + its own. The alert's message now names `[auth].ad_bind_dn` and its password first. A corrected + service password takes effect only after a restart. diff --git a/docs/CONFIGURATION.md b/docs/CONFIGURATION.md index 83311a1bee..fd9cde0fab 100644 --- a/docs/CONFIGURATION.md +++ b/docs/CONFIGURATION.md @@ -1024,8 +1024,8 @@ A configuration refusal opens its own `ad_reconcile_aborted` instance as well, w `directory_misconfigured` and source `directory-reconciler-misconfigured` (BACKLOG #3010). The reconciler raises it on every pass in which the directory refuses a search with noSuchObject, invalidDNSyntax or insufficientAccessRights, as a deleted or moved search base does, or refuses the -service-account bind with one of those codes or invalidCredentials, as a wrong or expired -`[auth].ad_bind_dn` password or a locked service account does. Before #3010 such a base read as +service-account bind with one of those codes or invalidCredentials, as a wrong or expired service +password or a locked `[auth].ad_bind_dn` account does. Before #3010 such a base read as "not found" for every account. Nothing resolves it automatically either. A search base changes only on a restart, and so does the service password: the engine reads `[auth].ad_bind_password` or `[auth].ad_bind_password_secret` once, at start. Resolve the alert by hand once the base or the diff --git a/docs/SECURITY.md b/docs/SECURITY.md index b2fb5b5ed8..5c97196665 100644 --- a/docs/SECURITY.md +++ b/docs/SECURITY.md @@ -6816,7 +6816,8 @@ refusal marks no alert clear. A service-account bind the directory refuses with takes the same path, as a malformed `ad_bind_dn` does, and so does one it refuses with invalidCredentials, as a wrong or expired service password or a locked service account does. Each probe still sends its own service bind, so a refused password is sent again for every -account a pass probes, and each try counts toward the service account's lockout. **The cost:** while the +account a pass probes, and each try with a wrong password counts toward the service account's +lockout. **The cost:** while the refusal lasts, the refused accounts' sessions are never revoked by the reconciler, so they run to the absolute cap. Other result codes that are not an answer, such as busy or unavailable, are an outage. A second-factor step-up and a passkey assertion, which probe the directory before they diff --git a/messagefoundry/api/app.py b/messagefoundry/api/app.py index 303a3a5859..04a9cf7fac 100644 --- a/messagefoundry/api/app.py +++ b/messagefoundry/api/app.py @@ -13144,8 +13144,9 @@ def _alert_reconcile_plan(plan: ReconcilePlan, auth: AuthService, sink: AlertSin A search the directory refused for its configuration (BACKLOG #3010) is not an outage either: a search base that was deleted or moved, or that the service account may not read, ends every - search with noSuchObject, invalidDNSyntax or insufficientAccessRights on every pass. Any pass - with such a refusal is ``auth.ad_reconcile_misconfigured`` and becomes one + search with noSuchObject, invalidDNSyntax or insufficientAccessRights on every pass, and a + service-account bind the directory refuses, as for a wrong password, refuses every probe. + Any pass with such a refusal is ``auth.ad_reconcile_misconfigured`` and becomes one ``ad_reconcile_aborted`` alert with reason ``directory_misconfigured``, under its own source label (:data:`_MISCONFIGURED_ALERT_SOURCE`). Like the fault's, it has no inverse. Before #3010 such a base read as "not found" for every account, so it tripped the breaker on an estate diff --git a/messagefoundry/auth/ldap.py b/messagefoundry/auth/ldap.py index d0d29683c6..1c26d66dde 100644 --- a/messagefoundry/auth/ldap.py +++ b/messagefoundry/auth/ldap.py @@ -251,10 +251,9 @@ class LdapUnansweredError(LdapError): the engine's for the case, never text the directory sent. ``operation`` is the engine's own name for what was refused, such as ``service-account bind`` or ``user search``, or empty when the raiser named none, so a refused bind DN and a refused search base read apart. - ``refused_bind`` says the directory refused a bind the raiser named a bind with one of - :data:`_REFUSING_BIND_CODES` (:func:`_unanswered`); the service-account bind is the only - caller that names one, and a user bind must not, since its refused password is no - configuration fault. All four default, so the exception survives + ``refused_bind`` is true when the raiser passed ``bind=True`` to :func:`_unanswered` and the + code is in :data:`_REFUSING_BIND_CODES`. Only the service-account bind passes it; a user bind + must not, since a user's wrong password is no configuration fault. All four default, so the exception survives a copy or a pickle, which rebuild it from its message and then restore them from its ``__dict__``. """ @@ -283,7 +282,7 @@ def configuration(self) -> bool: service password or a locked service account. Such a refusal recurs on every attempt while it lasts, so the session reconciler reads it as misconfigured, which alerts, and not as unavailable, which pages only once an outage lasts (BACKLOG #3010, #3709).""" - return self.refused_bind or self.code in _CONFIGURATION_CODES + return _reads_as_configuration(self.code, refused_bind=self.refused_bind) class LdapUndecodableError(LdapError): @@ -1013,6 +1012,12 @@ def _referral_error(operation: str, message: str) -> LdapReferralError: _CONFIGURATION_CODES = frozenset({32, 34, 50}) +def _reads_as_configuration(code: int | None, *, refused_bind: bool) -> bool: + """Whether a refusal ending with ``code`` points at the configuration: the one rule both the + refusal's wording (:func:`_unanswered`) and :attr:`LdapUnansweredError.configuration` read.""" + return refused_bind or code in _CONFIGURATION_CODES + + def _refuse_unanswered( conn: Any, operation: str, *, answers: frozenset[int] | None = None, bind: bool = False ) -> None: @@ -1058,8 +1063,8 @@ def _refuse_unanswered( without one. Only a test double can. ``answers`` is a parameter so an operation whose answers differ, such as a bind, can reuse this - with its own set; ``bind`` names the operation a bind, for the refusal's wording - (:func:`_unanswered`). A referral is refused first, as a referral, whatever ``answers`` holds, so + with its own set; ``bind`` names the operation the service-account bind, for the refusal's + wording and its configuration reading (:func:`_unanswered`). A referral is refused first, as a referral, whatever ``answers`` holds, so the reconciler still reads it as referred (BACKLOG #2538). """ from ldap3.core.results import RESULT_SUCCESS # lazy, like every ldap3 import here @@ -1084,8 +1089,10 @@ def _refuse_unanswered( def _unanswered(operation: str, code: int | None, *, bind: bool = False) -> LdapUnansweredError: """The refusal for ``operation`` ending with ``code``, warned once per operation and code name. - ``bind`` says the operation was a bind, whose refusing codes (:data:`_REFUSING_BIND_CODES`) - are named as a refusal rather than as no answer. + ``bind`` says the operation was the service-account bind, whose refusing codes + (:data:`_REFUSING_BIND_CODES`) are named as a refusal rather than as no answer and read as a + configuration refusal (:attr:`LdapUnansweredError.refused_bind`). Never pass it for a user + bind: a user's wrong password would then page as a misconfiguration. The text carries the code, ldap3's name for it and the operation, never directory text. """ @@ -1103,7 +1110,7 @@ def _unanswered(operation: str, code: int | None, *, bind: bool = False) -> Ldap # refusal too: a wrong or expired service password, or a locked service account, recurs on every # pass while it lasts, so read as an outage it would page only once the outage run grew long. refused = bind and code in _REFUSING_BIND_CODES - if code in _CONFIGURATION_CODES or refused: + if _reads_as_configuration(code, refused_bind=refused): reading = "the engine reads it as a fault in the configuration" else: reading = "the engine reads it as the directory not answering" diff --git a/messagefoundry/auth/reconcile.py b/messagefoundry/auth/reconcile.py index a993069200..5d857a3ac3 100644 --- a/messagefoundry/auth/reconcile.py +++ b/messagefoundry/auth/reconcile.py @@ -49,11 +49,11 @@ It too still strikes an UNKEYED row (BACKLOG #3170). A search the directory refused for a reason that points at the configuration is not an outage -either (BACKLOG #3010), nor is a service-account bind it refused. A :attr:`ProbeOutcome.MISCONFIGURED` account is left unjudged like an -unreachable one, and unlike one it alerts on every pass that probes it. A pass whose only answers -are those refusals, faults and failures, at least one such refusal and no referral, aborts as -``directory_misconfigured``, which judges no account it asked about, alerts, and still strikes an -UNKEYED row. +either (BACKLOG #3010), nor is a service-account bind it refused. A +:attr:`ProbeOutcome.MISCONFIGURED` account is left unjudged like an unreachable one, and unlike one +it alerts on every pass that probes it. A pass whose only answers are those refusals, faults and +failures, at least one such refusal and no referral, aborts as ``directory_misconfigured``, which +judges no account it asked about, alerts, and still strikes an UNKEYED row. The pass also re-diffs channel scope (ADR 0198, BACKLOG #1957). It revokes when the directory would withdraw or narrow a principal's scope, and it never writes the scope: the next login does, through @@ -134,8 +134,8 @@ class ProbeOutcome(Enum): #: :attr:`UNAVAILABLE`: no strike, no revocation, no strike reset, no recorded outcome, and it #: never moves the ADR 0195 hold. Unlike it, it alerts, because it recurs on every pass while #: the configuration or the service account stays wrong: read as unavailable, it would stop - #: revocation without a page. Before BACKLOG #3010 such a search read as "not found", so a deleted base - #: struck every account and could trip the breaker. + #: revocation without a page. Before BACKLOG #3010 such a search read as "not found", so a + #: deleted base struck every account and could trip the breaker. MISCONFIGURED = "misconfigured" #: The row carries no ``directory_object_id``, so it was NOT probed (BACKLOG #2434). A name #: probe could read another account's entry. No sign-in or step-up admits such a row, so a @@ -430,7 +430,8 @@ def directory_misconfigured(self) -> bool: configuration, faulted or failed, at least one refused for its configuration and none referred (BACKLOG #3010). It judged nothing, like an outage, but it alerts: a deleted or moved search base, or one the service account may not read, stays wrong until someone - fixes it. A pass with such a refusal beside other answers is NOT this; only + fixes it, and a refused service-account bind stays refused while its password is wrong or + expired or the account is locked. A pass with such a refusal beside other answers is NOT this; only ``misconfigured`` says it saw one.""" return self.aborted == MISCONFIGURED_ABORT diff --git a/messagefoundry/auth/service.py b/messagefoundry/auth/service.py index acf4f72d88..ed7f375cec 100644 --- a/messagefoundry/auth/service.py +++ b/messagefoundry/auth/service.py @@ -10221,9 +10221,10 @@ async def _probe_principal(self, user: UserRecord) -> reconcile.Probe: # read, refuses every probe on every pass, and so does a service-account bind the # directory refused, such as for a wrong service password. Read as UNAVAILABLE it # would stop revocation without a page; MISCONFIGURED alerts instead, and never - # strikes or revokes this account. DEBUG here, as for a referral: the reconciler logs one - # ERROR per pass carrying the first refusal's text. That text is the engine's own, - # naming the operation and the code, never the directory's diagnostic message. + # strikes or revokes this account. DEBUG here, as for a referral: the reconciler + # logs one ERROR per pass carrying the first refusal's text. That text is the + # engine's own, naming the operation and the code, never the directory's + # diagnostic message. _log.debug("directory probe of %s was refused: %s", user.username, exc) return reconcile.Probe( user.id, user.username, reconcile.ProbeOutcome.MISCONFIGURED, detail=str(exc) @@ -12224,7 +12225,8 @@ async def _record_reconcile_misconfigured( it, is wrong, not that the account is gone (:attr:`~reconcile.ProbeOutcome.MISCONFIGURED`). So does a service-account bind the directory refused, such as with invalidCredentials for a wrong or expired service password or a locked service account, which is why the message - names ``[auth].ad_bind_dn`` and its password first. It leaves that account unjudged: no strike and no revocation. A deleted or moved search base + names ``[auth].ad_bind_dn`` and its password first. It leaves that account unjudged: no + strike and no revocation. A deleted or moved search base, or a refused service bind, refuses every account on every pass, so while it lasts nothing is revoked and the sessions run to the absolute cap. Before #3010 such a search read as "not found", which tripped the mass-revoke breaker on a large enough estate, and a plain outage would page nobody until @@ -15136,7 +15138,8 @@ def _note_cert_directory_answer(self, answer: reconcile.Probe | str) -> None: """Log the certificate path's directory refusals without logging one line per request. An outage is a refusal that says the directory could not be asked: unreachable, referring, - refusing the search for its configuration (``misconfigured``, BACKLOG #3010), or the probe + refusing the search or the service-account bind for its configuration (``misconfigured``, + BACKLOG #3010), or the probe cap full. It logs one WARNING per outage and, if that WARNING was logged, one INFO on the next answer the directory actually gave, whatever it said about the account. WARNINGs are at least :data:`_CERT_OUTAGE_LOG_INTERVAL_SECONDS` diff --git a/tests/test_ldap_refused_service_bind_reconcile.py b/tests/test_ldap_refused_service_bind_reconcile.py index eff2ef4384..c438752b32 100644 --- a/tests/test_ldap_refused_service_bind_reconcile.py +++ b/tests/test_ldap_refused_service_bind_reconcile.py @@ -6,8 +6,9 @@ The refusal's own text tells the operator to fix ``[auth].ad_bind_dn`` and its password. Read as an outage, the reconciler would page only once the run of outage passes reached ``[auth].ad_reconcile_outage_passes``, although a wrong or expired service password, or a locked -service account, recurs on every pass while it lasts. It now reads as ``MISCONFIGURED``, which alerts on every pass, -like a bind refused with a code that names its DN. Neither reading strikes or revokes. +service account, recurs on every pass while it lasts. It now reads as ``MISCONFIGURED``, which +alerts on every pass, like a bind refused with a code that names its DN. Neither reading strikes or +revokes. The controls: an outage code on the same bind, and 49 on an operation that is not a bind, still read as the directory not answering. @@ -172,7 +173,7 @@ async def test_a_refused_service_bind_pages_on_every_pass_and_never_revokes( # The directory's diagnostic text reaches no row, page or log line. assert all(_LEAK not in str(dict(r)["detail"]) for r in refused) assert all(_LEAK not in str(e[2].get("detail", "")) for e in sink.events) - assert all(_LEAK not in r.getMessage() for r in caplog.records) + assert _LEAK not in caplog.text # formatted records, tracebacks included pages = [e[1] for e in sink.events if e[0] == "ad_reconcile_aborted"] if misconfigured: assert pages == ["directory-reconciler-misconfigured"] * passes From 2e64c0a5feba45d517ea8bfb726c11225baadee8 Mon Sep 17 00:00:00 2001 From: Scott Hall Date: Wed, 2 Dec 2026 19:08:06 -0600 Subject: [PATCH 4/5] A refused service-account bind pages under its own alert source A notifier keys a suspend on the alert's type and source. With the refused service bind folded into directory-reconciler-misconfigured, an operator who suspended that source for a deleted search base would get no page when the service password later expired, where main would still page under the outage source after its pass count. Probe.refused_bind carries LdapUnansweredError.refused_bind out of _probe_principal. plan_pass sets ReconcilePlan.refused_bind and refused_search at both returns that carry misconfigured probes. _alert_reconcile_plan raises a refused bind under the new source directory-reconciler-service-bind, a refused search under the existing source, and both when both happened; a plan naming refusals with neither flag still raises under the existing source. Bind codes 32, 34 and 50 move to the new source too, since the exception already marks them refused_bind. Tests: with the search source suspended, a refused service bind still pages (failed on the held head); a refused search keeps its source and a pass with both raises both, aborted or beside an answer. Docs and changelog name the new source. BACKLOG #8161 (item 1), repair of the Lander's hold on PR 3594. Verified-by: tests --- .../refused-service-bind-pages.changed.md | 5 +- docs/CONFIGURATION.md | 4 +- docs/PHI.md | 2 +- docs/SECURITY.md | 4 +- messagefoundry/api/app.py | 34 +++++-- messagefoundry/auth/reconcile.py | 15 +++ messagefoundry/auth/service.py | 6 +- ...est_ldap_refused_service_bind_reconcile.py | 93 ++++++++++++++++++- 8 files changed, 148 insertions(+), 15 deletions(-) diff --git a/changelog.d/refused-service-bind-pages.changed.md b/changelog.d/refused-service-bind-pages.changed.md index 338ff79a68..194176ced6 100644 --- a/changelog.d/refused-service-bind-pages.changed.md +++ b/changelog.d/refused-service-bind-pages.changed.md @@ -5,7 +5,10 @@ `[auth].ad_reconcile_outage_passes` passes, although the refusal recurs on every pass while it lasts. It now reads as a configuration refusal, like a bind refused for its DN: each such pass raises `ad_reconcile_aborted` with reason `directory_misconfigured` and audits - `auth.ad_reconcile_misconfigured`. Neither reading strikes or revokes an account. That alert has + `auth.ad_reconcile_misconfigured`. A refused service-account bind raises it under its own source, + `directory-reconciler-service-bind`, so suspending the search refusal's + `directory-reconciler-misconfigured` instance does not mute it; a service bind refused with + noSuchObject, invalidDNSyntax or insufficientAccessRights moves to that source too. Neither reading strikes or revokes an account. That alert has no inverse, so resolve it by hand once the bind succeeds again, including after a lockout ends on its own. The alert's message now names `[auth].ad_bind_dn` and its password first. A corrected service password takes effect only after a restart. diff --git a/docs/CONFIGURATION.md b/docs/CONFIGURATION.md index fd9cde0fab..bf0a68969e 100644 --- a/docs/CONFIGURATION.md +++ b/docs/CONFIGURATION.md @@ -1025,7 +1025,9 @@ A configuration refusal opens its own `ad_reconcile_aborted` instance as well, w reconciler raises it on every pass in which the directory refuses a search with noSuchObject, invalidDNSyntax or insufficientAccessRights, as a deleted or moved search base does, or refuses the service-account bind with one of those codes or invalidCredentials, as a wrong or expired service -password or a locked `[auth].ad_bind_dn` account does. Before #3010 such a base read as +password or a locked `[auth].ad_bind_dn` account does. A refused service-account bind raises +under its own source, `directory-reconciler-service-bind`, with the same reason, so suspending +one source's instance does not mute the other. Before #3010 such a base read as "not found" for every account. Nothing resolves it automatically either. A search base changes only on a restart, and so does the service password: the engine reads `[auth].ad_bind_password` or `[auth].ad_bind_password_secret` once, at start. Resolve the alert by hand once the base or the diff --git a/docs/PHI.md b/docs/PHI.md index 2920abe4fc..cc50d9782d 100644 --- a/docs/PHI.md +++ b/docs/PHI.md @@ -2385,7 +2385,7 @@ with materially different PHI profiles, so they get their own rows; stream 4 is | **5. `audit_log` table** (SQLite, Postgres, SQL Server) | who / what / **where-from** / when of auth + PHI *access* and admin actions — plus, while `[security].audit_all_authorization_decisions` is on (**default `true`** since BACKLOG #1277, 2026-09-02, which reversed the ADR 0118 §5 `false`; the internal field it desugars to is `audit_all_authz`, whose old `[diagnostics]` TOML spelling is **refused at load** — ADR 0118), an `authz` row for **every** authorization decision including successes. That is the shipped volume of this stream, not an opt-in addition to it: one row per authenticated request on each `require()`-gated route, and this row's retention cell records that **nothing prunes the table** — `actor`, `action`, `channel_id`, `client`, `detail`, `row_hash` | JSON `detail`; **tamper-evident hash chain** over `prev_hash` + the row (the `client` address is **inside** the chained payload — ADR 0150) | the store database | HIPAA §164.312(b) audit controls; incident response; `verify_audit_chain` integrity checks | `GET /audit` requires **`audit:read`**; `GET /audit/export` requires the separate **`audit:export`** and streams CSV with formula-injection neutralisation, recording its own `audit.export` row *before* streaming; `GET /me/security-events` is a per-user view of the same table | **`[retention].audit_days` is reserved and NOT enforced — keep-forever by design** (the audit-retention requirement, ~6 years — **not** chain-breakage; [§8](#8-retention--purge) states the position and cites its source of record) | `detail` is stored **in the clear** (it is not a cipher-covered column): its protection is that writers store at least filter shapes, counts, ids, keyed digests, bounded engine-authored text and client addresses, the `audit_log.detail` row above says which — never bodies or credentials — plus the store ACL and the volume layer. *Corrected 2026-10-16 (vault BACKLOG #3145):* this said writers "only ever store filter shapes, counts and ids" | | **6. `message_events` table** | the per-message disposition timeline — the **complete** vocabulary is `received`, `routed`, `unrouted`, `filtered`, `transformed`, `delivered`, `failed`, `dead`, `error`, `replayed`, `resent`, `reingressed`, `passthrough`, `passthrough_dropped`, `cancelled`, `edit_resend`, `edit_resubmit`, `viewed`, `not_deployed`, the ADR 0154 synchronous-reply pair `reply_returned` / `reply_timeout` (names, counts and `waited_ms` only — **never** a fragment of the partner's reply body), and `reply_dropped`, a delivery whose 2xx reply body was over the byte bound and dropped (the status and the bound only, vault BACKLOG #3040) (CI asserts this list against the engine's own `MESSAGE_EVENT_KINDS`). `[diagnostics].message_events` can thin the set, but never below the compliance floor `viewed` / `dead` / `error` / `failed` / `not_deployed` / `reply_timeout` / `reply_dropped` | rows: `message_id`, `ts`, `event`, `destination`, `detail` | the store database | operator timeline on the message-detail view; the `viewed` row is the HIPAA PHI-access record | `GET /messages/{id}` under **`messages:view_raw`** + `require_phi_read`; the read itself writes a `viewed` event **and** a `message_view` audit row | no dedicated window — `purge_message_bodies` sets `message_events.detail` to `NULL` in the same transaction that blanks the body, so it inherits `[retention].messages_days` | `detail` is `safe_text()`-scrubbed **then** cipher-encrypted (AAD `("message_events","detail",message_id,ts,event)`). Verbosity gate `[diagnostics].message_events` = `all` (default) / `errors` / `off`, with a **compliance floor that can never be thinned**: `viewed`, `dead`, `error`, `failed`, `not_deployed`, `reply_timeout`, `reply_dropped` are retained at every level (`reply_timeout` is the one row that explains a "we called you and got a 504" complaint, so an instance that thinned its logs would lose exactly the record it is later asked for; `reply_dropped` is the one row that answers "you ignored our reply", for the same reason) | | **7. `connection_event` table — DEFAULT ON** (`[diagnostics].connection_events = true`) | transport/lifecycle events per connection: `established`, `closed` (reason `eof`, `idle_timeout` or `frame_deadline` — a fixed vocabulary chosen by the listener, never free text), `idle_timeout`, `at_capacity`, `peer_not_allowlisted`, `frame_oversize`, `framing_error`, `peer_reset`, the MLLP, raw-TCP, X12 and HTTP listeners' and the DATABASE poll source's `handler_error` (BACKLOG #1619, #5022, #5680 for the HTTP listener, which answers it `503` or `500` by the exception's type, as [CONNECTIONS.md Table B](CONNECTIONS.md#table-b--per-service-resource-strategy-asvs-1313) states -- the inbound handler faulted on a frame the listener read cleanly, such as a failed ingress commit; on the X12 listener also, BACKLOG #5971, the engine's own reply to an interchange already recorded could not be encoded in the inbound's charset, so it was not sent; on the DATABASE source, BACKLOG #4921, on a polled row, which is left unmarked and, when the source has a mark statement, stops that poll; the reason is scrubbed at the source like every other), the MLLP, raw-TCP and X12 listeners' `reply_replaced` (BACKLOG #5799 -- the engine's own reply held characters the inbound's charset cannot encode, and each was replaced before the reply was written to the connection; throttled per listener: the first such reply sends one at once, then at most one a minute, sent by the first such reply past the minute and carrying the count of such replies since the last one, with no trailing report, so replies counted after the last event are not reported if no later one comes; an event is sent whether or not the write then succeeds, while the WARNING log line is written once per connection per process; a frame byte turned into a space writes no event; the reason is a count and fixed text that names neither the charset setting nor any part of the reply), the MLLP and HTTP listeners' `tls_handshake_failed` (vault BACKLOG #2613, #3302 and #3785 -- an inbound TLS handshake failed, on any event loop. **This is the one statement of the failed-handshake throttle, and other pages link here.** The first failure is reported at once, then at most one report per listener per minute, carrying the count since the last report. The reason is a count, an exception class name and OpenSSL's reason mnemonic, never the peer's bytes or certificate. A report names a peer only for a single failure, and only where the listener runs its own handshakes or awaits each one's outcome itself, which the MLLP and HTTP listeners do on every loop (BACKLOG #1606, #2479) and the DICOM C-STORE SCP always does. Such a listener also counts a handshake that runs past its bound. Where only the loop sees them, which is at least the API listener on every loop, the report names no peer, since the loop's hook does not read it (the module docstring of `messagefoundry/tls_handshake_failures.py` says what was measured), and a handshake that only runs past its bound is not counted. A peer that closes or resets the socket mid-handshake is not counted anywhere. That is what a load balancer's TCP health check does. The past-bound and hang-up limits stand by owner ruling 2026-10-26 (vault BACKLOG #3785 items 7 and 8), and that ruling covers only those two. Whether the API's report should name the peer is still an open owner question (vault BACKLOG #3302). The item 8 decline keeps the hang-up counting that came before #3785 and adds none. So a close_notify after the ClientHello is still counted, and the DICOM C-STORE SCP counts it too. A handshake that the listener's own stop ends is not counted. At least every listener also drops a genuine failure that lands once its stop has begun. The DICOM C-STORE SCP drops them for the whole of its server shutdown. On the MLLP and HTTP listeners, a stop that is cancelled before it finishes loses the failures its trailing report still held. The DICOM C-STORE SCP still reports them when its server shutdown raises or is cancelled. The API listener and the DICOM C-STORE SCP write the same report, throttled the same way, as a WARNING log line rather than an event: the API has no connection to carry one, and the SCP emits none (vault BACKLOG #3784)), the DATABASE poll source's `row_undecodable` (BACKLOG #1662 — a polled row the source cannot turn into a body; the reason is scrubbed at the source and names the exception type or the operator's own configured column, never a row value), the FILE poll source's quarantine kinds `file_oversize` / `file_decompress_failed` / `file_content_mismatch` / `file_scan_rejected` (BACKLOG #1621 — a drop moved to `.error`; the reason is a size, a content type or a codec or scanner message, and **that message can still name the file**. The name scrub on both the FILE and REMOTEFILE sources is `safe_exc(exc, file_name=...)`. safe_exc replaces the file name and, at least, its repr, ascii, bytes-repr and JSON-escaped forms, each also with uppercase hex digits. A scanner's `ScanRejected` message that quotes the name in at least another case, without its extension, percent-encoded, in another Unicode normalization, or escaped in a spelling those forms do not produce, such as a JSON escape of a decomposed spelling, keeps that text in the reason (`tests/test_file_source_quarantine_events.py` and `tests/test_remotefile_source_quarantine_events.py` pin this on each source's scan-reject arm), so a scan hook should leave the name out of its message. The directory part of a path stays, so a subdirectory a partner made under a recursive FILE source can appear in the reason; the REMOTEFILE poll source records the same kinds except `file_decompress_failed`, since it does not decompress), the inbound-HTTP intake-auth refusals `intake_auth_failed` / `auth_subject_denied` / `auth_rate_limited` (ADR 0154 D6 — peer address and mode only, plus, behind a proxy the connection lists in its trusted_proxies setting, the forwarded client address as a forwarded_for suffix on the reason and the audit detail (BACKLOG #5525); **never** the credential, a prefix of it, or its length. Each of these also writes a tamper-evident audit-log row — the copy that survives an operator turning this diagnostics stream off. The MLLP listener writes `auth_subject_denied` and `auth_rate_limited` too, with the same audit rows, when its expected-sender allowlist refuses a sender, naming the peer address and never a certificate field; BACKLOG #4907), plus the runner's `connection_lost` / `connection_restored` / `config_fault`. That is the whole vocabulary, asserted in CI against the literal emit call sites in `transports/` and the pipeline runner **and** against `CONNECTION_EVENT_KINDS` (`messagefoundry/connection_events.py`), the one set the store enforces on write and the console's filter reads (BACKLOG #1624). The MLLP, raw-TCP, X12 and HTTP listeners emit these; the **DATABASE poll source** emits `row_undecodable` and `handler_error` and nothing else (it dials out, so there is no lifecycle to report and its rows carry a **NULL peer column**); the **FILE poll source** emits only its four quarantine kinds, and the **REMOTEFILE poll source** only three of them, both with a NULL peer column; the **DICOM inbound C-STORE SCP** emits none — the runner injects the sink onto **every** source (`wiring_runner.py`, over the base-class `on_connection_event` field), so that connector *has* the wiring and simply never calls it — so this stream covers those four listeners plus those poll-source events and the runner's outbound-lane transitions — not literally every connection. A DICOM association's connects and refusals are therefore **absent** from this stream. The **`ISA`/`IEA`-framed X12 inbound** was equally absent until BACKLOG #1665 and is not any more: it emits the same kinds as the raw-TCP listener | rows: `ts`, `connection`, `transport`, `direction`, `kind`, `peer_host`, `message_id` (correlation hint), `reason` | the store database, **all three backends** | Corepoint-style transport diagnostics — "did the sender connect, and why did it drop" | `GET /events` and `GET /connections/{name}/events` under **`monitoring:read`** (**not** a PHI permission) with per-channel RBAC — an out-of-scope `connection=` is 403'd *and* audited — server-clamped to ≤1000 rows. `reason` alone is gated on `messages:view_summary` and masked as `****` until the audited per-event `reveal=` act (BACKLOG #2443; the `connection_event.reason` row of §3's PL-2 block says how) | `[retention].connection_event_retention_hours` (its own **hours** window); 0 inherits `[retention].messages_days`; both 0 = keep forever. Plain age `DELETE` | **`reason` is free text that can carry sensitive fragments.** Defended twice — `safe_exc()` at the source, `safe_text(reason, limit=200)` at the store (the bound §3's PL-2 block states) — then cipher-encrypted (AAD `("connection_event","reason",connection,ts,kind)`). Every other column is engine or config metadata except `peer_host`, and `reason` is not metadata-only: the [data-at-rest inventory](#2-where-phi-lives--data-at-rest-inventory) grades `reason` and `peer_host` in rows of their own (BACKLOG #5021). Writes are a pure side observer: a bounded in-memory queue drained by a background task outside any handoff transaction, so a flood can never block a listener or pin a message disposition | -| **8. `alert_instance` table — default on wherever an `[alerts]` notifier exists** | resolvable operator alerts: `connection_stopped`, `queue_buildup`, `lane_stuck`, `message_stall`, `saturation`, `connection_error`, `connection_error.config_fault`, `storage_threshold`, `cert_expiry`, `secret_rotation`, `initial_credential_expiring` (an UNCLAIMED admin-issued temporary password nearing the instant the login gate stops accepting it -- ASVS 6.4.5, BACKLOG #1141; keyed on `user:`, and the payload is the ISO deadline plus whole hours remaining, repeated in the reason column, never the password), `integrity_drift`, `update_available`, `backup_failed`, `store_privilege_warning` (the store privilege preflight found the store principal over-granted or could not read it -- BACKLOG #305; the payload is the finding, a count and the preflight's summary line, which names the login, the database and role names, never a password or message content), `vault_privilege_warning` (the Vault privilege preflight found a Vault token over-granted or could not read it -- BACKLOG #2903, ADR 0216; keyed on `vault:store` or `vault:secrets`, and the payload is the finding, a count of refusing-class grants and the hop's judgment, which names policy names, paths and capabilities, never a token, an accessor, a digest of either or message content), `leadership_acquired`, `dr_activated`, `dr_restarted_passive` (a DR box last recorded as activated came back up passive after a restart -- BACKLOG #5965; also raised when the start could not read whether the box was activated; keyed on the box's host label, with the engine shard appended on an engine shard, and the payload is that label, never message content), `log_write_failed` (an application-log sink was rolled after a write failure, or is UNWRITABLE and this process's connections were stopped -- BACKLOG #122, ADR 0162; the payload is the sink LABEL, the stage, a `safe_exc` reason and a count of connections stopped, never the record whose write failed), `log_forward_failed` (the off-box log forwarder is absent, losing records or not sending -- BACKLOG #2612; keyed on `forwarder:`, with `@node:` or `@shard:` appended when several engine processes share the store, and the payload is that key, fixed reason words and a count, never a record, the collector's address or an error text; an unpinned cluster node's `node_id` holds this engine's own host name and process id, so the key carries them), `gcm_invocations` (the per-key AES-GCM invocation bound crossing its 2^31 soft warn — ASVS 11.3.4; its payload carries a one-way `key_id` fingerprint plus counters, never key bytes), `approval_stale_requester` (a dual-control release refused because the requester no longer holds the authority the operation needs -- ASVS 8.3.2, BACKLOG #289; keyed on the approval id, and the payload is that id, the operation key and a closed-set reason slug, never the requester's name or the captured params), `approval_too_early` (a dual-control release refused because it arrived before `[approvals].min_dwell_seconds` -- ASVS 2.4.2, BACKLOG #287; keyed on `approval:`, and the payload is that key, the operation key and a fixed reason string, never the approver's or requester's name or the captured params), `audit_write_failed` (the approval gate could not write one of its audit rows -- vault BACKLOG #2255; keyed on `approval:`, on `approval::resolve` for a resolution's lost provenance row -- vault BACKLOG #3438, on the fixed `approval:listing` for a queue listing's lost `approval.standing_shown` row -- vault BACKLOG #3747, on `approval::seal-check` for a lost `approval.seal_check_unavailable` row -- vault BACKLOG #8202, on `config_reload:inline` when an ungated config reload could not write its `config_reload_attempted` row -- vault BACKLOG #2254, or on `step_up_return:audit_budget:` when the IdP step-up return audit budget's backstop stopped a row -- BACKLOG #3965, its rules stated once as control 11 of [SECURITY.md](SECURITY.md#the-documented-protection-set-asvs-611)'s 6.1.1 protection set, or on `directory-reconciler:` when a directory reconcile pass that completed could not write a row -- BACKLOG #3018 step 2, or on `directory-sign-in:` when a directory sign-in's role-sync row was refused twice -- BACKLOG #2221; the payload is that key and the lost row's audit action name, never the row's detail, a username or the captured params; the ERROR log line beside it holds the detail on some paths and only the exception on others), `audit_offbox_copy_missing` (an approval audit row whose write the gate read back as committed, whose off-box copy was never sent -- vault BACKLOG #3193; keyed on `approval:`, and the payload is that key and the row's audit action name, never the row's detail, a username or the captured params), `ad_reconcile_aborted` (a directory reconciler pass left signed-in accounts unrevoked and needs an operator: the mass-revoke breaker tripped and nothing was revoked, or one or more probes were answered with an LDAP referral and those accounts were left unjudged while the rest of the pass was applied, BACKLOG #2538, or one or more probes raised a fault the engine could not read and those accounts were left unjudged the same way, BACKLOG #3100, or the directory refused one or more probes with a result code that points at the configuration, such as a deleted search base, and those accounts were left unjudged the same way, vault BACKLOG #3010, or an account's group search was refused for the engine's own deadline or cap, so a role or scope change in the directory does not revoke that account's sessions, though a disable or deletion still does, vault BACKLOG #3696, or every lookup failed to reach the directory for `[auth].ad_reconcile_outage_passes` passes running, BACKLOG #3709; for the breaker, a referral, a probe fault, a configuration refusal and a lasting outage the payload is a fixed source label, `directory-reconciler` for the breaker, `directory-reconciler-referral` for a referral, `directory-reconciler-probe-fault` for a probe fault, `directory-reconciler-misconfigured` for a configuration refusal and `directory-reconciler-outage` for a lasting outage so each is its own instance, the closed-set reason slug `mass_revoke_breaker`, `directory_referral`, `probe_fault`, `directory_misconfigured` or `directory_unavailable`, a count (the accounts the breaker judged, or for each of the other four the lookups the pass sent, which leaves out an id-less row -- vault BACKLOG #3170) and the latched operator explanation, or for a lasting outage a fixed sentence with the run's length, never a username; a paging refusal is instead keyed on that operator account's username, as `directory-reconciler-paging:`, so each account is its own instance, raised as the account enters that state and again after a restart while it stands, and the payload is that key, the closed-set reason slug `group_search_deadline` or `group_search_cap`, the same count as the breaker's and a fixed sentence naming the cause, never anything else about the account; an account the directory keeps failing to answer for is keyed the same way, as `directory-reconciler-unreached:`, raised as it enters that state, and its payload is that key, the closed-set reason slug `account_unreachable`, the count of lookups the pass sent and a fixed sentence with two numbers, how many probes failed and the most recent probes its window can hold (faults aside), never anything else about the account -- vault BACKLOG #3100, #3709; on a rolled-up pass, those entering page as one instance under the source `directory-reconciler-unreached-rollup:`, with no username. The key is an unkeyed SHA-256 prefix of the entering accounts' sorted internal user ids, not a pseudonym: anyone who can list user ids can recompute it for a set of accounts and so learn which accounts a rollup covers (vault BACKLOG #3100 item 14), and the `ad_reconcile_outage_passes` row of [CONFIGURATION.md](CONFIGURATION.md) states when), `ad_reconcile_held` (the reconciler is holding accounts whose `userAccountControl` it cannot read, ADR 0195; the payload is the same fixed source label, a closed-set reason slug, the count of undetermined accounts and the latched operator explanation, never a username), `ad_session_revoked` (the reconciler revoked a directory principal's sessions; keyed on that operator account's username, with at least a `directory_absent`, `directory_disabled`, `directory_undetermined`, `directory_object_id_missing`, `roles_changed` or `scope_changed` reason), `approval_approver_provenance` (a dual-control release, or the resolution of an interrupted one, went ahead with an approver or resolver account created, re-passworded or TOTP-enrolled after the request -- BACKLOG #315, #2125; keyed on `approval:`, or `approval::resolve` for a resolution, and the payload is the operation key and the closed-set change slugs, never a username or the captured params), `administrator_granted` (the built-in Administrator role was granted by account creation, a role change, a directory group newly mapped to it -- BACKLOG #315 --, a directory sign-in whose role sync newly gave the account the role -- vault BACKLOG #2610 -- or a directory reconcile pass whose role re-diff did -- vault BACKLOG #3141; keyed on `user:` or `ad-group:`, with the grant route and the granting administrator's username, or `` for a directory sign-in or reconcile pass), `no_enabled_administrator` (a directory sign-in's role sync or the session reconciler took Administrator from its last enabled holder -- vault BACKLOG #3229; keyed on `user:`, and the payload is `via`, `ad-sync` or `ad-reconcile`, and a fixed reason sentence, never message content), `intake_paused` (the engine paused intake because the staged backlog went over `[inbound].max_staged_depth` or the SQLite volume fell below `[retention].min_free_disk_mb` -- BACKLOG #290; keyed on `intake:staged_depth` or `intake:disk_floor`, with `@node:` or `@shard:` appended when several engine processes share the store (BACKLOG #2272), and the payload is the reason, a count or a MiB figure, its limit and the store backend's name, never message content), `config_changed` (a start's config differs from the store's baseline: the bytes it loaded, or the directory just after the load -- vault BACKLOG #2597, #3765; keyed on `config:`, and the payload is the two digests, the node and engine shard labels, the action, actor username, time and node of the row the older digest came from, and the `comparison` outcome, never the config directory, a git commit or message content), `crl_reload_refused` (the CRL reload refused a replaced CRL file, so running TLS contexts keep the copy they hold -- vault BACKLOG #2904; keyed on `crl_reload:`, with `@node:` or `@shard:` appended when several engine processes share the store, and the payload is that key, the file's path, a short class token for the remedy, a count of contexts, the engine's own fixed remedy sentence and, when a start would refuse the file too, a `start_refuses` flag, never the refusal's reason, which quotes CRL issuer names and dates; that reason is in the application log, and in the `detail` of the CRL expiry alert once the held copy nears its `nextUpdate`), `remote_debug_refused` (the engine's remote-debugging guard refused scripts that another process injected into the engine process -- vault BACKLOG #2742; keyed on `remote_debug:refused`, with `@node:` or `@shard:` appended when several engine processes share the store, and the payload is that key, the count of scripts refused since the alert was last raised, the count since the process started and a fixed sentence built from the two, never a script's file name, which the injecting process chooses; that name is in the application log, in the guard's WARNING line), `sandbox_worker_refused` (a `[sandbox].mode = "subprocess"` worker was refused because the graph it loaded differs from the engine's, most often a config file edited on disk with no reload -- vault BACKLOG #2724; keyed on the inbound's name, raised once per refusal, and the payload is that name and a fixed sentence naming the cause and the remedy, never a message body or the refusal text, which names config names and digests and is in the application log), `cert_monitor_stalled` (a cert-expiry scan pass ran past its stall threshold, most likely on a blocked certificate or CRL read, so no expiry alert is raised until it returns -- vault BACKLOG #5885; keyed on `cert_monitor:scan`, raised once the pass runs past the threshold and again each threshold while it runs, and the payload holds at least that key, the seconds the pass has run and a fixed sentence built from them, never a file's path), `store_restored` (the first `serve` on a store `messagefoundry restore` placed ended every session -- BACKLOG #2614; keyed on `store:restored`, raised once per restore, and the payload is that key; a fixed sentence carrying the archive's age in days, the count of sessions ended, a pointer to `messagefoundry restore --help` and the time of the archive's newest audit row, of which the alert instance's reason column keeps the age, the count and the pointer whole and the time redacted or cut; that time again as `last_audit_at`; and the fixed notice of what a restore rolls back as `rollback_notice` (`messagefoundry/restore_notice.py`, BACKLOG #5094), fixed text the reason column never holds; never an account name or a row's content), and the seven security signals of the audit-stream rule layer -- vault BACKLOG #2613: `signin_failure_burst` (keyed on `signin:`, never the typed username), `access_denied_burst`, `body_view_burst` and `bulk_export` (each keyed on `account:`), `peer_refused_burst` (keyed on `inbound:`, never the refused peer's address), `log_level_debug` (keyed on `logging:debug`) and `posture_loosened` (keyed on `posture:start`, with `@node:` or `@shard:` appended when several engine processes share the store); the payload is a count and a fixed sentence holding a level name, switch names or a username, never a message body, a message id or an audit row's detail. The reachable **inverse** signals — `connection_restored`, `leadership_lost`, `dr_released`, `dr_restart_cleared` (raised by each `dr_activated` and `dr_released`, so an activation, or a release that leaves a restarted box passive, resolves the open `dr_restarted_passive` for the same box label -- BACKLOG #5965), `store_privilege_clean`, `vault_privilege_clean`, `intake_resumed`, `posture_restored` (it resolves `posture_loosened` under the same key, so for the same engine process, when a start records no security loosening in a row marked neither `superseded` nor `baseline_unchecked` and a live posture read then names none -- vault BACKLOG #2613; an unpinned cluster node's key changes on every start, so that node raises the inverse for its own instance as it shuts down; when that instance can still stay open is in [SECURITY.md](SECURITY.md)), `crl_reload_applied` (it resolves `crl_reload_refused` under the same key, so for the same file and the same engine identity, at least once the reload's record no longer holds the refusal, once no hop holds any CRL, and when the reload stops -- vault BACKLOG #2904; it is also raised once per held file outside a CA bundle, at the first pass that judges it with no refusal standing, whether or not an alert is open, so it can resolve nothing, and it then clears one an earlier run under that identity left open -- vault BACKLOG #3543. An alert for a file no hop holds now stays open, and so does one an unpinned cluster node raised, because that node's identity changes on every start; [CONFIGURATION.md](CONFIGURATION.md), *The alert resolves itself*, is the source of record), `ad_reconcile_breaker_cleared`, `ad_reconcile_hold_released` (the last two resolve `ad_reconcile_held` and `ad_reconcile_aborted`, the latter only under the breaker's, the referral's or the lasting outage's source: the probe fault's, the configuration refusal's, a paging refusal's and an unreached account's instances have no inverse; when they do, and where they never do, is stated once in [CONFIGURATION.md](CONFIGURATION.md#when-the-reconcilers-alerts-resolve-themselves) -- BACKLOG #2136) — are never rows here: `_record_state` routes an inverse through `_AUTO_RESOLVE` to `resolve_alert_instances_fenced` (BACKLOG #4916), or `resolve_alert_instances_for` on a store without the fence methods, never to `upsert_alert_instance`. So is `connection_started`, which resolves `connection_stopped` under the bare connection name: the runner raises it only when an operator's start or restart finds an inbound up and no cause it can see still holds the name down in either direction (BACKLOG #1741). Every other start raises nothing, at least an engine start, a committed reload, the scheduler and every alert rule's restart, so an open stop keeps its instance, ack and suspend across them. `AlertSink.connection_started` states the full contract, including the operator starts that still raise nothing. An instance raised under a prefixed stand-in such as `reference:` is never resolved by it. | rows: `event_type`, `connection`, `severity`, `status`, `first_seen`, `last_seen`, `count`, `reason`, `acked_by`, `acked_at`, `resolved_at`, `suspended_until`, `escalation_tier`, `raised_by` (a random per-process id naming the newest raise's writer, BACKLOG #4916; never a host, user or message value) | the store database, **all three backends** | the operator alert list — acknowledge / resolve / suspend. Durable state is recorded **before** any suppression or throttle return, so a muted alert still leaves a record | `GET /alerts/active` under **`monitoring:diagnose`** (**not** a PHI permission) with the same per-channel scope, and `reason` alone gated on `messages:view_summary` and masked as `****` until the audited per-alert `reveal=` act (BACKLOG #2443; the `alert_instance.reason` row of §3's PL-2 block says how); ack/resolve/suspend/**resume** are POSTs on the same tier, and the separate read-only `GET /alerts/rules` view sits on its own gate | shares the connection-event window; **only RESOLVED instances are DELETEd**, by `resolved_at` — retention never ages out an open or acknowledged condition from under an operator; a row can still close with no inverse and no operator, at least through the `intake_paused` staleness sweep (BACKLOG #3269), which resolves another engine process's open or acknowledged pause under the expiry rule in [CONFIGURATION.md](CONFIGURATION.md#alerts), after which retention treats it as any resolved row | **`reason` is free text** taken from the event's internal `_detail` (the `connection_error` reason kept off the wire, BACKLOG #5021), `detail` or `reason`: `safe_text(reason, limit=200)` (the bound §3's PL-2 block states) then cipher-encrypted (AAD `("alert_instance","reason",event_type,connection)` — the de-dup grain, so one AAD covers both the INSERT and the re-fire UPDATE). | +| **8. `alert_instance` table — default on wherever an `[alerts]` notifier exists** | resolvable operator alerts: `connection_stopped`, `queue_buildup`, `lane_stuck`, `message_stall`, `saturation`, `connection_error`, `connection_error.config_fault`, `storage_threshold`, `cert_expiry`, `secret_rotation`, `initial_credential_expiring` (an UNCLAIMED admin-issued temporary password nearing the instant the login gate stops accepting it -- ASVS 6.4.5, BACKLOG #1141; keyed on `user:`, and the payload is the ISO deadline plus whole hours remaining, repeated in the reason column, never the password), `integrity_drift`, `update_available`, `backup_failed`, `store_privilege_warning` (the store privilege preflight found the store principal over-granted or could not read it -- BACKLOG #305; the payload is the finding, a count and the preflight's summary line, which names the login, the database and role names, never a password or message content), `vault_privilege_warning` (the Vault privilege preflight found a Vault token over-granted or could not read it -- BACKLOG #2903, ADR 0216; keyed on `vault:store` or `vault:secrets`, and the payload is the finding, a count of refusing-class grants and the hop's judgment, which names policy names, paths and capabilities, never a token, an accessor, a digest of either or message content), `leadership_acquired`, `dr_activated`, `dr_restarted_passive` (a DR box last recorded as activated came back up passive after a restart -- BACKLOG #5965; also raised when the start could not read whether the box was activated; keyed on the box's host label, with the engine shard appended on an engine shard, and the payload is that label, never message content), `log_write_failed` (an application-log sink was rolled after a write failure, or is UNWRITABLE and this process's connections were stopped -- BACKLOG #122, ADR 0162; the payload is the sink LABEL, the stage, a `safe_exc` reason and a count of connections stopped, never the record whose write failed), `log_forward_failed` (the off-box log forwarder is absent, losing records or not sending -- BACKLOG #2612; keyed on `forwarder:`, with `@node:` or `@shard:` appended when several engine processes share the store, and the payload is that key, fixed reason words and a count, never a record, the collector's address or an error text; an unpinned cluster node's `node_id` holds this engine's own host name and process id, so the key carries them), `gcm_invocations` (the per-key AES-GCM invocation bound crossing its 2^31 soft warn — ASVS 11.3.4; its payload carries a one-way `key_id` fingerprint plus counters, never key bytes), `approval_stale_requester` (a dual-control release refused because the requester no longer holds the authority the operation needs -- ASVS 8.3.2, BACKLOG #289; keyed on the approval id, and the payload is that id, the operation key and a closed-set reason slug, never the requester's name or the captured params), `approval_too_early` (a dual-control release refused because it arrived before `[approvals].min_dwell_seconds` -- ASVS 2.4.2, BACKLOG #287; keyed on `approval:`, and the payload is that key, the operation key and a fixed reason string, never the approver's or requester's name or the captured params), `audit_write_failed` (the approval gate could not write one of its audit rows -- vault BACKLOG #2255; keyed on `approval:`, on `approval::resolve` for a resolution's lost provenance row -- vault BACKLOG #3438, on the fixed `approval:listing` for a queue listing's lost `approval.standing_shown` row -- vault BACKLOG #3747, on `approval::seal-check` for a lost `approval.seal_check_unavailable` row -- vault BACKLOG #8202, on `config_reload:inline` when an ungated config reload could not write its `config_reload_attempted` row -- vault BACKLOG #2254, or on `step_up_return:audit_budget:` when the IdP step-up return audit budget's backstop stopped a row -- BACKLOG #3965, its rules stated once as control 11 of [SECURITY.md](SECURITY.md#the-documented-protection-set-asvs-611)'s 6.1.1 protection set, or on `directory-reconciler:` when a directory reconcile pass that completed could not write a row -- BACKLOG #3018 step 2, or on `directory-sign-in:` when a directory sign-in's role-sync row was refused twice -- BACKLOG #2221; the payload is that key and the lost row's audit action name, never the row's detail, a username or the captured params; the ERROR log line beside it holds the detail on some paths and only the exception on others), `audit_offbox_copy_missing` (an approval audit row whose write the gate read back as committed, whose off-box copy was never sent -- vault BACKLOG #3193; keyed on `approval:`, and the payload is that key and the row's audit action name, never the row's detail, a username or the captured params), `ad_reconcile_aborted` (a directory reconciler pass left signed-in accounts unrevoked and needs an operator: the mass-revoke breaker tripped and nothing was revoked, or one or more probes were answered with an LDAP referral and those accounts were left unjudged while the rest of the pass was applied, BACKLOG #2538, or one or more probes raised a fault the engine could not read and those accounts were left unjudged the same way, BACKLOG #3100, or the directory refused one or more probes with a result code that points at the configuration, such as a deleted search base, and those accounts were left unjudged the same way, vault BACKLOG #3010, or an account's group search was refused for the engine's own deadline or cap, so a role or scope change in the directory does not revoke that account's sessions, though a disable or deletion still does, vault BACKLOG #3696, or every lookup failed to reach the directory for `[auth].ad_reconcile_outage_passes` passes running, BACKLOG #3709; for the breaker, a referral, a probe fault, a configuration refusal and a lasting outage the payload is a fixed source label, `directory-reconciler` for the breaker, `directory-reconciler-referral` for a referral, `directory-reconciler-probe-fault` for a probe fault, `directory-reconciler-misconfigured` for a configuration refusal of a search, `directory-reconciler-service-bind` for one of the service-account bind and `directory-reconciler-outage` for a lasting outage so each is its own instance, the closed-set reason slug `mass_revoke_breaker`, `directory_referral`, `probe_fault`, `directory_misconfigured` or `directory_unavailable`, a count (the accounts the breaker judged, or for each of the other four the lookups the pass sent, which leaves out an id-less row -- vault BACKLOG #3170) and the latched operator explanation, or for a lasting outage a fixed sentence with the run's length, never a username; a paging refusal is instead keyed on that operator account's username, as `directory-reconciler-paging:`, so each account is its own instance, raised as the account enters that state and again after a restart while it stands, and the payload is that key, the closed-set reason slug `group_search_deadline` or `group_search_cap`, the same count as the breaker's and a fixed sentence naming the cause, never anything else about the account; an account the directory keeps failing to answer for is keyed the same way, as `directory-reconciler-unreached:`, raised as it enters that state, and its payload is that key, the closed-set reason slug `account_unreachable`, the count of lookups the pass sent and a fixed sentence with two numbers, how many probes failed and the most recent probes its window can hold (faults aside), never anything else about the account -- vault BACKLOG #3100, #3709; on a rolled-up pass, those entering page as one instance under the source `directory-reconciler-unreached-rollup:`, with no username. The key is an unkeyed SHA-256 prefix of the entering accounts' sorted internal user ids, not a pseudonym: anyone who can list user ids can recompute it for a set of accounts and so learn which accounts a rollup covers (vault BACKLOG #3100 item 14), and the `ad_reconcile_outage_passes` row of [CONFIGURATION.md](CONFIGURATION.md) states when), `ad_reconcile_held` (the reconciler is holding accounts whose `userAccountControl` it cannot read, ADR 0195; the payload is the same fixed source label, a closed-set reason slug, the count of undetermined accounts and the latched operator explanation, never a username), `ad_session_revoked` (the reconciler revoked a directory principal's sessions; keyed on that operator account's username, with at least a `directory_absent`, `directory_disabled`, `directory_undetermined`, `directory_object_id_missing`, `roles_changed` or `scope_changed` reason), `approval_approver_provenance` (a dual-control release, or the resolution of an interrupted one, went ahead with an approver or resolver account created, re-passworded or TOTP-enrolled after the request -- BACKLOG #315, #2125; keyed on `approval:`, or `approval::resolve` for a resolution, and the payload is the operation key and the closed-set change slugs, never a username or the captured params), `administrator_granted` (the built-in Administrator role was granted by account creation, a role change, a directory group newly mapped to it -- BACKLOG #315 --, a directory sign-in whose role sync newly gave the account the role -- vault BACKLOG #2610 -- or a directory reconcile pass whose role re-diff did -- vault BACKLOG #3141; keyed on `user:` or `ad-group:`, with the grant route and the granting administrator's username, or `` for a directory sign-in or reconcile pass), `no_enabled_administrator` (a directory sign-in's role sync or the session reconciler took Administrator from its last enabled holder -- vault BACKLOG #3229; keyed on `user:`, and the payload is `via`, `ad-sync` or `ad-reconcile`, and a fixed reason sentence, never message content), `intake_paused` (the engine paused intake because the staged backlog went over `[inbound].max_staged_depth` or the SQLite volume fell below `[retention].min_free_disk_mb` -- BACKLOG #290; keyed on `intake:staged_depth` or `intake:disk_floor`, with `@node:` or `@shard:` appended when several engine processes share the store (BACKLOG #2272), and the payload is the reason, a count or a MiB figure, its limit and the store backend's name, never message content), `config_changed` (a start's config differs from the store's baseline: the bytes it loaded, or the directory just after the load -- vault BACKLOG #2597, #3765; keyed on `config:`, and the payload is the two digests, the node and engine shard labels, the action, actor username, time and node of the row the older digest came from, and the `comparison` outcome, never the config directory, a git commit or message content), `crl_reload_refused` (the CRL reload refused a replaced CRL file, so running TLS contexts keep the copy they hold -- vault BACKLOG #2904; keyed on `crl_reload:`, with `@node:` or `@shard:` appended when several engine processes share the store, and the payload is that key, the file's path, a short class token for the remedy, a count of contexts, the engine's own fixed remedy sentence and, when a start would refuse the file too, a `start_refuses` flag, never the refusal's reason, which quotes CRL issuer names and dates; that reason is in the application log, and in the `detail` of the CRL expiry alert once the held copy nears its `nextUpdate`), `remote_debug_refused` (the engine's remote-debugging guard refused scripts that another process injected into the engine process -- vault BACKLOG #2742; keyed on `remote_debug:refused`, with `@node:` or `@shard:` appended when several engine processes share the store, and the payload is that key, the count of scripts refused since the alert was last raised, the count since the process started and a fixed sentence built from the two, never a script's file name, which the injecting process chooses; that name is in the application log, in the guard's WARNING line), `sandbox_worker_refused` (a `[sandbox].mode = "subprocess"` worker was refused because the graph it loaded differs from the engine's, most often a config file edited on disk with no reload -- vault BACKLOG #2724; keyed on the inbound's name, raised once per refusal, and the payload is that name and a fixed sentence naming the cause and the remedy, never a message body or the refusal text, which names config names and digests and is in the application log), `cert_monitor_stalled` (a cert-expiry scan pass ran past its stall threshold, most likely on a blocked certificate or CRL read, so no expiry alert is raised until it returns -- vault BACKLOG #5885; keyed on `cert_monitor:scan`, raised once the pass runs past the threshold and again each threshold while it runs, and the payload holds at least that key, the seconds the pass has run and a fixed sentence built from them, never a file's path), `store_restored` (the first `serve` on a store `messagefoundry restore` placed ended every session -- BACKLOG #2614; keyed on `store:restored`, raised once per restore, and the payload is that key; a fixed sentence carrying the archive's age in days, the count of sessions ended, a pointer to `messagefoundry restore --help` and the time of the archive's newest audit row, of which the alert instance's reason column keeps the age, the count and the pointer whole and the time redacted or cut; that time again as `last_audit_at`; and the fixed notice of what a restore rolls back as `rollback_notice` (`messagefoundry/restore_notice.py`, BACKLOG #5094), fixed text the reason column never holds; never an account name or a row's content), and the seven security signals of the audit-stream rule layer -- vault BACKLOG #2613: `signin_failure_burst` (keyed on `signin:`, never the typed username), `access_denied_burst`, `body_view_burst` and `bulk_export` (each keyed on `account:`), `peer_refused_burst` (keyed on `inbound:`, never the refused peer's address), `log_level_debug` (keyed on `logging:debug`) and `posture_loosened` (keyed on `posture:start`, with `@node:` or `@shard:` appended when several engine processes share the store); the payload is a count and a fixed sentence holding a level name, switch names or a username, never a message body, a message id or an audit row's detail. The reachable **inverse** signals — `connection_restored`, `leadership_lost`, `dr_released`, `dr_restart_cleared` (raised by each `dr_activated` and `dr_released`, so an activation, or a release that leaves a restarted box passive, resolves the open `dr_restarted_passive` for the same box label -- BACKLOG #5965), `store_privilege_clean`, `vault_privilege_clean`, `intake_resumed`, `posture_restored` (it resolves `posture_loosened` under the same key, so for the same engine process, when a start records no security loosening in a row marked neither `superseded` nor `baseline_unchecked` and a live posture read then names none -- vault BACKLOG #2613; an unpinned cluster node's key changes on every start, so that node raises the inverse for its own instance as it shuts down; when that instance can still stay open is in [SECURITY.md](SECURITY.md)), `crl_reload_applied` (it resolves `crl_reload_refused` under the same key, so for the same file and the same engine identity, at least once the reload's record no longer holds the refusal, once no hop holds any CRL, and when the reload stops -- vault BACKLOG #2904; it is also raised once per held file outside a CA bundle, at the first pass that judges it with no refusal standing, whether or not an alert is open, so it can resolve nothing, and it then clears one an earlier run under that identity left open -- vault BACKLOG #3543. An alert for a file no hop holds now stays open, and so does one an unpinned cluster node raised, because that node's identity changes on every start; [CONFIGURATION.md](CONFIGURATION.md), *The alert resolves itself*, is the source of record), `ad_reconcile_breaker_cleared`, `ad_reconcile_hold_released` (the last two resolve `ad_reconcile_held` and `ad_reconcile_aborted`, the latter only under the breaker's, the referral's or the lasting outage's source: the probe fault's, the configuration refusal's, a paging refusal's and an unreached account's instances have no inverse; when they do, and where they never do, is stated once in [CONFIGURATION.md](CONFIGURATION.md#when-the-reconcilers-alerts-resolve-themselves) -- BACKLOG #2136) — are never rows here: `_record_state` routes an inverse through `_AUTO_RESOLVE` to `resolve_alert_instances_fenced` (BACKLOG #4916), or `resolve_alert_instances_for` on a store without the fence methods, never to `upsert_alert_instance`. So is `connection_started`, which resolves `connection_stopped` under the bare connection name: the runner raises it only when an operator's start or restart finds an inbound up and no cause it can see still holds the name down in either direction (BACKLOG #1741). Every other start raises nothing, at least an engine start, a committed reload, the scheduler and every alert rule's restart, so an open stop keeps its instance, ack and suspend across them. `AlertSink.connection_started` states the full contract, including the operator starts that still raise nothing. An instance raised under a prefixed stand-in such as `reference:` is never resolved by it. | rows: `event_type`, `connection`, `severity`, `status`, `first_seen`, `last_seen`, `count`, `reason`, `acked_by`, `acked_at`, `resolved_at`, `suspended_until`, `escalation_tier`, `raised_by` (a random per-process id naming the newest raise's writer, BACKLOG #4916; never a host, user or message value) | the store database, **all three backends** | the operator alert list — acknowledge / resolve / suspend. Durable state is recorded **before** any suppression or throttle return, so a muted alert still leaves a record | `GET /alerts/active` under **`monitoring:diagnose`** (**not** a PHI permission) with the same per-channel scope, and `reason` alone gated on `messages:view_summary` and masked as `****` until the audited per-alert `reveal=` act (BACKLOG #2443; the `alert_instance.reason` row of §3's PL-2 block says how); ack/resolve/suspend/**resume** are POSTs on the same tier, and the separate read-only `GET /alerts/rules` view sits on its own gate | shares the connection-event window; **only RESOLVED instances are DELETEd**, by `resolved_at` — retention never ages out an open or acknowledged condition from under an operator; a row can still close with no inverse and no operator, at least through the `intake_paused` staleness sweep (BACKLOG #3269), which resolves another engine process's open or acknowledged pause under the expiry rule in [CONFIGURATION.md](CONFIGURATION.md#alerts), after which retention treats it as any resolved row | **`reason` is free text** taken from the event's internal `_detail` (the `connection_error` reason kept off the wire, BACKLOG #5021), `detail` or `reason`: `safe_text(reason, limit=200)` (the bound §3's PL-2 block states) then cipher-encrypted (AAD `("alert_instance","reason",event_type,connection)` — the de-dup grain, so one AAD covers both the INSERT and the re-fire UPDATE). | | **9. `response` rows with `kind='ack_sent'` — DEFAULT ON** (`[diagnostics].response_sent = true`) | the ACK/NAK the engine returned to an inbound sender, under a sentinel destination `\x1fack:` | rows: `ack_code` (`AA`/`AE`/`AR`/`CA`/`CE`/`CR`), `ack_phase` (`decode`/`parse`/`strict`/`ingest`), `outcome`, `body`, `detail` | the store database | "what did we actually reply, and why" — the operator's answer to a sender disputing an ACK | `GET /messages/{id}/responses` under `messages:read` + `require_phi_read`; the `body` only for a caller who also holds `messages:view_raw` and `messages:view_summary`; every read writes a `response.read` audit row | `body`, `detail` and `resp_headers` are set to `NULL` in place by `purge_message_bodies` on the message-body window, on all three backends | **PHI fail-safe:** the ACK **body** is stored **only when the store cipher is active** — on a keyless store it is `NULL` rather than plaintext — and every NAK passes no body at all, so the offending field value is never persisted. The disposition metadata (`ack_code`/`ack_phase`/`outcome`) is non-PHI and always captured; `detail` is `safe_text`-scrubbed, held to the 200-character bound §3's PL-2 block states, and encrypted | | **10. `[alerts]` webhook transport** (off by default — `webhook_url` unset) | one HTTPS POST per alert, carrying every non-underscore event key as JSON | JSON | the operator's webhook endpoint (Slack/Teams/PagerDuty/custom) | operator notification | **`https` only** — a plaintext `http://` webhook URL is refused at construction. Redirects are refused; an optional `webhook_allowed_hosts` egress allowlist gates the host. A verifying `https` hop off this box also takes the revocation guard at build, on a host the `webhook_allowed_hosts` allowlist admits. An unset or empty allowlist admits every host, an explicit `[]` included, and so does an environment value that splits to no host, such as `""` or `","`. A host off a non-empty allowlist is refused at build, before this guard (BACKLOG #5088). A TOML list keeps its entries as written, so `[""]` or `[","]` is not empty and names no real host, and the build refuses every real host. Under an enforcing or unknown posture the guarded hop is refused unless the `[alerts].webhook_tls_revocation_attested` pair is set ([ADR 0173](adr/0173-tls-peer-revocation-checking-and-ocsp-stapling-across-terminating-and-originating-surfaces.md) states the guard and its levers) | the endpoint's | **carries the alert's `detail`/`reason` free text** for at least `connection_stopped`, `log_write_failed` and `backup_failed` (`safe_exc()`-scrubbed at the emit sites, but **not** re-run through `safe_text` on this path, and a scrubbed reason can still echo a partner's reply text). `connection_error` no longer carries its detail: in its place it sends the exception class (or the fixed token `unnamed error` for a class that is not a plain identifier), beside at least the connection and the kind, and keeps the detail under the internal `_detail` key, which the notifier pops before any transport is handed the event and which the alert instance's stored `reason` (row 8) still keeps (`NotifierAlertSink.connection_error`, BACKLOG #5021). Internal `_`-prefixed keys, at least `_detail`, `_transports`, the per-rule recipients, the rule id and the cooldown, are stripped before send, so recipient addresses never cross the wire | | **11. `[alerts]` SMTP transport — operator alert list** (off unless `email_smtp_host` + `email_from` + ≥1 `email_to`) | one email per alert; default subject `[MessageFoundry] — `, default body every non-underscore event key as `k: v` | plain text (always kept — never HTML-only); optional HTML alternative | the operators' mailboxes | operator notification | `smtp_allowed_hosts` egress allowlist; the SMTP password comes from `MEFOR_ALERTS_EMAIL_PASSWORD` or a `[secrets]` provider, never the config file; per-send timeout `email_timeout` | the mail system's | carries the same `detail`/`reason` free text as the webhook, and like it leaves out `connection_error`'s detail (row 10, BACKLOG #5021). #138 operator templates are constrained to a **closed non-PHI variable allowlist** validated fail-closed at config load. **Transport posture:** `send_plain_email` builds an explicit **verifying** context (chain + hostname + strict RFC 5280, TLS 1.2 floor) via `tls_policy.build_smtp_tls_context()` and passes it to `starttls()`, anchored to the OS roots, `[alerts].email_tls_ca_file`, or `[tls].internal_ca_file` — the same factory the EMAIL and DIRECT *message destinations* use, so all three SMTP cells now share one policy ([#323](BACKLOG.md), closed 2026-08-02). Before that this call passed **no** context and Python's stdlib default applied (`ssl._create_stdlib_context` **is** `ssl._create_unverified_context` — `CERT_NONE`, `check_hostname = False`), leaving the hop encrypted but unauthenticated. There is still **no hop gradient or attestation for this path's TLS deviations** — unlike the connectors, this cell is constructed outside the `active_hop_posture` scope, so those deviations (`email_use_tls = false`, or `email_tls_verify = false`) are gated by a `[security].allow_unverified_alert_smtp_tls` **acknowledgment switch at the serve gate** rather than by the clamped escape: on an enforcing PHI instance `serve` refuses to start without it, and permits + `AUDIT`-logs the start with it. That switch covers a hop with no login: beside `email_username` either deviation is refused at settings load, with no escape (vault BACKLOG #3533). Both deviations are named by `security_loosenings()` and reported by `messagefoundry check`'s `alert-smtp-tls` advisory. Revocation is a separate gate: a hop off this box that carries a login takes the revocation guard at build, on a host the `smtp_allowed_hosts` allowlist admits; that allowlist reads as row 10 says the webhook's does, a TOML `[""]` included. A host off a non-empty allowlist is refused at build, before this guard (BACKLOG #5088). Under an enforcing or unknown posture the guarded hop is refused unless one of its levers holds ([ADR 0173](adr/0173-tls-peer-revocation-checking-and-ocsp-stapling-across-terminating-and-originating-surfaces.md) states the guard, its levers, and why a hop with no login takes none) | diff --git a/docs/SECURITY.md b/docs/SECURITY.md index 5c97196665..db0f87c800 100644 --- a/docs/SECURITY.md +++ b/docs/SECURITY.md @@ -6814,7 +6814,9 @@ probe is refused, faulted or fails, at least one refused and none referred, the Like the fault's, that alert has no inverse; an operator resolves it, and a pass with such a refusal marks no alert clear. A service-account bind the directory refuses with one of those codes takes the same path, as a malformed `ad_bind_dn` does, and so does one it refuses with -invalidCredentials, as a wrong or expired service password or a locked service account does. +invalidCredentials, as a wrong or expired service password or a locked service account does, +except that a refused service bind raises its alert under its own source +`directory-reconciler-service-bind`, so a suspend of the search refusal's alert does not mute it. Each probe still sends its own service bind, so a refused password is sent again for every account a pass probes, and each try with a wrong password counts toward the service account's lockout. **The cost:** while the diff --git a/messagefoundry/api/app.py b/messagefoundry/api/app.py index 04a9cf7fac..64c544bf13 100644 --- a/messagefoundry/api/app.py +++ b/messagefoundry/api/app.py @@ -13048,6 +13048,10 @@ async def _directory_reconciler( #: The source label of the configuration refusal's own ``ad_reconcile_aborted`` instance (BACKLOG #: #3010), apart from the others for the same reasons. _MISCONFIGURED_ALERT_SOURCE = "directory-reconciler-misconfigured" +#: The source label of a refused service-account bind's own ``ad_reconcile_aborted`` instance, +#: with the same reason as the search refusal's: a suspend of a deleted search base's page must +#: not mute a service password that later expires, and the reverse. +_SERVICE_BIND_ALERT_SOURCE = "directory-reconciler-service-bind" #: The source label prefix of a paging refusal's ``ad_reconcile_aborted`` instance (vault BACKLOG #: #3696). The account name follows it, so each account is its own instance and throttle, as #: ``ad_session_revoked`` is keyed on the account: a second account entering inside the first's @@ -13148,7 +13152,9 @@ def _alert_reconcile_plan(plan: ReconcilePlan, auth: AuthService, sink: AlertSin service-account bind the directory refuses, as for a wrong password, refuses every probe. Any pass with such a refusal is ``auth.ad_reconcile_misconfigured`` and becomes one ``ad_reconcile_aborted`` alert with reason ``directory_misconfigured``, under its own source - label (:data:`_MISCONFIGURED_ALERT_SOURCE`). Like the fault's, it has no inverse. Before #3010 + label: a refused search under :data:`_MISCONFIGURED_ALERT_SOURCE`, a refused service-account + bind under :data:`_SERVICE_BIND_ALERT_SOURCE`, and one under each when the pass saw both. Like + the fault's, it has no inverse. Before #3010 such a base read as "not found" for every account, so it tripped the breaker on an estate large enough; read as an outage, it would page only once the outage lasted (BACKLOG #3709). @@ -13235,13 +13241,25 @@ def _alert_reconcile_plan(plan: ReconcilePlan, auth: AuthService, sink: AlertSin detail=auth.directory_reconcile_referral or REFERRAL_ABORT, ) if plan.misconfigured: - # BACKLOG #3010. Beside the referral's, in the same order the service records them. - sink.ad_reconcile_aborted( - _MISCONFIGURED_ALERT_SOURCE, - reason=MISCONFIGURED_ABORT, - probed=plan.asked, - detail=auth.directory_reconcile_misconfigured or MISCONFIGURED_ABORT, - ) + # BACKLOG #3010. Beside the referral's, in the same order the service records them. A + # refused service bind and a refused search each raise under their own source, both when + # both happened, so a suspend of one cannot mute the other. A plan naming refusals with + # neither flag set raises under the search's source rather than nothing. + detail = auth.directory_reconcile_misconfigured or MISCONFIGURED_ABORT + if plan.refused_bind: + sink.ad_reconcile_aborted( + _SERVICE_BIND_ALERT_SOURCE, + reason=MISCONFIGURED_ABORT, + probed=plan.asked, + detail=detail, + ) + if plan.refused_search or not plan.refused_bind: + sink.ad_reconcile_aborted( + _MISCONFIGURED_ALERT_SOURCE, + reason=MISCONFIGURED_ABORT, + probed=plan.asked, + detail=detail, + ) if plan.faulted: # BACKLOG #3100. sink.ad_reconcile_aborted( diff --git a/messagefoundry/auth/reconcile.py b/messagefoundry/auth/reconcile.py index 5d857a3ac3..815c115127 100644 --- a/messagefoundry/auth/reconcile.py +++ b/messagefoundry/auth/reconcile.py @@ -169,6 +169,10 @@ class Probe: #: group search was refused for its bounds rather than unanswered (vault BACKLOG #3696), else #: None. None for every other outcome. detail: str | None = None + #: For :attr:`ProbeOutcome.MISCONFIGURED`: true when the directory refused the service-account + #: bind (``LdapUnansweredError.refused_bind``) rather than a search, so the pass pages it under + #: its own source and a suspend of the search refusal's page cannot mute it. False otherwise. + refused_bind: bool = False @dataclass(frozen=True) @@ -318,6 +322,11 @@ class ReconcilePlan: #: (:attr:`ProbeOutcome.MISCONFIGURED`, BACKLOG #3010). Any one alerts, and none of them stops #: the rest of the pass being judged. misconfigured: tuple[str, ...] = () + #: Whether any of ``misconfigured`` was a refused service-account bind + #: (:attr:`Probe.refused_bind`), and whether any was a refused search. The API pages each under + #: its own source, so suspending one does not mute the other. + refused_bind: bool = False + refused_search: bool = False #: Non-None when the pass ABORTED and must apply nothing: the breaker tripped, every probe the #: pass asked failed (a whole-directory outage), or every probe it asked went unjudged with at #: least one of them referred, refused for its configuration or faulted, which take the slug in @@ -593,6 +602,8 @@ def plan_pass( referred = [p for p in probes if p.outcome is ProbeOutcome.REFERRED] faulted = [p for p in probes if p.outcome is ProbeOutcome.FAULT] misconfigured = [p for p in probes if p.outcome is ProbeOutcome.MISCONFIGURED] + refused_bind = any(p.refused_bind for p in misconfigured) + refused_search = any(not p.refused_bind for p in misconfigured) # BACKLOG #2434. The caller reads a row it may not ask about as UNKEYED, so that outcome is # the one mark of "never asked": it says nothing about whether the directory answered. asked = sum(1 for p in probes if p.outcome is not ProbeOutcome.UNKEYED) @@ -620,6 +631,8 @@ def plan_pass( referred=tuple(p.user_id for p in referred), faulted=tuple(p.user_id for p in faulted), misconfigured=tuple(p.user_id for p in misconfigured), + refused_bind=refused_bind, + refused_search=refused_search, aborted=aborted, latched=latched, ) @@ -730,6 +743,8 @@ def plan_pass( referred=tuple(p.user_id for p in referred), faulted=tuple(p.user_id for p in faulted), misconfigured=tuple(p.user_id for p in misconfigured), + refused_bind=refused_bind, + refused_search=refused_search, outcomes=outcomes, hold=hold, latched=hold_latches(undetermined=undetermined, latched=latched), diff --git a/messagefoundry/auth/service.py b/messagefoundry/auth/service.py index ed7f375cec..dbc1af5e5e 100644 --- a/messagefoundry/auth/service.py +++ b/messagefoundry/auth/service.py @@ -10227,7 +10227,11 @@ async def _probe_principal(self, user: UserRecord) -> reconcile.Probe: # diagnostic message. _log.debug("directory probe of %s was refused: %s", user.username, exc) return reconcile.Probe( - user.id, user.username, reconcile.ProbeOutcome.MISCONFIGURED, detail=str(exc) + user.id, + user.username, + reconcile.ProbeOutcome.MISCONFIGURED, + detail=str(exc), + refused_bind=exc.refused_bind, ) # FAIL OPEN, for the reconciler. verify_mfa reads the same UNAVAILABLE as a refusal and # fails closed, because it grants rather than revokes (BACKLOG #2023). It writes an audit diff --git a/tests/test_ldap_refused_service_bind_reconcile.py b/tests/test_ldap_refused_service_bind_reconcile.py index c438752b32..6ceae0abc3 100644 --- a/tests/test_ldap_refused_service_bind_reconcile.py +++ b/tests/test_ldap_refused_service_bind_reconcile.py @@ -21,6 +21,7 @@ import copy import logging import pickle +import time from types import SimpleNamespace from typing import Any @@ -34,9 +35,17 @@ RESULT_UNAVAILABLE, ) +from messagefoundry.api.app import _alert_reconcile_plan from messagefoundry.auth import ldap as ldap_module from messagefoundry.auth.ldap import LdapUnansweredError -from messagefoundry.auth.reconcile import MISCONFIGURED_ABORT, OUTAGE_ABORT, ProbeOutcome +from messagefoundry.auth.reconcile import ( + MISCONFIGURED_ABORT, + OUTAGE_ABORT, + Probe, + ProbeOutcome, + plan_pass, +) +from messagefoundry.pipeline.alert_sinks import NotifierAlertSink from tests.test_ad_user_account_control import ( _alive, _audited, @@ -44,6 +53,7 @@ _settings, _signed_in_estate, ) +from tests.test_alert_sinks import _drain, _RecordingTransport from tests.test_approval_requester_recheck import _Sink #: The service account the estate's settings bind as. @@ -176,7 +186,7 @@ async def test_a_refused_service_bind_pages_on_every_pass_and_never_revokes( assert _LEAK not in caplog.text # formatted records, tracebacks included pages = [e[1] for e in sink.events if e[0] == "ad_reconcile_aborted"] if misconfigured: - assert pages == ["directory-reconciler-misconfigured"] * passes + assert pages == ["directory-reconciler-service-bind"] * passes alert = service.directory_reconcile_misconfigured assert alert is not None # The setting a refused bind points at leads the message, inside the store's @@ -187,3 +197,82 @@ async def test_a_refused_service_bind_pages_on_every_pass_and_never_revokes( outage = [e[2]["reason"] for e in sink.events if e[1] == "directory-reconciler-outage"] assert pages == ["directory-reconciler-outage"] and outage == [OUTAGE_ABORT] assert service.directory_reconcile_misconfigured is None + + +async def test_a_refused_service_bind_still_pages_while_the_search_refusal_is_suspended( + monkeypatch: pytest.MonkeyPatch, +) -> None: + """A notifier keys a suspend on the alert's type and source. An operator who suspends the + search refusal's page, for a deleted group base, must still be paged when the service password + then expires, so the refused service bind pages under its own source. + + RED before the fix: the refused bind paged under the search refusal's source, which the + suspend muted.""" + names = ["user00", "user01"] + async with _signed_in_estate(monkeypatch, names) as (_directory, service, _store, _tokens): + _refuse_the_service_bind(monkeypatch, RESULT_INVALID_CREDENTIALS) + transport = _RecordingTransport("t") + sink = NotifierAlertSink([transport], realert_seconds=0.0) + sink.suspend( + "ad_reconcile_aborted", "directory-reconciler-misconfigured", until=time.time() + 3600 + ) + plan = await _pass(service, sink) + assert plan.aborted == MISCONFIGURED_ABORT + await _drain(sink) + assert [ + (e["connection"], e["reason"]) + for e in transport.events + if e["type"] == "ad_reconcile_aborted" + ] == [("directory-reconciler-service-bind", MISCONFIGURED_ABORT)] + + +class _Auth: + """The latched messages :func:`_alert_reconcile_plan` reads, none latched.""" + + directory_reconcile_alert = None + directory_reconcile_referral = None + directory_reconcile_misconfigured = None + directory_reconcile_fault = None + + +@pytest.mark.parametrize( + ("bind", "search", "sources"), + [ + pytest.param(True, False, ["directory-reconciler-service-bind"], id="bind"), + # THE CONTROLS: a refused search keeps its source, and a pass with both raises both. + pytest.param(False, True, ["directory-reconciler-misconfigured"], id="search"), + pytest.param( + True, + True, + ["directory-reconciler-service-bind", "directory-reconciler-misconfigured"], + id="both", + ), + ], +) +@pytest.mark.parametrize("answered", [False, True], ids=["aborted", "beside-an-answer"]) +def test_each_refusal_raises_under_its_own_source( + bind: bool, search: bool, sources: list[str], answered: bool +) -> None: + """A refused service bind raises under ``directory-reconciler-service-bind`` and a refused + search under ``directory-reconciler-misconfigured``, on an aborted pass and on one that judged + another account.""" + probes = [ + Probe(f"u{n}", f"user{n}", ProbeOutcome.MISCONFIGURED, refused_bind=refused) + for n, refused in enumerate([True] * bind + [False] * search) + ] + if answered: + probes.append(Probe("ok", "ok", ProbeOutcome.PRESENT)) + plan = plan_pass( + probes, + prior_strikes={}, + current_roles={}, + target_roles={}, + strike_threshold=3, + max_absolute=10, + max_fraction=0.5, + ) + assert (plan.refused_bind, plan.refused_search) == (bind, search) + assert (plan.aborted == MISCONFIGURED_ABORT) is not answered + sink = _Sink() + _alert_reconcile_plan(plan, _Auth(), sink) # type: ignore[arg-type] + assert [e[1] for e in sink.events if e[0] == "ad_reconcile_aborted"] == sources From a1be7c31ab667fb7b943c512312f87f959276daa Mon Sep 17 00:00:00 2001 From: Scott Hall Date: Wed, 2 Dec 2026 19:19:49 -0600 Subject: [PATCH 5/5] Name the service-bind alert source in the sink contract and docs Review round-95dc8a2c71 on the repair: the AlertSink.ad_reconcile_aborted docstring now lists directory-reconciler-service-bind; the CONFIGURATION.md paragraph names each source in the sentence that says when it is raised; the changelog fragment keeps its readings together and its wrapping. The suspend test gains its negative control, a search refusal's page the suspend mutes, and the source table test reuses the shared _AUTH stand-in. BACKLOG #8161 (item 1), repair of the Lander's hold on PR 3594. Verified-by: tests --- .../refused-service-bind-pages.changed.md | 11 ++++++----- docs/CONFIGURATION.md | 14 +++++++------- messagefoundry/pipeline/alerts.py | 3 ++- ...est_ldap_refused_service_bind_reconcile.py | 19 +++++++++---------- 4 files changed, 24 insertions(+), 23 deletions(-) diff --git a/changelog.d/refused-service-bind-pages.changed.md b/changelog.d/refused-service-bind-pages.changed.md index 194176ced6..0cdc415620 100644 --- a/changelog.d/refused-service-bind-pages.changed.md +++ b/changelog.d/refused-service-bind-pages.changed.md @@ -5,10 +5,11 @@ `[auth].ad_reconcile_outage_passes` passes, although the refusal recurs on every pass while it lasts. It now reads as a configuration refusal, like a bind refused for its DN: each such pass raises `ad_reconcile_aborted` with reason `directory_misconfigured` and audits - `auth.ad_reconcile_misconfigured`. A refused service-account bind raises it under its own source, - `directory-reconciler-service-bind`, so suspending the search refusal's - `directory-reconciler-misconfigured` instance does not mute it; a service bind refused with - noSuchObject, invalidDNSyntax or insufficientAccessRights moves to that source too. Neither reading strikes or revokes an account. That alert has + `auth.ad_reconcile_misconfigured`. Neither reading strikes or revokes an account. That alert has no inverse, so resolve it by hand once the bind succeeds again, including after a lockout ends on its own. The alert's message now names `[auth].ad_bind_dn` and its password first. A corrected - service password takes effect only after a restart. + service password takes effect only after a restart. A refused service-account bind raises that + alert under its own source, `directory-reconciler-service-bind`, apart from a refused search's + `directory-reconciler-misconfigured`; a service bind refused with noSuchObject, invalidDNSyntax + or insufficientAccessRights, which raised under `directory-reconciler-misconfigured`, moves to + the new source too. diff --git a/docs/CONFIGURATION.md b/docs/CONFIGURATION.md index bf0a68969e..3f51ade110 100644 --- a/docs/CONFIGURATION.md +++ b/docs/CONFIGURATION.md @@ -1021,13 +1021,13 @@ which a probe fails to read an entry. Nothing resolves it automatically. Resolve WARNING lines that name each faulting account stop. A configuration refusal opens its own `ad_reconcile_aborted` instance as well, with reason -`directory_misconfigured` and source `directory-reconciler-misconfigured` (BACKLOG #3010). The -reconciler raises it on every pass in which the directory refuses a search with noSuchObject, -invalidDNSyntax or insufficientAccessRights, as a deleted or moved search base does, or refuses the -service-account bind with one of those codes or invalidCredentials, as a wrong or expired service -password or a locked `[auth].ad_bind_dn` account does. A refused service-account bind raises -under its own source, `directory-reconciler-service-bind`, with the same reason, so suspending -one source's instance does not mute the other. Before #3010 such a base read as +`directory_misconfigured` (BACKLOG #3010). The reconciler raises it on every pass in which the +directory refuses a search with noSuchObject, invalidDNSyntax or insufficientAccessRights, as a +deleted or moved search base does, under the source `directory-reconciler-misconfigured`. It +raises it under the source `directory-reconciler-service-bind` on every pass in which the +directory refuses the service-account bind with one of those codes or invalidCredentials, as a +wrong or expired service password or a locked `[auth].ad_bind_dn` account does, and under both +sources on a pass that saw both. Before #3010 such a base read as "not found" for every account. Nothing resolves it automatically either. A search base changes only on a restart, and so does the service password: the engine reads `[auth].ad_bind_password` or `[auth].ad_bind_password_secret` once, at start. Resolve the alert by hand once the base or the diff --git a/messagefoundry/pipeline/alerts.py b/messagefoundry/pipeline/alerts.py index 21cf1830dd..2318f767b6 100644 --- a/messagefoundry/pipeline/alerts.py +++ b/messagefoundry/pipeline/alerts.py @@ -834,7 +834,8 @@ def ad_reconcile_aborted(self, name: str, *, reason: str, probed: int, detail: s ``name`` labels the source: ``"directory-reconciler"`` for the breaker, ``"directory-reconciler-referral"`` for a referral, ``"directory-reconciler-probe-fault"`` - for a probe fault, ``"directory-reconciler-misconfigured"`` for a configuration refusal, + for a probe fault, ``"directory-reconciler-misconfigured"`` for a configuration refusal of + a search, ``"directory-reconciler-service-bind"`` for one of the service-account bind, ``"directory-reconciler-paging:"`` for a paging refusal, ``"directory-reconciler-outage"`` for a lasting outage, and ``"directory-reconciler-unreached:"`` for an unreached account, or diff --git a/tests/test_ldap_refused_service_bind_reconcile.py b/tests/test_ldap_refused_service_bind_reconcile.py index 6ceae0abc3..2633173a85 100644 --- a/tests/test_ldap_refused_service_bind_reconcile.py +++ b/tests/test_ldap_refused_service_bind_reconcile.py @@ -47,6 +47,7 @@ ) from messagefoundry.pipeline.alert_sinks import NotifierAlertSink from tests.test_ad_user_account_control import ( + _AUTH, _alive, _audited, _pass, @@ -218,6 +219,13 @@ async def test_a_refused_service_bind_still_pages_while_the_search_refusal_is_su ) plan = await _pass(service, sink) assert plan.aborted == MISCONFIGURED_ABORT + # THE CONTROL: the suspend mutes what it names, a search refusal's page. + sink.ad_reconcile_aborted( + "directory-reconciler-misconfigured", + reason=MISCONFIGURED_ABORT, + probed=1, + detail="search refused", + ) await _drain(sink) assert [ (e["connection"], e["reason"]) @@ -226,15 +234,6 @@ async def test_a_refused_service_bind_still_pages_while_the_search_refusal_is_su ] == [("directory-reconciler-service-bind", MISCONFIGURED_ABORT)] -class _Auth: - """The latched messages :func:`_alert_reconcile_plan` reads, none latched.""" - - directory_reconcile_alert = None - directory_reconcile_referral = None - directory_reconcile_misconfigured = None - directory_reconcile_fault = None - - @pytest.mark.parametrize( ("bind", "search", "sources"), [ @@ -274,5 +273,5 @@ def test_each_refusal_raises_under_its_own_source( assert (plan.refused_bind, plan.refused_search) == (bind, search) assert (plan.aborted == MISCONFIGURED_ABORT) is not answered sink = _Sink() - _alert_reconcile_plan(plan, _Auth(), sink) # type: ignore[arg-type] + _alert_reconcile_plan(plan, _AUTH, sink) # type: ignore[arg-type] assert [e[1] for e in sink.events if e[0] == "ad_reconcile_aborted"] == sources