From d8708d68533abe111adf036871a47df69c4ee37a 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 | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/inventory/any.cf b/inventory/any.cf index 8d20ead7b3..0073a3e981 100644 --- a/inventory/any.cf +++ b/inventory/any.cf @@ -975,7 +975,13 @@ 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), meta => { "inventory", "attribute_name=$(dmidefs[$(dmivars)])" };