Skip to content

feat: [OCISDEV-1032] ldap config and retry policy - #673

Merged
2403905 merged 5 commits into
stable-8.0from
feat/ocisdev-1032
Jul 30, 2026
Merged

2403905 merged 5 commits into
stable-8.0from
feat/ocisdev-1032

Conversation

@mklos-kw

Copy link
Copy Markdown
Member

No description provided.

@kw-security

kw-security commented Jul 29, 2026 •

Copy link
Copy Markdown

✅ Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues
✅ Licenses 0 0 0 0 0 issues
✅ Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@mklos-kw mklos-kw changed the title feat: ldap config and retry policy feat: [OCISDEV-1032] ldap config and retry policy Jul 29, 2026
@mklos-kw
mklos-kw marked this pull request as ready for review July 29, 2026 08:29
Comment thread pkg/utils/ldap/reconnect.go Outdated
"fmt"
"time"

backoff "github.com/cenkalti/backoff"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What version of backoff are we using here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No version suffix is v2 based on go.mod

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Any reason to use such an old version?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No, it was pulled by default from go.mod, bumped to v5

@2403905

2403905 commented Jul 29, 2026

Copy link
Copy Markdown

Correctness

1. Exhaustion masks the real error code (behavioral regression for the new codes).
RetryOp returns ldap.NewError(ldap.ErrorNetwork, errMaxRetries) on exhaustion regardless of the actual failure. Previously this only ever happened after ErrorNetwork retries, so the label was truthful. Now a read that exhausts on LDAPResultBusy/Unavailable/Timeout is reported to callers as ErrorNetwork. This misleads logs and any caller that inspects the code (e.g. pkg/auth/manager/ldap/ldap.go:127 keys on result codes). Recommend returning the last real err (or wrapping it) instead of a synthetic ErrorNetwork.

2. ldapErrCode maps every non-LDAP error to ErrorNetwork → write double-apply risk.
For writes, ErrorNetwork is retryable with reconnect. The ticket's premise is that these codes mean "provably never reached the server." But go-ldap surfaces a connection that breaks mid-operation (after the request was transmitted, response not yet read) as ErrorNetwork too — and any unrecognized/wrapped error is also coerced to ErrorNetwork here. That reopens exactly the double-apply / spurious EntryAlreadyExists hazard the write policy is meant to avoid. It's partly inherent to the ticket's design, but the blanket "unknown → ErrorNetwork" default widens the exposure. Worth a comment acknowledging the assumption, and ideally not coercing unknown errors into a retryable write code.

3. Backoff collapses to zero when MaxDelay is unset but BaseDelay > 0.
bo.MaxInterval = policy.MaxDelay. With cenkalti/backoff v2, once currentInterval is incremented past MaxInterval/Multiplier, it's clamped to MaxInterval; if that's 0, every sleep after the first becomes ~0. So a config of BaseDelay=50ms, MaxDelay=0 silently degrades to a single delay then hot-retries. Recommend validating/defaulting MaxDelay (e.g. to a multiple of BaseDelay) when BaseDelay > 0.

@mklos-kw

Copy link
Copy Markdown
Member Author

Correctness

1. Exhaustion masks the real error code (behavioral regression for the new codes). RetryOp returns ldap.NewError(ldap.ErrorNetwork, errMaxRetries) on exhaustion regardless of the actual failure. Previously this only ever happened after ErrorNetwork retries, so the label was truthful. Now a read that exhausts on LDAPResultBusy/Unavailable/Timeout is reported to callers as ErrorNetwork. This misleads logs and any caller that inspects the code (e.g. pkg/auth/manager/ldap/ldap.go:127 keys on result codes). Recommend returning the last real err (or wrapping it) instead of a synthetic ErrorNetwork.

2. ldapErrCode maps every non-LDAP error to ErrorNetwork → write double-apply risk. For writes, ErrorNetwork is retryable with reconnect. The ticket's premise is that these codes mean "provably never reached the server." But go-ldap surfaces a connection that breaks mid-operation (after the request was transmitted, response not yet read) as ErrorNetwork too — and any unrecognized/wrapped error is also coerced to ErrorNetwork here. That reopens exactly the double-apply / spurious EntryAlreadyExists hazard the write policy is meant to avoid. It's partly inherent to the ticket's design, but the blanket "unknown → ErrorNetwork" default widens the exposure. Worth a comment acknowledging the assumption, and ideally not coercing unknown errors into a retryable write code.

3. Backoff collapses to zero when MaxDelay is unset but BaseDelay > 0. bo.MaxInterval = policy.MaxDelay. With cenkalti/backoff v2, once currentInterval is incremented past MaxInterval/Multiplier, it's clamped to MaxInterval; if that's 0, every sleep after the first becomes ~0. So a config of BaseDelay=50ms, MaxDelay=0 silently degrades to a single delay then hot-retries. Recommend validating/defaulting MaxDelay (e.g. to a multiple of BaseDelay) when BaseDelay > 0.

Thank you, good points. Added tests and fixes for these in latest commit

  • [feat: tests + fixes for review] (576df7e)

@2403905
2403905 merged commit 0c6a26f into stable-8.0 Jul 30, 2026
13 checks passed
@2403905
2403905 deleted the feat/ocisdev-1032 branch July 30, 2026 07:46
mklos-kw added a commit that referenced this pull request Aug 3, 2026
* feat: [OCISDEV-1032] ldap config and retry policy (#673)

* feat: ldap config and retry policy

* feat: remove unused functions

* feat: use cenkalti/backoff/v5

* feat: tests + fixes for review

* feat: harden LDAP retry (#678)

* feat: harden ldap retry

* fix: Retry LDAP operations that fail while sending the request

---------

Co-authored-by: Roman Perekhod <[email protected]>

---------

Co-authored-by: Roman Perekhod <[email protected]>
mklos-kw added a commit that referenced this pull request Aug 3, 2026
* feat: [OCISDEV-1032] ldap config and retry policy (#673)

* feat: ldap config and retry policy

* feat: remove unused functions

* feat: use cenkalti/backoff/v5

* feat: tests + fixes for review

* feat: harden LDAP retry (#678)

* feat: harden ldap retry

* fix: Retry LDAP operations that fail while sending the request

---------

Co-authored-by: Roman Perekhod <[email protected]>

---------

Co-authored-by: Roman Perekhod <[email protected]>
mklos-kw added a commit that referenced this pull request Aug 4, 2026
* feat: ldap config and retry policy

* feat: remove unused functions

* feat: use cenkalti/backoff/v5

* feat: tests + fixes for review
mklos-kw added a commit that referenced this pull request Aug 4, 2026
* feat: [OCISDEV-1032] ldap config and retry policy (#673)

* feat: ldap config and retry policy

* feat: remove unused functions

* feat: use cenkalti/backoff/v5

* feat: tests + fixes for review

* feat: harden LDAP retry (#678)

* feat: harden ldap retry

* fix: Retry LDAP operations that fail while sending the request

---------

Co-authored-by: Roman Perekhod <[email protected]>

* feat: trim long comments

---------

Co-authored-by: Roman Perekhod <[email protected]>
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.

4 participants