File tree Expand file tree Collapse file tree 7 files changed +135
-9
lines changed
Expand file tree Collapse file tree 7 files changed +135
-9
lines changed Original file line number Diff line number Diff line change 1010 describe libvirt_socket_admin do
1111 it { should exist }
1212 its ( 'type' ) { should eq :socket }
13- its ( 'owner' ) { should eq 'root' }
14- its ( 'group' ) { should eq 'root' }
15- its ( 'mode' ) { should cmp '0700' }
13+ its ( 'owner' ) { should eq libvirt_socket_admin . config_owner }
14+ its ( 'group' ) { should eq libvirt_socket_admin . config_group }
15+ its ( 'mode' ) { should cmp libvirt_socket_admin . config_mode }
1616 end
1717end
Original file line number Diff line number Diff line change 1010 describe libvirt_socket_ro do
1111 it { should exist }
1212 its ( 'type' ) { should eq :socket }
13- its ( 'owner' ) { should eq 'root' }
14- its ( 'group' ) { should eq 'root' }
15- its ( 'mode' ) { should cmp '0777' }
13+ its ( 'owner' ) { should eq libvirt_socket_ro . config_owner }
14+ its ( 'group' ) { should eq libvirt_socket_ro . config_group }
15+ its ( 'mode' ) { should cmp libvirt_socket_ro . config_mode }
1616 end
1717end
Original file line number Diff line number Diff line change 1010 describe libvirt_socket_rw do
1111 it { should exist }
1212 its ( 'type' ) { should eq :socket }
13- its ( 'owner' ) { should eq 'root' }
14- its ( 'group' ) { should eq 'root' }
15- its ( 'mode' ) { should cmp '0770' }
13+ its ( 'owner' ) { should eq libvirt_socket_rw . config_owner }
14+ its ( 'group' ) { should eq libvirt_socket_rw . config_group }
15+ its ( 'mode' ) { should cmp libvirt_socket_rw . config_mode }
1616 end
1717end
Original file line number Diff line number Diff line change @@ -15,6 +15,31 @@ class LibvirtSocketAdminResource < Inspec.resource(1)
1515
1616 def initialize
1717 @file = inspec . file ( '/var/run/libvirt/libvirt-admin-sock' )
18+ @systemd_status = inspec . systemd_config ( 'libvirtd-admin.socket' )
19+ end
20+
21+ def config_owner
22+ if @systemd_status . active?
23+ @systemd_status . config ( 'SocketUser' ) || 'root'
24+ else
25+ 'root'
26+ end
27+ end
28+
29+ def config_group
30+ if @systemd_status . active?
31+ @systemd_status . config ( 'SocketGroup' ) || 'root'
32+ else
33+ 'root'
34+ end
35+ end
36+
37+ def config_mode
38+ if @systemd_status . active?
39+ @systemd_status . config ( 'SocketMode' ) || '0666'
40+ else
41+ '0700'
42+ end
1843 end
1944
2045 # We could not inherit from Inspec::Resources::FileResource
Original file line number Diff line number Diff line change @@ -15,6 +15,31 @@ class LibvirtSocketRoResource < Inspec.resource(1)
1515
1616 def initialize
1717 @file = inspec . file ( '/var/run/libvirt/libvirt-sock-ro' )
18+ @systemd_status = inspec . systemd_config ( 'libvirtd-ro.socket' )
19+ end
20+
21+ def config_owner
22+ if @systemd_status . active?
23+ @systemd_status . config ( 'SocketUser' ) || 'root'
24+ else
25+ 'root'
26+ end
27+ end
28+
29+ def config_group
30+ if @systemd_status . active?
31+ @systemd_status . config ( 'SocketGroup' ) || 'root'
32+ else
33+ 'root'
34+ end
35+ end
36+
37+ def config_mode
38+ if @systemd_status . active?
39+ @systemd_status . config ( 'SocketMode' ) || '0666'
40+ else
41+ '0777'
42+ end
1843 end
1944
2045 # We could not inherit from Inspec::Resources::FileResource
Original file line number Diff line number Diff line change @@ -15,6 +15,31 @@ class LibvirtSocketRwResource < Inspec.resource(1)
1515
1616 def initialize
1717 @file = inspec . file ( '/var/run/libvirt/libvirt-sock' )
18+ @systemd_status = inspec . systemd_config ( 'libvirtd.socket' )
19+ end
20+
21+ def config_owner
22+ if @systemd_status . active?
23+ @systemd_status . config ( 'SocketUser' ) || 'root'
24+ else
25+ 'root'
26+ end
27+ end
28+
29+ def config_group
30+ if @systemd_status . active?
31+ @systemd_status . config ( 'SocketGroup' ) || 'root'
32+ else
33+ 'root'
34+ end
35+ end
36+
37+ def config_mode
38+ if @systemd_status . active?
39+ @systemd_status . config ( 'SocketMode' ) || '0666'
40+ else
41+ '0770'
42+ end
1843 end
1944
2045 # We could not inherit from Inspec::Resources::FileResource
Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ # systemd_config.rb -- InSpec resource for systemd service configuration
4+ # Author: Daniel Dehennin <[email protected] > 5+ # Copyright (C) 2020 Daniel Dehennin <[email protected] > 6+
7+ class SystemdConfigResource < Inspec . resource ( 1 )
8+ name 'systemd_config'
9+
10+ supports platform_name : 'debian'
11+ supports platform_name : 'ubuntu'
12+ supports platform_name : 'centos'
13+ supports platform_name : 'fedora'
14+ supports platform_name : 'opensuse'
15+
16+ def initialize ( service_name )
17+ @service_name = service_name
18+ @service_config = read_systemd_show
19+ end
20+
21+ def enabled?
22+ @service_config . send ( 'UnitFileState' ) == 'enabled'
23+ end
24+
25+ def active?
26+ @service_config . send ( 'ActiveState' ) == 'active'
27+ end
28+
29+ def test
30+ @service_config . methods
31+ end
32+
33+ def config ( param )
34+ @service_config . send ( param )
35+ end
36+
37+ def read_systemd_show
38+ cmd_string = "systemctl show #{ @service_name } "
39+ cmd = inspec . command ( cmd_string )
40+
41+ unless cmd . exit_status . zero?
42+ raise Inspec ::Exceptions ::ResourceSkipped ,
43+ "Error running '#{ cmd_string } ': #{ cmd . stderr } "
44+ end
45+
46+ parse_options = {
47+ assignment_regex : /^\s *([^=]*?)\s *=\s *(.*?)\s *$/
48+ }
49+ inspec . parse_config ( cmd . stdout . strip , parse_options )
50+ end
51+ end
You can’t perform that action at this time.
0 commit comments