thin-edge / thin-edge.io

The open edge framework for lightweight IoT devices
https://thin-edge.io
Apache License 2.0
221 stars 54 forks source link

Custom restart should only use sudo if sudo is installed #2096

Closed reubenmiller closed 1 year ago

reubenmiller commented 1 year ago

Is your feature improvement request related to a problem? Please describe.

The custom restart command (defined in the system.toml file), always assumes that sudo needs to be used when calling the custom command. When using a container setup, this is generally not the case as certain privileged functions are available to a non-root user (e.g. restarting the container when using s6-overlay is allowed by a non root user.)

Ideally sudo should be an optional dependency, and only called if it is actually installed.

Below shows a snippet of the log entry when sudo is not installed and the restart manager tries to execute the script (notice it doesn't actually say that sudo is missing, but it was definitely caused by the missing sudo as shown in the rust snippet following the example).

tedge-agent | 2023-07-25T19:56:47.185282174Z ERROR tedge_agent::restart_manager::actor: No such file or directory (os error 2)

The rust source code shows the problem with the reliance on sudo, and it blindly uses it without any prior checks if it exists or not.

File: crates/core/tedge_agent/src/restart_manager/actor.rs

let mut command = Command::new(SUDO);
command.args(system_config.system.reboot);
vec.push(command);
Ok(vec)

Describe the solution you'd like

Describe alternatives you've considered

Additional context

gligorisaev commented 1 year ago

QA has thoroughly checked the feature and here are the results: