mirror of
https://github.com/juanfont/headscale.git
synced 2025-09-02 13:47:00 +02:00
types/pak: make user/tag optional
Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
This commit is contained in:
parent
4d3483ed3a
commit
bdcd5496fc
@ -734,6 +734,20 @@ AND auth_key_id NOT IN (
|
|||||||
},
|
},
|
||||||
Rollback: func(db *gorm.DB) error { return nil },
|
Rollback: func(db *gorm.DB) error { return nil },
|
||||||
},
|
},
|
||||||
|
// Migrate preauthkey table to make users and tags optional.
|
||||||
|
// Use prefix+hash for keys.
|
||||||
|
{
|
||||||
|
ID: "202505231615-preauthkey-user-optional-tags-user",
|
||||||
|
Migrate: func(tx *gorm.DB) error {
|
||||||
|
err = tx.AutoMigrate(&types.PreAuthKey{})
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("automigrating types.PreAuthKey: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
Rollback: func(db *gorm.DB) error { return nil },
|
||||||
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -9,19 +9,30 @@ import (
|
|||||||
|
|
||||||
// PreAuthKey describes a pre-authorization key usable in a particular user.
|
// PreAuthKey describes a pre-authorization key usable in a particular user.
|
||||||
type PreAuthKey struct {
|
type PreAuthKey struct {
|
||||||
ID uint64 `gorm:"primary_key"`
|
ID uint64 `gorm:"primary_key"`
|
||||||
Key string
|
|
||||||
UserID uint
|
// Old Key, for backwards compatibility
|
||||||
User User `gorm:"constraint:OnDelete:SET NULL;"`
|
Key string
|
||||||
|
|
||||||
|
// Encrypted key
|
||||||
|
Prefix string
|
||||||
|
Hash []byte
|
||||||
|
|
||||||
Reusable bool
|
Reusable bool
|
||||||
Ephemeral bool `gorm:"default:false"`
|
Ephemeral bool `gorm:"default:false"`
|
||||||
Used bool `gorm:"default:false"`
|
Used bool `gorm:"default:false"`
|
||||||
|
|
||||||
|
// UserID if set, is the owner of the key.
|
||||||
|
// If a node is authenticated with this key, the node
|
||||||
|
// is assigned to this user.
|
||||||
|
UserID *uint `sql:"DEFAULT:NULL"`
|
||||||
|
User *User
|
||||||
|
|
||||||
// Tags are always applied to the node and is one of
|
// Tags are always applied to the node and is one of
|
||||||
// the sources of tags a node might have. They are copied
|
// the sources of tags a node might have. They are copied
|
||||||
// from the PreAuthKey when the node logs in the first time,
|
// from the PreAuthKey when the node logs in the first time,
|
||||||
// and ignored after.
|
// and ignored after.
|
||||||
Tags []string `gorm:"serializer:json"`
|
Tags []string `gorm:"column:tags;serializer:json"`
|
||||||
|
|
||||||
CreatedAt *time.Time
|
CreatedAt *time.Time
|
||||||
Expiration *time.Time
|
Expiration *time.Time
|
||||||
@ -48,3 +59,16 @@ func (key *PreAuthKey) Proto() *v1.PreAuthKey {
|
|||||||
|
|
||||||
return &protoKey
|
return &protoKey
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsTagged reports if a key is tagged.
|
||||||
|
func (key *PreAuthKey) IsTagged() bool {
|
||||||
|
if key.Tags == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(key.Tags) > 0 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user