From 10cb50739c51a482ca4712f58c5e487c42179b7a Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Sun, 8 Nov 2026 15:40:06 +0100 Subject: [PATCH] DMI inventory now skips sysfs files that `cf-agent` cannot read Some files in `/sys/devices/virtual/dmi/id/`, such as `product_serial`, are only readable by root. `fileexists()` lets `readfile()` run anyway, causing unprivileged agents to log a permission denied error. Instead we use `isreadable()` to guard the read. However, `isreadable()` is only available in CFEngine >= 3.22. Changelog: Title Signed-off-by: Lars Erik Wik (cherry picked from commit 640062bdcaefdd516479ecaf5e9c5edb4a2d487e) --- inventory/any.cf | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/inventory/any.cf b/inventory/any.cf index 5fd8f3ad76..1e696a63f8 100644 --- a/inventory/any.cf +++ b/inventory/any.cf @@ -1165,9 +1165,17 @@ bundle agent cfe_autorun_inventory_dmidecode # which would be undesirable. "dmi[$(dmivars)]" unless => isvariable("dmi[$(dmivars)]"), # This is just for system-uuid really, which we get from the awk script above by preference. +@if minimum_version(3.22.0) + # Some files (e.g. product_serial) are only readable by root. + # The isreadable() was introduced in CFEngine 3.22. + if => isreadable( + "/sys/devices/virtual/dmi/id/$(sysfs_name_for[$(dmivars)])", 1 + ), +@else if => fileexists( "/sys/devices/virtual/dmi/id/$(sysfs_name_for[$(dmivars)])" ), +@endif string => readfile( "/sys/devices/virtual/dmi/id/$(sysfs_name_for[$(dmivars)])", 0 ),