Skip to content

[#1126] Support PROXY protocol on LDAP listeners - #1293

Open
vharseko wants to merge 6 commits into
OpenIdentityPlatform:masterfrom
vharseko:features/haproxy
Open

vharseko wants to merge 6 commits into
OpenIdentityPlatform:masterfrom
vharseko:features/haproxy

Conversation

@vharseko

@vharseko vharseko commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

LDAP clients behind an nginx or HAProxy load balancer currently appear to OpenDJ as the balancer, so address-based access rules, logs and monitoring cannot identify the client. Support PROXY protocol v1 and v2 on LDAP connection handlers to carry the client address and port before LDAP or TLS traffic.

  • Require a header from a trusted TCP peer when enabled. An empty proxy-protocol-allowed-client list rejects every connection. Changes to the list apply to new connections.
  • Apply address-based admission, limits, plugins, logs and monitoring to the forwarded address. In lockdown mode, require both the TCP peer and the forwarded client to be loopback at final admission. Normalize IPv4-mapped IPv6 addresses for IPv4 rules and connection limits.
  • Forward validated v2 SSL metadata to secure-authentication and SSF checks without inventing a TLS session or client certificate. Preserve the TCP peer for LOCAL, UNKNOWN and UNSPEC addresses. Missing or unrecognized ciphers contribute zero proxy SSF.
  • Use the PingDS attribute and syntax OIDs, reject this configuration on the legacy handler, and document the feature and a Docker/nginx walkthrough using the openidentityplatform/opendj:latest and nginx:latest release images. Document send-proxy-v2-ssl proxy-v2-options ssl-cipher for HAProxy TLS termination while retaining backend-connection protection guidance. PingDS-style &{...} configuration expressions are not implemented.
  • Report invalid numeric fields as protocol errors, with explicit handling for numeric conversion failures.
  • Copy PROXY header bytes from each Grizzly receive buffer. Retain incomplete header bytes in a bounded array and return each fragment's receive buffer to the pool. Forward remaining LDAP or TLS bytes only while the connection is active.
  • Run post-connect plugins outside the connection monitor so a close can release the address slot while the plugin is running. Keep CONNECT logging ordered with disconnect cleanup.

Validation

  • On Java 27, the latest revision passed 75 focused tests with zero failures, errors or skips. This includes 13 decoder tests, 11 Grizzly tests and 51 server integration tests. Both nginx integration tests ran with nginx:latest (1.31.9 at validation time) and Docker API 1.44, covering PROXY v1/v2, LDAPS and StartTLS. The preceding revision also passed the full Grizzly suite (1,074 invocations) and 70 server integration tests.
  • Grizzly regressions check pool returns for a header-only read, invalid input, callback disconnect and close during an incomplete header. The incomplete-header test checks that the buffer returns exactly once, with one return before close and the same count after close. The active-connection control verifies delivery of a BIND from the same buffer.
  • Server regressions require a successful BindResponse after a post-connect plugin fails or a connection closes while its plugin is blocked. The blocked-plugin test also verifies that close releases the forwarded address slot before the plugin resumes. The deferred lockdown test verifies a usable local TCP path before checking rejection of a non-loopback TCP peer.
  • The earlier mutation run on the original coalesced-buffer test confirmed that removing the post-callback active guard delivered the buffered BIND after a disconnect. The active-connection control still passed.
  • Rendered the administration-guide chapter with AsciidoctorJ 2.5.11 on Java 17 and checked the HAProxy guidance in the HTML output. git diff --check passed.
  • Earlier in the PR, exercised the Docker walkthrough with an OpenDJ image built from the branch. LDAP bind and search succeeded, the access log showed the client address, and the server rejected a direct connection from an untrusted client. On the latest revision, rendered the How-To guide with AsciidoctorJ 2.5.11, checked all ten Bash examples with bash -n, and ran nginx -t on the example configuration with nginx:latest.

Fixes #1126

@vharseko vharseko added enhancement java Changes to Java sources protocol LDAP protocol extensions, controls and RFC support tls TLS connections, certificates, and encrypted handshakes tests Test suites: fixing, enabling, un-disabling docs schema LDAP schema: attribute types, object classes, DIT structure rules, name forms docker labels Nov 13, 2026
@vharseko
vharseko requested a review from maximthomas November 13, 2026 12:46
@vharseko vharseko added the security Security fixes / CodeQL code-scanning alerts label Nov 13, 2026
@vharseko
vharseko requested review from maximthomas and removed request for maximthomas November 13, 2026 13:16

@maximthomas maximthomas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: The feature has regression coverage at the decoder, Grizzly transport, and server integration layers.

  • ProxyProtocolDecoderTestCase: 13 tests passed at HEAD.
  • GrizzlyProxyProtocolTestCase: 6 passed; LDAPProxyProtocolTestCase: 24 passed. All three XML reports show zero failures, errors, and skips on Java 26.

suggestion (non-blocking): The callback-disconnect test does not ensure that the request is coalesced with the PROXY header.

opendj-grizzly/src/test/java/org/forgerock/opendj/grizzly/GrizzlyProxyProtocolTestCase.java:174-178

The header and BIND are sent in separate socket writes. If the server reads only the header, the callback closes the connection and input.hasRemaining() is false, so the assertions can pass even with the post-callback active guard removed from ProxyProtocolFilter.handleRead. This is a static scheduling gap; no mutation survival rate was measured.

Pin: In a follow-up Grizzly filter test, supply one input buffer containing both the header and BIND, make the header callback set the active supplier to false, and assert that the downstream filter is never invoked. Removing the active guard must make that test fail. No change is required in this PR.


issue (non-blocking): send-proxy-v2-ssl alone does not forward the cipher used for SSF evaluation.

opendj-doc-generated-ref/src/main/asciidoc/admin-guide/chap-connection-handlers.adoc:158

HAProxy enables its cipher TLV separately through proxy-v2-options ssl-cipher; see the HAProxy configuration manual and versioned parser. Without that TLV, LDAPServerFilter.getProxySecurityStrengthFactor() returns zero, so SSF requirements can reject the connection when backend TLS/SASL supplies no independent strength. The missing-cipher fallback is correct; the documentation omits the setting needed for its claim.

Document the option pair explicitly:

send-proxy-v2-ssl proxy-v2-options ssl-cipher

Keep the guidance to protect the backend connection. The option pair was checked against upstream documentation/source; no live HAProxy run was performed.

@vharseko

Copy link
Copy Markdown
Member Author

@maximthomas Addressed both non-blocking points in 9c4f4ce19e.

  • Documented send-proxy-v2-ssl proxy-v2-options ssl-cipher on HAProxy backend server lines, retaining the missing/unknown cipher fallback and the guidance to protect the backend connection.
  • Added a direct Grizzly filter-chain test with one buffer containing the PROXY header and BIND. The header callback changes the active supplier to false, and the downstream filter must not run. A positive control keeps the supplier true and verifies delivery. The existing socket test is retained.

Validation on Java 27: all 1,071 Grizzly test invocations and 13 decoder tests passed, with zero failures, errors, or skips. An isolated mutation removing the post-callback active guard fails the new disconnect case with downstream reads expected 0, actual 1; the positive control still passes. The changed administration-guide chapter was rendered with AsciidoctorJ 2.5.11.

@vharseko
vharseko requested a review from maximthomas November 13, 2026 15:07

@maximthomas maximthomas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: The new direct-buffer regression test pins callback-triggered suppression of buffered LDAP traffic.

  • headerCallbackControlsDeliveryOfCoalescedRequest supplies the header and BIND in one buffer and checks both inactive and active states.
  • Reviewer execution on Java 26 passed all eight class invocations; removing only the post-callback active guard failed the inactive row while the active control passed.

@vharseko vharseko added this to the 5.3.0 milestone Nov 14, 2026
@maximthomas
maximthomas self-requested a review November 18, 2026 14:59

@maximthomas maximthomas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: The coalesced-header test checks that the callback stops delivery after a disconnect and still delivers the request on an active connection.


issue (blocking): Return PROXY header buffers to the Grizzly pool.

ProxyProtocolFilter.java:51–74

On a pooled receive buffer, input.duplicate() adds a reference, and the filter drops that reference after copying the prefix. Disposing the original downstream therefore leaves the buffer unavailable for reuse. A header-only read also stops the chain without releasing its original buffer. Copy the prefix without duplicating the Grizzly buffer, and release the input on terminal paths that do not hand it downstream or retain it for the next read.


issue (non-blocking): Run post-connect plugins outside the connection monitor.

LDAPConnectionHandler2.java:1231–1265

finishProxyAdmission() invokes plugins while holding the connection monitor. If the first-request timer expires during a slow callback, the handler's only timer thread enters connectionClosed() and waits for that same monitor. Other first-request deadlines on the handler then wait for the callback to return. Keep the address-slot bookkeeping under the monitor and release it before invoking plugins.


issue (non-blocking): Recheck the TCP peer when completing admission in lockdown mode.

LDAPConnectionHandler2.java:1231–1240

The TCP peer is checked on accept. If lockdown starts while a connection is waiting for its header, the final admission check sees only the forwarded address and can admit a non-loopback TCP peer when the forwarded address is loopback. Recheck both addresses at final admission to enforce the documented loopback requirement. Administration guide

@vharseko

Copy link
Copy Markdown
Member Author

@maximthomas I addressed the three findings in 207f6d31d3. The branch is rebased onto origin/master.

  • F1. ProxyProtocolFilter copies the header directly from the receive buffer. The test covers pool returns for a header-only read, a malformed header and a callback-triggered disconnect. The active control checks delivery and downstream release of the same-buffer BIND. Grizzly retains incomplete reads for the next fragment. Its handling of a pending read on close is a separate path. Grizzly 3.0.1 filter chain
  • F2. The connection monitor protects address-slot bookkeeping. The post-connect callback runs outside it, and the regression requires disconnect() to finish while the plugin is still blocked. The next connection verifies slot reuse.
  • F3. Final admission checks both addresses in lockdown mode and logs the TCP peer and client when it rejects a connection. The regression enables lockdown after TCP acceptance and before the header arrives.

On Java 27, all 1,073 Grizzly invocations passed with the transport changes. The final revision passed 13 decoder tests, 10 focused Grizzly tests and 70 server integration tests, including two with nginx 1.31.4, with zero failures, errors or skips.

@vharseko
vharseko requested a review from maximthomas November 18, 2026 16:39

@maximthomas maximthomas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: The pooled-buffer regression checks disposal on terminal reads and verifies the full BIND payload on the active path.


issue (non-blocking): Release pending PROXY read buffers when the connection closes.

ProxyProtocolFilter.java:55–57

An incomplete header transfers its pooled receive buffer to Grizzly’s READ state. A peer close or the first-request timeout runs the separate CLOSE operation and leaves the READ buffer checked out. This forfeits pool reuse and can trigger additional direct-buffer allocations before the original memory is reclaimed. Give pending header data an explicit owner that releases pooled buffers on both completion and close. Grizzly 3.0.1 filter-chain state


suggestion (non-blocking): Require a successful bind in both address-slot reuse checks.

LDAPProxyProtocolTestCase.java:551 and LDAPProxyProtocolTestCase.java:697

Both fixtures enable rejection notices. If cleanup retains the reservation, the next connection hits the per-address limit and receives a Notice of Disconnection, which also starts with BER 0x30. The address assertion can still use the value recorded by the first callback. Use the existing assertSuccessfulBind(next) helper at both sites.

Pin: A replacement with the previous slot still reserved must fail the assertion because the helper requires a successful BindResponse.


issue (non-blocking): Use a reachable local interface for the deferred lockdown test.

LDAPProxyProtocolTestCase.java:137–144

The test uses the first up non-loopback IPv4 interface as both endpoints. On macOS this selected the point-to-point utun4 interface, and the test timed out before enabling lockdown. A standalone local TCP check also timed out in accept() on that interface after connect() returned. The ordinary non-loopback interface passed the same check. Select a non-loopback address with a working local TCP path and skip the case when none is available.

Require successful binds when checking address-slot reuse and select
a reachable non-loopback address for the deferred lockdown test.
@vharseko

Copy link
Copy Markdown
Member Author

@maximthomas I addressed the three follow-up findings in 625a057f8f.

  • R3-F1. The filter copies each incomplete header fragment into a bounded byte array and returns the receive buffer to the pool during the read. The regression drives a read followed by a close and observed zero pool returns before the fix and one after it.
  • R3-F2. Both address-slot reuse checks now use assertSuccessfulBind(next), which verifies a successful BindResponse.
  • R3-F3. The deferred lockdown test checks both TCP connect and accept on a temporary listener before selecting a non-loopback IPv4 or IPv6 address. It skips when no address provides a working local TCP path.

On Java 27, 13 decoder tests, all 1,074 Grizzly test invocations and 70 server integration tests passed. The server total includes both nginx 1.31.4 tests, which passed separately with Docker API 1.44.

@vharseko
vharseko requested a review from maximthomas November 19, 2026 17:33

@maximthomas maximthomas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: Both address-slot reuse tests now require a successful LDAP BindResponse.


suggestion (non-blocking): Assert that an incomplete read returns its receive buffer before close.

GrizzlyProxyProtocolTestCase.java:270–272

The probe is read after both READ and CLOSED. A filter that copies an incomplete fragment and holds its receive buffer until close would pass this check while keeping the buffer checked out between reads. Check the count immediately after the synchronous READ and keep the existing check after CLOSED.

Pin: The count is one when the incomplete read returns and remains one after close. An explicit split inside the v2 prefix can also verify one header callback and exact delivery of the trailing BindRequest.


suggestion (non-blocking): Check that close frees the address slot while the plugin is still blocked.

LDAPProxyProtocolTestCase.java:703–707

The test waits for close to finish while the plugin is blocked, then releases the plugin before opening the replacement connection. A change that lets close return and defers slot cleanup to callback completion could still pass the subsequent bind. Assert that the address has no reservation immediately after close.get(...) and before release.countDown(), then keep the successful replacement bind. The existing limit test already reads the handler’s reservation count. LDAPConnectionLimitsTestCase.java:761–771

Pin: The slot count for the forwarded address is zero while the original callback is still blocked.


suggestion (non-blocking): State which OpenDJ image the walkthrough requires.

nginx-proxy-protocol.adoc:28–33

The documentation can publish from master before the release workflow advances the Docker Hub latest tag. At review time that tag points to 5.2.0, whose dsconfig does not have the new PROXY properties, so the handler creation step would fail before the first supporting release. As a documentation follow-up, require an image with LDAP PROXY support and point readers to a branch build until the release image is available. Docker Hub tags, deploy.yml:325–340, release.yml:239–263


suggestion (non-blocking): Refresh the pinned nginx image in a dependency follow-up.

nginx-proxy-protocol.adoc:76, LDAPProxyProtocolNginxTestCase.java:82, LDAPProxyProtocolNginxTestCase.java:202

The walkthrough and integration fixture pin nginx:1.31.4. The official nginx:1.31.9 image retains outbound PROXY v2 support and includes upstream security fixes. Update both pins and the fixture’s version assertion together. NGINX directive documentation, NGINX security advisories, official image manifest

@vharseko

Copy link
Copy Markdown
Member Author

@maximthomas I addressed the test and nginx image follow-ups in c01e0afd44.

  • R4-F1: The Grizzly test now checks for one pool return immediately after the incomplete read and again after close.
  • R4-F2: The server test checks that closing the connection frees the forwarded address slot while the plugin is still blocked. It still requires a successful bind on the replacement connection.
  • R4-F3: The walkthrough targets the release that ships LDAP PROXY support and uses openidentityplatform/opendj:latest.
  • R4-F4: The walkthrough and both integration scenarios now use nginx:latest. The tests check the nginx configuration and exercise the protocol directly.

All 75 focused tests passed on Java 27 with zero failures, errors or skips. This includes both nginx scenarios with nginx:latest (1.31.9 at validation time). The How-To rendered successfully, its Bash examples passed syntax checks, and nginx -t accepted its configuration.

@vharseko
vharseko requested a review from maximthomas November 20, 2026 08:40

@maximthomas maximthomas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: The Grizzly test now checks the pool count immediately after the incomplete read and again after close.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docker docs enhancement java Changes to Java sources protocol LDAP protocol extensions, controls and RFC support schema LDAP schema: attribute types, object classes, DIT structure rules, name forms security Security fixes / CodeQL code-scanning alerts tests Test suites: fixing, enabling, un-disabling tls TLS connections, certificates, and encrypted handshakes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support the PROXY protocol (v1 and v2) in the LDAP connection handler so a server behind a load balancer sees the real client address

3 participants