Use the etc_fstab Chef InSpec audit resource to test information about all partitions and storage devices on a Linux system.
This resource is distributed along with Chef InSpec itself. You can use it automatically.
This resource first became available in v1.37.6 of InSpec.
An etc_fstab rule specifies a device name, its mount point, its mount type, the options it mounted with, its dump options and the files system options should be checked.
Use the where clause to match a property to one or more rules in the fstab file:
describe etc_fstab.where { device_name == 'value' } do
its('mount_point') { should cmp 'hostname' }
its('file_system_type') { should cmp 'list' }
its('mount_options') { should cmp 'list' }
its('dump_options') { should cmp 'list' }
its('file_system_options') { should cmp 'list' }
end
Use the optional constructor parameter to give an alternative path to fstab file:
describe etc_fstab(hosts_path).where { device_name == 'value' } do
its('mount_point') { should cmp 'hostname' }
its('file_system_type') { should cmp 'list' }
its('mount_options') { should cmp 'list' }
its('dump_options') { should cmp 'list' }
its('file_system_options') { should cmp 'list ' }
end
The device_name property returns a string array including the device names mounted on the system.
describe etc_fstab.where { mount_point == '/mnt/sr0' } do
its('device_name') { should cmp '/dev/sr0' }
end
The mount_point property returns a string array including the path of directories at which filesystems are configured to be mounted.
describe etc_fstab.where { device_name == '/dev/sr0' } do
its('mount_point') { should cmp '/mnt/sr0' }
end
The file_system_type property returns a string array including each device or partitions file system type.
describe etc_fstab.where { device_name == '/dev/sr0' } do
its('file_system_type') { should cmp 'iso9660' }
end
The mount_options property returns a two dimensional array of each partition’s mount options.
describe etc_fstab.where { mount_point == '/' } do
its('mount_options') { should eq [['defaults', 'x-systemd.device-timeout=0']] }
end
The dump_options property returns an integer array of each partitions dump option. This is a number used by dump to decide if a file system should be backed up.
describe etc_fstab.where { device_name == '/dev/sr0' } do
its('dump_options') { should cmp 0 }
end
The file_system_options property returns an integer array of each partitions file system option. This is a number that specifies the order in which the file system should be checked.
describe etc_fstab.where { device_name == '/dev/sr0' } do
its('file_system_options') { should cmp 0 }
end
nfs_systems = etc_fstab.nfs_file_systems.entries
nfs_systems.each do |partition|
describe partition do
its('mount_options') { should include 'nosuid' }
end
end
describe etc_fstab do
its('home_mount_options') { should include 'nosuid' }
end
describe etc_fstab.where { mount_point == '/home' } do
it { should be_configured }
end
For a full list of available matchers, please visit our matchers page.
© Chef Software, Inc.
Licensed under the Creative Commons Attribution 3.0 Unported License.
The Chef™ Mark and Chef Logo are either registered trademarks/service marks or trademarks/servicemarks of Chef, in the United States and other countries and are used with Chef Inc's permission.
We are not affiliated with, endorsed or sponsored by Chef Inc.
https://docs.chef.io/inspec/resources/etc_fstab/