mirror of
https://github.com/gravitl/netmaker.git
synced 2025-09-04 04:04:17 +08:00
* feat: api access tokens
* revoke all user tokens
* redefine access token api routes, add auto egress option to enrollment keys
* add server settings apis, add db table for settigs
* handle server settings updates
* switch to using settings from DB
* fix sever settings migration
* revet force migration for settings
* fix server settings database write
* fix revoked tokens to be unauthorized
* remove unused functions
* convert access token to sql schema
* switch access token to sql schema
* fix merge conflicts
* fix server settings types
* bypass basic auth setting for super admin
* add TODO comment
* feat(go): add types for idp package;
* feat(go): import azure sdk;
* feat(go): add stub for google workspace client;
* feat(go): implement azure ad client;
* feat(go): sync users and groups using idp client;
* publish peer update on settings update
* feat(go): read creds from env vars;
* feat(go): add api endpoint to trigger idp sync;
* fix(go): sync member changes;
* fix(go): handle error;
* fix(go): set correct response type;
* feat(go): support disabling user accounts;
1. Add api endpoints to enable and disable user accounts.
2. Add checks in authenticators to prevent disabled users from logging in.
3. Add checks in middleware to prevent api usage by disabled users.
* feat(go): use string slice for group members;
* feat(go): sync user account status from idp;
* feat(go): import google admin sdk;
* feat(go): add support for google workspace idp;
* feat(go): initialize idp client on sync;
* feat(go): sync from idp periodically;
* feat(go): improvements for google idp;
1. Use the impersonate package to authenticate.
2. Use Pages method to get all data.
* chore(go): import style changes from migration branch;
1. Singular file names for table schema.
2. No table name method.
3. Use .Model instead of .Table.
4. No unnecessary tagging.
* remove nat check on egress gateway request
* Revert "remove nat check on egress gateway request"
This reverts commit 0aff12a189
.
* feat(go): add db middleware;
* feat(go): restore method;
* feat(go): add user access token schema;
* fix user auth api:
* re initalise oauth and email config
* feat(go): fetch idp creds from server settings;
* feat(go): add filters for users and groups;
* feat(go): skip sync from idp if disabled;
* feat(go): add endpoint to remove idp integration;
* feat(go): import all users if no filters;
* feat(go): assign service-user role on sync;
* feat(go): remove microsoft-go-sdk;
* feat(go): add display name field for user;
* fix(go): set account disabled correctly;
* fix(go): update user if display name changes;
* fix(go): remove auth provider when removing idp integration;
* fix(go): ignore display name if empty;
* feat(go): add idp sync interval setting;
* fix(go): error on invalid auth provider;
* fix(go): no error if no user on group delete;
* fix(go): check superadmin using platform role id;
* feat(go): add display name and account disabled to return user as well;
* feat(go): tidy go mod after merge;
* feat(go): reinitialize auth provider and idp sync hook;
* fix(go): merge error;
* fix(go): merge error;
* feat(go): use id as the external provider id;
* fix(go): comments;
* feat(go): add function to return pending users;
* feat(go): prevent external id erasure;
* fix(go): user and group sync errors;
* chore(go): cleanup;
* fix(go): delete only oauth users;
* feat(go): use uuid group id;
* export ipd id to in rest api
* feat(go): don't use uuid for default groups;
* feat(go): migrate group only if id not uuid;
* chore(go): go mod tidy;
---------
Co-authored-by: abhishek9686 <abhi281342@gmail.com>
Co-authored-by: Abhishek K <abhishek@netmaker.io>
Co-authored-by: the_aceix <aceixsmartx@gmail.com>
130 lines
3.8 KiB
Go
130 lines
3.8 KiB
Go
package logic
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"github.com/gravitl/netmaker/database"
|
|
"github.com/gravitl/netmaker/models"
|
|
)
|
|
|
|
// Pre-Define Permission Templates for default Roles
|
|
var SuperAdminPermissionTemplate = models.UserRolePermissionTemplate{
|
|
ID: models.SuperAdminRole,
|
|
Default: true,
|
|
FullAccess: true,
|
|
}
|
|
|
|
var AdminPermissionTemplate = models.UserRolePermissionTemplate{
|
|
ID: models.AdminRole,
|
|
Default: true,
|
|
FullAccess: true,
|
|
}
|
|
|
|
var GetFilteredNodesByUserAccess = func(user models.User, nodes []models.Node) (filteredNodes []models.Node) {
|
|
return
|
|
}
|
|
|
|
var CreateRole = func(r models.UserRolePermissionTemplate) error {
|
|
return nil
|
|
}
|
|
|
|
var DeleteRole = func(r models.UserRoleID, force bool) error {
|
|
return nil
|
|
}
|
|
|
|
var FilterNetworksByRole = func(allnetworks []models.Network, user models.User) []models.Network {
|
|
return allnetworks
|
|
}
|
|
|
|
var IsGroupsValid = func(groups map[models.UserGroupID]struct{}) error {
|
|
return nil
|
|
}
|
|
var IsGroupValid = func(groupID models.UserGroupID) error {
|
|
return nil
|
|
}
|
|
var IsNetworkRolesValid = func(networkRoles map[models.NetworkID]map[models.UserRoleID]struct{}) error {
|
|
return nil
|
|
}
|
|
|
|
var MigrateUserRoleAndGroups = func(u models.User) {
|
|
|
|
}
|
|
|
|
var MigrateGroups = func() {}
|
|
|
|
var UpdateUserGwAccess = func(currentUser, changeUser models.User) {}
|
|
|
|
var UpdateRole = func(r models.UserRolePermissionTemplate) error { return nil }
|
|
|
|
var InitialiseRoles = userRolesInit
|
|
var IntialiseGroups = func() {}
|
|
var DeleteNetworkRoles = func(netID string) {}
|
|
var CreateDefaultNetworkRolesAndGroups = func(netID models.NetworkID) {}
|
|
var CreateDefaultUserPolicies = func(netID models.NetworkID) {}
|
|
var GetUserGroupsInNetwork = func(netID models.NetworkID) (networkGrps map[models.UserGroupID]models.UserGroup) { return }
|
|
var GetUserGroup = func(groupId models.UserGroupID) (userGrps models.UserGroup, err error) { return }
|
|
var AddGlobalNetRolesToAdmins = func(u *models.User) {}
|
|
var EmailInit = func() {}
|
|
|
|
// GetRole - fetches role template by id
|
|
func GetRole(roleID models.UserRoleID) (models.UserRolePermissionTemplate, error) {
|
|
// check if role already exists
|
|
data, err := database.FetchRecord(database.USER_PERMISSIONS_TABLE_NAME, roleID.String())
|
|
if err != nil {
|
|
return models.UserRolePermissionTemplate{}, err
|
|
}
|
|
ur := models.UserRolePermissionTemplate{}
|
|
err = json.Unmarshal([]byte(data), &ur)
|
|
if err != nil {
|
|
return ur, err
|
|
}
|
|
return ur, nil
|
|
}
|
|
|
|
// ListPlatformRoles - lists user platform roles permission templates
|
|
func ListPlatformRoles() ([]models.UserRolePermissionTemplate, error) {
|
|
data, err := database.FetchRecords(database.USER_PERMISSIONS_TABLE_NAME)
|
|
if err != nil && !database.IsEmptyRecord(err) {
|
|
return []models.UserRolePermissionTemplate{}, err
|
|
}
|
|
userRoles := []models.UserRolePermissionTemplate{}
|
|
for _, dataI := range data {
|
|
userRole := models.UserRolePermissionTemplate{}
|
|
err := json.Unmarshal([]byte(dataI), &userRole)
|
|
if err != nil {
|
|
continue
|
|
}
|
|
if userRole.NetworkID != "" {
|
|
continue
|
|
}
|
|
userRoles = append(userRoles, userRole)
|
|
}
|
|
return userRoles, nil
|
|
}
|
|
|
|
func GetUserGrpMap() map[models.UserGroupID]map[string]struct{} {
|
|
grpUsersMap := make(map[models.UserGroupID]map[string]struct{})
|
|
users, _ := GetUsersDB()
|
|
for _, user := range users {
|
|
for gID := range user.UserGroups {
|
|
if grpUsers, ok := grpUsersMap[gID]; ok {
|
|
grpUsers[user.UserName] = struct{}{}
|
|
grpUsersMap[gID] = grpUsers
|
|
} else {
|
|
grpUsersMap[gID] = make(map[string]struct{})
|
|
grpUsersMap[gID][user.UserName] = struct{}{}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
return grpUsersMap
|
|
}
|
|
|
|
func userRolesInit() {
|
|
d, _ := json.Marshal(SuperAdminPermissionTemplate)
|
|
database.Insert(SuperAdminPermissionTemplate.ID.String(), string(d), database.USER_PERMISSIONS_TABLE_NAME)
|
|
d, _ = json.Marshal(AdminPermissionTemplate)
|
|
database.Insert(AdminPermissionTemplate.ID.String(), string(d), database.USER_PERMISSIONS_TABLE_NAME)
|
|
|
|
}
|