T13.3: Okta deprovisioning sync job, fail closed (D18)

run_sync() compares the Okta user list (T13.2) to active local accounts and
disables the ones Okta no longer vouches for. One AuditLog row per change,
actor system:okta_sync, action user_deprovisioned_by_sync.

Fail closed: any exception from the fetch, an empty or untrusted answer, or a
failed save changes nothing and writes nothing. The fetch runs before the
database is read, so a failed fetch has no path to a change. It only ever
disables; an already-disabled account is untouched and gets no new row.

Decided with Matt 2026-10-16: disable on missing, SUSPENDED or DEPROVISIONED.
PASSWORD_EXPIRED, LOCKED_OUT and RECOVERY do not disable (the job never
re-enables, so a literal "not ACTIVE" would lock people out for good).
Added a guard: no match between any active local account and any Okta user is
refused as a wrong identity attribute, not read as a mass offboarding.

tests/okta_sync_job_check.py: 71 checks; removing the fail-closed branch and the
guard fails 28 of them. BL-069 logs the missing per-run cap.
This commit is contained in:
2026-10-16 11:31:39 -07:00
parent 2f7de6e33b
commit 103e4d40ee
4 changed files with 402 additions and 8 deletions

View File

@@ -662,3 +662,20 @@ deliberately deferred.
worth confirming rather than assuming).
- **Suggested wave or follow-up:** next housekeeping pass — needs Nick on
whether to delete, archive, or rewrite it as historical record.
### BL-069 - The sync has no cap on one run and no last-admin guard
- **Found during:** T13.3 (D18)
- **Where:** `server/okta_sync.py` `run_sync()`
- **What:** a run disables every account the rules select, however many. If the
identity attribute is partly wrong (it matches some accounts and not others),
one run can disable most of the company, including every admin. The
zero-match guard only stops the case where nothing matches. Disabled accounts
cannot sign in, so re-enabling needs an admin who is still active, or the
`manage_users.py` command line on the host.
- **Why not now:** D18 does not ask for it, and the right limit is a product
call: a count, a share of accounts, a rule that the last active admin never
disables, or all three.
- **Suggested wave or follow-up:** before the first live run, or in T13.6 if
Matt decides. Needs Matt.

View File

@@ -144,18 +144,44 @@ assert zero rows changed and zero `AuditLog` entries written.
**Done when:**
- [ ] a user missing from Okta's list, or present but not active, is disabled
- [x] a user missing from Okta's list, or present but not active, is disabled
with a correctly-detailed audit row
- [ ] a user already disabled is left alone (no duplicate audit row each run)
- [ ] an active Okta user already active locally produces no audit row (only
*(2026-10-16: see "Decided 2026-10-16" below for which statuses count as "not active". Audit row: actor `system:okta_sync`, action `user_deprovisioned_by_sync`, `entity_type` user, `detail` `{okta_status, via}`; a missing user is recorded as `MISSING`.)*
- [x] a user already disabled is left alone (no duplicate audit row each run)
*(2026-10-16: a second run over the same data writes no new rows.)*
- [x] an active Okta user already active locally produces no audit row (only
changes are logged, not a clean bill of health every cycle)
- [ ] **a simulated Okta API failure results in zero account changes and zero
*(2026-10-16: verified in `tests/okta_sync_job_check.py`.)*
- [x] **a simulated Okta API failure results in zero account changes and zero
audit rows** — this is the one check that must never be skipped or
weakened
- [ ] the job never re-enables an account under any input
*(2026-10-16: 10 stand-in failures (OktaSyncError, RuntimeError, ConnectionError, TimeoutError, ValueError, KeyError, empty list, None, two kinds of garbage), 4 through the real client (HTTP 401/403/429/500), the default path with no token, a failed commit, and a wrong identity attribute. Each: `ok` is False, zero accounts changed, zero audit rows. Mutation test: removing the fail-closed branch and the zero-match guard fails 28 of these.)*
- [x] the job never re-enables an account under any input
*(2026-10-16: a disabled account that is ACTIVE in Okta stays disabled, and `okta_sync.py` contains no assignment of `is_active` to True.)*
---
**Decided 2026-10-16 (Matt, in chat):** which Okta statuses disable an account.
The spec says "a non-active status". Read literally, that also catches
`PASSWORD_EXPIRED`, `LOCKED_OUT` and `RECOVERY`, which people leave on their
own, and this job never re-enables, so one AD password expiry would lock someone
out of the app until an admin stepped in. Decided: an account disables when it is
**missing** from Okta's list, or every Okta entry for it is **SUSPENDED** or
**DEPROVISIONED** (`DISABLING_STATUSES` in `server/okta_sync.py`). Okta's default
user list already leaves out DEPROVISIONED users, so those arrive as "missing".
**Added 2026-10-16, inside decision 4's "anything the sync can't confidently
parse":** if there are active local accounts and **none** of them matches any
Okta user, the run is refused and nothing changes. That pattern means the
identity attribute is wrong (`OKTA_SYNC_PROFILE_ATTRIBUTE`), not that the whole
company left. It is a guard, not a new feature. Raise it in the PR.
**Open, for the PR / Nick:** which Okta profile attribute equals the
`preferred_username` claim in this tenant. The client assumes `profile.login`,
Okta's default. Confirm before the first live run. A wrong value is caught by the
zero-match guard above only when it matches nobody at all; a value that matches
some accounts and not others would disable the rest. See `BL-069`.
### T13.4 — D18: run it on a schedule
- **Items:** `D18`