├── .foodcritic ├── templates └── default │ ├── ssh_key.erb │ └── dist-ossec-keys.sh.erb ├── test ├── fixtures │ └── data_bags │ │ └── ossec │ │ └── ssh.json └── integration │ └── server │ └── default_spec.rb ├── Berksfile ├── spec ├── spec_helper.rb └── unit │ └── recipes │ ├── agent_spec.rb │ ├── client_spec.rb │ ├── server_spec.rb │ └── default_spec.rb ├── Gemfile ├── TESTING.md ├── .gitignore ├── CHANGELOG.md ├── metadata.rb ├── recipes ├── agent.rb ├── default.rb ├── install_server.rb ├── install_agent.rb ├── repository.rb ├── client.rb ├── server.rb └── common.rb ├── .kitchen.yml ├── Rakefile ├── .travis.yml ├── chefignore ├── libraries └── helpers.rb ├── .kitchen.docker.yml ├── attributes └── default.rb ├── README.md └── LICENSE /.foodcritic: -------------------------------------------------------------------------------- 1 | ~FC003 2 | -------------------------------------------------------------------------------- /templates/default/ssh_key.erb: -------------------------------------------------------------------------------- 1 | <%= @key %> 2 | -------------------------------------------------------------------------------- /test/fixtures/data_bags/ossec/ssh.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "ssh", 3 | "pubkey": "pubkey", 4 | "privkey": "privkey" 5 | } 6 | -------------------------------------------------------------------------------- /Berksfile: -------------------------------------------------------------------------------- 1 | source 'https://supermarket.chef.io' 2 | 3 | metadata 4 | 5 | group :integration do 6 | cookbook 'yum' 7 | cookbook 'apt' 8 | end 9 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | require 'chefspec' 2 | require 'chefspec/berkshelf' 3 | 4 | RSpec.configure do |config| 5 | config.color = true # Use color in STDOUT 6 | config.formatter = :documentation # Use the specified formatter 7 | end 8 | 9 | at_exit { ChefSpec::Coverage.report! } 10 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gem 'berkshelf', '~> 4.3' 4 | gem 'chefspec', '~> 4.6' 5 | gem 'cookstyle' 6 | gem 'foodcritic', '~> 6.2' 7 | gem 'kitchen-dokken' 8 | gem 'kitchen-inspec', '~> 0.12' 9 | gem 'kitchen-vagrant', '~> 0.20' 10 | gem 'rake' 11 | gem 'stove' 12 | gem 'test-kitchen', '~> 1.9' 13 | gem 'tomlrb' 14 | -------------------------------------------------------------------------------- /test/integration/server/default_spec.rb: -------------------------------------------------------------------------------- 1 | service_name = case os[:family] 2 | when 'ubuntu', 'debian' 3 | 'ossec' 4 | else 5 | 'ossec-hids' 6 | end 7 | 8 | describe service(service_name) do 9 | it { should be_enabled } 10 | # it { should be_running } # can't be enabled due to status command returning 1 11 | end 12 | -------------------------------------------------------------------------------- /templates/default/dist-ossec-keys.sh.erb: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | 4 | for host in <%= @ssh_hosts.join(' ') %> 5 | do 6 | key=`mktemp` 7 | grep $host <%= node['ossec']['dir'] %>/etc/client.keys > $key 8 | scp -i <%= node['ossec']['dir'] %>/.ssh/id_rsa -B -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no $key ossec@$host:<%= node['ossec']['dir'] %>/etc/client.keys >/dev/null 2>/dev/null 9 | rm $key 10 | done 11 | -------------------------------------------------------------------------------- /TESTING.md: -------------------------------------------------------------------------------- 1 | This cookbook includes support for running tests via Test Kitchen. This has some requirements. 2 | 3 | 1. You must be using the Git repository, rather than the downloaded cookbook from the Supermarket Site. 4 | 2. You must have Vagrant installed. 5 | 3. You must have a "sane" Ruby 1.9.3+ environment. 6 | 7 | Once the above requirements are met, install the additional requirements: 8 | 9 | Install test kitchen and other testing bems via bundler 10 | bundle install 11 | 12 | Once the above are installed, you should be able to run Test Kitchen: 13 | 14 | kitchen list 15 | kitchen test 16 | -------------------------------------------------------------------------------- /spec/unit/recipes/agent_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | require 'json' 3 | 4 | describe 'ossec::agent' do 5 | let(:data_bags_path) { File.expand_path('../../../../test/fixtures/data_bags', __FILE__) } 6 | let(:data_bag_ossec_ssh) { JSON.parse(File.read("#{data_bags_path}/ossec/ssh.json")) } 7 | 8 | cached(:chef_run) do 9 | ChefSpec::ServerRunner.new do |_node, server| 10 | server.create_data_bag('ossec', 'ssh' => data_bag_ossec_ssh) 11 | end.converge('ossec::agent') 12 | end 13 | 14 | it 'includes ossec::client recipe' do 15 | expect(chef_run).to include_recipe('ossec::client') 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.rbc 2 | .config 3 | coverage 4 | InstalledFiles 5 | lib/bundler/man 6 | pkg 7 | rdoc 8 | spec/reports 9 | test/tmp 10 | test/version_tmp 11 | tmp 12 | _Store 13 | *~ 14 | *# 15 | .#* 16 | \#*# 17 | .*.sw[a-z] 18 | *.un~ 19 | *.tmp 20 | *.bk 21 | *.bkup 22 | 23 | # ruby/bundler files 24 | .ruby-version 25 | .ruby-gemset 26 | .rvmrc 27 | Gemfile.lock 28 | .bundle 29 | *.gem 30 | 31 | # YARD artifacts 32 | .yardoc 33 | _yardoc 34 | doc/ 35 | .idea 36 | 37 | #chef stuff 38 | Berksfile.lock 39 | .kitchen 40 | .kitchen.local.yml 41 | vendor/ 42 | .coverage/ 43 | .zero-knife.rb 44 | 45 | #vagrant stuff 46 | .vagrant/ 47 | .vagrant.d/ 48 | .kitchen/ 49 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # v1.0.5 2 | 3 | ## Bug 4 | 5 | - Avoid node.save to prevent incomplete attribute collections 6 | - `dist-ossec-keys.sh` should be sorted for idempotency 7 | 8 | ## Improvement 9 | 10 | - Ability to disable ossec configuration template 11 | - Support for encrypted databags 12 | - Support for environment-scoped searches 13 | - Support for multiple email_to addresses 14 | 15 | # v1.0.4 16 | 17 | ## Bug 18 | 19 | - [COOK-2740]: Use FQDN for a client name 20 | 21 | ## Improvement 22 | 23 | - [COOK-2739]: Upgrade OSSEC to version 2.7 24 | 25 | # v1.0.2: 26 | 27 | - [COOK-1394] - update ossec to version 2.6 28 | 29 | # v1.0.0: 30 | 31 | - Initial/current release 32 | -------------------------------------------------------------------------------- /metadata.rb: -------------------------------------------------------------------------------- 1 | name 'ossec' 2 | maintainer 'Joshua Timberman' 3 | maintainer_email 'cookbooks@housepub.org' 4 | license 'Apache 2.0' 5 | description 'Installs and configures ossec' 6 | long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) 7 | version '1.2.8' 8 | 9 | %w( apt yum-atomic ).each do |pkg| 10 | depends pkg 11 | end 12 | 13 | %w( debian ubuntu redhat centos fedora scientific oracle amazon ).each do |os| 14 | supports os 15 | end 16 | 17 | source_url 'https://github.com/jtimberman/ossec-cookbook' if respond_to?(:source_url) 18 | issues_url 'https://github.com/jtimberman/ossec-cookbook/issues' if respond_to?(:issues_url) 19 | -------------------------------------------------------------------------------- /recipes/agent.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook Name:: ossec 3 | # Recipe:: agent 4 | # 5 | # Copyright 2010-2016, Chef Software, Inc. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | include_recipe 'ossec::client' 21 | -------------------------------------------------------------------------------- /recipes/default.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook Name:: ossec 3 | # Recipe:: default 4 | # 5 | # Copyright 2010-2016, Chef Software, Inc. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | include_recipe 'ossec::install_server' 21 | include_recipe 'ossec::common' 22 | -------------------------------------------------------------------------------- /.kitchen.yml: -------------------------------------------------------------------------------- 1 | driver: 2 | name: vagrant 3 | 4 | provisioner: 5 | name: chef_zero 6 | 7 | verifier: 8 | name: inspec 9 | format: doc 10 | 11 | platforms: 12 | - name: centos-5.11 13 | - name: centos-6.7 14 | - name: centos-7.2 15 | - name: debian-7.10 16 | run_list: apt::default 17 | - name: debian-8.4 18 | run_list: apt::default 19 | - name: fedora-23 20 | run_list: yum::dnf_yum_compat 21 | - name: ubuntu-12.04 22 | run_list: apt::default 23 | - name: ubuntu-14.04 24 | run_list: apt::default 25 | - name: ubuntu-16.04 26 | run_list: apt::default 27 | 28 | suites: 29 | - name: client 30 | run_list: 31 | - recipe[ossec::client] 32 | data_bags_path: 'test/fixtures/data_bags' 33 | - name: server 34 | run_list: 35 | - recipe[ossec::server] 36 | data_bags_path: 'test/fixtures/data_bags' 37 | -------------------------------------------------------------------------------- /recipes/install_server.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook Name:: ossec 3 | # Recipe:: install_server 4 | # 5 | # Copyright 2015-2016, Chef Software, Inc. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | include_recipe 'ossec::repository' 21 | 22 | package 'ossec' do 23 | package_name value_for_platform_family('debian' => 'ossec-hids', 'default' => 'ossec-hids-server') 24 | end 25 | -------------------------------------------------------------------------------- /recipes/install_agent.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook Name:: ossec 3 | # Recipe:: install_agent 4 | # 5 | # Copyright 2015-2016, Chef Software, Inc. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | include_recipe 'ossec::repository' 21 | 22 | package 'ossec' do 23 | package_name value_for_platform_family('debian' => 'ossec-hids-agent', 'default' => 'ossec-hids-client') 24 | end 25 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'rspec/core/rake_task' 2 | require 'cookstyle' 3 | require 'rubocop/rake_task' 4 | require 'foodcritic' 5 | require 'kitchen' 6 | 7 | # Style tests. Rubocop and Foodcritic 8 | namespace :style do 9 | desc 'Run Ruby style checks' 10 | RuboCop::RakeTask.new(:ruby) 11 | 12 | desc 'Run Chef style checks' 13 | FoodCritic::Rake::LintTask.new(:chef) do |t| 14 | t.options = { 15 | fail_tags: ['any'] 16 | } 17 | end 18 | end 19 | 20 | desc 'Run all style checks' 21 | task style: ['style:chef', 'style:ruby'] 22 | 23 | # Rspec and ChefSpec 24 | desc 'Run ChefSpec examples' 25 | RSpec::Core::RakeTask.new(:spec) 26 | 27 | # Integration tests. Kitchen.ci 28 | namespace :integration do 29 | desc 'Run Test Kitchen with Vagrant' 30 | task :vagrant do 31 | Kitchen.logger = Kitchen.default_file_logger 32 | Kitchen::Config.new.instances.each do |instance| 33 | instance.test(:always) 34 | end 35 | end 36 | end 37 | 38 | desc 'Run all tests on Travis' 39 | task travis: ['style', 'spec', 'integration:cloud'] 40 | 41 | # Default 42 | task default: %w(style spec) 43 | -------------------------------------------------------------------------------- /recipes/repository.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook Name:: ossec 3 | # Recipe:: repository 4 | # 5 | # Copyright 2015-2016, Chef Software, Inc. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | case node['platform_family'] 21 | when 'fedora', 'rhel' 22 | include_recipe 'yum-atomic' 23 | when 'debian' 24 | package 'lsb-release' 25 | 26 | ohai 'reload lsb' do 27 | plugin 'lsb' 28 | action :nothing 29 | subscribes :reload, 'package[lsb-release]', :immediately 30 | end 31 | 32 | apt_repository 'ossec' do 33 | uri 'http://ossec.wazuh.com/repos/apt/' + node['platform'] 34 | key 'http://ossec.wazuh.com/repos/apt/conf/ossec-key.gpg.key' 35 | distribution lazy { node['lsb']['codename'] } 36 | components ['main'] 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: required 2 | dist: trusty 3 | 4 | # install the pre-release chef-dk. Use chef-stable-precise to install the stable release 5 | addons: 6 | apt: 7 | sources: 8 | - chef-current-precise 9 | packages: 10 | - chefdk 11 | 12 | branches: 13 | only: 14 | - master 15 | 16 | services: docker 17 | 18 | env: 19 | matrix: 20 | - INSTANCE=default-ubuntu-1204 21 | - INSTANCE=default-ubuntu-1404 22 | - INSTANCE=default-ubuntu-1604 23 | - INSTANCE=default-centos-6 24 | - INSTANCE=default-centos-7 25 | - INSTANCE=default-debian-7 26 | - INSTANCE=default-debian-8 27 | 28 | fast_finish: true 29 | 30 | before_script: 31 | - sudo iptables -L DOCKER || ( echo "DOCKER iptables chain missing" ; sudo iptables -N DOCKER ) 32 | - eval "$(/opt/chefdk/bin/chef shell-init bash)" 33 | - /opt/chefdk/embedded/bin/chef gem install kitchen-dokken 34 | 35 | script: 36 | - /opt/chefdk/embedded/bin/chef --version 37 | - /opt/chefdk/embedded/bin/cookstyle --version 38 | - /opt/chefdk/embedded/bin/cookstyle 39 | - /opt/chefdk/embedded/bin/foodcritic --version 40 | - /opt/chefdk/embedded/bin/foodcritic . --exclude spec -f any 41 | - /opt/chefdk/embedded/bin/rspec 42 | - KITCHEN_LOCAL_YAML=.kitchen.docker.yml /opt/chefdk/embedded/bin/kitchen verify ${INSTANCE} 43 | -------------------------------------------------------------------------------- /chefignore: -------------------------------------------------------------------------------- 1 | # Put files/directories that should be ignored in this file when uploading 2 | # to a chef-server or supermarket. 3 | # Lines that start with '# ' are comments. 4 | 5 | # OS generated files # 6 | ###################### 7 | .DS_Store 8 | Icon? 9 | nohup.out 10 | ehthumbs.db 11 | Thumbs.db 12 | 13 | # SASS # 14 | ######## 15 | .sass-cache 16 | 17 | # EDITORS # 18 | ########### 19 | \#* 20 | .#* 21 | *~ 22 | *.sw[a-z] 23 | *.bak 24 | REVISION 25 | TAGS* 26 | tmtags 27 | *_flymake.* 28 | *_flymake 29 | *.tmproj 30 | .project 31 | .settings 32 | mkmf.log 33 | 34 | ## COMPILED ## 35 | ############## 36 | a.out 37 | *.o 38 | *.pyc 39 | *.so 40 | *.com 41 | *.class 42 | *.dll 43 | *.exe 44 | */rdoc/ 45 | 46 | # Testing # 47 | ########### 48 | .watchr 49 | .rspec 50 | spec/* 51 | spec/fixtures/* 52 | test/* 53 | features/* 54 | examples/* 55 | Guardfile 56 | Procfile 57 | .kitchen* 58 | .rubocop.yml 59 | spec/* 60 | Rakefile 61 | .travis.yml 62 | .foodcritic 63 | .codeclimate.yml 64 | 65 | # SCM # 66 | ####### 67 | .git 68 | */.git 69 | .gitignore 70 | .gitmodules 71 | .gitconfig 72 | .gitattributes 73 | .svn 74 | */.bzr/* 75 | */.hg/* 76 | */.svn/* 77 | 78 | # Berkshelf # 79 | ############# 80 | Berksfile 81 | Berksfile.lock 82 | cookbooks/* 83 | tmp 84 | 85 | # Cookbooks # 86 | ############# 87 | CONTRIBUTING* 88 | CHANGELOG* 89 | TESTING* 90 | MAINTAINERS.toml 91 | 92 | # Strainer # 93 | ############ 94 | Colanderfile 95 | Strainerfile 96 | .colander 97 | .strainer 98 | 99 | # Vagrant # 100 | ########### 101 | .vagrant 102 | Vagrantfile 103 | -------------------------------------------------------------------------------- /spec/unit/recipes/client_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | require 'json' 3 | 4 | describe 'ossec::client' do 5 | let(:data_bags_path) { File.expand_path('../../../../test/fixtures/data_bags', __FILE__) } 6 | let(:data_bag_ossec_ssh) { JSON.parse(File.read("#{data_bags_path}/ossec/ssh.json")) } 7 | 8 | cached(:chef_run) do 9 | ChefSpec::ServerRunner.new do |_node, server| 10 | server.create_data_bag('ossec', 'ssh' => data_bag_ossec_ssh) 11 | end.converge('ossec::client') 12 | end 13 | 14 | it 'includes ossec::client recipe' do 15 | expect(chef_run).to include_recipe('ossec') 16 | end 17 | 18 | it 'creates ossecd user' do 19 | expect(chef_run).to create_user('ossecd').with( 20 | comment: 'OSSEC Distributor', 21 | shell: '/bin/bash', 22 | system: true, 23 | gid: 'ossec', 24 | home: chef_run.node['ossec']['user']['dir'] 25 | ) 26 | end 27 | 28 | it 'creates ossecd user .ssh directory' do 29 | expect(chef_run).to create_directory("#{chef_run.node['ossec']['user']['dir']}/.ssh").with( 30 | owner: 'ossecd', 31 | group: 'ossec', 32 | mode: 0750 33 | ) 34 | end 35 | 36 | it 'creates ossec user authorized_keys template' do 37 | expect(chef_run).to create_template("#{chef_run.node['ossec']['user']['dir']}/.ssh/authorized_keys").with( 38 | source: 'ssh_key.erb', 39 | owner: 'ossecd', 40 | group: 'ossec', 41 | mode: 0600 42 | ) 43 | end 44 | 45 | it 'creates ossec user /etc/client.keys file' do 46 | expect(chef_run).to create_file("#{chef_run.node['ossec']['user']['dir']}/etc/client.keys").with( 47 | owner: 'ossecd', 48 | group: 'ossec', 49 | mode: 0660 50 | ) 51 | end 52 | end 53 | -------------------------------------------------------------------------------- /spec/unit/recipes/server_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | require 'json' 3 | 4 | describe 'ossec::server' do 5 | let(:data_bags_path) { File.expand_path('../../../../test/fixtures/data_bags', __FILE__) } 6 | let(:data_bag_ossec_ssh) { JSON.parse(File.read("#{data_bags_path}/ossec/ssh.json")) } 7 | 8 | cached(:chef_run) do 9 | www_node = stub_node(platform: 'ubuntu', version: '14.04') do |node| 10 | node.set['ipaddress'] = '33.33.33.33' 11 | node.set['fqdn'] = 'chefspec_client.local' 12 | end 13 | 14 | ChefSpec::ServerRunner.new do |_node, server| 15 | server.create_node(www_node, run_list: ['ossec']) 16 | server.create_data_bag('ossec', 'ssh' => data_bag_ossec_ssh) 17 | end.converge('ossec::server') 18 | end 19 | 20 | before(:each) do 21 | stub_command("grep 'chefspec.local 127.0.0.1' /var/ossec/etc/client.keys").and_return(true) 22 | stub_command("grep 'fauxhai.local 10.0.0.2' /var/ossec/etc/client.keys").and_return(true) 23 | end 24 | 25 | it 'includes ossec::client recipe' do 26 | expect(chef_run).to include_recipe('ossec') 27 | end 28 | 29 | it 'creates /usr/local/bin/dist-ossec-keys.sh template' do 30 | expect(chef_run).to create_template('/usr/local/bin/dist-ossec-keys.sh').with( 31 | source: 'dist-ossec-keys.sh.erb', 32 | owner: 'root', 33 | group: 'root', 34 | mode: 0755 35 | ) 36 | end 37 | 38 | it 'creates ossec user .ssh directory' do 39 | expect(chef_run).to create_directory("#{chef_run.node['ossec']['user']['dir']}/.ssh").with( 40 | owner: 'root', 41 | group: 'ossec', 42 | mode: 0750 43 | ) 44 | end 45 | 46 | it 'creates ossec ssh id_rsa key template' do 47 | expect(chef_run).to create_template("#{chef_run.node['ossec']['user']['dir']}/.ssh/id_rsa").with( 48 | source: 'ssh_key.erb', 49 | owner: 'root', 50 | group: 'ossec', 51 | mode: 0600 52 | ) 53 | end 54 | end 55 | -------------------------------------------------------------------------------- /libraries/helpers.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook Name:: ossec 3 | # Library:: helpers 4 | # 5 | # Copyright 2015-2016, Chef Software, Inc. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | class Chef 21 | module OSSEC 22 | module Helpers 23 | # Gyoku looks for a symbol called :content! but Chef attributes 24 | # are always stringified. We can't just call symbolize_keys 25 | # because we need to recurse through the hash structure. Doing 26 | # this also gives us the opportunity to convert true/false to 27 | # yes/no, which is handy. 28 | def self.object_to_ossec(object) 29 | case object 30 | when Hash 31 | object.keys.each do |k| 32 | if k == 'content!' 33 | object[:content!] = object_to_ossec(object.delete(k)) 34 | else 35 | object[k] = object_to_ossec(object[k]) 36 | end 37 | end 38 | object 39 | when Array 40 | object.map! do |e| 41 | object_to_ossec(e) 42 | end 43 | when TrueClass 44 | 'yes' 45 | when FalseClass 46 | 'no' 47 | when NilClass 48 | '' 49 | else 50 | object 51 | end 52 | end 53 | 54 | def self.ossec_to_xml(hash) 55 | require 'gyoku' 56 | Gyoku.xml object_to_ossec(hash) 57 | end 58 | end 59 | end 60 | end 61 | -------------------------------------------------------------------------------- /recipes/client.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook Name:: ossec 3 | # Recipe:: client 4 | # 5 | # Copyright 2010-2016, Chef Software, Inc. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | ossec_server = [] 21 | 22 | search_string = "role:#{node['ossec']['server_role']}" 23 | search_string << " AND chef_environment:#{node['ossec']['server_env']}" if node['ossec']['server_env'] 24 | 25 | if node.run_list.roles.include?(node['ossec']['server_role']) 26 | ossec_server << node['ipaddress'] 27 | else 28 | search(:node, search_string) do |n| 29 | ossec_server << n['ipaddress'] 30 | end 31 | end 32 | 33 | node.set['ossec']['agent_server_ip'] = ossec_server.first 34 | 35 | include_recipe 'ossec::install_agent' 36 | 37 | dbag_name = node['ossec']['data_bag']['name'] 38 | dbag_item = node['ossec']['data_bag']['ssh'] 39 | ossec_key = if node['ossec']['data_bag']['encrypted'] 40 | Chef::EncryptedDataBagItem.load(dbag_name, dbag_item) 41 | else 42 | data_bag_item(dbag_name, dbag_item) 43 | end 44 | 45 | directory "#{node['ossec']['dir']}/.ssh" do 46 | owner 'ossec' 47 | group 'ossec' 48 | mode '0750' 49 | end 50 | 51 | template "#{node['ossec']['dir']}/.ssh/authorized_keys" do 52 | source 'ssh_key.erb' 53 | owner 'ossec' 54 | group 'ossec' 55 | mode '0600' 56 | variables(key: ossec_key['pubkey']) 57 | end 58 | 59 | file "#{node['ossec']['dir']}/etc/client.keys" do 60 | owner 'ossec' 61 | group 'ossec' 62 | mode '0660' 63 | end 64 | 65 | include_recipe 'ossec::common' 66 | -------------------------------------------------------------------------------- /recipes/server.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook Name:: ossec 3 | # Recipe:: server 4 | # 5 | # Copyright 2010-2016, Chef Software, Inc. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | include_recipe 'ossec::install_server' 21 | 22 | ssh_hosts = [] 23 | 24 | search_string = 'ossec:[* TO *]' 25 | search_string << " AND chef_environment:#{node['ossec']['server_env']}" if node['ossec']['server_env'] 26 | search_string << " AND NOT (role:#{node['ossec']['server_role']} OR fqdn:#{node['fqdn']})" 27 | 28 | search(:node, search_string) do |n| 29 | ssh_hosts << n['ipaddress'] if n['keys'] 30 | 31 | execute "#{node['ossec']['agent_manager']} -a --ip #{n['ipaddress']} -n #{n['fqdn'][0..31]}" do 32 | not_if "grep '#{n['fqdn'][0..31]} #{n['ipaddress']}' #{node['ossec']['dir']}/etc/client.keys" 33 | end 34 | end 35 | 36 | template '/usr/local/bin/dist-ossec-keys.sh' do 37 | source 'dist-ossec-keys.sh.erb' 38 | owner 'root' 39 | group 'root' 40 | mode 0755 41 | variables(ssh_hosts: ssh_hosts.sort) 42 | not_if { ssh_hosts.empty? } 43 | end 44 | 45 | dbag_name = node['ossec']['data_bag']['name'] 46 | dbag_item = node['ossec']['data_bag']['ssh'] 47 | ossec_key = if node['ossec']['data_bag']['encrypted'] 48 | Chef::EncryptedDataBagItem.load(dbag_name, dbag_item) 49 | else 50 | data_bag_item(dbag_name, dbag_item) 51 | end 52 | 53 | directory "#{node['ossec']['dir']}/.ssh" do 54 | owner 'root' 55 | group 'ossec' 56 | mode '0750' 57 | end 58 | 59 | template "#{node['ossec']['dir']}/.ssh/id_rsa" do 60 | source 'ssh_key.erb' 61 | owner 'root' 62 | group 'ossec' 63 | mode '0600' 64 | variables(key: ossec_key['privkey']) 65 | end 66 | 67 | include_recipe 'ossec::common' 68 | 69 | cron 'distribute-ossec-keys' do 70 | minute '0' 71 | command '/usr/local/bin/dist-ossec-keys.sh' 72 | only_if { ::File.exist?("#{node['ossec']['dir']}/etc/client.keys") } 73 | end 74 | -------------------------------------------------------------------------------- /.kitchen.docker.yml: -------------------------------------------------------------------------------- 1 | driver: 2 | name: dokken 3 | chef_version: latest 4 | privileged: true # because Docker and SystemD/Upstart 5 | 6 | transport: 7 | name: dokken 8 | 9 | provisioner: 10 | name: dokken 11 | 12 | verifier: 13 | name: inspec 14 | format: doc 15 | 16 | platforms: 17 | - name: debian-7 18 | driver: 19 | image: debian:7 20 | pid_one_command: /sbin/init 21 | intermediate_instructions: 22 | - RUN /usr/bin/apt-get update 23 | - RUN /usr/bin/apt-get install lsb-release -y 24 | 25 | - name: debian-8 26 | driver: 27 | image: debian:8 28 | pid_one_command: /bin/systemd 29 | intermediate_instructions: 30 | - RUN /usr/bin/apt-get update 31 | - RUN /usr/bin/apt-get install lsb-release -y 32 | 33 | - name: centos-5 34 | driver: 35 | image: centos:5 36 | platform: rhel 37 | pid_one_command: /sbin/init 38 | intermediate_instructions: 39 | - RUN yum install -y which initscripts 40 | 41 | - name: centos-6 42 | driver: 43 | image: centos:6 44 | platform: rhel 45 | pid_one_command: /sbin/init 46 | intermediate_instructions: 47 | - RUN yum -y install which initscripts 48 | 49 | - name: centos-7 50 | driver: 51 | image: centos:7 52 | platform: rhel 53 | pid_one_command: /usr/lib/systemd/systemd 54 | intermediate_instructions: 55 | - RUN yum -y install lsof which 56 | 57 | - name: fedora-23 58 | driver: 59 | image: fedora:23 60 | pid_one_command: /usr/lib/systemd/systemd 61 | intermediate_instructions: 62 | - RUN dnf -y install yum which 63 | 64 | - name: ubuntu-12.04 65 | driver: 66 | image: ubuntu-upstart:12.04 67 | pid_one_command: /sbin/init 68 | intermediate_instructions: 69 | - RUN /usr/bin/apt-get update 70 | 71 | - name: ubuntu-14.04 72 | driver: 73 | image: ubuntu-upstart:14.04 74 | pid_one_command: /sbin/init 75 | intermediate_instructions: 76 | - RUN /usr/bin/apt-get update 77 | 78 | - name: ubuntu-16.04 79 | driver: 80 | image: ubuntu:16.04 81 | pid_one_command: /bin/systemd 82 | intermediate_instructions: 83 | - RUN /usr/bin/apt-get update 84 | 85 | - name: opensuse-13.2 86 | driver: 87 | image: opensuse:13.2 88 | pid_one_command: /bin/systemd 89 | 90 | suites: 91 | - name: client 92 | run_list: 93 | - recipe[ossec::client] 94 | data_bags_path: 'test/fixtures/data_bags' 95 | - name: server 96 | run_list: 97 | - recipe[ossec::server] 98 | data_bags_path: 'test/fixtures/data_bags' 99 | -------------------------------------------------------------------------------- /spec/unit/recipes/default_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe 'ossec::default' do 4 | cached(:chef_run) { ChefSpec::ServerRunner.new.converge('ossec::default') } 5 | let(:ossec_dir) { "ossec-hids-#{chef_run.node['ossec']['version']}" } 6 | 7 | it 'includes build-essential recipe' do 8 | expect(chef_run).to include_recipe('build-essential') 9 | end 10 | 11 | it 'creates ossec remote_file' do 12 | expect(chef_run).to create_remote_file("#{Chef::Config[:file_cache_path]}/#{ossec_dir}.tar.gz").with( 13 | source: chef_run.node['ossec']['url'], 14 | checksum: chef_run.node['ossec']['checksum'] 15 | ) 16 | end 17 | 18 | it 'executes untar on ossec tar.gz file' do 19 | expect(chef_run).to run_execute("tar zxvf #{ossec_dir}.tar.gz").with( 20 | cwd: Chef::Config[:file_cache_path], 21 | creates: "#{Chef::Config[:file_cache_path]}/#{ossec_dir}" 22 | ) 23 | end 24 | 25 | it 'creates preloaded-vars.conf template' do 26 | expect(chef_run).to create_template("#{Chef::Config[:file_cache_path]}/#{ossec_dir}/etc/preloaded-vars.conf").with( 27 | source: 'preloaded-vars.conf.erb' 28 | ) 29 | end 30 | 31 | it 'runs bash install-ossec' do 32 | expect(chef_run).to run_bash('install-ossec') 33 | end 34 | 35 | it 'creates ossec-batch-manager.pl template' do 36 | expect(chef_run).to create_template("#{chef_run.node['ossec']['user']['dir']}/bin/ossec-batch-manager.pl").with( 37 | source: "#{Chef::Config[:file_cache_path]}/#{ossec_dir}/contrib/ossec-batch-manager.pl", 38 | local: true, 39 | owner: 'root', 40 | group: 'ossec', 41 | mode: 0755 42 | ) 43 | end 44 | 45 | it 'creates ossec.conf template' do 46 | expect(chef_run).to create_template("#{chef_run.node['ossec']['user']['dir']}/etc/ossec.conf").with( 47 | source: 'ossec.conf.erb', 48 | owner: 'root', 49 | group: 'ossec', 50 | mode: 0440 51 | ) 52 | end 53 | 54 | it 'enables ossec service' do 55 | expect(chef_run).to enable_service('ossec') 56 | end 57 | 58 | it 'starts ossec service' do 59 | expect(chef_run).to start_service('ossec') 60 | end 61 | 62 | context 'Arch Linux platform' do 63 | let(:chef_run_arch) do 64 | ChefSpec::ServerRunner.new(platform: 'arch', version: '3.10.5-1-ARCH').converge('ossec::default') 65 | end 66 | 67 | it 'creates ossec.service template' do 68 | expect(chef_run_arch).to create_template('/usr/lib/systemd/system/ossec.service') 69 | end 70 | end 71 | end 72 | -------------------------------------------------------------------------------- /attributes/default.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook Name:: ossec 3 | # Attributes:: default 4 | # 5 | # Copyright 2010-2016, Chef Software, Inc. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | # general settings 21 | default['ossec']['dir'] = '/var/ossec' 22 | default['ossec']['server_role'] = 'ossec_server' 23 | default['ossec']['server_env'] = nil 24 | default['ossec']['agent_server_ip'] = nil 25 | 26 | # data bag configuration 27 | default['ossec']['data_bag']['encrypted'] = false 28 | default['ossec']['data_bag']['name'] = 'ossec' 29 | default['ossec']['data_bag']['ssh'] = 'ssh' 30 | 31 | # ossec-batch-manager.pl location varies 32 | default['ossec']['agent_manager'] = value_for_platform_family( 33 | %w( rhel fedora suse ) => '/usr/share/ossec/contrib/ossec-batch-manager.pl', 34 | 'default' => "#{node['ossec']['dir']}/contrib/ossec-batch-manager.pl" 35 | ) 36 | 37 | # The following attributes are mapped to XML for ossec.conf using 38 | # Gyoku. See the README for details on how this works. 39 | 40 | default['ossec']['conf']['all']['syscheck']['frequency'] = 21_600 41 | default['ossec']['conf']['all']['rootcheck']['disabled'] = false 42 | default['ossec']['conf']['all']['rootcheck']['rootkit_files'] = "#{node['ossec']['dir']}/etc/shared/rootkit_files.txt" 43 | default['ossec']['conf']['all']['rootcheck']['rootkit_trojans'] = "#{node['ossec']['dir']}/etc/shared/rootkit_trojans.txt" 44 | 45 | %w( local server ).each do |type| 46 | default['ossec']['conf'][type]['global']['email_notification'] = false 47 | default['ossec']['conf'][type]['global']['email_from'] = "ossecm@#{node['fqdn']}" 48 | default['ossec']['conf'][type]['global']['email_to'] = 'ossec@example.com' 49 | default['ossec']['conf'][type]['global']['smtp_server'] = '127.0.0.1' 50 | 51 | default['ossec']['conf'][type]['alerts']['email_alert_level'] = 7 52 | default['ossec']['conf'][type]['alerts']['log_alert_level'] = 1 53 | default['ossec']['conf'][type]['alerts']['use_geoip'] = false unless platform_family?('debian') 54 | end 55 | 56 | default['ossec']['conf']['server']['remote']['connection'] = 'secure' 57 | default['ossec']['conf']['agent']['client']['server-ip'] = node['ossec']['agent_server_ip'] 58 | 59 | # agent.conf is also populated with Gyoku but in a slightly different 60 | # way. We leave this blank by default because Chef is better at 61 | # distributing agent configuration than OSSEC is. 62 | default['ossec']['agent_conf'] = [] 63 | -------------------------------------------------------------------------------- /recipes/common.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook Name:: ossec 3 | # Recipe:: common 4 | # 5 | # Copyright 2010-2016, Chef Software, Inc. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | ruby_block 'ossec install_type' do # ~FC014 21 | block do 22 | if node['recipes'].include?('ossec::default') 23 | type = 'local' 24 | else 25 | type = nil 26 | 27 | File.open('/etc/ossec-init.conf') do |file| 28 | file.each_line do |line| 29 | if line =~ /^TYPE="([^"]+)"/ 30 | type = Regexp.last_match(1) 31 | break 32 | end 33 | end 34 | end 35 | end 36 | 37 | node.set['ossec']['install_type'] = type 38 | end 39 | end 40 | 41 | # # Gyoku renders the XML. 42 | # chef_gem 'gyoku' do 43 | # compile_time false if respond_to?(:compile_time) 44 | # end 45 | # 46 | # file "#{node['ossec']['dir']}/etc/ossec.conf" do 47 | # owner 'root' 48 | # group 'ossec' 49 | # mode '0440' 50 | # manage_symlink_source true 51 | # notifies :restart, 'service[ossec]' 52 | # 53 | # content lazy { 54 | # # Merge the "typed" attributes over the "all" attributes. 55 | # all_conf = node['ossec']['conf']['all'].to_hash 56 | # type_conf = node['ossec']['conf'][node['ossec']['install_type']].to_hash 57 | # conf = Chef::Mixin::DeepMerge.deep_merge(type_conf, all_conf) 58 | # Chef::OSSEC::Helpers.ossec_to_xml('ossec_config' => conf) 59 | # } 60 | # end 61 | # 62 | # file "#{node['ossec']['dir']}/etc/shared/agent.conf" do 63 | # owner 'root' 64 | # group 'ossec' 65 | # mode '0440' 66 | # notifies :restart, 'service[ossec]' 67 | # 68 | # # Even if agent.cont is not appropriate for this kind of 69 | # # installation, we need to create an empty file instead of deleting 70 | # # for two reasons. Firstly, install_type is set at converge time 71 | # # while action can't be lazy. Secondly, a subsequent package update 72 | # # would just replace the file. 73 | # action :create 74 | # 75 | # content lazy { 76 | # if node['ossec']['install_type'] == 'server' 77 | # conf = node['ossec']['agent_conf'].to_a 78 | # Chef::OSSEC::Helpers.ossec_to_xml('agent_config' => conf) 79 | # else 80 | # '' 81 | # end 82 | # } 83 | # end 84 | 85 | # Both the RPM and DEB packages enable and start the service 86 | # immediately after installation, which isn't helpful. An empty 87 | # client.keys file will cause a server not to listen and an agent to 88 | # abort immediately. Explicitly stopping the service here after 89 | # installation allows Chef to start it when client.keys has content. 90 | service 'stop ossec' do # ~FC037 91 | service_name platform_family?('debian') ? 'ossec' : 'ossec-hids' 92 | action :nothing 93 | 94 | %w( disable stop ).each do |action| 95 | subscribes action, 'package[ossec]', :immediately 96 | end 97 | end 98 | 99 | service 'ossec' do 100 | service_name platform_family?('debian') ? 'ossec' : 'ossec-hids' 101 | supports status: true, restart: true 102 | action [:enable, :start] 103 | 104 | not_if do 105 | (node['ossec']['install_type'] != 'local' && !File.size?("#{node['ossec']['dir']}/etc/client.keys")) || 106 | (node['ossec']['install_type'] == 'agent' && node['ossec']['agent_server_ip'].nil?) 107 | end 108 | end 109 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ossec cookbook 2 | 3 | [![Cookbook Version](https://img.shields.io/cookbook/v/ossec.svg)](https://supermarket.chef.io/cookbooks/ossec) 4 | 5 | Installs OSSEC from source in a server-agent installation. See: 6 | 7 | 8 | 9 | ## Requirements 10 | 11 | ### Platforms 12 | 13 | - Ubuntu / Debian 14 | - RHEL and derivatives 15 | - Fedora 16 | 17 | ### Chef 18 | 19 | - Chef 11+ 20 | 21 | ### Cookbooks 22 | 23 | - apt 24 | - yum-atomic 25 | 26 | ## Attributes 27 | 28 | - `node['ossec']['dir']` - Installation directory for OSSEC, default `/var/ossec`. All existing packages use this directory so you should not change this. 29 | - `node['ossec']['server_role']` - When using server/agent setup, this role is used to search for the OSSEC server, default `ossec_server`. 30 | - `node['ossec']['server_env']` - When using server/agent setup, this value will scope the role search to the specified environment, default nil. 31 | - `node['ossec']['agent_server_ip']` - The IP of the OSSEC server. The client recipe will attempt to determine this value via search. Default is nil, only required for agent installations. 32 | - `node['ossec']['data_bag']['encrypted']` - Boolean value which indicates whether or not the OSSEC data bag is encrypted 33 | - `node['ossec']['data_bag']['name']` - The name of the data bag to use 34 | - `node['ossec']['data_bag']['ssh']` - The name of the data bag item which contains the OSSEC keys 35 | 36 | ### ossec.conf 37 | 38 | OSSEC's configuration is mainly read from an XML file called `ossec.conf`. You can directly control the contents of this file using node attributes under `node['ossec']['conf']`. These attributes are mapped to XML using Gyoku. See the [Gyoku site](https://github.com/savonrb/gyoku) for details on how this works. 39 | 40 | Chef applies attributes from all attribute files regardless of which recipes were executed. In order to make wrapper cookbooks easier to write, `node['ossec']['conf']` is divided into the three installation types mentioned below, `local`, `server`, and `agent`. You can also set attributes under `all` to apply settings across all installation types. The typed attributes are automatically deep merged over the `all` attributes in the normal Chef manner. 41 | 42 | `true` and `false` values are automatically mapped to `"yes"` and `"no"` as OSSEC expects the latter. 43 | 44 | `ossec.conf` makes little use of XML attributes so you can generally construct nested hashes in the usual fashion. Where an attribute is required, you can do it like this: 45 | 46 | ``` 47 | default['ossec']['conf']['all']['syscheck']['directories'] = [ 48 | { '@check_all' => true, 'content!' => '/bin,/sbin' }, 49 | '/etc,/usr/bin,/usr/sbin' 50 | ] 51 | ``` 52 | 53 | This produces: 54 | 55 | ``` 56 | 57 | /bin,/sbin 58 | /etc,/usr/bin,/usr/sbin 59 | 60 | ``` 61 | 62 | The default values are based on those given in the OSSEC manual. They do not include any specific rules, checks, outputs, or alerts as everyone has different requirements. 63 | 64 | ### agent.conf 65 | 66 | OSSEC servers can also distribute configuration to agents through the centrally managed XM file called `agent.conf`. Since Chef is better at distributing configuration than OSSEC is, the cookbook leaves this file blank by default. Should you want to populate it, it is done in a similar manner to the above. Since this file is only used on servers, you can define the attributes directly under `node['ossec']['agent_conf']`. Unlike conventional XML files, `agent.conf` has multiple root nodes so `node['ossec']['agent_conf']` must be treated as an array like so. 67 | 68 | ```ruby 69 | default['ossec']['agent_conf'] = [ 70 | { 71 | 'syscheck' => { 'frequency' => 4321 }, 72 | 'rootcheck' => { 'disabled' => true } 73 | }, 74 | { 75 | '@os' => 'Windows', 76 | 'content!' => { 77 | 'syscheck' => { 'frequency' => 1234 } 78 | } 79 | } 80 | ] 81 | ``` 82 | 83 | This produces: 84 | 85 | ``` 86 | 87 | 88 | 4321 89 | 90 | 91 | yes 92 | 93 | 94 | 95 | 96 | 97 | 1234 98 | 99 | 100 | ``` 101 | 102 | ## Recipes 103 | 104 | ### repository 105 | 106 | Adds the OSSEC repository to the package manager. This recipe is included by others and should not be used directly. For highly customised setups, you should use `ossec::install_agent` or `ossec::install_server` instead. 107 | 108 | ### install_agent 109 | 110 | Installs the agent packages but performs no explicit configuation. 111 | 112 | ### install_server 113 | 114 | Install the server packages but performs no explicit configuation. 115 | 116 | ### common 117 | 118 | Puts the configuration file in place and starts the (agent or server) service. This recipe is included by other recipes and generally should not be used directly. 119 | 120 | Note that the service will not be started if the client.keys file is missing or empty. For agents, this results in an error. For servers, this prevents ossec-remoted from starting, resulting in agents being unable to connect. Once client.keys does exist with content, simply perform another chef-client run to start the service. 121 | 122 | ### default 123 | 124 | Runs `ossec::install_server` and then configures for local-only use. Do not mix this recipe with the others below. 125 | 126 | ### agent 127 | 128 | OSSEC uses the term `agent` instead of client. The agent recipe includes the `ossec::client` recipe. 129 | 130 | ### client 131 | 132 | Configures the system as an OSSEC agent to the OSSEC server. This recipe will search for the server based on `node['ossec']['server_role']`. It will also set the `agent_server_ip` attribute. The ossec user will have an SSH key created so the server can distribute the agent key. 133 | 134 | ### server 135 | 136 | Sets up a system to be an OSSEC server. This recipe will search for all nodes that have an `ossec` attribute and add them as an agent. 137 | 138 | To manage additional agents on the server that don't run chef, or for agentless OSSEC configuration (for example, routers), add a new node for them and create the `node['ossec']['agentless']` attribute as true. For example if we have a router named gw01.example.com with the IP `192.168.100.1`: 139 | 140 | ``` 141 | % knife node create gw01.example.com 142 | { 143 | "name": "gw01.example.com", 144 | "json_class": "Chef::Node", 145 | "automatic": { 146 | }, 147 | "normal": { 148 | "hostname": "gw01", 149 | "fqdn": "gw01.example.com", 150 | "ipaddress": "192.168.100.1", 151 | "ossec": { 152 | "agentless": true 153 | } 154 | }, 155 | "chef_type": "node", 156 | "default": { 157 | }, 158 | "override": { 159 | }, 160 | "run_list": [ 161 | ] 162 | } 163 | ``` 164 | 165 | Enable agentless monitoring in OSSEC and register the hosts on the server. Automated configuration of agentless nodes is not yet supported by this cookbook. For more information on the commands and configuration directives required in `ossec.conf`, see the [OSSEC Documentation](http://www.ossec.net/doc/manual/agent/agentless-monitoring.html) 166 | 167 | ## Usage 168 | 169 | The cookbook can be used to install OSSEC in one of the three types: 170 | 171 | - local - use the ossec::default recipe. 172 | - server - use the ossec::server recipe. 173 | - agent - use the ossec::client recipe 174 | 175 | For local-only installations, add just `recipe[ossec]` to the node run list, or put it in a role (like a base role). 176 | 177 | ### Server/Agent 178 | 179 | This section describes how to use the cookbook for server/agent configurations. 180 | 181 | The server will use SSH to distribute the OSSEC agent keys. Create a data bag `ossec`, with an item `ssh`. It should have the following structure: 182 | 183 | ``` 184 | { 185 | "id": "ssh", 186 | "pubkey": "", 187 | "privkey": "" 188 | } 189 | ``` 190 | 191 | Generate an ssh keypair and get the privkey and pubkey values. The output of the two ruby commands should be used as the privkey and pubkey values respectively in the data bag. 192 | 193 | ``` 194 | ssh-keygen -t rsa -f /tmp/id_rsa 195 | ruby -e 'puts IO.read("/tmp/id_rsa")' 196 | ruby -e 'puts IO.read("/tmp/id_rsa.pub")' 197 | ``` 198 | 199 | For the OSSEC server, create a role, `ossec_server`. Add attributes per above as needed to customize the installation. 200 | 201 | ``` 202 | % cat roles/ossec_server.rb 203 | name "ossec_server" 204 | description "OSSEC Server" 205 | run_list("recipe[ossec::server]") 206 | override_attributes( 207 | "ossec" => { 208 | "conf" => { 209 | "server" => { 210 | "global" => { 211 | "email_to" => "ossec@yourdomain.com", 212 | "smtp_server" => "smtp.yourdomain.com" 213 | } 214 | } 215 | } 216 | } 217 | ) 218 | ``` 219 | 220 | For OSSEC agents, create a role, `ossec_client`. 221 | 222 | ``` 223 | % cat roles/ossec_client.rb 224 | name "ossec_client" 225 | description "OSSEC Client Agents" 226 | run_list("recipe[ossec::client]") 227 | override_attributes( 228 | "ossec" => { 229 | "conf" => { 230 | "agent" => { 231 | "syscheck" => { 232 | "frequency" => 321 233 | } 234 | } 235 | } 236 | } 237 | ) 238 | ``` 239 | 240 | ## Customization 241 | 242 | The main configuration file is maintained by Chef as a template, `ossec.conf.erb`. It should just work on most installations, but can be customized for the local environment. Notably, the rules, ignores and commands may be modified. 243 | 244 | Further reading: 245 | 246 | - [OSSEC Documentation](http://www.ossec.net/doc/index.html) 247 | 248 | ## License and Author 249 | 250 | Copyright 2010-2016, Chef Software, Inc ([legal@chef.io](mailto:legal@chef.io)) 251 | 252 | ``` 253 | Licensed under the Apache License, Version 2.0 (the "License"); 254 | you may not use this file except in compliance with the License. 255 | You may obtain a copy of the License at 256 | 257 | http://www.apache.org/licenses/LICENSE-2.0 258 | 259 | Unless required by applicable law or agreed to in writing, software 260 | distributed under the License is distributed on an "AS IS" BASIS, 261 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 262 | See the License for the specific language governing permissions and 263 | limitations under the License. 264 | ``` 265 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------