Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sdk/ldaputil: add connection_timeout configurable #20144

Merged
merged 5 commits into from
Apr 13, 2023
Merged

Conversation

jasonodonnell
Copy link
Contributor

@jasonodonnell jasonodonnell commented Apr 13, 2023

The go-ldap package sets a 60 second timeout in their package for dial attempts which aligns with Vault's 60 second client timeout. Since these timeouts are the same if the first value in our LDAP config url is unavailable, no other URLs in the list will be tried and all connections will fail.

This adds a new LDAP config connection_timeout which allows operators to override this timeout value. By setting this value lower you can leverage the backup URLs in the config.

This is not the same as the existing config request_timeout which tunes timeout values after a connection is made to LDAP.

A workaround exists where clients can set VAULT_CLIENT_TIMEOUT. By adding this config though we can set timeouts for all user connections and may be a better overall experience.

Copy link
Contributor

@raymonstah raymonstah left a comment

Choose a reason for hiding this comment

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

Looks good; I provided an alternative option for setting the timeout since it appears that the Dial* methods we're using are deprecated.

// Default timeout in the pacakge is 60 seconds, which we default to on our
// end. This is useful if you want to take advantage of the URL list to increase
// availability of LDAP.
ldap.DefaultTimeout = time.Duration(cfg.ConnectionTimeout) * time.Second
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of changing the external package's DefaultTmeout, there is an ldap.DialURL that allows for a DialWithDialer option where we can set the timeout.

Copy link
Contributor Author

@jasonodonnell jasonodonnell Apr 13, 2023

Choose a reason for hiding this comment

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

I looked into this during implementation but I think it will require a lot more changes to this helper library instead of modifying the Dial wrapper. That seemed a lot more risky even though I don't take changing an exported package variable lightly.

Copy link
Contributor

Choose a reason for hiding this comment

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

@jasonodonnell it looks like this is triggering the race detector in tests, since two tests running in parallel modify ldap.DefaultTimeout. https://github.com/hashicorp/vault/actions/runs/4697499717/jobs/8329395640. I can remove the parallel tests as a workaround, but this is perhaps more reason to switch to DialURL

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looking into this. Thanks!

@jasonodonnell jasonodonnell merged commit 2f7f0d2 into main Apr 13, 2023
@jasonodonnell jasonodonnell deleted the ldap-dial-timeout branch April 13, 2023 16:43
jasonodonnell added a commit that referenced this pull request Apr 13, 2023
* sdk/ldaputil: add connection_timeout configurable

* changelog

* Update doc

* Fix test

* Change default to 30s
jasonodonnell added a commit that referenced this pull request Apr 13, 2023
* sdk/ldaputil: add connection_timeout configurable

* changelog

* Update doc

* Fix test

* Change default to 30s
jasonodonnell added a commit that referenced this pull request Apr 13, 2023
* sdk/ldaputil: add connection_timeout configurable

* changelog

* Update doc

* Fix test

* Change default to 30s
jasonodonnell added a commit that referenced this pull request Apr 13, 2023
* sdk/ldaputil: add connection_timeout configurable

* changelog

* Update doc

* Fix test

* Change default to 30s
jasonodonnell added a commit that referenced this pull request Apr 13, 2023
* sdk/ldaputil: add connection_timeout configurable

* changelog

* Update doc

* Fix test

* Change default to 30s

Co-authored-by: Jason O'Donnell <2160810+jasonodonnell@users.noreply.github.com>
jasonodonnell added a commit that referenced this pull request Apr 17, 2023
* sdk/ldaputil: add connection_timeout configurable

* changelog

* Update doc

* Fix test

* Change default to 30s

Co-authored-by: Jason O'Donnell <2160810+jasonodonnell@users.noreply.github.com>
jasonodonnell added a commit that referenced this pull request Apr 17, 2023
* sdk/ldaputil: add connection_timeout configurable

* changelog

* Update doc

* Fix test

* Change default to 30s
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