Ресурс SELinux
Используйте ресурс аудита Chef InSpec, чтобы проверить данные конфигурации политики SELinux, модулей SELinux и булевых переменных SELinux.
Ресурс извлекает и отображает данные, которые предоставляет команда sestatus, semodule -lfull, и semanage boolean -l -n.
Доступность
Установка
Этот ресурс распространяется вместе с самим Chef InSpec. Вы можете использовать его автоматически.
Версия
Этот ресурс впервые стал доступен в версии InSpec v4.35.1.
Синтаксис
Блок ресурса selinux Chef InSpec проверяет состояние и режим политики SELinux.
describe selinux do
it { should be_installed }
it { should_not be_disabled }
it { should be_enforcing }
it { should_not be_permissive }
end
Блок ресурса selinux также позволяет вам создавать тесты для нескольких модулей:
describe selinux.modules.where("zebra") do
it { should exist }
it { should be_installed }
it { should be_enabled }
end
или:
describe selinux.modules.where(status: "installed") do
it { should exist }
its('count') { should cmp 404 }
end
где:
-
.where()указывает параметр и ожидаемое значение. -
name,status,state, иpriority— допустимые параметры.
Блок ресурса selinux также позволяет вам создавать тесты для нескольких булевых переменных:
describe selinux.booleans.where(name: "httpd_enable_homedirs") do
it { should_not be_on }
end
или:
describe selinux.booleans.where(name: "xend_run_blktap", state: "on") do
it { should exist }
its('defaults') { should cmp "on" }
end
-
.where()указывает параметр и ожидаемое значение. -
name,state, иdefault— допустимые параметры дляbooleans.
Примеры
В следующих примерах показано, как использовать этот ресурс Chef InSpec selinux.
Проверка установки и активации SELinux
describe selinux do
it { should be_installed }
it { should_not be_disabled }
end
Проверка активации SELinux и работы в режиме принудительного выполнения
describe selinux do
it { should_not be_disabled }
it { should be_enforcing }
end
Проверка типа политики selinux
describe selinux do
its('policy') { should eq "targeted"}
end
Матчи
Полный список доступных матчей можно найти на нашей странице matchers.
be_installed
Матчер be_installed проверяет, установлена ли политика SElinux или модули SElinux на системе:
it { should be_installed }
be_disabled
Матчер be_disabled проверяет, отключен ли SELinux на системе:
it { should be_disabled }
be_enforcing
Матчер be_enforcing проверяет, установлен ли режим SELinux на принудительное выполнение:
it { should be_enforcing }
be_permissive
Матчер be_permissive проверяет, установлен ли режим SELinux на разрешительный:
it { should be_permissive }
be_on
Матчер be_on проверяет, включена ли булевая переменная SELinux:
it { should be_on }
be_enabled
Матчер be_enabled проверяет, включен ли модуль SElinux:
it { should be_enabled }
Параметры ресурса
-
names,status,states, иpriorities— допустимые параметры для модулей политики SELinux. -
names,status,states, иdefaults— допустимые параметры для булевых переменных SELinux.
Примеры параметров ресурса
modules
modules возвращает информацию о модулях SELinux с помощью команды semodule -lfull.
Примечание: Команда semodule -l не предоставляет информацию о версии для более новых версий систем на основе Linux, таких как RHEL8 и Centos8, поэтому мы не поддерживаем этот вариант.
describe selinux.modules do
its("names") { should include "zebra" }
its("status") { should include "installed" }
its("states") { should include "enabled" }
its("priorities") { should include "100" }
end
booleans
booleans возвращает информацию о булевых переменных SELinux с помощью команды semanage boolean -l -n.
describe selinux.booleans do
its("names") { should include "httpd_enable_homedirs" }
its("states") { should include "on" }
its("states") { should include "off" }
its("defaults") { should include "on" }
its("defaults") { should include "off" }
end
© 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/selinux/