Skip to content

Commit

Permalink
Separate Authentication and Modification in AccountManager (#321)
Browse files Browse the repository at this point in the history
* feat: separate adduser addaccount and addqos

* feat: separate AM add partition and qos

* feat: Standardize item in proto and rename it to modifyField

* fix: CheckAddUserAllowedQos check qos already in user allowed

* feat: modifyUser overwrite

* refactor: Replace pointer parameters with references

* feat: modifyuser delete

* feat: delete user and fix delete user in default account(bug 179)

* feat: deleteAccount deleteQos

* feat: modifyAccount

* fix: Cannot modify partition and qos simultaneously

* feat: blockuser blockaccount

* feat: refactor QueryUser QueryAccount QueryQos

* feat: refactor modifyUser

* feat: refactor blockaccount blockuser

* fix: modifyUserdefaultqos

* feat: CheckPartitionIsAllowed CheckQosIsAllowed

* fix: fix modify adminLevel, new_level must <= op_level

* fix: modify qos modifyField error

* fix: adduser Check whether the account exists

* fix: addcount opuser existed and account empty bug

* fix: CheckOpUserHasPermissionToAccount

* fix: simultaneous modification conflict

* feat: Return front-end error code demo.

* feat:fix CheckSetUserAllowedQos No result returned issue.

* feat: update err code

* feat: Error Code Specification

* merge Add display of coordinator field (#180)

* feat: To upgrade to C++23, use std::expected and std::unreachable.

* feat: update errCode

* delete tl expected head file

* fix: errCode

* fix: add ERR_PARENT_ALLOWED_ err code

* fix: ERR_USER_EMPTY_PARTITION

* fix: set account qos err code

* refactor

* refactor

* refactor

* refactor

* refactor

* refactor

* refactor

* refactor: unused-parameters

* refactor: CraneExpected<bool> to CraneExpected<void>

* refactor

* refactor

Signed-off-by: RileyW <wrllrwwrllrw@gmail.com>

* refactor

* refactor: CheckIfUserHasPemOnUser CheckIfUserHasPemOnUser CheckIfUserHasPemOnUser CheckIfUserHasPemOnUser

* refactor: HasPermissionToUser

* Refactor.

Signed-off-by: RileyW <wrllrwwrllrw@gmail.com>

* fix: double locking

* refactor

* refactor

* fix: AddAccount

* Update PublicDefs.proto

Remove useless changes

* fix: The default QoS setting was missed when adding the account.

* refactor

* Reformat cmake.

Signed-off-by: RileyW <wrllrwwrllrw@gmail.com>

---------

Signed-off-by: RileyW <wrllrwwrllrw@gmail.com>
Co-authored-by: RileyW <wrllrwwrllrw@gmail.com>
  • Loading branch information
huerni and RileyWen authored Nov 21, 2024
1 parent 25bc351 commit 1779794
Show file tree
Hide file tree
Showing 12 changed files with 2,502 additions and 2,187 deletions.
58 changes: 28 additions & 30 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,53 +37,53 @@ else ()
)
endif ()

if(VERSION_CONTENT STREQUAL "")
if (VERSION_CONTENT STREQUAL "")
# Fallback version
set(VERSION_CONTENT "Unknown")
set(CMAKE_PROJECT_VERSION "0.0.0")
endif()
endif ()

project(Crane VERSION ${CMAKE_PROJECT_VERSION} LANGUAGES C CXX)
# check and set compiler
# check and set compiler
set(REQUIRED_GNU_VERSION 13.0.0)
set(REQUIRED_CLANG_VERSION 19.0.0)
set(REQUIRED_BPF_CLANG_VERSION 17.0.0)

set(CLANG_VERSION "0.0.0")

if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL REQUIRED_GNU_VERSION)
if(CRANE_ENABLE_CGROUP_V2)
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL REQUIRED_GNU_VERSION)
if (CRANE_ENABLE_CGROUP_V2)
message(STATUS "Enabling Cgroup V2 will build cgroup_dev_bpf_object, which requires Clang ${REQUIRED_BPF_CLANG_VERSION}+. Use GNU ${CMAKE_CXX_COMPILER_VERSION} for other modules. ")
find_program(CLANG_EXECUTABLE NAMES clang)
if(CLANG_EXECUTABLE)
if (CLANG_EXECUTABLE)
execute_process(
COMMAND ${CLANG_EXECUTABLE} --version
OUTPUT_VARIABLE CLANG_VERSION_OUTPUT
OUTPUT_STRIP_TRAILING_WHITESPACE
COMMAND ${CLANG_EXECUTABLE} --version
OUTPUT_VARIABLE CLANG_VERSION_OUTPUT
OUTPUT_STRIP_TRAILING_WHITESPACE
)
string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" CLANG_VERSION ${CLANG_VERSION_OUTPUT})
if(CLANG_VERSION VERSION_GREATER_EQUAL REQUIRED_BPF_CLANG_VERSION)
if (CLANG_VERSION VERSION_GREATER_EQUAL REQUIRED_BPF_CLANG_VERSION)
set(ENABLE_BPF ON)
message(STATUS "Found Clang at ${CLANG_EXECUTABLE} with version ${CLANG_VERSION}; using this version for the cgroup_dev_bpf_object module.")
else()
else ()
message(FATAL_ERROR "Clang found at ${CLANG_EXECUTABLE} is version ${CLANG_VERSION}, but version ${REQUIRED_BPF_CLANG_VERSION} or higher is required for device management on Cgroup V2. You may use Cgroup V1 instead.")
endif()
else()
endif ()
else ()
message(FATAL_ERROR "Clang ${REQUIRED_BPF_CLANG_VERSION} or higher is required for device management on Cgroup V2. You can use Cgroup V1.")
endif()
endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL REQUIRED_CLANG_VERSION)
if(CRANE_ENABLE_CGROUP_V2)
endif ()
endif ()
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL REQUIRED_CLANG_VERSION)
if (CRANE_ENABLE_CGROUP_V2)
set(ENABLE_BPF ON)
endif()
endif ()
message(STATUS "Using Clang for all module.")
else()
else ()
message(FATAL_ERROR "Clang ${REQUIRED_CLANG_VERSION} or higher is required.")
endif()
else()
endif ()
else ()
message(FATAL_ERROR "Neither GNU ${REQUIRED_GNU_VERSION}+ nor Clang ${REQUIRED_CLANG_VERSION}+ found. Stop compiling crane")
endif()
endif ()


# Options start here ----------------------------------------------------------------------------
Expand Down Expand Up @@ -115,9 +115,7 @@ option(CRANE_MIN_LOG_LEVEL "Set the minimal log level (INFO/DEBUG/TRACE)" OFF)
option(CRANE_USE_MIMALLOC "Override malloc using mimalloc" OFF)
# Options end here -------------------------------------------------------------------------------



set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD 23)

if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CRANE_ENABLE_TESTS ON)
Expand Down Expand Up @@ -173,8 +171,8 @@ endif ()
# 1. devtoolset-11-libasan-devel.x86_64
# 2. devtoolset-11-libtsan-devel.x86_64
if (CRANE_ADDRESS_SANITIZER AND CRANE_THREAD_SANITIZER)
message(FATAL_ERROR "CRANE_ADDRESS_SANITIZER and CRANE_THREAD_SANITIZER cannot be enabled at the same time.")
endif()
message(FATAL_ERROR "CRANE_ADDRESS_SANITIZER and CRANE_THREAD_SANITIZER cannot be enabled at the same time.")
endif ()

if (${CRANE_ADDRESS_SANITIZER})
message(STATUS "address_sanitizer is enabled")
Expand Down Expand Up @@ -340,10 +338,10 @@ set(_PROTOBUF_PROTOC $<TARGET_FILE:protoc>)
set(_GRPC_GRPCPP grpc++)
set(_GRPC_CPP_PLUGIN_EXECUTABLE $<TARGET_FILE:grpc_cpp_plugin>)

if(ENABLE_BPF)
if (ENABLE_BPF)
find_package(PkgConfig REQUIRED)
pkg_check_modules(libbpf REQUIRED IMPORTED_TARGET libbpf>=1.4.6)
endif()
endif ()
# @formatter:off
add_definitions(-DCRANE_BUILD_DIRECTORY=\("${CMAKE_BINARY_DIR}"\))
# @formatter:on
Expand Down
4 changes: 2 additions & 2 deletions dependencies/cmake/grpc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ else ()
set(C_ARES_SRC_URL "https://github.com/c-ares/c-ares/releases/download/cares-1_18_1/c-ares-1.18.1.tar.gz")
set(PROTOBUF_SRC_URL "https://github.com/protocolbuffers/protobuf/releases/download/v27.2/protobuf-27.2.tar.gz")
set(RE2_SRC_URL "https://github.com/google/re2/archive/refs/tags/2022-06-01.tar.gz")
set(GRPC_SRC_URL "https://github.com/grpc/grpc/archive/refs/tags/v1.65.2.tar.gz")
set(GRPC_SRC_URL "https://github.com/grpc/grpc/archive/refs/tags/v1.67.0.tar.gz")
endif ()

set(ABSL_PROPAGATE_CXX_STD ON)
Expand Down Expand Up @@ -110,7 +110,7 @@ FetchContent_Declare(grpc
OVERRIDE_FIND_PACKAGE

URL ${GRPC_SRC_URL}
URL_HASH SHA256=0ff2e0a6abf195cf23b4ce808570bcbb2ff4b5bee453af0b45afd496e661f2c0
URL_HASH SHA256=af0638f73e4452e22e295f8b3f452518234254104713a08497f3d3aaa76733ad
INACTIVITY_TIMEOUT 5
)
FetchContent_MakeAvailable(grpc)
Expand Down
8 changes: 4 additions & 4 deletions dependencies/cmake/libcgroup/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ if (${CRANE_USE_SYSTEM_LIBCGROUP})

if (libcgroup_FOUND)
message(STATUS "Found libcgroup ${libcgroup_VERSION} in system using pkg-config.")
if(CRANE_ENABLE_CGROUP_V2 AND libcgroup_VERSION VERSION_LESS "3.1.0")
if (CRANE_ENABLE_CGROUP_V2 AND libcgroup_VERSION VERSION_LESS "3.1.0")
message(FATAL_ERROR "libcgroup version must be higher than 3.1.0 when CRANE_ENABLE_CGROUP_V2 is set.")
endif()
else()
endif ()
else ()
message(FATAL_ERROR "libcgroup in system is not found using pkg-config.")
endif()
endif ()

add_library(libcgroup INTERFACE)
target_link_libraries(libcgroup INTERFACE PkgConfig::libcgroup)
Expand Down
20 changes: 10 additions & 10 deletions dependencies/cmake/mimalloc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
include(FetchContent)
FetchContent_Declare(
mimalloc
GIT_REPOSITORY https://github.com/microsoft/mimalloc.git
GIT_TAG v2.1.7
GIT_SHALLOW TRUE
mimalloc
GIT_REPOSITORY https://github.com/microsoft/mimalloc.git
GIT_TAG v2.1.7
GIT_SHALLOW TRUE
)
# If MI_OVERRIDE is ON then operator new and delete will be override not only malloc and free
# ref: https://github.com/microsoft/mimalloc/issues/535
Expand All @@ -13,19 +13,19 @@ if (BUILD_SHARED_LIBS)
set(MI_BUILD_SHARED ON)
else ()
set(MI_BUILD_SHARED OFF)
endif()
endif ()

if(CRANE_ADDRESS_SANITIZER)
if (CRANE_ADDRESS_SANITIZER)
set(MI_TRACK_ASAN ON)
message(STATUS "Set ASAN enable in mimalloc")
endif()
endif ()

FetchContent_MakeAvailable(mimalloc)

