mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-21 04:49:10 +02:00
Merge branch 'main' into feature/user-info-with-role-permissions
This commit is contained in:
@@ -167,6 +167,11 @@ func (m *AuthMiddleware) checkPATFromRequest(r *http.Request, auth []string) (*h
|
|||||||
IsPAT: true,
|
IsPAT: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if impersonate, ok := r.URL.Query()["account"]; ok && len(impersonate) == 1 {
|
||||||
|
userAuth.AccountId = impersonate[0]
|
||||||
|
userAuth.IsChild = ok
|
||||||
|
}
|
||||||
|
|
||||||
return nbcontext.SetUserAuthInRequest(r, userAuth), nil
|
return nbcontext.SetUserAuthInRequest(r, userAuth), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -242,14 +242,15 @@ func TestAuthMiddleware_Handler_Child(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Valid PAT Token ignores child",
|
name: "Valid PAT Token accesses child",
|
||||||
path: "/test?account=xyz",
|
path: "/test?account=xyz",
|
||||||
authHeader: "Token " + PAT,
|
authHeader: "Token " + PAT,
|
||||||
expectedUserAuth: &nbcontext.UserAuth{
|
expectedUserAuth: &nbcontext.UserAuth{
|
||||||
AccountId: accountID,
|
AccountId: "xyz",
|
||||||
UserId: userID,
|
UserId: userID,
|
||||||
Domain: testAccount.Domain,
|
Domain: testAccount.Domain,
|
||||||
DomainCategory: testAccount.DomainCategory,
|
DomainCategory: testAccount.DomainCategory,
|
||||||
|
IsChild: true,
|
||||||
IsPAT: true,
|
IsPAT: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package roles
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/netbirdio/netbird/management/server/permissions/operations"
|
||||||
|
"github.com/netbirdio/netbird/management/server/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
var Auditor = RolePermissions{
|
||||||
|
Role: types.UserRoleAuditor,
|
||||||
|
AutoAllowNew: map[operations.Operation]bool{
|
||||||
|
operations.Read: true,
|
||||||
|
operations.Create: false,
|
||||||
|
operations.Update: false,
|
||||||
|
operations.Delete: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
package roles
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/netbirdio/netbird/management/server/permissions/modules"
|
||||||
|
"github.com/netbirdio/netbird/management/server/permissions/operations"
|
||||||
|
"github.com/netbirdio/netbird/management/server/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
var NetworkAdmin = RolePermissions{
|
||||||
|
Role: types.UserRoleNetworkAdmin,
|
||||||
|
AutoAllowNew: map[operations.Operation]bool{
|
||||||
|
operations.Read: false,
|
||||||
|
operations.Create: false,
|
||||||
|
operations.Update: false,
|
||||||
|
operations.Delete: false,
|
||||||
|
},
|
||||||
|
Permissions: Permissions{
|
||||||
|
modules.Networks: {
|
||||||
|
operations.Read: true,
|
||||||
|
operations.Create: true,
|
||||||
|
operations.Update: true,
|
||||||
|
operations.Delete: true,
|
||||||
|
},
|
||||||
|
modules.Groups: {
|
||||||
|
operations.Read: true,
|
||||||
|
operations.Create: false,
|
||||||
|
operations.Update: false,
|
||||||
|
operations.Delete: false,
|
||||||
|
},
|
||||||
|
modules.Settings: {
|
||||||
|
operations.Read: true,
|
||||||
|
operations.Create: false,
|
||||||
|
operations.Update: false,
|
||||||
|
operations.Delete: false,
|
||||||
|
},
|
||||||
|
modules.Accounts: {
|
||||||
|
operations.Read: true,
|
||||||
|
operations.Create: false,
|
||||||
|
operations.Update: false,
|
||||||
|
operations.Delete: false,
|
||||||
|
},
|
||||||
|
modules.Dns: {
|
||||||
|
operations.Read: true,
|
||||||
|
operations.Create: true,
|
||||||
|
operations.Update: true,
|
||||||
|
operations.Delete: true,
|
||||||
|
},
|
||||||
|
modules.Nameservers: {
|
||||||
|
operations.Read: true,
|
||||||
|
operations.Create: true,
|
||||||
|
operations.Update: true,
|
||||||
|
operations.Delete: true,
|
||||||
|
},
|
||||||
|
modules.Events: {
|
||||||
|
operations.Read: true,
|
||||||
|
operations.Create: false,
|
||||||
|
operations.Update: false,
|
||||||
|
operations.Delete: false,
|
||||||
|
},
|
||||||
|
modules.Policies: {
|
||||||
|
operations.Read: true,
|
||||||
|
operations.Create: true,
|
||||||
|
operations.Update: true,
|
||||||
|
operations.Delete: true,
|
||||||
|
},
|
||||||
|
modules.Routes: {
|
||||||
|
operations.Read: true,
|
||||||
|
operations.Create: true,
|
||||||
|
operations.Update: true,
|
||||||
|
operations.Delete: true,
|
||||||
|
},
|
||||||
|
modules.Users: {
|
||||||
|
operations.Read: true,
|
||||||
|
operations.Create: false,
|
||||||
|
operations.Update: false,
|
||||||
|
operations.Delete: false,
|
||||||
|
},
|
||||||
|
modules.SetupKeys: {
|
||||||
|
operations.Read: true,
|
||||||
|
operations.Create: false,
|
||||||
|
operations.Update: false,
|
||||||
|
operations.Delete: false,
|
||||||
|
},
|
||||||
|
modules.Pats: {
|
||||||
|
operations.Read: true,
|
||||||
|
operations.Create: true,
|
||||||
|
operations.Update: true,
|
||||||
|
operations.Delete: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
@@ -15,7 +15,9 @@ type RolePermissions struct {
|
|||||||
type Permissions map[modules.Module]map[operations.Operation]bool
|
type Permissions map[modules.Module]map[operations.Operation]bool
|
||||||
|
|
||||||
var RolesMap = map[types.UserRole]RolePermissions{
|
var RolesMap = map[types.UserRole]RolePermissions{
|
||||||
types.UserRoleOwner: Owner,
|
types.UserRoleOwner: Owner,
|
||||||
types.UserRoleAdmin: Admin,
|
types.UserRoleAdmin: Admin,
|
||||||
types.UserRoleUser: User,
|
types.UserRoleUser: User,
|
||||||
|
types.UserRoleAuditor: Auditor,
|
||||||
|
types.UserRoleNetworkAdmin: NetworkAdmin,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ const (
|
|||||||
UserRoleUser UserRole = "user"
|
UserRoleUser UserRole = "user"
|
||||||
UserRoleUnknown UserRole = "unknown"
|
UserRoleUnknown UserRole = "unknown"
|
||||||
UserRoleBillingAdmin UserRole = "billing_admin"
|
UserRoleBillingAdmin UserRole = "billing_admin"
|
||||||
|
UserRoleAuditor UserRole = "auditor"
|
||||||
|
UserRoleNetworkAdmin UserRole = "network_admin"
|
||||||
|
|
||||||
UserStatusActive UserStatus = "active"
|
UserStatusActive UserStatus = "active"
|
||||||
UserStatusDisabled UserStatus = "disabled"
|
UserStatusDisabled UserStatus = "disabled"
|
||||||
@@ -35,6 +37,8 @@ func StrRoleToUserRole(strRole string) UserRole {
|
|||||||
return UserRoleUser
|
return UserRoleUser
|
||||||
case "billing_admin":
|
case "billing_admin":
|
||||||
return UserRoleBillingAdmin
|
return UserRoleBillingAdmin
|
||||||
|
case "auditor":
|
||||||
|
return UserRoleAuditor
|
||||||
default:
|
default:
|
||||||
return UserRoleUnknown
|
return UserRoleUnknown
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user