Skip to content
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

no edit of oidc users, minimum hostname length #2393

Merged
merged 3 commits into from
Feb 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
[#2350](https://github.com/juanfont/headscale/pull/2350)
- Print Tailscale version instead of capability versions for outdated nodes
[#2391](https://github.com/juanfont/headscale/pull/2391)
- Do not allow renaming of users from OIDC
[#2393](https://github.com/juanfont/headscale/pull/2393)
- Change minimum hostname length to 2
[#2393](https://github.com/juanfont/headscale/pull/2393)
- Pre auth keys belonging to a user are no longer deleted with the user
[#2396](https://github.com/juanfont/headscale/pull/2396)
- Pre auth keys that are used by a node can no longer be deleted
Expand Down
6 changes: 6 additions & 0 deletions hscontrol/db/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ func (hsdb *HSDatabase) RenameUser(uid types.UserID, newName string) error {
})
}

var ErrCannotChangeOIDCUser = errors.New("cannot edit OIDC user")

// RenameUser renames a User. Returns error if the User does
// not exist or if another User exists with the new name.
func RenameUser(tx *gorm.DB, uid types.UserID, newName string) error {
Expand All @@ -94,6 +96,10 @@ func RenameUser(tx *gorm.DB, uid types.UserID, newName string) error {
return err
}

if oldUser.Provider == util.RegisterMethodOIDC {
return ErrCannotChangeOIDCUser
}

oldUser.Name = newName

if err := tx.Save(&oldUser).Error; err != nil {
Expand Down
5 changes: 5 additions & 0 deletions hscontrol/util/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ func ValidateUsername(username string) error {
}

func CheckForFQDNRules(name string) error {
// Ensure the username meets the minimum length requirement
if len(name) < 2 {
return errors.New("name must be at least 2 characters long")
}

if len(name) > LabelHostnameLength {
return fmt.Errorf(
"DNS segment must not be over 63 chars. %v doesn't comply with this rule: %w",
Expand Down
Loading