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

feat: Initialize connectors lazily (not on server start) #2789

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dlipovetsky
Copy link
Contributor

@dlipovetsky dlipovetsky commented Jan 13, 2023

Overview

Initialize connectors lazily (not on server start).

What this PR does / why we need it

Dex initializes all connectors on server start. Connectors may fail to initialize, e.g. if they require a remote service that is unavailable, or if they are misconfigured. If any connector fails to initialize, dex exits. This PR adds an option to skip connector initialization during server start. Dex will initialize each connector when it needs it to serve a request.

This change is backward-compatible. The current behavior (exiting) remains the default; the new behavior is enabled by a field in the configuration file:

lazyInitConnectors: true

Closes #1723

Special notes for your reviewer

Does this PR introduce a user-facing change?

Add a configuration option to start the server without initializing connectors.

@dlipovetsky dlipovetsky force-pushed the skip-openconnector-error branch from e043b00 to a4e14d1 Compare January 14, 2023 00:00
cmd/dex/config.go Outdated Show resolved Hide resolved
Copy link

@msdolbey msdolbey left a comment

Choose a reason for hiding this comment

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

👍 ❤️

@dlipovetsky dlipovetsky force-pushed the skip-openconnector-error branch from a4e14d1 to 1890bf3 Compare January 17, 2023 17:55
@nabokihms nabokihms self-requested a review January 18, 2023 15:17
@dlipovetsky
Copy link
Contributor Author

@nabokihms Could you please allow the CI workflows to run? Thanks!

@dlipovetsky
Copy link
Contributor Author

The PR is backward compatible, addresses a long-standing issue, comes with a unit test, and CI is passing (ne job fails because the PR needs some labels, which I don't have the permission to create)

@nabokihms and/or @sagikazarmark, please let me know if there's anything else I can do to help it along, or if you disagree with the approach I took. Thank you! 🙏

@nabokihms
Copy link
Member

Sorry, slacked a little because of KubeCon. I will take a look till the end of the week and give my feedback.

@nabokihms
Copy link
Member

@dlipovetsky Sorry for the long delay. This feature overlaps with what we in Palak also need, so I'd be happy to work with you on this feature.

I had a chance to look through the code and even test the PR, and there are some questions I'd like to discuss upfront.

  1. A connector is available from the start if it is a lazily initialized connector. Thus, users can see the connector on the list of available connectors and click on it, attempting to authenticate with it (despite Dex knowing that the connector is not ready).

    This does not seem like a valid UX to me. Connectors should not be pickable until initialized.

  2. Each failed attempt is a request to the external provider. Dex will try to make a request to the provider without exponential backoff or any other protection mechanisms in case of unavailability.

  3. If all connectors are lazily initialized, it is possible to end up with a working Dex without working connectors, which is misleading. Dex may be working but not ready to serve to auth requests.

What do you think about the following proposal? This is more complicated, but I believe provides better UX for users.

  • Initialize connectors in the background in a loop if the first initialization attempt fails (like Kubernetes does).
  • Do not show the connector in the list of connectors until initialized.
  • Fail the readiness probe if there are no initialized connectors.

@dlipovetsky
Copy link
Contributor Author

@dlipovetsky Sorry for the long delay. This feature overlaps with what we in Palak also need, so I'd be happy to work with you on this feature.

Thanks for the review!

  1. A connector is available from the start if it is a lazily initialized connector. Thus, users can see the connector on the list of available connectors and click on it, attempting to authenticate with it (despite Dex knowing that the connector is not ready).
    This does not seem like a valid UX to me. Connectors should not be pickable until initialized.

Good point. I do not use the dex UI directly, so I did not see (or consider) this.

  1. Each failed attempt is a request to the external provider. Dex will try to make a request to the provider without exponential backoff or any other protection mechanisms in case of unavailability.

Good point. A couple of questions: Does "attempt" mean a login attempt? When you say "Dex will try to make a request to the provider," are you referring to this code path:

conn, err := s.OpenConnector(storageConnector)

  1. If all connectors are lazily initialized, it is possible to end up with a working Dex without working connectors, which is misleading. Dex may be working but not ready to serve to auth requests.

Good point.

What do you think about the following proposal? This is more complicated, but I believe provides better UX for users.

I agree, your proposal does provide better UX. Being unfamiliar with the dex code, I made the smallest possible change that allowed dex to start in the presence of a misconfigured connector 😅

Let me know if you'd like to me to work on this, or if you'd like to do it yourself. Also, let me know if you'd like the work to go in a new PR.

@nabokihms
Copy link
Member

@dlipovetsky I would be happy if you had time to work on this feature. It is ok to work on this improvement in the scope of this PR. Opening a new PR is not necessary.

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.

OIDC discovery blocks other connectors
3 participants