Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
SlideShare a Scribd company logo
Тестирование серверной
конфигурации
Тимур Батыршин
zurdeploy.ru
QA Meetup - Kazan - June 2016
Обо мне
• Основатель ZurDeploy
• 10 лет работаю с Linux
• 5 лет занимаюсь облаками и DevOps
• 5 лет программирую
О вас
Конфигурация и ее
тестирование
20 лет назад
Dev Dev Test User
10 лет назад
Dev
Production
10 лет назад
Dev
Production
Staging
10 лет назад
Dev
Production
Staging
Взаимная любовь
В чем проблема?
Dev Staging Production
В чем проблема?
Dev Staging Production
В чем проблема?
• Версии OS
• Версии пакетов
• Расположение на диске
• Пользователи и права файлов
• Настройки приложения
• Параметры sysctl (открытые файлы и т.п.)
Как решить?
Как решить?
• Инструкции по установке
• “Золотой” образ
• Скрипты установки
• Гибридные варианты
Как решить?
• Инструкции по установке
• “Золотой” образ
• Скрипты установки
• Гибридные варианты
• Уважайте друг друга
Чем тестировать?
https://github.com/aelsabbahy/goss
$ goss autoadd httpd
package:

httpd:

installed: true

versions:

- 2.2.15
service:

http:

enabled: true

running: true
$ goss render | ssh remote-host 'goss validate'
Чем тестировать?
https://github.com/aelsabbahy/goss
user:

sshd:

meta:

sev: 5

exists: true

uid:

and:

gt: 50

lt: 100

home:

or:

- /var/empty/sshd

- /var/run/sshd
package:

kernel:

installed: true

versions:

and:

- have-len: 3

- not:

contain-element: 4.4.0
Чем тестировать?
https://github.com/mizzy/serverspec

https://github.com/chef/inspec
describe package('httpd') do

it { should be_installed }

its(:version) { should eq '2.2.15' }

end
describe service('httpd') do

it { should be_enabled }

it { should be_running }

end

Зачем тестировать?
package 'redis' do

action :install

end
service 'redis' do

action :enable

end
describe package('redis') do

it { should be_installed }

end
describe service('redis') do

it { should be_enabled }

end

Вот зачем
control 'redis01' do

describe package('redis') do

it { should be_installed }

end
describe service('redis') do

it { should be_enabled }

end
describe command(

'redis-cli config get bind') do

its('stdout') {

should match /^192.168./

}

end

end
Вот зачем
control 'redis-sysctl' do
title 'Redis requires vm.overcommit_memory = 1 for BGSAVE'

tag 'production'

impact 0.8
ref 'Redis FAQ', url: 'http://redis.io/topics/
faq#background-saving-is-failing-with-a-fork-error-under-
linux-even-if-i39ve-a-lot-of-free-ram'

ref 'Redis Admin Guide', url: 'http://redis.io/topics/admin'
describe kernel_parameter('vm.overcommit_memory') do

its(:value) { should eq 1 }

end
end
Тестирование
• Ручных конфигураций
• Реального состояния (запущен ли сервис?
применились ли параметры?)
• Сложной логики
Политики
control 'os-03' do

impact 1.0

title 'Check owner and permissions for /etc/passwd'

desc 'Check periodically the owner and permissions for /etc/passwd'

describe file('/etc/passwd') do

it { should exist }

it { should be_file }

it { should be_owned_by 'root' }

its('group') { should eq 'root' }

it { should_not be_executable }

it { should be_writable.by('owner') }

it { should_not be_writable.by('group') }

it { should_not be_writable.by('other') }

it { should be_readable.by('owner') }

it { should be_readable.by('group') }

it { should be_readable.by('other') }

end

end
https://github.com/dev-sec/tests-os-hardening
Политики
control 'package-01' do

impact 1.0

title 'Do not run deprecated inetd or xinetd'

desc 'http://www.nsa.gov/ia/_files/os/redhat/rhel5-guide-
i731.pdf, Chapter 3.2.1’
describe package('inetd') do

it { should_not be_installed }

end
describe package('xinetd') do

it { should_not be_installed }

end

end
https://github.com/dev-sec/tests-os-hardening
Политики
control 'nginx-04' do

impact 1.0

title 'Check for multiple instances'

desc 'Different instances of the nginx webserver should
run in separate environments'
describe command('ps aux | egrep "nginx: master" | egrep -
v "grep" | wc -l') do

its(:stdout) { should match(/^1$/) }

end

end
https://github.com/dev-sec/tests-nginx-hardening
Итоги
• Тесты как инструмент коммуникации
• Компенсируем сложность
• Ловим ошибки людей
Спасибо!
Напишите мне:
erthad@gmail.com
@erthad

More Related Content

Тестирование серверной конфигурации