Skip to content

Commit 51b4d81

Browse files
committed
Moved users and groups management to use proxmox instead of ldap
1 parent a98faac commit 51b4d81

20 files changed

Lines changed: 962 additions & 1044 deletions

internal/api/auth/auth_service.go

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,21 @@ package auth
22

33
import (
44
"fmt"
5-
"strings"
5+
"slices"
66

77
"github.com/cpp-cyber/proclone/internal/ldap"
8+
"github.com/cpp-cyber/proclone/internal/proxmox"
89
)
910

10-
func NewAuthService() (*AuthService, error) {
11+
func NewAuthService(proxmoxService *proxmox.ProxmoxService) (*AuthService, error) {
1112
ldapService, err := ldap.NewLDAPService()
1213
if err != nil {
1314
return nil, fmt.Errorf("failed to create LDAP service: %w", err)
1415
}
1516

1617
return &AuthService{
17-
ldapService: ldapService,
18+
ldapService: ldapService,
19+
proxmoxService: proxmoxService,
1820
}, nil
1921
}
2022

@@ -51,38 +53,18 @@ func (s *AuthService) Authenticate(username string, password string) (bool, erro
5153
}
5254

5355
func (s *AuthService) IsAdmin(username string) (bool, error) {
54-
// Input validation
55-
if username == "" {
56-
return false, fmt.Errorf("username cannot be empty")
57-
}
58-
59-
// Get user DN
60-
userDN, err := s.ldapService.GetUserDN(username)
61-
if err != nil {
62-
return false, fmt.Errorf("failed to get user DN: %w", err)
63-
}
64-
65-
// Get user's groups
66-
userGroups, err := s.ldapService.GetUserGroups(userDN)
56+
// Get user's groups from Proxmox
57+
userGroups, err := s.proxmoxService.GetUserGroups(username)
6758
if err != nil {
6859
return false, fmt.Errorf("failed to get user groups: %w", err)
6960
}
7061

71-
// Load LDAP config to get admin group DN
72-
config, err := ldap.LoadConfig()
73-
if err != nil {
74-
return false, fmt.Errorf("failed to load LDAP config: %w", err)
75-
}
76-
77-
if config.AdminGroupDN == "" {
78-
return false, fmt.Errorf("admin group DN not configured")
79-
}
62+
// Get the admin group name from config
63+
adminGroupName := s.proxmoxService.Config.AdminGroupName
8064

8165
// Check if user is in the admin group
82-
for _, groupDN := range userGroups {
83-
if strings.EqualFold(groupDN, "Proxmox-Admins") {
84-
return true, nil
85-
}
66+
if slices.Contains(userGroups, adminGroupName) {
67+
return true, nil
8668
}
8769

8870
return false, nil

internal/api/auth/types.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package auth
22

33
import (
44
"github.com/cpp-cyber/proclone/internal/ldap"
5+
"github.com/cpp-cyber/proclone/internal/proxmox"
56
)
67

78
// =================================================
@@ -19,13 +20,14 @@ type Service interface {
1920
}
2021

2122
type AuthService struct {
22-
ldapService ldap.Service
23+
ldapService ldap.Service
24+
proxmoxService *proxmox.ProxmoxService
2325
}
2426

2527
// =================================================
2628
// Types for Auth Service (re-exported from ldap)
2729
// =================================================
2830

29-
type User = ldap.User
30-
type Group = ldap.Group
31+
type User = proxmox.User
32+
type Group = proxmox.Group
3133
type UserRegistrationInfo = ldap.UserRegistrationInfo

0 commit comments

Comments
 (0)