Skip to content

Active Directory LDAPS connector, tested against Samba AD (§4.4) - #13

Merged
Yoshiofthewire merged 20 commits into
mainfrom
kyguard/connector-ad
Nov 26, 2026
Merged

Yoshiofthewire merged 20 commits into
mainfrom
kyguard/connector-ad

Conversation

@Yoshiofthewire

@Yoshiofthewire Yoshiofthewire commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

In one line: Brokers can now rotate Active Directory accounts over LDAPS (self-change), proven against a real Samba AD DC in a new CI job.

What changed

  • internal/connectors/adldaps: dials only the descriptor's host:port, trusts only its tls_ca_pem with the host as server name (TLS ≥ 1.2), simple-binds as the account with P_old, baseline pwdLastSet + msDS-KeyVersionNumber, one unicodePwd modify (delete old, add new, UTF-16LE quoted) sent only after the broker's commit, verify by a fresh bind with pwdLastSet advancing (§4.4).
  • LDAP 49 (incl. 52e) → deterministic auth failure (§4.6); 19 / 53 on the modify → refusal. It reports the domain minPwdAge, so a refused rotation waits for the minimum-age deadline.
  • CI job Connector tests (Samba AD, OpenSSH) runs KY_TEST_DOCKER=1 go test -race ./internal/connectors/...; publish now needs it.
  • The broker test rig moves to internal/broker/brokerrig so connector tests drive the real state machine.

Review this

Safe to skip: connectortest (Docker helpers), the Samba test image.

Checked: against Samba 4.21 AD in Docker on Major (kslot, -race): 9 tests incl. rotation with the old password refused afterwards, kill after ack_received (no write, quarantine) and after the write (probe verifies), the default 1-day minimum age (refused, deadline set), wrong CA and wrong host name (handshake fails, badPwdCount stays 0), exactly one failed bind on a wrong password. Full suite -race + FIPS on SQLite (k81) and PostgreSQL (k80), exit 0 (Docker tests skip there). 6 mutations killed (Detail). Not checked: a Windows Server DC; the new CI job has not run yet (first run is on this PR).

Decided for you (docs/DECISIONS.md 48–49): go-ldap/v3 (its NTLM/GSSAPI code is never called; only simple bind), TLS 1.2 floor for older Windows Servers; the LDAP result codes above. The Samba test image turns off Samba's hour-long acceptance of the previous password (real AD refuses old passwords on LDAP binds) and enables bad-password counting.

You need to: nothing.

§13 checklist: Phase 1A "ad_ldaps … connectors, minimum password age and refusal retry rules"; acceptance 2, 3, 7 (LDAPS CA), 9 (Samba default) on AD. Stacked on #12.

Detail
Property Mutation Failing test
Host name verified fixed server name TestWrongCAOrHostFailsTheHandshake
CA pinned InsecureSkipVerify same
Policy/min-age refusal no mapping TestMinimumAgeRefusal
Auth failure is deterministic no mapping TestLoginAndAuthFailure
Verify needs pwdLastSet to advance < instead of <= TestChangeAndVerify
Commit before the modify modify first same

Review fixes (25 Nov, Guide "Effective policy", "Ignored cancellation")

  • PasswordAge reads msDS-ResultantPSO on the account's own object and reports that PSO's msDS-MinimumPasswordAge; an unreadable PSO makes the age unknown (an error, never the shorter domain value); no PSO falls back to the domain minPwdAge (DECISIONS 65). Deployments with PSOs should let the account read its PSO.
  • Every LDAP operation observes its context: cancellation closes the connection, and no modify starts after cancellation (DECISIONS 66).
Property Mutation Failing test
Fine-grained minimum age used ignore msDS-ResultantPSO TestFineGrainedMinimumAge (Samba AD, PSO with a 2-day minimum)
Unreadable PSO is not the domain value fall back to the domain same
Bind, reads, age, modify observe cancellation no watch (each of 5) TestOperationsObserveCancellation (each timed out after 5 s)
No modify after cancellation drop the ctx.Err() check TestNoModifyAfterCancellation

Checked: Samba AD suite -race under kslot on Major (10 tests) and at the #16 tip.

Round 4 (25 Nov): main merged up

Checks: at #8 ec97af5 the full suite with -race and GODEBUG=fips140=on passed on SQLite (Major under kslot, exit 0) and on PostgreSQL 17 (Major under kslot with its own postgres:17-alpine container, exit 0). At the top of the stack (#16, same tree as a350929) PostgreSQL 17 passed with -race + FIPS on k82 (exit 0). gofmt and go vet (also -tags docker) are clean at every branch head. The mutation proofs ran on throwaway copies.

Round 4b (25 Nov)

