Add AlreadyUsed field to Auth Keys (fixes #157 and #158)

This commit is contained in:
Juan Font Alonso 2021-10-13 18:13:26 +02:00
parent dd1e425d02
commit 30788e1a70
4 changed files with 20 additions and 3 deletions

View file

@ -21,6 +21,7 @@ type PreAuthKey struct {
Namespace Namespace
Reusable bool
Ephemeral bool `gorm:"default:false"`
AlreadyUsed bool `gorm:"default:false"`
CreatedAt *time.Time
Expiration *time.Time
@ -110,11 +111,10 @@ func (h *Headscale) checkKeyValidity(k string) (*PreAuthKey, error) {
return nil, err
}
if len(machines) != 0 {
if len(machines) != 0 || pak.AlreadyUsed {
return nil, errorAuthKeyNotReusableAlreadyUsed
}
// missing here validation on current usage
return &pak, nil
}