Skip to content

Commit 8fa7626

Browse files
committed
Added inventory-fde to inventory full disk encryption
1 parent cbaf3fd commit 8fa7626

4 files changed

Lines changed: 124 additions & 1 deletion

File tree

cfbs.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,23 @@
137137
},
138138
"inventory-windows-services": {
139139
"description": "Inventory running Windows services.",
140-
"subdirectory": "inventory",
140+
"subdirectory": "inventory/inventory-windows-services",
141141
"steps": [
142142
"copy inventory-windows-services.cf services/cfbs/inventory-windows-services/",
143143
"policy_files services/cfbs/inventory-windows-services/",
144144
"bundles inventory_windows_services_running"
145145
]
146146
},
147+
"inventory-fde": {
148+
"description": "Inventory full disk encryption status (LUKS, FileVault, BitLocker).",
149+
"tags": ["inventory", "security"],
150+
"subdirectory": "inventory/inventory-fde",
151+
"steps": [
152+
"copy inventory-fde.cf services/cfbs/inventory-fde/",
153+
"policy_files services/cfbs/inventory-fde/",
154+
"bundles inventory_fde:main"
155+
]
156+
},
147157
"library-for-promise-types-in-bash": {
148158
"description": "Library enabling promise types implemented in bash.",
149159
"subdirectory": "libraries/bash",

inventory/inventory-fde/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
Full disk encryption (FDE) protects data at rest by encrypting entire block devices.
2+
This module detects mounted volumes backed by dm-crypt (LUKS1, LUKS2, or plain dm-crypt) on Linux systems.
3+
4+
Detection is performed entirely through virtual filesystem reads (`/sys/block/` and `/proc/mounts`), with no dependency on external commands like `dmsetup` or `findmnt`.
5+
6+
## How it works
7+
8+
1. Enumerates device-mapper block devices from `/sys/block/dm-*`
9+
2. Reads each device's DM subsystem UUID from `/sys/block/dm-N/dm/uuid`
10+
3. Identifies crypt devices by the `CRYPT-` prefix in the UUID
11+
4. Checks `/proc/mounts` for any mounted filesystem referencing a crypt device (via `/dev/mapper/<name>` or `/dev/dm-N`)
12+
13+
## Inventory
14+
15+
- **Full disk encryption enabled** -- `yes` if any mounted volume is on a dm-crypt device, `no` otherwise.
16+
- **Full disk encryption method** -- The encryption type(s) detected, e.g. `LUKS2`, `LUKS1`, `PLAIN`, or `none`. Multiple types are comma-separated if different methods are in use.
17+
- **Full disk encryption volumes** -- List of device-mapper names for mounted encrypted volumes.
18+
19+
## Example
20+
21+
```
22+
$ sudo cf-agent -Kf ./inventory-fde.cf --show-evaluated-vars=inventory_fde
23+
Variable name Variable value Meta tags Comment
24+
inventory_fde:main.fde_enabled yes source=promise,inventory,attribute_name=Full disk encryption enabled
25+
inventory_fde:main.fde_method LUKS2 source=promise,inventory,attribute_name=Full disk encryption method
26+
inventory_fde:main.fde_volumes {"luks-4c56337e-878a-48c7-bca3-ed6fa50cf017"} source=promise,inventory,attribute_name=Full disk encryption volumes
27+
```
28+
29+
## Platform
30+
31+
- Linux only (requires `/sys/block/` and `/proc/mounts`)
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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+
}

inventory/inventory-windows-services.cf renamed to inventory/inventory-windows-services/inventory-windows-services.cf

File renamed without changes.

0 commit comments

Comments
 (0)