Add support for ephemeral nodes via a special type of pre-auth key. Add

tests for that feature.

Other fixes: clean up a few typos in comments. Fix a bug that caused the
tests to run four times each. Be more consistent in the use of log
rather than fmt to print errors and notices.
This commit is contained in:
Ward Vandewege
2021-05-22 20:15:29 -04:00
parent 1faed2764f
commit 41f6740ddd
17 changed files with 151 additions and 38 deletions

View File

@@ -18,13 +18,14 @@ type PreAuthKey struct {
NamespaceID uint
Namespace Namespace
Reusable bool
Ephemeral bool `gorm:"default:false"`
CreatedAt *time.Time
Expiration *time.Time
}
// CreatePreAuthKey creates a new PreAuthKey in a namespace, and returns it
func (h *Headscale) CreatePreAuthKey(namespaceName string, reusable bool, expiration *time.Time) (*PreAuthKey, error) {
func (h *Headscale) CreatePreAuthKey(namespaceName string, reusable bool, ephemeral bool, expiration *time.Time) (*PreAuthKey, error) {
n, err := h.GetNamespace(namespaceName)
if err != nil {
return nil, err
@@ -48,6 +49,7 @@ func (h *Headscale) CreatePreAuthKey(namespaceName string, reusable bool, expira
NamespaceID: n.ID,
Namespace: *n,
Reusable: reusable,
Ephemeral: ephemeral,
CreatedAt: &now,
Expiration: expiration,
}
@@ -94,7 +96,7 @@ func (h *Headscale) checkKeyValidity(k string) (*PreAuthKey, error) {
return nil, errorAuthKeyExpired
}
if pak.Reusable { // we don't need to check if has been used before
if pak.Reusable || pak.Ephemeral { // we don't need to check if has been used before
return &pak, nil
}