-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
c58ce6f
Generalise the registration method to DRY stuff up
kradalby acb9458
Generalise registration for pre auth keys
kradalby fd1e4a1
Generalise registration for openid
kradalby caffbd8
Update cli registration with new method
kradalby ecc2643
Fix excessive replace
kradalby 1caa6f5
Add todo for JSON datatype
kradalby 469551b
Register new machines needing callback in memory
kradalby 402a760
Reuse machine structure for parameters, named parameters
kradalby 54cc3c0
Implement new machine register parameter
kradalby 50053e6
Ignore complexity linter
kradalby c6b87de
Remove poorly aged test
kradalby e7bef56
Remove reference to registered in integration test
kradalby 35616eb
Fix oidc error were namespace isnt created #365
kradalby 16b21e8
Remove all references to Machine.Registered
kradalby a8649d8
Remove all references to Machine.Registered from tests
kradalby 78251ce
Remove registrated field
kradalby eea8e7b
Update changelog
kradalby 5e1b129
Remove registered field from proto
kradalby e64bee7
Regenerate proto
kradalby 5e92dda
Remove redundant caches
kradalby 8bef04d
Remove sorted todo
kradalby 3790176
Reformat and add db backup note
kradalby 82cb6b9
Cleanup some unreachable code
kradalby 7c63412
Remove todo
kradalby d34d617
Merge branch 'main' into registration-simplification
kradalby a9d4fa8
Merge branch 'main' into registration-simplification
kradalby 86ade72
Remove err check
kradalby ec4dc68
Use correct machinekey format for oidc reg
kradalby ef422e6
Protect against expiry nil
kradalby 1f8c7f4
Add comment
kradalby e4d81bb
Merge branch 'main' into registration-simplification
kradalby File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,8 +44,10 @@ type Machine struct { | |
|
||
Registered bool // temp | ||
RegisterMethod string | ||
AuthKeyID uint | ||
AuthKey *PreAuthKey | ||
|
||
// TODO(kradalby): This seems like irrelevant information? | ||
AuthKeyID uint | ||
AuthKey *PreAuthKey | ||
|
||
LastSeen *time.Time | ||
LastSuccessfulUpdate *time.Time | ||
|
@@ -686,6 +688,13 @@ func (machine *Machine) toProto() *v1.Machine { | |
func (h *Headscale) RegisterMachine( | ||
machineKeyStr string, | ||
namespaceName string, | ||
registrationMethod string, | ||
|
||
// Optionals | ||
expiry *time.Time, | ||
authKey *PreAuthKey, | ||
nodePublicKey *string, | ||
lastSeen *time.Time, | ||
) (*Machine, error) { | ||
namespace, err := h.GetNamespace(namespaceName) | ||
if err != nil { | ||
|
@@ -709,27 +718,13 @@ func (h *Headscale) RegisterMachine( | |
return nil, err | ||
} | ||
|
||
// TODO(kradalby): Currently, if it fails to find a requested expiry, non will be set | ||
// This means that if a user is to slow with register a machine, it will possibly not | ||
// have the correct expiry. | ||
requestedTime := time.Time{} | ||
if requestedTimeIf, found := h.requestedExpiryCache.Get(machineKey.String()); found { | ||
log.Trace(). | ||
Caller(). | ||
Str("machine", machine.Name). | ||
Msg("Expiry time found in cache, assigning to node") | ||
if reqTime, ok := requestedTimeIf.(time.Time); ok { | ||
requestedTime = reqTime | ||
} | ||
} | ||
|
||
if machine.isRegistered() { | ||
log.Trace(). | ||
Caller(). | ||
Str("machine", machine.Name). | ||
Msg("machine already registered, reauthenticating") | ||
|
||
h.RefreshMachine(machine, requestedTime) | ||
h.RefreshMachine(machine, *expiry) | ||
|
||
return machine, nil | ||
} | ||
|
@@ -739,17 +734,6 @@ func (h *Headscale) RegisterMachine( | |
Str("machine", machine.Name). | ||
Msg("Attempting to register machine") | ||
|
||
if machine.isRegistered() { | ||
err := errMachineAlreadyRegistered | ||
log.Error(). | ||
Caller(). | ||
Err(err). | ||
Str("machine", machine.Name). | ||
Msg("Attempting to register machine") | ||
|
||
return nil, err | ||
} | ||
|
||
h.ipAllocationMutex.Lock() | ||
defer h.ipAllocationMutex.Unlock() | ||
|
||
|
@@ -764,17 +748,36 @@ func (h *Headscale) RegisterMachine( | |
return nil, err | ||
} | ||
|
||
log.Trace(). | ||
Caller(). | ||
Str("machine", machine.Name). | ||
Str("ip", strings.Join(ips.ToStringSlice(), ",")). | ||
Msg("Found IP for host") | ||
|
||
machine.IPAddresses = ips | ||
|
||
if expiry != nil { | ||
machine.Expiry = expiry | ||
} | ||
|
||
if authKey != nil { | ||
machine.AuthKeyID = uint(authKey.ID) | ||
} | ||
|
||
if nodePublicKey != nil { | ||
machine.NodeKey = *nodePublicKey | ||
} | ||
|
||
if lastSeen != nil { | ||
machine.LastSeen = lastSeen | ||
} | ||
|
||
machine.NamespaceID = namespace.ID | ||
|
||
// TODO(kradalby): This field is uneccessary metadata, | ||
// move it to tags instead of having a column. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tags of the node? to be used in acls? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
machine.RegisterMethod = registrationMethod | ||
|
||
// TODO(kradalby): Registered is a very frustrating value | ||
// to keep up to date, and it makes is have to care if a | ||
// machine is registered, authenticated and expired. | ||
// Let us simplify the model, a machine is _only_ saved if | ||
// it is registered. | ||
machine.Registered = true | ||
machine.RegisterMethod = RegisterMethodCLI | ||
machine.Expiry = &requestedTime | ||
h.db.Save(&machine) | ||
|
||
log.Trace(). | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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