|
| 1 | +body file control |
| 2 | +{ |
| 3 | + namespace => "inventory_fde"; |
| 4 | +} |
| 5 | + |
| 6 | +bundle agent main |
| 7 | +# @brief Inventory full disk encryption status |
| 8 | +# @inventory Full disk encryption enabled Whether any mounted volume uses dm-crypt encryption (yes/no). |
| 9 | +# @inventory Full disk encryption method The encryption type(s) in use, e.g. LUKS2, LUKS1, PLAIN, or none. |
| 10 | +# @inventory Full disk encryption volumes List of device-mapper names for mounted encrypted volumes, e.g. luks-4c56337e-878a-48c7-bca3-ed6fa50cf017. |
| 11 | +{ |
| 12 | + vars: |
| 13 | + linux:: |
| 14 | + # Enumerate all device-mapper block devices |
| 15 | + "_dm_devices" slist => lsdir("/sys/block", "dm-\d+", false); |
| 16 | + |
| 17 | + # Read the DM subsystem uuid and name for each dm device |
| 18 | + "_dm_uuid[${_dm_devices}]" |
| 19 | + string => readfile("/sys/block/${_dm_devices}/dm/uuid"), |
| 20 | + if => fileexists("/sys/block/${_dm_devices}/dm/uuid"); |
| 21 | + "_dm_name[${_dm_devices}]" |
| 22 | + string => readfile("/sys/block/${_dm_devices}/dm/name"), |
| 23 | + if => fileexists("/sys/block/${_dm_devices}/dm/name"); |
| 24 | + |
| 25 | + # Extract the encryption type (e.g. LUKS1, LUKS2, PLAIN) from the uuid |
| 26 | + # UUID format: CRYPT-<TYPE>-<uuid>-<name> |
| 27 | + "_dm_crypt_type[${_dm_devices}]" |
| 28 | + string => regex_replace("${_dm_uuid[${_dm_devices}]}", "^CRYPT-([^-]+)-.*", "\1", ""), |
| 29 | + if => canonify("_mnt_on_crypt_${_dm_devices}"); |
| 30 | + |
| 31 | + # Collect mapper name and method for each mounted crypt volume |
| 32 | + "_mounted_crypt_name[${_dm_devices}]" |
| 33 | + string => "${_dm_name[${_dm_devices}]}", |
| 34 | + if => canonify("_mnt_on_crypt_${_dm_devices}"); |
| 35 | + "_mounted_crypt_method[${_dm_devices}]" |
| 36 | + string => "${_dm_crypt_type[${_dm_devices}]}", |
| 37 | + if => canonify("_mnt_on_crypt_${_dm_devices}"); |
| 38 | + |
| 39 | + _fde_detected:: |
| 40 | + "fde_enabled" |
| 41 | + string => "yes", |
| 42 | + meta => { "inventory", "attribute_name=Full disk encryption enabled" }; |
| 43 | + "fde_method" |
| 44 | + string => join(", ", unique(getvalues(_mounted_crypt_method))), |
| 45 | + meta => { "inventory", "attribute_name=Full disk encryption method" }; |
| 46 | + "fde_volumes" |
| 47 | + slist => getvalues(_mounted_crypt_name), |
| 48 | + meta => { "inventory", "attribute_name=Full disk encryption volumes" }; |
| 49 | + |
| 50 | + linux.!_fde_detected:: |
| 51 | + "fde_enabled" |
| 52 | + string => "no", |
| 53 | + meta => { "inventory", "attribute_name=Full disk encryption enabled" }; |
| 54 | + "fde_method" |
| 55 | + string => "none", |
| 56 | + meta => { "inventory", "attribute_name=Full disk encryption method" }; |
| 57 | + |
| 58 | + classes: |
| 59 | + linux:: |
| 60 | + # Flag each dm device that has a CRYPT uuid |
| 61 | + "_dm_is_crypt_${_dm_devices}" |
| 62 | + expression => regcmp("CRYPT-.*", "${_dm_uuid[${_dm_devices}]}"); |
| 63 | + |
| 64 | + # Check if any mounted volume references a crypt dm device |
| 65 | + "_mnt_on_crypt_${_dm_devices}" |
| 66 | + expression => regline("/dev/(mapper/${_dm_name[${_dm_devices}]}|${_dm_devices})\s.*", |
| 67 | + "/proc/mounts"), |
| 68 | + if => canonify("_dm_is_crypt_${_dm_devices}"); |
| 69 | + |
| 70 | + "_fde_detected" expression => classmatch("_mnt_on_crypt_.*"); |
| 71 | +} |
| 72 | + |
| 73 | +body file control |
| 74 | +{ |
| 75 | + namespace => "default"; |
| 76 | +} |
| 77 | + |
| 78 | +bundle agent __main__ |
| 79 | +{ |
| 80 | + methods: |
| 81 | + "inventory_fde:main"; |
| 82 | +} |
0 commit comments