Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions changelog.d/refused-service-bind-pages.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
- **A service-account bind the directory refuses with invalidCredentials now pages on every
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. 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. 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.
18 changes: 12 additions & 6 deletions docs/CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -1021,12 +1021,18 @@ 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. 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.
`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
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:<username>` (vault BACKLOG #3696). Nothing resolves it automatically.
Expand Down
2 changes: 1 addition & 1 deletion docs/PHI.md

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion docs/SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -6813,7 +6813,13 @@ 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 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
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
Expand Down
39 changes: 29 additions & 10 deletions messagefoundry/api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -13144,10 +13148,13 @@ 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
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).

Expand Down Expand Up @@ -13234,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(
Expand Down
74 changes: 48 additions & 26 deletions messagefoundry/auth/ldap.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,11 @@ 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`` 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__``.
"""

def __init__(
Expand All @@ -262,20 +265,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
"""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 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.code in _CONFIGURATION_CODES
return _reads_as_configuration(self.code, refused_bind=self.refused_bind)


class LdapUndecodableError(LdapError):
Expand Down Expand Up @@ -998,12 +1005,19 @@ 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})


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:
Expand All @@ -1029,16 +1043,18 @@ 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
no caller sees a shorter group list.
**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
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.

Expand All @@ -1047,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
Expand All @@ -1073,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.
"""
Expand All @@ -1088,20 +1106,22 @@ 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 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:
if _reads_as_configuration(code, refused_bind=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"
message = f"AD ended the {operation} with {shown}, {verdict}; {reading} (BACKLOG #3010).{hint}"
# 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),
Expand Down Expand Up @@ -1704,7 +1724,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.
Expand Down
Loading
Loading