Search icon
Script icon
If icon
Log icon
SlackIncomingWebhook icon
Pause icon
Modify icon
Fail icon
Schedule icon

Lock Expired LDAP Accounts That Slipped Through Offboarding

Find expired LDAP accounts that are still unlocked, lock them with an LDIF modify, then re-search to confirm the lock before the run passes.

Categories
Infrastructure

An account whose shadowExpire date has passed is meant to be dead, but expiry alone does not lock it. If the directory has a password policy, the account stays usable until something sets the lock attribute. These are the accounts that outlive an offboarding: expired on paper, still able to bind in practice. This blueprint finds them and locks them.

How it works

  1. detect (io.kestra.plugin.ldap.Search) searches under the base DN for shadowAccount entries that have a shadowExpire value and do not yet carry the lock attribute. The search writes the matching entries to an LDIF file.
  2. parse_detect (io.kestra.plugin.scripts.python.Script) reads that file and keeps only the entries whose shadowExpire day is in the past, minus an optional grace window. The date test runs here on purpose: shadowExpire has an equality rule but no ordering rule, so a server-side shadowExpire<=N filter matches nothing. The step writes an LDIF changetype: modify record for each target and reports the count.
  3. findings_alert (io.kestra.plugin.core.flow.If) posts the count and the DNs to Slack whenever at least one stale account is found, so a read-only run still surfaces the problem.
  4. remediate_gate runs only when auto_remediate is true, dry_run is false and there is something to fix. It pauses for human approval, then remediate (io.kestra.plugin.ldap.Modify) applies the LDIF and sets the lock attribute on each target.
  5. verify (io.kestra.plugin.ldap.Search) runs the same search again and parse_verify re-applies the past-expiry test. If any target is still unlocked, assert_locked fails the run so the gap cannot pass silently. The errors block then alerts Slack.

What you get

  • A list of accounts that are expired by shadowExpire but still unlocked, the ones most likely to be a forgotten offboarding.
  • A read-only default: the flow reports and never writes unless two inputs are flipped and a human approves.
  • A lock applied through a plain LDIF modify, so it works with whatever attribute your schema uses for lockout.
  • A re-search that fails the run when a lock did not land, because the Modify task logs a rejected record rather than failing on it.
  • A Slack alert on detection and a second alert on failure.

Who it's for

  • IT and identity teams running OpenLDAP or 389 Directory Server who track account expiry with shadowExpire.
  • Security teams that need expired accounts locked, not just flagged, with proof the lock took.
  • Platform teams who want a scheduled audit that is safe to leave on because it defaults to read-only.

Why orchestrate this with Kestra

Locking stale accounts by hand means an ldapsearch, eyeballing dates, writing LDIF then running ldapmodify, with nothing checking the result. Kestra turns that into one audited flow: the detection, the date logic, the approval, the write and the re-check all run in order with logs and a Slack trail. The read-only default and the approval pause make it safe to schedule.

Tested end to end

Run against OpenLDAP (osixia/openldap) with the ppolicy overlay loaded. Five seeded accounts: two expired and unlocked, one expired and already locked, one with a future expiry, one with no expiry. Detection found exactly the two expired unlocked accounts. A dry_run pass reported them and left the directory untouched (confirmed with ldapsearch). A remediation pass locked both and the re-search returned zero. The failure path was exercised with a bad bind password, which fired the errors block.

Prerequisites

An LDAP directory reachable from Kestra, with a bind account allowed to search and modify entries plus a lock attribute your schema accepts (pwdAccountLockedTime with the OpenLDAP ppolicy overlay or nsAccountLock on 389 Directory Server).

Secrets

  • LDAP_PASSWORD: bind password for the account named in bind_dn.
  • SLACK_WEBHOOK_URL: Slack incoming webhook for the findings and failure alerts.

Inputs

  • dry_run (default true) and auto_remediate (default false): both guard every write.
  • ldap_host, ldap_port, bind_dn, base_dn: connection and search scope.
  • lock_attribute (default pwdAccountLockedTime) and lock_value (default 000001010000Z): what marks an account locked.
  • inactive_grace_days (default 0): lock only accounts whose expiry passed at least this many days ago.

Quick start

  1. Add the LDAP_PASSWORD and SLACK_WEBHOOK_URL secrets to your namespace.
  2. Run with the defaults. The flow reports expired unlocked accounts and writes nothing.
  3. When the report looks right, run with dry_run false and auto_remediate true, then approve the pause to lock the accounts.
  4. Enable the schedule once you trust the report. It stays in read-only mode until you change its inputs.

How to extend

  • Point base_dn at a specific OU to scope the audit to one part of the tree.
  • Set inactive_grace_days to leave freshly expired accounts alone for a few days.
  • Swap lock_attribute and lock_value for the convention your directory uses, for example nsAccountLock set to true.
  • Add a step that moves locked accounts into an archive OU after a retention period.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.