diff --git a/pillar.example b/pillar.example index 5986bba..966a743 100644 --- a/pillar.example +++ b/pillar.example @@ -4,6 +4,8 @@ sudoers: # By default the main sudoers file is managed by this formula (False to skip) manage_main_config: true + # By default the included directory is not purged from unwanted files + purge_includedir: false users: johndoe: - 'ALL=(ALL) ALL' diff --git a/sudoers/defaults.yaml b/sudoers/defaults.yaml index 6115c5b..09224b0 100644 --- a/sudoers/defaults.yaml +++ b/sudoers/defaults.yaml @@ -4,6 +4,7 @@ sudoers: pkg: sudo manage_main_config: true + purge_includedir: false configpath: /etc group: root execprefix: /usr/sbin diff --git a/sudoers/included.sls b/sudoers/included.sls index 1b6490c..34c3ab4 100644 --- a/sudoers/included.sls +++ b/sudoers/included.sls @@ -9,6 +9,13 @@ include: - sudoers +{{ sudoers.includedir }}: + file.directory: + - user: root + - group: {{ sudoers.group }} + - mode: 440 + - clean: {{ sudoers.purge_includedir }} + {% set included_files = sudoers.included_files %} {% for included_file, spec in included_files.items() -%} sudoers include {{ included_file }}: diff --git a/test/integration/default/files/_mapdata/amazonlinux-1.yaml b/test/integration/default/files/_mapdata/amazonlinux-1.yaml index edef984..9575548 100644 --- a/test/integration/default/files/_mapdata/amazonlinux-1.yaml +++ b/test/integration/default/files/_mapdata/amazonlinux-1.yaml @@ -61,6 +61,7 @@ sudoers: sysadmins: - ALL=(ALL) ALL pkg: sudo + purge_includedir: false users: johndoe: - ALL=(ALL) ALL diff --git a/test/integration/default/files/_mapdata/amazonlinux-2.yaml b/test/integration/default/files/_mapdata/amazonlinux-2.yaml index 5852272..61b0f1a 100644 --- a/test/integration/default/files/_mapdata/amazonlinux-2.yaml +++ b/test/integration/default/files/_mapdata/amazonlinux-2.yaml @@ -61,6 +61,7 @@ sudoers: sysadmins: - ALL=(ALL) ALL pkg: sudo + purge_includedir: false users: johndoe: - ALL=(ALL) ALL diff --git a/test/integration/default/files/_mapdata/arch-base-latest.yaml b/test/integration/default/files/_mapdata/arch-base-latest.yaml index 035e66a..66d0d5f 100644 --- a/test/integration/default/files/_mapdata/arch-base-latest.yaml +++ b/test/integration/default/files/_mapdata/arch-base-latest.yaml @@ -61,6 +61,7 @@ sudoers: sysadmins: - ALL=(ALL) ALL pkg: sudo + purge_includedir: false users: johndoe: - ALL=(ALL) ALL diff --git a/test/integration/default/files/_mapdata/centos-6.yaml b/test/integration/default/files/_mapdata/centos-6.yaml index 24115e8..b690c79 100644 --- a/test/integration/default/files/_mapdata/centos-6.yaml +++ b/test/integration/default/files/_mapdata/centos-6.yaml @@ -61,6 +61,7 @@ sudoers: sysadmins: - ALL=(ALL) ALL pkg: sudo + purge_includedir: false users: johndoe: - ALL=(ALL) ALL diff --git a/test/integration/default/files/_mapdata/centos-7.yaml b/test/integration/default/files/_mapdata/centos-7.yaml index 3ff7930..2bb1c53 100644 --- a/test/integration/default/files/_mapdata/centos-7.yaml +++ b/test/integration/default/files/_mapdata/centos-7.yaml @@ -61,6 +61,7 @@ sudoers: sysadmins: - ALL=(ALL) ALL pkg: sudo + purge_includedir: false users: johndoe: - ALL=(ALL) ALL diff --git a/test/integration/default/files/_mapdata/centos-8.yaml b/test/integration/default/files/_mapdata/centos-8.yaml index e3e1d7e..bac8e20 100644 --- a/test/integration/default/files/_mapdata/centos-8.yaml +++ b/test/integration/default/files/_mapdata/centos-8.yaml @@ -61,6 +61,7 @@ sudoers: sysadmins: - ALL=(ALL) ALL pkg: sudo + purge_includedir: false users: johndoe: - ALL=(ALL) ALL diff --git a/test/integration/default/files/_mapdata/debian-10.yaml b/test/integration/default/files/_mapdata/debian-10.yaml index a20a280..0492b71 100644 --- a/test/integration/default/files/_mapdata/debian-10.yaml +++ b/test/integration/default/files/_mapdata/debian-10.yaml @@ -61,6 +61,7 @@ sudoers: sysadmins: - ALL=(ALL) ALL pkg: sudo + purge_includedir: false users: johndoe: - ALL=(ALL) ALL diff --git a/test/integration/default/files/_mapdata/debian-9.yaml b/test/integration/default/files/_mapdata/debian-9.yaml index 0eb7db2..2931695 100644 --- a/test/integration/default/files/_mapdata/debian-9.yaml +++ b/test/integration/default/files/_mapdata/debian-9.yaml @@ -61,6 +61,7 @@ sudoers: sysadmins: - ALL=(ALL) ALL pkg: sudo + purge_includedir: false users: johndoe: - ALL=(ALL) ALL diff --git a/test/integration/default/files/_mapdata/fedora-31.yaml b/test/integration/default/files/_mapdata/fedora-31.yaml index 22fb5b5..d9ee555 100644 --- a/test/integration/default/files/_mapdata/fedora-31.yaml +++ b/test/integration/default/files/_mapdata/fedora-31.yaml @@ -61,6 +61,7 @@ sudoers: sysadmins: - ALL=(ALL) ALL pkg: sudo + purge_includedir: false users: johndoe: - ALL=(ALL) ALL diff --git a/test/integration/default/files/_mapdata/fedora-32.yaml b/test/integration/default/files/_mapdata/fedora-32.yaml index 04d31e3..c07e8ec 100644 --- a/test/integration/default/files/_mapdata/fedora-32.yaml +++ b/test/integration/default/files/_mapdata/fedora-32.yaml @@ -61,6 +61,7 @@ sudoers: sysadmins: - ALL=(ALL) ALL pkg: sudo + purge_includedir: false users: johndoe: - ALL=(ALL) ALL diff --git a/test/integration/default/files/_mapdata/opensuse-15.yaml b/test/integration/default/files/_mapdata/opensuse-15.yaml index f2cbe4f..5a757b5 100644 --- a/test/integration/default/files/_mapdata/opensuse-15.yaml +++ b/test/integration/default/files/_mapdata/opensuse-15.yaml @@ -61,6 +61,7 @@ sudoers: sysadmins: - ALL=(ALL) ALL pkg: sudo + purge_includedir: false users: johndoe: - ALL=(ALL) ALL diff --git a/test/integration/default/files/_mapdata/ubuntu-16.yaml b/test/integration/default/files/_mapdata/ubuntu-16.yaml index 53e020c..fbf96f4 100644 --- a/test/integration/default/files/_mapdata/ubuntu-16.yaml +++ b/test/integration/default/files/_mapdata/ubuntu-16.yaml @@ -61,6 +61,7 @@ sudoers: sysadmins: - ALL=(ALL) ALL pkg: sudo + purge_includedir: false users: johndoe: - ALL=(ALL) ALL diff --git a/test/integration/default/files/_mapdata/ubuntu-18.yaml b/test/integration/default/files/_mapdata/ubuntu-18.yaml index ddc1737..a514554 100644 --- a/test/integration/default/files/_mapdata/ubuntu-18.yaml +++ b/test/integration/default/files/_mapdata/ubuntu-18.yaml @@ -61,6 +61,7 @@ sudoers: sysadmins: - ALL=(ALL) ALL pkg: sudo + purge_includedir: false users: johndoe: - ALL=(ALL) ALL diff --git a/test/integration/default/files/_mapdata/ubuntu-20.yaml b/test/integration/default/files/_mapdata/ubuntu-20.yaml index aad863a..76f85c0 100644 --- a/test/integration/default/files/_mapdata/ubuntu-20.yaml +++ b/test/integration/default/files/_mapdata/ubuntu-20.yaml @@ -61,6 +61,7 @@ sudoers: sysadmins: - ALL=(ALL) ALL pkg: sudo + purge_includedir: false users: johndoe: - ALL=(ALL) ALL diff --git a/test/integration/share/libraries/system.rb b/test/integration/share/libraries/system.rb index 3c6304c..220493e 100644 --- a/test/integration/share/libraries/system.rb +++ b/test/integration/share/libraries/system.rb @@ -4,47 +4,18 @@ # Author: Daniel Dehennin # Copyright (C) 2020 Daniel Dehennin -HOSTNAME_CMDS = %w[hostname hostnamectl].freeze -HOSTNAME_CMDS_OPT = { - 'hostname' => '-s', - 'hostnamectl' => '--static' -}.freeze - class SystemResource < Inspec.resource(1) name 'system' attr_reader :platform - attr_reader :hostname def initialize + super @platform = build_platform - @hostname = found_hostname end private - def found_hostname - cmd = guess_hostname_cmd - - unless cmd.exit_status.zero? - raise Inspec::Exceptions::ResourceSkipped, - "Error running '#{cmd}': #{cmd.stderr}" - end - - cmd.stdout.chomp - end - - def guess_hostname_cmd - HOSTNAME_CMDS.each do |cmd| - if inspec.command(cmd).exist? - return inspec.command("#{cmd} #{HOSTNAME_CMDS_OPT[cmd]}") - end - end - - raise Inspec::Exceptions::ResourceSkipped, - "Error: #{@platform[:finger]}} has none of #{HOSTNAME_CMDS.join(', ')}" - end - def build_platform { family: build_platform_family, @@ -79,11 +50,22 @@ class SystemResource < Inspec.resource(1) inspec.platform[:release].gsub(/2018.*/, '1') when 'arch' 'base-latest' + when 'gentoo' + "#{inspec.platform[:release].split('.')[0]}-#{derive_gentoo_init_system}" else inspec.platform[:release] end end + def derive_gentoo_init_system + case inspec.command('systemctl').exist? + when true + 'sysd' + else + 'sysv' + end + end + def build_platform_finger "#{build_platform_name}-#{build_finger_release}" end