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

Registration simplification #366

Merged
merged 31 commits into from
Mar 2, 2022

Conversation

kradalby
Copy link
Collaborator

@kradalby kradalby commented Feb 28, 2022

Resolves #294, #341, #365

This PR simplifies registration in a couple of ways:

  • DRY the registration logic into a function in machine.go
    We had quite a lot of duplicate logic as noted in Machine allocation logic exists in multiple locations. #294, and this reduces this and centers the logic around RegisterMachine.

  • Only write machines/nodes to the database when they are registered
    In the current setup, we write the machine to the database when the registration process starts, and this means that machines that dont successfully register becomes ghost machines in the DB. They dont really have anything to do in persistent storage until successful, so this PR moves them to a cache like memory storage which is cleaned up occasionally.

  • Remove Registered column, use Expiry as main machine filter
    Since we dont have machines that isnt "unregistered" anymore, we can simplify a lot of logic and only check if a machine exist, and if it is expired or not. This makes it easier to reason about if we should care for a machine in particular scenarios (no more if registered and !expired).

  • read the CONTRIBUTING guidelines
  • raised a GitHub issue or discussed it on the projects chat beforehand
  • added unit tests
  • added integration tests
  • updated documentation if needed
  • updated CHANGELOG.md

This commit stores temporary registration data in cache, instead of
memory allowing us to only have actually registered machines in the
database.
This commit removes the field from the database and does a DB migration
**removing** all unregistered machines from headscale.

This means that from this version, all machines in the database is
considered registered.
This commit removes the two extra caches (oidc, requested time) and uses
the new central registration cache instead. The requested time is
unified into the main machine object and the oidc key is just added to
the same cache, as a string with the state as a key instead of machine
key.
@kradalby kradalby marked this pull request as ready for review February 28, 2022 23:17
@kradalby kradalby mentioned this pull request Mar 1, 2022
@restanrm restanrm mentioned this pull request Mar 1, 2022
3 tasks
google.protobuf.Timestamp last_seen = 10;
google.protobuf.Timestamp last_successful_update = 11;
google.protobuf.Timestamp expiry = 12;
google.protobuf.Timestamp last_seen = 8;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it ok to change theses keys in protobuf ? I thought that we couldn't change these without breaking compatibility

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes it will, I think we should change it still, so make sure we don't start accumulating tech debt before the api is stable.

Copy link
Contributor

Choose a reason for hiding this comment

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

Of course having debt without a first version is nonsense 👍

juanfont
juanfont previously approved these changes Mar 1, 2022
AuthKeyID uint
AuthKey *PreAuthKey

// TODO(kradalby): This seems like irrelevant information?
Copy link
Owner

Choose a reason for hiding this comment

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

You can see which machine has been registered with what 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.

Yes, but is it really relevant? I delete the keys quite often so not sure

machine.go Outdated
machine.NamespaceID = namespace.ID

// TODO(kradalby): This field is uneccessary metadata,
// move it to tags instead of having a column.
Copy link
Owner

Choose a reason for hiding this comment

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

tags of the node? to be used in acls?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That was the idea, but not sure if it makes sense. Might just keep it around for now.

@kradalby
Copy link
Collaborator Author

kradalby commented Mar 2, 2022

@juanfont Please take another look, there was a flow breaker in the OpenID login.

@kradalby kradalby requested a review from juanfont March 2, 2022 07:31
@kradalby kradalby merged commit eeded85 into juanfont:main Mar 2, 2022
@kradalby kradalby deleted the registration-simplification branch March 2, 2022 08:02
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.

Machine allocation logic exists in multiple locations.
3 participants