Remove sudo from docker commands - use docker group membership instead
All checks were successful
Build and Release / build-and-release (push) Successful in 1m19s

Agent changes:
- Changed docker ps and docker images commands to run without sudo
- cm-agent user is already in docker group, so sudo is not needed
- Fixes "unable to change to root gid: Operation not permitted" error
- Systemd security restrictions were blocking sudo gid changes

This fixes Docker container and image collection on systems with
systemd security hardening enabled.

Updated to version 0.1.178
This commit is contained in:
Christoffer Martinsson 2025-11-27 12:35:38 +01:00
parent fb40cce748
commit fefe30ec51
4 changed files with 9 additions and 9 deletions

View File

@ -1,6 +1,6 @@
[package] [package]
name = "cm-dashboard-agent" name = "cm-dashboard-agent"
version = "0.1.177" version = "0.1.178"
edition = "2021" edition = "2021"
[dependencies] [dependencies]

View File

@ -779,10 +779,10 @@ impl SystemdCollector {
fn get_docker_containers(&self) -> Vec<(String, String)> { fn get_docker_containers(&self) -> Vec<(String, String)> {
let mut containers = Vec::new(); let mut containers = Vec::new();
// Check if docker is available (use sudo for permissions) // Check if docker is available (cm-agent user is in docker group)
// Use -a to show ALL containers (running and stopped) // Use -a to show ALL containers (running and stopped)
let output = Command::new("sudo") let output = Command::new("docker")
.args(&["docker", "ps", "-a", "--format", "{{.Names}},{{.Status}}"]) .args(&["ps", "-a", "--format", "{{.Names}},{{.Status}}"])
.output(); .output();
let output = match output { let output = match output {
@ -826,9 +826,9 @@ impl SystemdCollector {
info!("Collecting Docker images"); info!("Collecting Docker images");
// Check if docker is available (use sudo for permissions) // Check if docker is available (cm-agent user is in docker group)
let output = Command::new("sudo") let output = Command::new("docker")
.args(&["docker", "images", "--format", "{{.Repository}}:{{.Tag}},{{.Size}}"]) .args(&["images", "--format", "{{.Repository}}:{{.Tag}},{{.Size}}"])
.output(); .output();
let output = match output { let output = match output {

View File

@ -1,6 +1,6 @@
[package] [package]
name = "cm-dashboard" name = "cm-dashboard"
version = "0.1.177" version = "0.1.178"
edition = "2021" edition = "2021"
[dependencies] [dependencies]

View File

@ -1,6 +1,6 @@
[package] [package]
name = "cm-dashboard-shared" name = "cm-dashboard-shared"
version = "0.1.177" version = "0.1.178"
edition = "2021" edition = "2021"
[dependencies] [dependencies]