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

Simplify and improve register/reauth flow #227

Merged
merged 38 commits into from
Nov 24, 2021

Conversation

kradalby
Copy link
Collaborator

@kradalby kradalby commented Nov 17, 2021

This PR addresses a series of issues with OpenID Connect (oidc), the register workflow, the reauthentication workflow and the concept of expiry.

oidc introduced some broken expiry behaviour which broke both pre auth key machines and CLI registered machines. This was done by adding a maximum expiry, where we previously had none.

This PR removes that and in general fixes issues that was discovered hunting for the bugs:

  • Registration flow is now split up into function so its easier to follow
  • Add support for reauthentication of nodes (if expired)
  • Add support for client which sends "requested expiry"
  • Add expire command to allow users to force nodes to reauthenticate
  • Only send list of "valid" (registered and not expired) nodes to client on update
  • The oidc support seem to work pretty well (I use it on my prod setup)

We no longer have weird expire behaviour, so we dont need this case
This commits tries to dismantle the complicated "if and or" in the
RegistrationHandler by factoring out the "is Registrated" into a root
if.

This, together with some new comments, should hopefully make it a bit
easier to follow what is happening in all the different cases that needs
to be handled when a Node contacts the registration endpoint.
We should never expose errors via web, it gives attackers a lot of info
(Insert OWASP guide).

Also handle error that didnt separate not found gorm issue and other
errors.
This commit fixes an issue where nodes were not able to reauthenticate.
This commit adds a sentral cache to keep track of clients whom has
requested an expiry time, but were we need to keep hold of it until the
second request comes in.
In addition, only pass the map of registered and not expired nodes to
clients.
@kradalby kradalby changed the title Move registration workflow into functions Simplify and improve register/reauth flow Nov 22, 2021
@kradalby kradalby requested review from juanfont and cure November 22, 2021 20:13
@kradalby kradalby marked this pull request as ready for review November 22, 2021 20:13
@kradalby
Copy link
Collaborator Author

This PR fixes #226.

I think this should make it so we can release 0.12.0 (preferably as beta/pre release).

@juanfont you did some work on setting up pre-releases right?

juanfont
juanfont previously approved these changes Nov 24, 2021
// https://github.com/tailscale/tailscale/blob/main/tailcfg/tailcfg.go#L648
if !req.Expiry.IsZero() && req.Expiry.UTC().Before(now) {
h.handleMachineLogOut(ctx, machineKey, req, *machine)
if machine.Registered {
Copy link
Owner

Choose a reason for hiding this comment

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

What if is already registering and we are reauth with a new key?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not sure if I understand

@kradalby kradalby requested a review from juanfont November 24, 2021 14:18
Copy link
Owner

@juanfont juanfont left a comment

Choose a reason for hiding this comment

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

Amazing work!

@kradalby kradalby merged commit 5620858 into juanfont:main Nov 24, 2021
@kradalby kradalby deleted the expired-issue branch November 24, 2021 17:49
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.

2 participants