├── .editorconfig ├── .envrc ├── .gitattributes ├── .github ├── CODEOWNERS ├── lock.yml └── workflows │ ├── ci.yml │ └── stale.yml ├── .gitignore ├── .markdownlint-cli2.yaml ├── .mdlrc ├── .overcommit.yml ├── .vscode └── extensions.json ├── .yamllint ├── Berksfile ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── Dangerfile ├── LICENSE ├── README.md ├── TESTING.md ├── attributes ├── authd.rb └── default.rb ├── chefignore ├── documentation └── .gitkeep ├── kitchen.dokken.yml ├── kitchen.exec.yml ├── kitchen.global.yml ├── kitchen.yml ├── libraries └── helpers.rb ├── metadata.rb ├── recipes ├── agent.rb ├── agent_auth.rb ├── authd.rb ├── client.rb ├── common.rb ├── default.rb ├── install_agent.rb ├── install_server.rb ├── repository.rb └── server.rb ├── renovate.json ├── spec ├── spec_helper.rb └── unit │ └── recipes │ ├── agent_spec.rb │ ├── authd_spec.rb │ ├── client_spec.rb │ ├── common_spec.rb │ └── server_spec.rb ├── templates └── default │ ├── dist-ossec-keys.sh.erb │ ├── ossec-authd.service.erb │ └── ssh_key.erb └── test ├── fixtures └── data_bags │ └── ossec │ └── ssh.json └── integration ├── client └── default_spec.rb └── server └── default_spec.rb /.editorconfig: -------------------------------------------------------------------------------- 1 | # https://EditorConfig.org 2 | 3 | # top-most EditorConfig file 4 | root=true 5 | 6 | # Unix-style newlines with a newline ending every file 7 | [*] 8 | end_of_line = lf 9 | insert_final_newline = true 10 | 11 | # 2 space indentation 12 | indent_style = space 13 | indent_size = 2 14 | 15 | # Avoid issues parsing cookbook files later 16 | charset = utf-8 17 | 18 | # Avoid cookstyle warnings 19 | trim_trailing_whitespace = true 20 | -------------------------------------------------------------------------------- /.envrc: -------------------------------------------------------------------------------- 1 | use chefworkstation 2 | export KITCHEN_GLOBAL_YAML=kitchen.global.yml 3 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto eol=lf 2 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @sous-chefs/maintainers 2 | -------------------------------------------------------------------------------- /.github/lock.yml: -------------------------------------------------------------------------------- 1 | --- 2 | daysUntilLock: 365 3 | exemptLabels: [] 4 | lockLabel: false 5 | lockComment: > 6 | This thread has been automatically locked since there has not been 7 | any recent activity after it was closed. Please open a new issue for 8 | related bugs. 9 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: ci 3 | 4 | "on": 5 | pull_request: 6 | push: 7 | branches: 8 | - main 9 | 10 | jobs: 11 | lint-unit: 12 | uses: sous-chefs/.github/.github/workflows/lint-unit.yml@3.0.0 13 | permissions: 14 | actions: write 15 | checks: write 16 | pull-requests: write 17 | statuses: write 18 | issues: write 19 | 20 | integration: 21 | needs: lint-unit 22 | runs-on: ubuntu-latest 23 | strategy: 24 | matrix: 25 | os: 26 | - "almalinux-8" 27 | - "almalinux-9" 28 | - "centos-7" 29 | - "centos-stream-8" 30 | - "centos-stream-9" 31 | - "debian-10" 32 | - "debian-11" 33 | - "rockylinux-8" 34 | - "rockylinux-9" 35 | - "ubuntu-1804" 36 | - "ubuntu-2004" 37 | - "ubuntu-2204" 38 | suite: 39 | - "client" 40 | - "server" 41 | fail-fast: false 42 | 43 | steps: 44 | - name: Check out code 45 | uses: actions/checkout@v4 46 | - name: Install Chef 47 | uses: actionshub/chef-install@3.0.0 48 | - name: Dokken 49 | uses: actionshub/test-kitchen@3.0.0 50 | env: 51 | CHEF_LICENSE: accept-no-persist 52 | KITCHEN_LOCAL_YAML: kitchen.dokken.yml 53 | with: 54 | suite: ${{ matrix.suite }} 55 | os: ${{ matrix.os }} 56 | -------------------------------------------------------------------------------- /.github/workflows/stale.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: Mark stale issues and pull requests 3 | 4 | "on": 5 | schedule: [cron: "0 0 * * *"] 6 | 7 | jobs: 8 | stale: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/stale@v9 12 | with: 13 | repo-token: ${{ secrets.GITHUB_TOKEN }} 14 | close-issue-message: > 15 | Closing due to inactivity. 16 | If this is still an issue please reopen or open another issue. 17 | Alternatively drop by the #sous-chefs channel on the [Chef Community Slack](http://community-slack.chef.io/) and we'll be happy to help! 18 | Thanks, Sous-Chefs. 19 | days-before-close: 7 20 | days-before-stale: 365 21 | stale-issue-message: > 22 | Marking stale due to inactivity. 23 | Remove stale label or comment or this will be closed in 7 days. 24 | Alternatively drop by the #sous-chefs channel on the [Chef Community Slack](http://community-slack.chef.io/) and we'll be happy to help! 25 | Thanks, Sous-Chefs. 26 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.rbc 2 | .config 3 | InstalledFiles 4 | pkg 5 | test/tmp 6 | test/version_tmp 7 | tmp 8 | _Store 9 | *~ 10 | *# 11 | .#* 12 | \#*# 13 | *.un~ 14 | *.tmp 15 | *.bk 16 | *.bkup 17 | 18 | # editor files 19 | .idea 20 | .*.sw[a-z] 21 | 22 | # ruby/bundler/rspec files 23 | .ruby-version 24 | .ruby-gemset 25 | .rvmrc 26 | Gemfile.lock 27 | .bundle 28 | *.gem 29 | coverage 30 | spec/reports 31 | 32 | # YARD / rdoc artifacts 33 | .yardoc 34 | _yardoc 35 | doc/ 36 | rdoc 37 | 38 | # chef infra stuff 39 | Berksfile.lock 40 | .kitchen 41 | kitchen.local.yml 42 | vendor/ 43 | .coverage/ 44 | .zero-knife.rb 45 | Policyfile.lock.json 46 | 47 | # vagrant stuff 48 | .vagrant/ 49 | .vagrant.d/ 50 | -------------------------------------------------------------------------------- /.markdownlint-cli2.yaml: -------------------------------------------------------------------------------- 1 | config: 2 | ul-indent: false # MD007 3 | line-length: false # MD013 4 | no-duplicate-heading: false # MD024 5 | reference-links-images: false # MD052 6 | ignores: 7 | - .github/copilot-instructions.md 8 | -------------------------------------------------------------------------------- /.mdlrc: -------------------------------------------------------------------------------- 1 | rules "~MD013", "~MD024", "~MD033" -------------------------------------------------------------------------------- /.overcommit.yml: -------------------------------------------------------------------------------- 1 | --- 2 | PreCommit: 3 | TrailingWhitespace: 4 | enabled: true 5 | YamlLint: 6 | enabled: true 7 | required_executable: "yamllint" 8 | ChefSpec: 9 | enabled: true 10 | required_executable: "chef" 11 | command: ["chef", "exec", "rspec"] 12 | Cookstyle: 13 | enabled: true 14 | required_executable: "cookstyle" 15 | command: ["cookstyle"] 16 | MarkdownLint: 17 | enabled: false 18 | required_executable: "npx" 19 | command: ["npx", "markdownlint-cli2", "'**/*.md'"] 20 | include: ["**/*.md"] 21 | 22 | CommitMsg: 23 | HardTabs: 24 | enabled: true 25 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "chef-software.chef", 4 | "rebornix.ruby", 5 | "editorconfig.editorconfig", 6 | "DavidAnson.vscode-markdownlint" 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /.yamllint: -------------------------------------------------------------------------------- 1 | --- 2 | extends: default 3 | rules: 4 | line-length: 5 | max: 256 6 | level: warning 7 | document-start: disable 8 | braces: 9 | forbid: false 10 | min-spaces-inside: 0 11 | max-spaces-inside: 1 12 | min-spaces-inside-empty: -1 13 | max-spaces-inside-empty: -1 14 | comments: 15 | min-spaces-from-content: 1 16 | -------------------------------------------------------------------------------- /Berksfile: -------------------------------------------------------------------------------- 1 | source 'https://supermarket.chef.io' 2 | 3 | metadata 4 | 5 | group :integration do 6 | cookbook 'yum' 7 | cookbook 'apt' 8 | end 9 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## Unreleased 4 | 5 | ## 2.0.15 - *2025-01-11* 6 | 7 | ## 2.0.14 - *2024-11-18* 8 | 9 | Standardise files with files in sous-chefs/repo-management 10 | 11 | Standardise files with files in sous-chefs/repo-management 12 | 13 | ## 2.0.13 - *2024-07-15* 14 | 15 | Standardise files with files in sous-chefs/repo-management 16 | 17 | Standardise files with files in sous-chefs/repo-management 18 | 19 | Standardise files with files in sous-chefs/repo-management 20 | 21 | ## 2.0.12 - *2024-05-06* 22 | 23 | ## 2.0.11 - *2023-10-31* 24 | 25 | ## 2.0.10 - *2023-09-04* 26 | 27 | ## 2.0.9 - *2023-05-03* 28 | 29 | ## 2.0.8 - *2023-04-07* 30 | 31 | Standardise files with files in sous-chefs/repo-management 32 | 33 | ## 2.0.7 - *2023-04-01* 34 | 35 | ## 2.0.6 - *2023-04-01* 36 | 37 | ## 2.0.5 - *2023-04-01* 38 | 39 | Standardise files with files in sous-chefs/repo-management 40 | 41 | ## 2.0.4 - *2023-03-20* 42 | 43 | Standardise files with files in sous-chefs/repo-management 44 | 45 | ## 2.0.3 - *2023-03-15* 46 | 47 | Standardise files with files in sous-chefs/repo-management 48 | 49 | ## 2.0.2 - *2023-02-23* 50 | 51 | Standardise files with files in sous-chefs/repo-management 52 | 53 | ## 2.0.1 - *2023-02-14* 54 | 55 | Standardise files with files in sous-chefs/repo-management 56 | 57 | ## 2.0.0 - *2023-01-12* 58 | 59 | - Standardise files with files in sous-chefs/repo-management 60 | - Partially modernize cookbook 61 | - Refactor library helper 62 | - Properly set repositories for various supported platforms 63 | - Cleanup and Fix CI 64 | - Add support to various platforms 65 | - Fix idempotency issues 66 | 67 | ## 1.2.7 - *2022-02-08* 68 | 69 | - Standardise files with files in sous-chefs/repo-management 70 | 71 | ## 1.2.6 - *2022-02-07* 72 | 73 | - Remove delivery folder 74 | - Standardise files with files in sous-chefs/repo-management 75 | 76 | ## 1.2.5 - *2021-09-08* 77 | 78 | - resolved cookstyle error: recipes/authd.rb:25:4 refactor: `Chef/Modernize/UseChefLanguageSystemdHelper` 79 | 80 | ## 1.2.4 - *2021-08-30* 81 | 82 | - Standardise files with files in sous-chefs/repo-management 83 | 84 | ## 1.2.3 - *2021-06-01* 85 | 86 | - resolved cookstyle error: spec/unit/recipes/agent_spec.rb:5:31 convention: `Style/ExpandPathArguments` 87 | - resolved cookstyle error: spec/unit/recipes/client_spec.rb:5:31 convention: `Style/ExpandPathArguments` 88 | - resolved cookstyle error: spec/unit/recipes/server_spec.rb:5:31 convention: `Style/ExpandPathArguments` 89 | 90 | ## 1.2.2 - 2020-05-14 91 | 92 | - resolved cookstyle error: recipes/common.rb:20:35 convention: `Layout/TrailingWhitespace` 93 | - resolved cookstyle error: recipes/common.rb:20:36 refactor: `ChefModernize/FoodcriticComments` 94 | - resolved cookstyle error: recipes/common.rb:90:24 convention: `Layout/TrailingWhitespace` 95 | - resolved cookstyle error: recipes/common.rb:90:25 refactor: `ChefModernize/FoodcriticComments` 96 | 97 | ## 1.2.1 - 2020-05-05 98 | 99 | ### Added 100 | 101 | - Migration to Github Actions 102 | 103 | ### Changed 104 | 105 | - Various Cookstyle and foodcritic fixes 106 | - resolved cookstyle error: libraries/helpers.rb:31:18 convention: `Style/HashEachMethods` 107 | 108 | ### Deprecated 109 | 110 | ### Removed 111 | 112 | ## [1.2.0] - 2019-05-13 113 | 114 | ### Added 115 | 116 | - Add distro based authd service name 117 | 118 | ### Changed 119 | 120 | ### Deprecated 121 | 122 | ### Removed 123 | 124 | ## [1.1.0] - 2018-08-13 125 | 126 | - README Updates: 127 | - Fix broken links 128 | - Add reference to Wazzuh 129 | - General updates to cookbook 130 | - Remove EOL distros 131 | - Update for current supported Chef version (13) 132 | 133 | ## [1.0.5] - 2014-04-15 134 | 135 | - Avoid node.save to prevent incomplete attribute collections 136 | - `dist-ossec-keys.sh` should be sorted for idempotency 137 | - Ability to disable ossec configuration template 138 | - Support for encrypted databags 139 | - Support for environment-scoped searches 140 | - Support for multiple email_to addresses 141 | 142 | ## [1.0.4] - 2013-05-14 143 | 144 | - [COOK-2740]: Use FQDN for a client name 145 | - [COOK-2739]: Upgrade OSSEC to version 2.7 146 | 147 | ## [1.0.2] - 2012-07-01 148 | 149 | - [COOK-1394] - update ossec to version 2.6 150 | 151 | ## 1.0.0 152 | 153 | - Initial/current release 154 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Community Guidelines 2 | 3 | This project follows the Chef Community Guidelines 4 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Please refer to 4 | [https://github.com/chef-cookbooks/community_cookbook_documentation/blob/main/CONTRIBUTING.MD](https://github.com/chef-cookbooks/community_cookbook_documentation/blob/main/CONTRIBUTING.MD) 5 | -------------------------------------------------------------------------------- /Dangerfile: -------------------------------------------------------------------------------- 1 | # Reference: http://danger.systems/reference.html 2 | 3 | # A pull request summary is required. Add a description of the pull request purpose. 4 | # Changelog must be updated for each pull request that changes code. 5 | # Warnings will be issued for: 6 | # Pull request with more than 400 lines of code changed 7 | # Pull reqest that change more than 5 lines without test changes 8 | # Failures will be issued for: 9 | # Pull request without summary 10 | # Pull requests with code changes without changelog entry 11 | 12 | def code_changes? 13 | code = %w(libraries attributes recipes resources files templates) 14 | code.each do |location| 15 | return true unless git.modified_files.grep(/#{location}/).empty? 16 | end 17 | false 18 | end 19 | 20 | def test_changes? 21 | tests = %w(spec test kitchen.yml kitchen.dokken.yml) 22 | tests.each do |location| 23 | return true unless git.modified_files.grep(/#{location}/).empty? 24 | end 25 | false 26 | end 27 | 28 | failure 'Please provide a summary of your Pull Request.' if github.pr_body.length < 10 29 | 30 | warn 'This is a big Pull Request.' if git.lines_of_code > 400 31 | 32 | warn 'This is a Table Flip.' if git.lines_of_code > 2000 33 | 34 | # Require a CHANGELOG entry for non-test changes. 35 | if !git.modified_files.include?('CHANGELOG.md') && code_changes? 36 | failure 'Please include a CHANGELOG entry.' 37 | end 38 | 39 | # Require Major Minor Patch version labels 40 | unless github.pr_labels.grep /minor|major|patch/i 41 | warn 'Please add a release label to this pull request' 42 | end 43 | 44 | # A sanity check for tests. 45 | if git.lines_of_code > 5 && code_changes? && !test_changes? 46 | warn 'This Pull Request is probably missing tests.' 47 | end 48 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ossec cookbook 2 | 3 | [![Cookbook Version](https://img.shields.io/cookbook/v/ossec.svg)](https://supermarket.chef.io/cookbooks/ossec) 4 | [![Build Status](https://img.shields.io/circleci/project/github/sous-chefs/ossec/master.svg)](https://circleci.com/gh/sous-chefs/ossec) 5 | [![OpenCollective](https://opencollective.com/sous-chefs/backers/badge.svg)](#backers) 6 | [![OpenCollective](https://opencollective.com/sous-chefs/sponsors/badge.svg)](#sponsors) 7 | [![License](https://img.shields.io/badge/License-Apache%202.0-green.svg)](https://opensource.org/licenses/Apache-2.0) 8 | 9 | Installs OSSEC from source in a server-agent installation. See: 10 | 11 | [http://www.ossec.net/docs/manual/installation/index.html](http://www.ossec.net/docs/manual/installation/index.html) 12 | 13 | For managing Wazuh, consider using the Wazuh Chef Cookbook here: [https://github.com/wazuh/wazuh-chef](https://github.com/wazuh/wazuh-chef) 14 | 15 | ## Maintainers 16 | 17 | This cookbook is maintained by the Sous Chefs. The Sous Chefs are a community of Chef cookbook maintainers working together to maintain important cookbooks. If you’d like to know more please visit [sous-chefs.org](https://sous-chefs.org/) or come chat with us on the Chef Community Slack in [#sous-chefs](https://chefcommunity.slack.com/messages/C2V7B88SF). 18 | 19 | ## Requirements 20 | 21 | ### Platforms 22 | 23 | - Ubuntu / Debian 24 | - RHEL and derivatives 25 | 26 | ### Chef 27 | 28 | - Chef 16.13+ 29 | 30 | ### Cookbooks 31 | 32 | - yum-atomic 33 | 34 | ## Attributes 35 | 36 | - `node['ossec']['dir']` - Installation directory for OSSEC, default `/var/ossec`. All existing packages use this directory so you should not change this. 37 | - `node['ossec']['server_role']` - When using server/agent setup, this role is used to search for the OSSEC server, default `ossec_server`. 38 | - `node['ossec']['server_env']` - When using server/agent setup, this value will scope the role search to the specified environment, default nil. 39 | - `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. 40 | - `node['ossec']['data_bag']['encrypted']` - Boolean value which indicates whether or not the OSSEC data bag is encrypted 41 | - `node['ossec']['data_bag']['name']` - The name of the data bag to use 42 | - `node['ossec']['data_bag']['ssh']` - The name of the data bag item which contains the OSSEC keys 43 | 44 | ### ossec.conf 45 | 46 | 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. 47 | 48 | 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. 49 | 50 | `true` and `false` values are automatically mapped to `"yes"` and `"no"` as OSSEC expects the latter. 51 | 52 | `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: 53 | 54 | ```ruby 55 | default['ossec']['conf']['all']['syscheck']['directories'] = [ 56 | { '@check_all' => true, 'content!' => '/bin,/sbin' }, 57 | '/etc,/usr/bin,/usr/sbin' 58 | ] 59 | ``` 60 | 61 | This produces: 62 | 63 | ```xml 64 | 65 | /bin,/sbin 66 | /etc,/usr/bin,/usr/sbin 67 | 68 | ``` 69 | 70 | 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. 71 | 72 | ### agent.conf 73 | 74 | 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. 75 | 76 | ```ruby 77 | default['ossec']['agent_conf'] = [ 78 | { 79 | 'syscheck' => { 'frequency' => 4321 }, 80 | 'rootcheck' => { 'disabled' => true } 81 | }, 82 | { 83 | '@os' => 'Windows', 84 | 'content!' => { 85 | 'syscheck' => { 'frequency' => 1234 } 86 | } 87 | } 88 | ] 89 | ``` 90 | 91 | This produces: 92 | 93 | ```xml 94 | 95 | 96 | 4321 97 | 98 | 99 | yes 100 | 101 | 102 | 103 | 104 | 105 | 1234 106 | 107 | 108 | ``` 109 | 110 | ## Recipes 111 | 112 | ### repository 113 | 114 | 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. 115 | 116 | ### install_agent 117 | 118 | Installs the agent packages but performs no explicit configuration. 119 | 120 | ### install_server 121 | 122 | Install the server packages but performs no explicit configuration. 123 | 124 | ### common 125 | 126 | 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. 127 | 128 | 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. 129 | 130 | ### default 131 | 132 | Runs `ossec::install_server` and then configures for local-only use. Do not mix this recipe with the others below. 133 | 134 | ### agent 135 | 136 | OSSEC uses the term `agent` instead of client. The agent recipe includes the `ossec::client` recipe. 137 | 138 | ### client 139 | 140 | 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. 141 | 142 | ### server 143 | 144 | 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. 145 | 146 | 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`: 147 | 148 | ```shell 149 | % knife node create gw01.example.com 150 | { 151 | "name": "gw01.example.com", 152 | "json_class": "Chef::Node", 153 | "automatic": { 154 | }, 155 | "normal": { 156 | "hostname": "gw01", 157 | "fqdn": "gw01.example.com", 158 | "ipaddress": "192.168.100.1", 159 | "ossec": { 160 | "agentless": true 161 | } 162 | }, 163 | "chef_type": "node", 164 | "default": { 165 | }, 166 | "override": { 167 | }, 168 | "run_list": [ 169 | ] 170 | } 171 | ``` 172 | 173 | 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/docs/manual/agent/agentless-monitoring.html) 174 | 175 | ### agent_auth 176 | 177 | If you do not wish to distribute agent keys via SSH then the authd mechanism provides an alternative. Set the `agent_server_ip` attribute manually and this recipe will attempt to register with the given server running ossec-authd. To allow registration with a new server after changing `agent_server_ip`, delete the client.keys file and rerun the recipe. 178 | 179 | ### authd 180 | 181 | For a server to accept agent registrations, it needs to be running ossec-authd. This recipe installs an init script for it (systemd only for now) and will attempt to start it once the mandatory SSL certificate and key have been put in place. From OSSEC 2.9, you can also set a CA certificate to validate agents against. 182 | 183 | ## Usage 184 | 185 | The cookbook can be used to install OSSEC in one of the three types: 186 | 187 | - local - use the ossec::default recipe. 188 | - server - use the ossec::server recipe. 189 | - agent - use the ossec::client recipe 190 | 191 | For local-only installations, add just `recipe[ossec]` to the node run list, or put it in a role (like a base role). 192 | 193 | ### Server/Agent 194 | 195 | This section describes how to use the cookbook for server/agent configurations. 196 | 197 | 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: 198 | 199 | ```shell 200 | { 201 | "id": "ssh", 202 | "pubkey": "", 203 | "privkey": "" 204 | } 205 | ``` 206 | 207 | 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. 208 | 209 | ```shell 210 | ssh-keygen -t rsa -f /tmp/id_rsa 211 | ruby -e 'puts IO.read("/tmp/id_rsa")' 212 | ruby -e 'puts IO.read("/tmp/id_rsa.pub")' 213 | ``` 214 | 215 | For the OSSEC server, create a role, `ossec_server`. Add attributes per above as needed to customize the installation. 216 | 217 | ```shell 218 | % cat roles/ossec_server.rb 219 | name "ossec_server" 220 | description "OSSEC Server" 221 | run_list("recipe[ossec::server]") 222 | override_attributes( 223 | "ossec" => { 224 | "conf" => { 225 | "server" => { 226 | "global" => { 227 | "email_to" => "ossec@yourdomain.com", 228 | "smtp_server" => "smtp.yourdomain.com" 229 | } 230 | } 231 | } 232 | } 233 | ) 234 | ``` 235 | 236 | For OSSEC agents, create a role, `ossec_client`. 237 | 238 | ```shell 239 | % cat roles/ossec_client.rb 240 | name "ossec_client" 241 | description "OSSEC Client Agents" 242 | run_list("recipe[ossec::client]") 243 | override_attributes( 244 | "ossec" => { 245 | "conf" => { 246 | "agent" => { 247 | "syscheck" => { 248 | "frequency" => 321 249 | } 250 | } 251 | } 252 | } 253 | ) 254 | ``` 255 | 256 | ## Customization 257 | 258 | 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. 259 | 260 | Further reading: 261 | 262 | - [OSSEC Documentation](http://www.ossec.net/docs/index.html) 263 | 264 | ## Contributors 265 | 266 | This project exists thanks to all the people who [contribute.](https://opencollective.com/sous-chefs/contributors.svg?width=890&button=false) 267 | 268 | ### Backers 269 | 270 | Thank you to all our backers! 271 | 272 | ![https://opencollective.com/sous-chefs#backers](https://opencollective.com/sous-chefs/backers.svg?width=600&avatarHeight=40) 273 | 274 | ### Sponsors 275 | 276 | Support this project by becoming a sponsor. Your logo will show up here with a link to your website. 277 | 278 | ![https://opencollective.com/sous-chefs/sponsor/0/website](https://opencollective.com/sous-chefs/sponsor/0/avatar.svg?avatarHeight=100) 279 | ![https://opencollective.com/sous-chefs/sponsor/1/website](https://opencollective.com/sous-chefs/sponsor/1/avatar.svg?avatarHeight=100) 280 | ![https://opencollective.com/sous-chefs/sponsor/2/website](https://opencollective.com/sous-chefs/sponsor/2/avatar.svg?avatarHeight=100) 281 | ![https://opencollective.com/sous-chefs/sponsor/3/website](https://opencollective.com/sous-chefs/sponsor/3/avatar.svg?avatarHeight=100) 282 | ![https://opencollective.com/sous-chefs/sponsor/4/website](https://opencollective.com/sous-chefs/sponsor/4/avatar.svg?avatarHeight=100) 283 | ![https://opencollective.com/sous-chefs/sponsor/5/website](https://opencollective.com/sous-chefs/sponsor/5/avatar.svg?avatarHeight=100) 284 | ![https://opencollective.com/sous-chefs/sponsor/6/website](https://opencollective.com/sous-chefs/sponsor/6/avatar.svg?avatarHeight=100) 285 | ![https://opencollective.com/sous-chefs/sponsor/7/website](https://opencollective.com/sous-chefs/sponsor/7/avatar.svg?avatarHeight=100) 286 | ![https://opencollective.com/sous-chefs/sponsor/8/website](https://opencollective.com/sous-chefs/sponsor/8/avatar.svg?avatarHeight=100) 287 | ![https://opencollective.com/sous-chefs/sponsor/9/website](https://opencollective.com/sous-chefs/sponsor/9/avatar.svg?avatarHeight=100) 288 | -------------------------------------------------------------------------------- /TESTING.md: -------------------------------------------------------------------------------- 1 | # Testing 2 | 3 | Please refer to [the community cookbook documentation on testing](https://github.com/chef-cookbooks/community_cookbook_documentation/blob/main/TESTING.MD). 4 | -------------------------------------------------------------------------------- /attributes/authd.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook:: ossec 3 | # Attributes:: authd 4 | # 5 | # Copyright:: 2015-2017, 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 | default['ossec']['authd']['ip_address'] = false 21 | default['ossec']['authd']['port'] = 1515 22 | 23 | default['ossec']['authd']['ca'] = nil 24 | default['ossec']['authd']['certificate'] = "#{node['ossec']['dir']}/etc/sslmanager.cert" 25 | default['ossec']['authd']['key'] = "#{node['ossec']['dir']}/etc/sslmanager.key" 26 | 27 | default['ossec']['agent_auth']['name'] = node['fqdn'] 28 | default['ossec']['agent_auth']['host'] = node['ossec']['agent_server_ip'] 29 | default['ossec']['agent_auth']['port'] = node['ossec']['authd']['port'] 30 | 31 | default['ossec']['agent_auth']['ca'] = nil 32 | default['ossec']['agent_auth']['certificate'] = nil 33 | default['ossec']['agent_auth']['key'] = nil 34 | -------------------------------------------------------------------------------- /attributes/default.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook:: ossec 3 | # Attributes:: default 4 | # 5 | # Copyright:: 2010-2017, 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 amazon ) => '/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 | -------------------------------------------------------------------------------- /chefignore: -------------------------------------------------------------------------------- 1 | # Put files/directories that should be ignored in this file when uploading 2 | # to a Chef Infra Server or Supermarket. 3 | # Lines that start with '# ' are comments. 4 | 5 | # OS generated files # 6 | ###################### 7 | .DS_Store 8 | ehthumbs.db 9 | Icon? 10 | nohup.out 11 | Thumbs.db 12 | .envrc 13 | 14 | # EDITORS # 15 | ########### 16 | .#* 17 | .project 18 | .settings 19 | *_flymake 20 | *_flymake.* 21 | *.bak 22 | *.sw[a-z] 23 | *.tmproj 24 | *~ 25 | \#* 26 | REVISION 27 | TAGS* 28 | tmtags 29 | .vscode 30 | .editorconfig 31 | 32 | ## COMPILED ## 33 | ############## 34 | *.class 35 | *.com 36 | *.dll 37 | *.exe 38 | *.o 39 | *.pyc 40 | *.so 41 | */rdoc/ 42 | a.out 43 | mkmf.log 44 | 45 | # Testing # 46 | ########### 47 | .circleci/* 48 | .codeclimate.yml 49 | .delivery/* 50 | .foodcritic 51 | .kitchen* 52 | .mdlrc 53 | .overcommit.yml 54 | .rspec 55 | .rubocop.yml 56 | .travis.yml 57 | .watchr 58 | .yamllint 59 | azure-pipelines.yml 60 | Dangerfile 61 | examples/* 62 | features/* 63 | Guardfile 64 | kitchen*.yml 65 | mlc_config.json 66 | Procfile 67 | Rakefile 68 | spec/* 69 | test/* 70 | 71 | # SCM # 72 | ####### 73 | .git 74 | .gitattributes 75 | .gitconfig 76 | .github/* 77 | .gitignore 78 | .gitkeep 79 | .gitmodules 80 | .svn 81 | */.bzr/* 82 | */.git 83 | */.hg/* 84 | */.svn/* 85 | 86 | # Berkshelf # 87 | ############# 88 | Berksfile 89 | Berksfile.lock 90 | cookbooks/* 91 | tmp 92 | 93 | # Bundler # 94 | ########### 95 | vendor/* 96 | Gemfile 97 | Gemfile.lock 98 | 99 | # Policyfile # 100 | ############## 101 | Policyfile.rb 102 | Policyfile.lock.json 103 | 104 | # Documentation # 105 | ############# 106 | CODE_OF_CONDUCT* 107 | CONTRIBUTING* 108 | documentation/* 109 | TESTING* 110 | UPGRADING* 111 | 112 | # Vagrant # 113 | ########### 114 | .vagrant 115 | Vagrantfile 116 | -------------------------------------------------------------------------------- /documentation/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sous-chefs/ossec/46bba8fd5b5a9a2e3ccfe9044545b238df32f769/documentation/.gitkeep -------------------------------------------------------------------------------- /kitchen.dokken.yml: -------------------------------------------------------------------------------- 1 | driver: 2 | name: dokken 3 | privileged: true 4 | chef_version: <%= ENV['CHEF_VERSION'] || 'current' %> 5 | 6 | transport: { name: dokken } 7 | provisioner: { name: dokken } 8 | 9 | platforms: 10 | - name: almalinux-8 11 | driver: 12 | image: dokken/almalinux-8 13 | pid_one_command: /usr/lib/systemd/systemd 14 | 15 | - name: almalinux-9 16 | driver: 17 | image: dokken/almalinux-9 18 | pid_one_command: /usr/lib/systemd/systemd 19 | 20 | - name: almalinux-10 21 | driver: 22 | image: dokken/almalinux-10 23 | pid_one_command: /usr/lib/systemd/systemd 24 | 25 | - name: amazonlinux-2023 26 | driver: 27 | image: dokken/amazonlinux-2023 28 | pid_one_command: /usr/lib/systemd/systemd 29 | 30 | - name: centos-stream-9 31 | driver: 32 | image: dokken/centos-stream-9 33 | pid_one_command: /usr/lib/systemd/systemd 34 | 35 | - name: centos-stream-10 36 | driver: 37 | image: dokken/centos-stream-10 38 | pid_one_command: /usr/lib/systemd/systemd 39 | 40 | - name: debian-11 41 | driver: 42 | image: dokken/debian-11 43 | pid_one_command: /bin/systemd 44 | 45 | - name: debian-12 46 | driver: 47 | image: dokken/debian-12 48 | pid_one_command: /bin/systemd 49 | 50 | - name: fedora-latest 51 | driver: 52 | image: dokken/fedora-latest 53 | pid_one_command: /usr/lib/systemd/systemd 54 | 55 | - name: opensuse-leap-15 56 | driver: 57 | image: dokken/opensuse-leap-15 58 | pid_one_command: /usr/lib/systemd/systemd 59 | 60 | - name: oraclelinux-8 61 | driver: 62 | image: dokken/oraclelinux-8 63 | pid_one_command: /usr/lib/systemd/systemd 64 | 65 | - name: oraclelinux-9 66 | driver: 67 | image: dokken/oraclelinux-9 68 | pid_one_command: /usr/lib/systemd/systemd 69 | 70 | - name: rockylinux-8 71 | driver: 72 | image: dokken/rockylinux-8 73 | pid_one_command: /usr/lib/systemd/systemd 74 | 75 | - name: rockylinux-9 76 | driver: 77 | image: dokken/rockylinux-9 78 | pid_one_command: /usr/lib/systemd/systemd 79 | 80 | - name: ubuntu-20.04 81 | driver: 82 | image: dokken/ubuntu-20.04 83 | pid_one_command: /bin/systemd 84 | 85 | - name: ubuntu-22.04 86 | driver: 87 | image: dokken/ubuntu-22.04 88 | pid_one_command: /bin/systemd 89 | 90 | - name: ubuntu-24.04 91 | driver: 92 | image: dokken/ubuntu-24.04 93 | pid_one_command: /bin/systemd 94 | -------------------------------------------------------------------------------- /kitchen.exec.yml: -------------------------------------------------------------------------------- 1 | --- 2 | driver: { name: exec } 3 | transport: { name: exec } 4 | 5 | platforms: 6 | - name: macos-latest 7 | - name: windows-latest 8 | -------------------------------------------------------------------------------- /kitchen.global.yml: -------------------------------------------------------------------------------- 1 | --- 2 | provisioner: 3 | name: chef_infra 4 | product_name: chef 5 | product_version: <%= ENV['CHEF_VERSION'] || 'latest' %> 6 | channel: stable 7 | install_strategy: once 8 | chef_license: accept 9 | enforce_idempotency: <%= ENV['ENFORCE_IDEMPOTENCY'] || true %> 10 | multiple_converge: <%= ENV['MULTIPLE_CONVERGE'] || 2 %> 11 | deprecations_as_errors: true 12 | log_level: <%= ENV['CHEF_LOG_LEVEL'] || 'auto' %> 13 | 14 | verifier: 15 | name: inspec 16 | 17 | platforms: 18 | - name: almalinux-8 19 | - name: almalinux-9 20 | - name: amazonlinux-2023 21 | - name: centos-stream-9 22 | - name: debian-11 23 | - name: debian-12 24 | - name: fedora-latest 25 | - name: opensuse-leap-15 26 | - name: oraclelinux-8 27 | - name: oraclelinux-9 28 | - name: rockylinux-8 29 | - name: rockylinux-9 30 | - name: ubuntu-20.04 31 | - name: ubuntu-22.04 32 | - name: ubuntu-24.04 33 | -------------------------------------------------------------------------------- /kitchen.yml: -------------------------------------------------------------------------------- 1 | --- 2 | driver: 3 | name: vagrant 4 | 5 | provisioner: 6 | name: chef_infra 7 | product_name: chef 8 | enforce_idempotency: true 9 | multiple_converge: 2 10 | deprecations_as_errors: true 11 | data_bags_path: test/fixtures/data_bags 12 | 13 | verifier: 14 | name: inspec 15 | 16 | platforms: 17 | - name: almalinux-8 18 | - name: almalinux-9 19 | - name: centos-7 20 | - name: centos-stream-8 21 | - name: centos-stream-9 22 | - name: debian-10 23 | - name: debian-11 24 | - name: rockylinux-8 25 | - name: rockylinux-9 26 | - name: ubuntu-18.04 27 | - name: ubuntu-20.04 28 | - name: ubuntu-22.04 29 | 30 | suites: 31 | - name: client 32 | run_list: 33 | - recipe[ossec::client] 34 | data_bags_path: 'test/fixtures/data_bags' 35 | - name: server 36 | run_list: 37 | - recipe[ossec::server] 38 | data_bags_path: 'test/fixtures/data_bags' 39 | -------------------------------------------------------------------------------- /libraries/helpers.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook:: ossec 3 | # Library:: helpers 4 | # 5 | # Copyright:: 2015-2017, 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 Ossec 21 | module Cookbook 22 | module Helpers 23 | def ossec_apt_repo_dist 24 | if node['os_release'] 25 | codename = node['os_release']['version_codename'] 26 | elsif node['lsb'] 27 | codename = node['lsb']['codename'] 28 | else 29 | raise 'unable to find release code name, please install the lsb-release package' 30 | end 31 | 32 | if ossec_apt_new_layout? 33 | "#{codename}/#{ossec_deb_arch}/" 34 | else 35 | codename 36 | end 37 | end 38 | 39 | def ossec_deb_arch 40 | case node['kernel']['machine'] 41 | when 'aarch64' 42 | 'arm64' 43 | else 44 | 'amd64' 45 | end 46 | end 47 | 48 | def ossec_apt_new_layout? 49 | if platform?('ubuntu') && node['platform_version'].to_f >= 20.04 50 | true 51 | elsif platform?('debian') && node['platform_version'].to_i >= 11 52 | true 53 | else 54 | false 55 | end 56 | end 57 | 58 | def ossec_to_xml(hash) 59 | require 'gyoku' 60 | Gyoku.xml object_to_ossec(hash) 61 | end 62 | 63 | def ossec_install_type 64 | type = nil 65 | 66 | if node['recipes'].include?('ossec::default') 67 | type = 'local' 68 | else 69 | begin 70 | File.open('/etc/ossec-init.conf') do |file| 71 | file.each_line do |line| 72 | if line =~ /^TYPE="([^"]+)"/ 73 | type = Regexp.last_match(1) 74 | break 75 | end 76 | end 77 | end 78 | rescue 79 | type = nil 80 | end 81 | end 82 | 83 | type 84 | end 85 | 86 | private 87 | 88 | # Gyoku looks for a symbol called :content! but Chef attributes 89 | # are always stringified. We can't just call symbolize_keys 90 | # because we need to recurse through the hash structure. Doing 91 | # this also gives us the opportunity to convert true/false to 92 | # yes/no, which is handy. 93 | def object_to_ossec(object) 94 | case object 95 | when Hash 96 | object.each_key do |k| 97 | if k == 'content!' 98 | object[:content!] = object_to_ossec(object.delete(k)) 99 | else 100 | object[k] = object_to_ossec(object[k]) 101 | end 102 | end 103 | object 104 | when Array 105 | object.map! do |e| 106 | object_to_ossec(e) 107 | end 108 | when TrueClass 109 | 'yes' 110 | when FalseClass 111 | 'no' 112 | when NilClass 113 | '' 114 | else 115 | object 116 | end 117 | end 118 | end 119 | end 120 | end 121 | Chef::DSL::Recipe.include Ossec::Cookbook::Helpers 122 | Chef::Resource.include Ossec::Cookbook::Helpers 123 | -------------------------------------------------------------------------------- /metadata.rb: -------------------------------------------------------------------------------- 1 | name 'ossec' 2 | maintainer 'Sous Chefs' 3 | maintainer_email 'help@sous-chefs.org' 4 | license 'Apache-2.0' 5 | source_url 'https://github.com/sous-chefs/ossec' 6 | issues_url 'https://github.com/sous-chefs/ossec/issues' 7 | description 'Installs and configures ossec' 8 | version '2.0.15' 9 | chef_version '>= 13.0' 10 | 11 | depends 'yum-atomic' 12 | 13 | supports 'debian' 14 | supports 'ubuntu' 15 | supports 'redhat' 16 | supports 'centos' 17 | supports 'fedora' 18 | supports 'scientific' 19 | supports 'oracle' 20 | supports 'amazon' 21 | -------------------------------------------------------------------------------- /recipes/agent.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook:: ossec 3 | # Recipe:: agent 4 | # 5 | # Copyright:: 2010-2017, 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/agent_auth.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook:: ossec 3 | # Recipe:: agent_auth 4 | # 5 | # Copyright:: 2015-2017, 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_agent' 21 | 22 | dir = node['ossec']['dir'] 23 | agent_auth = node['ossec']['agent_auth'] 24 | 25 | args = "-m #{agent_auth['host']} -p #{agent_auth['port']} -A #{agent_auth['name']}" 26 | 27 | if agent_auth['ca'] && File.exist?(agent_auth['ca']) 28 | args << ' -v ' + agent_auth['ca'] 29 | end 30 | 31 | if agent_auth['certificate'] && File.exist?(agent_auth['certificate']) 32 | args << ' -x ' + agent_auth['certificate'] 33 | end 34 | 35 | if agent_auth['key'] && File.exist?(agent_auth['key']) 36 | args << ' -k ' + agent_auth['key'] 37 | end 38 | 39 | execute "#{dir}/bin/agent-auth #{args}" do 40 | timeout 30 41 | ignore_failure true 42 | only_if { agent_auth['host'] && !File.size?("#{dir}/etc/client.keys") } 43 | end 44 | 45 | include_recipe 'ossec::common' 46 | -------------------------------------------------------------------------------- /recipes/authd.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook:: ossec 3 | # Recipe:: authd 4 | # 5 | # Copyright:: 2015-2017, 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 | 23 | authd = node['ossec']['authd'] 24 | 25 | if systemd? 26 | template 'ossec-authd init' do 27 | path '/lib/systemd/system/ossec-authd.service' 28 | source 'ossec-authd.service.erb' 29 | owner 'root' 30 | group 'root' 31 | mode '644' 32 | variables authd 33 | end 34 | 35 | execute 'systemctl daemon-reload' do 36 | action :nothing 37 | subscribes :run, 'template[ossec-authd init]', :immediately 38 | end 39 | end 40 | 41 | service 'ossec-authd' do 42 | service_name platform_family?('debian') ? 'ossec-authd' : 'ossec-hids-authd' 43 | supports restart: true 44 | action [:enable, :start] 45 | subscribes :restart, 'template[ossec-authd init]' 46 | 47 | only_if do 48 | File.exist?(authd['certificate']) && File.exist?(authd['key']) && 49 | (authd['ca'].nil? || File.exist?(authd['ca'])) 50 | end 51 | end 52 | -------------------------------------------------------------------------------- /recipes/client.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook:: ossec 3 | # Recipe:: client 4 | # 5 | # Copyright:: 2010-2017, 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.default['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 = data_bag_item(dbag_name, dbag_item) 40 | 41 | directory "#{node['ossec']['dir']}/.ssh" do 42 | owner 'ossec' 43 | group 'ossec' 44 | mode '0750' 45 | end 46 | 47 | template "#{node['ossec']['dir']}/.ssh/authorized_keys" do 48 | source 'ssh_key.erb' 49 | owner 'ossec' 50 | group 'ossec' 51 | mode '0600' 52 | variables(key: ossec_key['pubkey']) 53 | end 54 | 55 | file "#{node['ossec']['dir']}/etc/client.keys" do 56 | owner 'ossec' 57 | group 'ossec' 58 | mode '0660' 59 | end 60 | 61 | include_recipe 'ossec::common' 62 | -------------------------------------------------------------------------------- /recipes/common.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook:: ossec 3 | # Recipe:: common 4 | # 5 | # Copyright:: 2010-2017, 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 | # Gyoku renders the XML. 21 | chef_gem 'gyoku' do 22 | compile_time false 23 | end 24 | 25 | file "#{node['ossec']['dir']}/etc/ossec.conf" do 26 | owner 'root' 27 | group 'ossec' 28 | mode '0440' 29 | manage_symlink_source true 30 | notifies :restart, 'service[ossec]' 31 | 32 | content lazy { 33 | # Merge the "typed" attributes over the "all" attributes. 34 | all_conf = node['ossec']['conf']['all'].to_hash 35 | type_conf = node['ossec']['conf'][ossec_install_type].to_hash 36 | conf = Chef::Mixin::DeepMerge.deep_merge(type_conf, all_conf) 37 | ossec_to_xml('ossec_config' => conf) 38 | } 39 | end 40 | 41 | file "#{node['ossec']['dir']}/etc/shared/agent.conf" do 42 | owner 'root' 43 | group 'ossec' 44 | mode '0440' 45 | notifies :restart, 'service[ossec]' 46 | 47 | # Even if agent.cont is not appropriate for this kind of 48 | # installation, we need to create an empty file instead of deleting 49 | # for two reasons. Firstly, install_type is set at converge time 50 | # while action can't be lazy. Secondly, a subsequent package update 51 | # would just replace the file. 52 | action :create 53 | 54 | content lazy { 55 | if ossec_install_type == 'server' 56 | conf = node['ossec']['agent_conf'].to_a 57 | ossec_to_xml('agent_config' => conf) 58 | else 59 | '' 60 | end 61 | } 62 | end 63 | 64 | # Both the RPM and DEB packages enable and start the service 65 | # immediately after installation, which isn't helpful. An empty 66 | # client.keys file will cause a server not to listen and an agent to 67 | # abort immediately. Explicitly stopping the service here after 68 | # installation allows Chef to start it when client.keys has content. 69 | service 'stop ossec' do 70 | service_name platform_family?('debian') ? 'ossec' : 'ossec-hids' 71 | action :nothing 72 | 73 | %w( disable stop ).each do |action| 74 | subscribes action, 'package[ossec]', :immediately 75 | end 76 | end 77 | 78 | service 'ossec' do 79 | service_name platform_family?('debian') ? 'ossec' : 'ossec-hids' 80 | supports status: true, restart: true 81 | action [:enable, :start] 82 | 83 | not_if do 84 | (ossec_install_type != 'local' && !File.size?("#{node['ossec']['dir']}/etc/client.keys")) || 85 | (ossec_install_type == 'agent' && node['ossec']['agent_server_ip'].nil?) 86 | end 87 | end 88 | -------------------------------------------------------------------------------- /recipes/default.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook:: ossec 3 | # Recipe:: default 4 | # 5 | # Copyright:: 2010-2017, 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 | -------------------------------------------------------------------------------- /recipes/install_agent.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook:: ossec 3 | # Recipe:: install_agent 4 | # 5 | # Copyright:: 2015-2017, 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 'ossec-hids-agent' 24 | end 25 | -------------------------------------------------------------------------------- /recipes/install_server.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook:: ossec 3 | # Recipe:: install_server 4 | # 5 | # Copyright:: 2015-2017, 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 'ossec-hids-server' 24 | end 25 | -------------------------------------------------------------------------------- /recipes/repository.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook:: ossec 3 | # Recipe:: repository 4 | # 5 | # Copyright:: 2015-2017, 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 | node.default['yum']['atomic']['mirrorlist'] = nil 23 | node.default['yum']['atomic']['baseurl'] = 24 | 'https://updates.atomicorp.com/channels/atomic/centos/$releasever/$basearch' 25 | 26 | include_recipe 'yum-atomic' 27 | when 'debian' 28 | apt_repository 'ossec' do 29 | uri "https://updates.atomicorp.com/channels/atomic/#{node['platform']}" 30 | key 'https://www.atomicorp.com/RPM-GPG-KEY.atomicorp.txt' 31 | arch ossec_deb_arch 32 | distribution ossec_apt_repo_dist 33 | trusted true if ossec_apt_new_layout? 34 | components ossec_apt_new_layout? ? [] : %w(main) 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /recipes/server.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook:: ossec 3 | # Recipe:: server 4 | # 5 | # Copyright:: 2010-2017, 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']}) AND (NOT fqdn:#{node['fqdn']})" 27 | 28 | filter_keys = { 'fqdn' => ['fqdn'], 'ipaddress' => ['ipaddress'] } 29 | 30 | search(:node, search_string, filter_result: filter_keys).each do |n| 31 | ssh_hosts << n['ipaddress'] if n['keys'] 32 | 33 | execute "#{node['ossec']['agent_manager']} -a --ip #{n['ipaddress']} -n #{n['fqdn'][0..31]}" do 34 | not_if "grep '#{n['fqdn'][0..31]} #{n['ipaddress']}' #{node['ossec']['dir']}/etc/client.keys" 35 | end 36 | end 37 | 38 | template '/usr/local/bin/dist-ossec-keys.sh' do 39 | source 'dist-ossec-keys.sh.erb' 40 | owner 'root' 41 | group 'root' 42 | mode '0755' 43 | variables(ssh_hosts: ssh_hosts.sort) 44 | not_if { ssh_hosts.empty? } 45 | end 46 | 47 | dbag_name = node['ossec']['data_bag']['name'] 48 | dbag_item = node['ossec']['data_bag']['ssh'] 49 | ossec_key = data_bag_item(dbag_name, dbag_item) 50 | 51 | directory "#{node['ossec']['dir']}/.ssh" do 52 | owner 'root' 53 | group 'ossec' 54 | mode '0750' 55 | end 56 | 57 | template "#{node['ossec']['dir']}/.ssh/id_rsa" do 58 | source 'ssh_key.erb' 59 | owner 'root' 60 | group 'ossec' 61 | mode '0600' 62 | variables(key: ossec_key['privkey']) 63 | end 64 | 65 | include_recipe 'ossec::common' 66 | 67 | cron 'distribute-ossec-keys' do 68 | minute '0' 69 | command '/usr/local/bin/dist-ossec-keys.sh' 70 | only_if { ::File.exist?("#{node['ossec']['dir']}/etc/client.keys") } 71 | end 72 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json", 3 | "extends": ["config:base"], 4 | "packageRules": [ 5 | { 6 | "groupName": "Actions", 7 | "matchUpdateTypes": ["minor", "patch", "pin"], 8 | "automerge": true, 9 | "addLabels": ["Release: Patch", "Skip: Announcements"] 10 | }, 11 | { 12 | "groupName": "Actions", 13 | "matchUpdateTypes": ["major"], 14 | "automerge": false, 15 | "addLabels": ["Release: Patch", "Skip: Announcements"] 16 | } 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /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 | config.platform = 'ubuntu' 8 | config.version = '20.04' 9 | end 10 | -------------------------------------------------------------------------------- /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', __dir__) } 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 | -------------------------------------------------------------------------------- /spec/unit/recipes/authd_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | require 'json' 3 | 4 | describe 'ossec::authd' do 5 | before do 6 | allow(File).to receive(:exist?).and_call_original 7 | allow(File).to receive(:exist?).with('/var/ossec/etc/sslmanager.cert').and_return(true) 8 | allow(File).to receive(:exist?).with('/var/ossec/etc/sslmanager.key').and_return(true) 9 | end 10 | 11 | cached(:chef_run) do 12 | ChefSpec::ServerRunner.new.converge('ossec::authd') 13 | end 14 | 15 | it 'includes ossec::install_server recipe' do 16 | expect(chef_run).to include_recipe('ossec::install_server') 17 | end 18 | 19 | it 'includes ossec::common recipe' do 20 | expect(chef_run).to include_recipe('ossec::common') 21 | end 22 | 23 | context 'systemd' do 24 | it 'setup ossec-authd.service' do 25 | expect(chef_run).to create_template('ossec-authd init') 26 | end 27 | 28 | it 'reload systemctl' do 29 | execute = chef_run.execute('systemctl daemon-reload') 30 | expect(execute).to subscribe_to('template[ossec-authd init]').on(:run).immediately 31 | end 32 | end 33 | 34 | it 'enable & start ossec-authd service' do 35 | expect(chef_run).to enable_service('ossec-authd') 36 | expect(chef_run).to start_service('ossec-authd') 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /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', __dir__) } 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::common recipe' do 15 | expect(chef_run).to include_recipe('ossec::client') 16 | end 17 | 18 | it 'includes ossec::install_agent recipe' do 19 | expect(chef_run).to include_recipe('ossec::install_agent') 20 | end 21 | 22 | it 'includes ossec::repository recipe' do 23 | expect(chef_run).to include_recipe('ossec::repository') 24 | end 25 | 26 | it 'creates ossecd user .ssh directory' do 27 | expect(chef_run).to create_directory("#{chef_run.node['ossec']['dir']}/.ssh").with( 28 | owner: 'ossec', 29 | group: 'ossec', 30 | mode: '0750' 31 | ) 32 | end 33 | 34 | it 'creates ossec user authorized_keys template' do 35 | expect(chef_run).to create_template("#{chef_run.node['ossec']['dir']}/.ssh/authorized_keys").with( 36 | source: 'ssh_key.erb', 37 | owner: 'ossec', 38 | group: 'ossec', 39 | mode: '0600' 40 | ) 41 | end 42 | 43 | it 'creates ossec user /etc/client.keys file' do 44 | expect(chef_run).to create_file("#{chef_run.node['ossec']['dir']}/etc/client.keys").with( 45 | owner: 'ossec', 46 | group: 'ossec', 47 | mode: '0660' 48 | ) 49 | end 50 | 51 | it 'installs agent package' do 52 | expect(chef_run).to install_package('ossec-hids-agent') 53 | end 54 | end 55 | -------------------------------------------------------------------------------- /spec/unit/recipes/common_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe 'ossec::common' do 4 | cached(:chef_run) { ChefSpec::ServerRunner.new.converge('ossec::common') } 5 | let(:ossec_dir) { "ossec-hids-#{chef_run.node['ossec']['version']}" } 6 | 7 | it 'converges successfully' do 8 | expect { chef_run }.to_not raise_error 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /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', __dir__) } 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: '18.04') do |node| 10 | node.normal['ipaddress'] = '33.33.33.33' 11 | node.normal['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::install_server recipe' do 26 | expect(chef_run).to include_recipe('ossec::install_server') 27 | end 28 | 29 | it 'includes ossec::repository recipe' do 30 | expect(chef_run).to include_recipe('ossec::repository') 31 | end 32 | 33 | it 'includes ossec::common recipe' do 34 | expect(chef_run).to include_recipe('ossec::repository') 35 | end 36 | 37 | it 'installs the server package' do 38 | expect(chef_run).to install_package('ossec-hids-server') 39 | end 40 | 41 | it 'creates ossec user .ssh directory' do 42 | expect(chef_run).to create_directory("#{chef_run.node['ossec']['dir']}/.ssh").with( 43 | owner: 'root', 44 | group: 'ossec', 45 | mode: '0750' 46 | ) 47 | end 48 | 49 | it 'creates ossec ssh id_rsa key template' do 50 | expect(chef_run).to create_template("#{chef_run.node['ossec']['dir']}/.ssh/id_rsa").with( 51 | source: 'ssh_key.erb', 52 | owner: 'root', 53 | group: 'ossec', 54 | mode: '0600' 55 | ) 56 | end 57 | end 58 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /templates/default/ossec-authd.service.erb: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=OSSEC authd 3 | 4 | [Service] 5 | EnvironmentFile=/etc/ossec-init.conf 6 | Environment=DIRECTORY=/var/ossec 7 | 8 | ExecStart=/usr/bin/env ${DIRECTORY}/bin/ossec-authd -p <%= @port %> <%= '-i' if @ip_address %> -x <%= @certificate %> -k <%= @key %> <%= "-v #{@ca}" if @ca %> 9 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /test/integration/client/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_installed } 10 | end 11 | 12 | describe package('ossec-hids-agent') do 13 | it { should be_installed } 14 | end 15 | -------------------------------------------------------------------------------- /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_installed } 10 | end 11 | 12 | describe package('ossec-hids-server') do 13 | it { should be_installed } 14 | end 15 | --------------------------------------------------------------------------------