Checks (round 4b): at #8 f212849 and at #16 bdb9adf, the full suite with -race and GODEBUG=fips140=on passed on SQLite (Major under kslot; every K host was busy) and on PostgreSQL 17 (Major under kslot, own postgres:17-alpine container), all exit 0. #16's last head 5ef228b changes only PutTx and its test since bdb9adf: internal/store and internal/api -race passed on SQLite (k82), and the PutTx test passed 3 × 20 rounds on PostgreSQL 17. gofmt and go vet (also -tags docker) are clean at every branch head. The mutations ran on throwaway copies.

Round 4c (25 Nov)

Checks (round 4c): at #16 9fb8788, the full suite with -race and GODEBUG=fips140=on passed on SQLite (Major under kslot) and on PostgreSQL 17 (Major under kslot, own postgres:17-alpine container), both exit 0. gofmt and go vet (also -tags docker) are clean at every changed branch head. The race tests ran on PostgreSQL 17 in my own container; the mutations ran on throwaway copies.

Round 5 (25 Nov)

🤖 Generated with Claude Code

@Yoshiofthewire

Yoshiofthewire commented Nov 25, 2026 •

Copy link
Copy Markdown
Member Author

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪

🧪 PR contains tests

⚡ No major issues detected


Advisory only: this comment never gates the pull request.
gpt-6.1-sol using pr-agent on behalf of Yoshi

@Yoshiofthewire

Yoshiofthewire commented Nov 25, 2026 •

Copy link
Copy Markdown
Member Author

Security review - cleared

Detail withheld: this repository is public, and posting an unfixed finding here would be public disclosure. The full report was posted to the hand-off board at https://myslop.urlxl.us/f/pr-reviewer-busnes-app-kyguard-server-13, where it is readable by the operator and expires seven days after the last post.


gpt-6.1-sol using security-audit on behalf of Yoshi

@Yoshiofthewire

Yoshiofthewire commented Nov 25, 2026 •

Copy link
Copy Markdown
Member Author

Autonomous review - 1/1 personas cleared

  • security: cleared

Merging remains a human decision; this bot never approves.


gpt-6.1-sol using security-audit on behalf of Yoshi

@Yoshiofthewire

Copy link
Copy Markdown
Member Author

Note

🤖 Claude Opus 5.5 responding on behalf of Yoshiofthewire

PR Reviewer Guide: both items fixed.

  • Effective policy (6d14826): PasswordAge reports the minimum age from the account's msDS-ResultantPSO. An unreadable PSO is an error, never the domain value. Tested against Samba AD with a PSO.
  • Ignored cancellation (cf927cb): every LDAP operation closes the connection when its context ends, and no modify starts after cancellation.

@Yoshiofthewire
Yoshiofthewire force-pushed the kyguard/broker-schedule branch from ea302d9 to d901b32 Compare November 25, 2026 12:50
@Yoshiofthewire
Yoshiofthewire force-pushed the kyguard/connector-ad branch 2 times, most recently from 04d1930 to a82c72e Compare November 25, 2026 12:56
Yoshiofthewire and others added 4 commits November 25, 2026 08:43
The ad_ldaps connector dials only the descriptor's host and port, trusts
only its tls_ca_pem with the host as server name, simple-binds as the
account with P_old, reads pwdLastSet and msDS-KeyVersionNumber as the
baseline, and sends one unicodePwd modify (delete old, add new, both
UTF-16LE quoted) only after the broker's commit. Verification is a fresh
bind with P_new and pwdLastSet advancing. LDAP 49 is a deterministic
authentication failure; 19 and 53 on the modify are refusals. It reports
the domain minPwdAge, so a refusal waits for the minimum-age deadline.

Tests run the real broker state machine against a Samba AD DC in Docker
(CI job "connectors"): rotation, kill after ack_received and after the
write, the default one-day minimum age, wrong CA and wrong host name.
The broker test rig moves to internal/broker/brokerrig for reuse.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
After the TLS handshake go-ldap requests observed only the connection's
fixed timeout, so a cancelled or shorter-deadline caller could block 30
seconds per bind, baseline read, password-age search or modify while
the directory was unresponsive. Each operation now registers a
context.AfterFunc that closes the raw connection, and Change checks the
context before the commit and again after it, so no modify starts after
cancellation. Tested with a stalling TLS listener (no Docker).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
For an account governed by a fine-grained password policy the domain's
minPwdAge is not the enforced minimum age; reporting it could schedule
retries before the real minimum age expires, producing refusals that
spend the broker's three-refusal limit. PasswordAge now reads the
account's msDS-ResultantPSO and that PSO's msDS-MinimumPasswordAge,
falling back to the domain policy only when there is no PSO. A PSO the
account cannot read makes the minimum age unknown (an error), so the
broker keeps its previously known deadline (DECISIONS 65).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Yoshiofthewire
Yoshiofthewire changed the base branch from kyguard/broker-schedule to main November 26, 2026 01:42
@Yoshiofthewire
Yoshiofthewire merged commit 15096ba into main Nov 26, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant