Skip to content

Commit

Permalink
Allow setting user for all modules and capabilities per module
Browse files Browse the repository at this point in the history
When setting system_user="myuser" property under settings in a config file
all modules are started as this user and its default gid.

After starting all modules the manager also switches to this user.

For each module, special Linux capabilities can be specified with e.g.
capabilities: "cap_chown+ep"
in the module section.

The manager will need to start as root or sufficient capabilities to do
that. If no user/capabilities are specified no change happens.

Implementation changes

- using SECBITS_KEEP_CAP in order to keep capabilities, when changing
  real user id
- using ambient capability set, in order to keep capabilities, when
  execve'ing
- changed name from 'system_user' to 'run_as_user'
- changed schema for capabilities in config file from string to array of
  strings
- dropped 'run_as_user' from ModuleStartInfo, could be added back, when
  configuration is possible
- known bugs:
  - incomplete error handling, when setting of capabilities fails
  - manager process doesn't change user yet (otherwise restarting of
    modules won't work), should use effective user id here
  - controller process doesn't get terminated, when forking process
    fails due to permission problems

Signed-off-by: aw <aw@pionix.de>
Signed-off-by: Cornelius Claussen <cc@pionix.de>
  • Loading branch information
corneliusclaussen committed Oct 13, 2023
1 parent 3887a64 commit 1237657
Show file tree
Hide file tree
Showing 9 changed files with 401 additions and 119 deletions.
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ find_package(Boost
REQUIRED
)

find_package(PkgConfig REQUIRED)
pkg_check_modules(libcap
REQUIRED
IMPORTED_TARGET
libcap
)

if(NOT DISABLE_EDM)
evc_setup_edm()

Expand Down
2 changes: 2 additions & 0 deletions include/framework/runtime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ struct RuntimeSettings {
std::string telemetry_prefix;
bool telemetry_enabled;

std::string run_as_user;

Check notice on line 117 in include/framework/runtime.hpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

include/framework/runtime.hpp#L117

struct member 'RuntimeSettings::run_as_user' is never used.

nlohmann::json config;

bool validate_schema;
Expand Down
1 change: 1 addition & 0 deletions lib/runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ RuntimeSettings::RuntimeSettings(const std::string& prefix_, const std::string&
} else {
validate_schema = defaults::VALIDATE_SCHEMA;
}
run_as_user = settings.value("run_as_user", "");
}

ModuleCallbacks::ModuleCallbacks(const std::function<void(ModuleAdapter module_adapter)>& register_module_adapter,
Expand Down
7 changes: 7 additions & 0 deletions schemas/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ properties:
type: boolean
validate_schema:
type: boolean
run_as_user:
type: string
additionalProperties: false
active_modules:
type: object
Expand All @@ -76,6 +78,11 @@ properties:
type: string
# module name
pattern: ^[a-zA-Z_][a-zA-Z0-9_-]*$
capabilities:
description: Linux capabilities required to run this module
type: array
items:
type: string
config_module:
description: Config map for the module
$ref: '#/$defs/config_map'
Expand Down
8 changes: 0 additions & 8 deletions schemas/manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,6 @@ properties:
description:
type: string
minLength: 2
capabilities:
description: linux capabilities this module should have (allowlist)
type: array
minItems: 0
items:
type: string
minLength: 6
default: []
config:
description: >-
Config set for this module (and possibly default values) declared
Expand Down
10 changes: 8 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
add_subdirectory(controller)

add_executable(manager manager.cpp)
add_executable(manager)
target_sources(manager
PRIVATE
system_unix.cpp
manager.cpp
)

target_link_libraries(manager
PRIVATE
Boost::program_options
PkgConfig::libcap
everest::framework
controller-ipc
Boost::program_options
)

target_compile_options(manager PRIVATE ${COMPILER_WARNING_OPTIONS})
Expand Down
Loading

0 comments on commit 1237657

Please sign in to comment.