Skip to content

Commit 1c7f3bc

Browse files
authored
no edit of oidc users, minimum hostname length (#2393)
* return an error when renaming users from OIDC * set minimum hostname length of 2
1 parent 9bd1438 commit 1c7f3bc

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
[#2350](https://github.com/juanfont/headscale/pull/2350)
2121
- Print Tailscale version instead of capability versions for outdated nodes
2222
[#2391](https://github.com/juanfont/headscale/pull/2391)
23+
- Do not allow renaming of users from OIDC
24+
[#2393](https://github.com/juanfont/headscale/pull/2393)
25+
- Change minimum hostname length to 2
26+
[#2393](https://github.com/juanfont/headscale/pull/2393)
2327
- Pre auth keys belonging to a user are no longer deleted with the user
2428
[#2396](https://github.com/juanfont/headscale/pull/2396)
2529
- Pre auth keys that are used by a node can no longer be deleted

hscontrol/db/users.go

+6
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ func (hsdb *HSDatabase) RenameUser(uid types.UserID, newName string) error {
8181
})
8282
}
8383

84+
var ErrCannotChangeOIDCUser = errors.New("cannot edit OIDC user")
85+
8486
// RenameUser renames a User. Returns error if the User does
8587
// not exist or if another User exists with the new name.
8688
func RenameUser(tx *gorm.DB, uid types.UserID, newName string) error {
@@ -94,6 +96,10 @@ func RenameUser(tx *gorm.DB, uid types.UserID, newName string) error {
9496
return err
9597
}
9698

99+
if oldUser.Provider == util.RegisterMethodOIDC {
100+
return ErrCannotChangeOIDCUser
101+
}
102+
97103
oldUser.Name = newName
98104

99105
if err := tx.Save(&oldUser).Error; err != nil {

hscontrol/util/dns.go

+5
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ func ValidateUsername(username string) error {
6565
}
6666

6767
func CheckForFQDNRules(name string) error {
68+
// Ensure the username meets the minimum length requirement
69+
if len(name) < 2 {
70+
return errors.New("name must be at least 2 characters long")
71+
}
72+
6873
if len(name) > LabelHostnameLength {
6974
return fmt.Errorf(
7075
"DNS segment must not be over 63 chars. %v doesn't comply with this rule: %w",

0 commit comments

Comments
 (0)