Project: Chef InSpec (Provisioning / Security & Compliance)
File: etc_fstab.md

+++ title = "etc_fstab resource" draft = false gh_repo = "inspec" platform = "linux" [menu] [menu.inspec] title = "etc_fstab" identifier = "inspec/resources/os/etcfstab.md etcfstab resource" parent = "inspec/resources/os" +++ Use the `etc_fstab` Chef InSpec audit resource to test information about all partitions and storage devices on a Linux system. {{< readfile file="content/inspec/reusable/md/inspec_installation.md" >}} 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 etcfstab.where { devicename == 'value' } do its('mount_point') { should cmp 'hostname' } its('filesystemtype') { should cmp 'list' } its('mount_options') { should cmp 'list' } its('dump_options') { should cmp 'list' } its('filesystemoptions') { should cmp 'list' } end Use the optional constructor parameter to give an alternative path to fstab file: describe etcfstab(hostspath).where { device_name == 'value' } do its('mount_point') { should cmp 'hostname' } its('filesystemtype') { should cmp 'list' } its('mount_options') { should cmp 'list' } its('dump_options') { should cmp 'list' } its('filesystemoptions') { should cmp 'list ' } end The `device_name` property returns a string array including the device names mounted on the system. describe etcfstab.where { mountpoint == '/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 etcfstab.where { devicename == '/dev/sr0' } do its('mount_point') { should cmp '/mnt/sr0' } end The `filesystemtype` property returns a string array including each device or partitions file system type. describe etcfstab.where { devicename == '/dev/sr0' } do its('filesystemtype') { should cmp 'iso9660' } end The `mount_options` property returns a two dimensional array of each partition's mount options. describe etcfstab.where { mountpoint == '/' } 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 etcfstab.where { devicename == '/dev/sr0' } do its('dump_options') { should cmp 0 } end The `filesystemoptions` 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 etcfstab.where { devicename == '/dev/sr0' } do its('filesystemoptions') { should cmp 0 } end nfssystems = etcfstab.nfsfilesystems.entries nfs_systems.each do |partition| describe partition do its('mount_options') { should include 'nosuid' } end end describe etc_fstab do its('homemountoptions') { should include 'nosuid' } end describe etcfstab.where { mountpoint == '/home' } do it { should be_configured } end {{< readfile file="content/inspec/reusable/md/inspecmatcherslink.md" >}}