if (BUILD_SHARED_LIBS)
add_library(dev_mimalloc ALIAS mimalloc)
add_library(dev_mimalloc ALIAS mimalloc)
else ()
# When building with static library, make sure that link it as the first object file.
# ref: https://github.com/microsoft/mimalloc?tab=readme-ov-file#static-override
add_library(dev_mimalloc ALIAS mimalloc-static)
endif()
add_library(dev_mimalloc ALIAS mimalloc-static)
endif ()
128 changes: 96 additions & 32 deletions protos/Crane.proto
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ message AddAccountRequest {

message AddAccountReply {
bool ok = 1;
string reason = 2;
ErrCode reason = 2;
}

message AddUserRequest {
Expand All @@ -252,7 +252,7 @@ message AddUserRequest {

message AddUserReply {
bool ok = 1;
string reason = 2;
ErrCode reason = 2;
}

message AddQosRequest {
Expand All @@ -262,57 +262,113 @@ message AddQosRequest {

message AddQosReply {
bool ok = 1;
string reason = 2;
ErrCode reason = 2;
}

message DeleteEntityRequest {
message DeleteAccountRequest {
uint32 uid = 1;
EntityType entity_type = 2;
string name = 3;
string account = 4;
string name = 2;
}

message DeleteEntityReply {
message DeleteAccountReply {
bool ok = 1;
string reason = 2;
ErrCode reason = 2;
}

message ModifyEntityRequest {
message DeleteUserRequest {
uint32 uid = 1;
string name = 2;
string account = 3;
}

enum OperatorType {
Overwrite = 0;
Add = 1;
Delete = 2;
}
message DeleteUserReply {
bool ok = 1;
ErrCode reason = 2;
}

message DeleteQosRequest {
uint32 uid = 1;
string name = 2;
}

message DeleteQosReply {
bool ok = 1;
ErrCode reason = 2;
}

message ModifyAccountRequest {
uint32 uid = 1;
ModifyField modify_field = 2; //modify item field
string value = 3; //new value
string name = 4;
OperationType type = 5;
bool force = 6;
}

message ModifyAccountReply {
bool ok = 1;
ErrCode reason = 2;
}

string item = 2; //modify item field
message ModifyUserRequest {
uint32 uid = 1;
ModifyField modify_field = 2; //modify item field
string value = 3; //new value
string name = 4;
string partition = 5;
OperatorType type = 6;
EntityType entity_type = 7;
OperationType type = 6;
string account = 8;
bool force = 9;
}

message ModifyEntityReply {
message ModifyUserReply {
bool ok = 1;
string reason = 2;
ErrCode reason = 2;
}

message QueryEntityInfoRequest {
message ModifyQosRequest {
uint32 uid = 1;
EntityType entity_type = 2;
string name = 3;
string account = 4;
ModifyField modify_field = 2; //modify item field
string value = 3; //new value
string name = 4;
}

message QueryEntityInfoReply {
message ModifyQosReply {
bool ok = 1;
string reason = 2;
repeated UserInfo user_list = 3;
repeated AccountInfo account_list = 4;
ErrCode reason = 2;
}

message QueryAccountInfoRequest {
uint32 uid = 1;
string name = 2;
}

message QueryAccountInfoReply {
bool ok = 1;
ErrCode reason = 2;
repeated AccountInfo account_list = 3;
}

message QueryUserInfoRequest {
uint32 uid = 1;
string name = 2;
string account = 3;
}

message QueryUserInfoReply {
bool ok = 1;
ErrCode reason = 2;
repeated UserInfo user_list = 3;
}

message QueryQosInfoRequest {
uint32 uid = 1;
string name = 2;
}

message QueryQosInfoReply {
bool ok = 1;
ErrCode reason = 2;
repeated QosInfo qos_list = 5;
}

Expand All @@ -326,7 +382,7 @@ message BlockAccountOrUserRequest {

message BlockAccountOrUserReply {
bool ok = 1;
string reason = 2;
ErrCode reason = 2;
}

message MigrateSshProcToCgroupRequest {
Expand Down Expand Up @@ -719,10 +775,18 @@ service CraneCtld {
rpc AddUser(AddUserRequest) returns (AddUserReply);
rpc AddQos(AddQosRequest) returns (AddQosReply);

rpc DeleteEntity(DeleteEntityRequest) returns (DeleteEntityReply);
rpc DeleteAccount(DeleteAccountRequest) returns (DeleteAccountReply);
rpc DeleteUser(DeleteUserRequest) returns (DeleteUserReply);
rpc DeleteQos(DeleteQosRequest) returns (DeleteQosReply);

rpc QueryAccountInfo(QueryAccountInfoRequest) returns (QueryAccountInfoReply);
rpc QueryUserInfo(QueryUserInfoRequest) returns (QueryUserInfoReply);
rpc QueryQosInfo(QueryQosInfoRequest) returns (QueryQosInfoReply);

rpc QueryEntityInfo(QueryEntityInfoRequest) returns (QueryEntityInfoReply);
rpc ModifyEntity(ModifyEntityRequest) returns (ModifyEntityReply);
rpc ModifyAccount(ModifyAccountRequest) returns (ModifyAccountReply);
rpc ModifyUser(ModifyUserRequest) returns (ModifyUserReply);
rpc ModifyQos(ModifyQosRequest) returns (ModifyQosReply);

rpc BlockAccountOrUser(BlockAccountOrUserRequest) returns (BlockAccountOrUserReply);

/* RPCs called from cinfo */
Expand Down
Loading

0 comments on commit 1779794

Please sign in to comment.