├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md └── workflows │ └── codespell.yml ├── .gitignore ├── .kitchen.vagrant.yml ├── .kitchen.yml ├── .rubocop.yml ├── .travis.yml ├── Berksfile ├── CHANGELOG.md ├── CONTRIBUTING.md ├── Gemfile ├── Guardfile ├── LICENSE ├── README.md ├── Rakefile ├── attributes ├── default.rb └── hardening.rb ├── gemfile.chef-11 ├── metadata.rb ├── recipes ├── default.rb └── hardening.rb ├── renovate.json ├── spec ├── spec_helper.rb └── unit │ └── recipes │ ├── default_spec.rb │ └── hardening_spec.rb └── templates └── default ├── hardening.cnf.erb └── mods └── alias.conf.erb /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | 5 | --- 6 | 7 | **Describe the bug** 8 | A clear and concise description of what the bug is. 9 | 10 | **Expected behavior** 11 | A clear and concise description of what you expected to happen. 12 | 13 | **Actual behavior** 14 | 15 | ```paste below 16 | 17 | ``` 18 | 19 | **Example code** 20 | 21 | ```paste below 22 | 23 | ``` 24 | 25 | **OS / Environment** 26 | 27 | 28 | 29 | **Chef Version** 30 | 31 | ```paste below 32 | 33 | ``` 34 | 35 | **Cookbook Version** 36 | 37 | ```paste below 38 | 39 | ``` 40 | 41 | **Additional context** 42 | Add any other context about the problem here. 43 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | 5 | --- 6 | 7 | **Is your feature request related to a problem? Please describe.** 8 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 9 | 10 | **Describe the solution you'd like** 11 | A clear and concise description of what you want to happen. 12 | 13 | **Describe alternatives you've considered** 14 | A clear and concise description of any alternative solutions or features you've considered. 15 | 16 | **Additional context** 17 | Add any other context or screenshots about the feature request here. 18 | -------------------------------------------------------------------------------- /.github/workflows/codespell.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: Codespell - Spellcheck 3 | 4 | on: # yamllint disable-line rule:truthy 5 | push: 6 | branches: [master] 7 | pull_request: 8 | branches: [master] 9 | 10 | jobs: 11 | codespell: 12 | uses: "dev-sec/.github/.github/workflows/codespell.yml@main" 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | exp.* 2 | .kitchen 3 | Gemfile.lock 4 | Berksfile.lock 5 | .kitchen.local.yml 6 | shared_test_repo/ 7 | test/integration 8 | coverage/**/* 9 | -------------------------------------------------------------------------------- /.kitchen.vagrant.yml: -------------------------------------------------------------------------------- 1 | --- 2 | driver: 3 | name: vagrant 4 | provisioner: 5 | name: chef_solo 6 | # require_chef_omnibus: 12.5 7 | # test_repo_uri: https://github.com/dev-sec/tests-apache-hardening.git 8 | platforms: 9 | - name: ubuntu-12.04 10 | driver_config: 11 | box: ubuntu/precise64 12 | box_url: https://atlas.hashicorp.com/ubuntu/boxes/precise64/versions/20160527.0.0/providers/virtualbox.box 13 | - name: ubuntu-14.04 14 | driver_config: 15 | box: ubuntu/trusty64 16 | box_url: https://atlas.hashicorp.com/ubuntu/boxes/trusty64/versions/20160601.0.0/providers/virtualbox.box 17 | - name: ubuntu-16.04 18 | driver_config: 19 | box: ubuntu/xenial64 20 | box_url: https://atlas.hashicorp.com/ubuntu/boxes/xenial64/versions/20160531.0.0/providers/virtualbox.box 21 | - name: centos-6.4 22 | driver_config: 23 | box: opscode-centos-6.7 24 | box_url: http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_centos-6.7_chef-provisionerless.box 25 | - name: centos-7.2 26 | driver_config: 27 | box: opscode-centos-7.2 28 | box_url: http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_centos-7.2_chef-provisionerless.box 29 | - name: oracle-6.4 30 | driver_config: 31 | box: oracle-6.4 32 | box_url: https://storage.us2.oraclecloud.com/v1/istoilis-istoilis/vagrant/oel64-64.box 33 | - name: oracle-6.5 34 | driver_config: 35 | box: oracle-6.5 36 | box_url: https://storage.us2.oraclecloud.com/v1/istoilis-istoilis/vagrant/oel65-64.box 37 | - name: debian-7 38 | driver_config: 39 | box: debian/wheezy64 40 | box_url: https://atlas.hashicorp.com/debian/boxes/wheezy64/versions/7.10.0/providers/virtualbox.box 41 | - name: debian-8 42 | driver_config: 43 | box: debian/jessie64 44 | box_url: https://atlas.hashicorp.com/debian/boxes/jessie64/versions/8.4.0/providers/virtualbox.box 45 | verifier: 46 | name: inspec 47 | sudo: true 48 | suites: 49 | - name: default 50 | run_list: 51 | - recipe[apt] 52 | - recipe[apache2] 53 | - recipe[apache2::mod_ssl] 54 | - recipe[apache-hardening::default] 55 | verifier: 56 | inspec_tests: 57 | - https://github.com/dev-sec/tests-apache-hardening.git 58 | -------------------------------------------------------------------------------- /.kitchen.yml: -------------------------------------------------------------------------------- 1 | --- 2 | driver: 3 | name: dokken 4 | chef_version: 12.5.1 5 | privileged: true # because Docker and SystemD/Upstart 6 | 7 | transport: 8 | name: dokken 9 | 10 | provisioner: 11 | name: dokken 12 | 13 | verifier: 14 | name: inspec 15 | sudo: true 16 | 17 | platforms: 18 | #- name: ubuntu-14.04 19 | # driver: 20 | # image: ubuntu:14.04 21 | # intermediate_instructions: 22 | # - RUN /usr/bin/apt-get update 23 | # - RUN /usr/bin/apt-get install apt-transport-https net-tools -y 24 | # - RUN mkdir /var/lock/apache2 25 | # pid_one_command: /sbin/init 26 | - name: ubuntu-14.04 27 | driver: 28 | image: ubuntu-upstart:14.04 29 | pid_one_command: /sbin/init 30 | - name: ubuntu-16.04 31 | driver: 32 | image: ubuntu:16.04 33 | pid_one_command: /bin/systemd 34 | - name: centos-6.8 35 | driver: 36 | image: centos:6.8 37 | intermediate_instructions: 38 | - RUN yum install -y initscripts 39 | - name: centos-7.2 40 | driver: 41 | image: centos:7.2.1511 42 | pid_one_command: /usr/lib/systemd/systemd 43 | intermediate_instructions: 44 | - RUN yum install -y initscripts 45 | - name: oracle-6.8 46 | driver: 47 | image: oraclelinux:6.8 48 | - name: oracle-7.2 49 | driver: 50 | image: oraclelinux:7.2 51 | pid_one_command: /usr/lib/systemd/systemd 52 | - name: debian-7 53 | driver: 54 | image: debian:7 55 | intermediate_instructions: 56 | - RUN /usr/bin/apt-get update 57 | - name: debian-8 58 | driver: 59 | image: debian:8 60 | pid_one_command: /bin/systemd 61 | 62 | suites: 63 | - name: default 64 | run_list: 65 | - recipe[apt] 66 | - recipe[apache2] 67 | - recipe[apache2::mod_ssl] 68 | - recipe[apache-hardening::default] 69 | 70 | verifier: 71 | inspec_tests: 72 | - https://github.com/dev-sec/tests-apache-hardening.git 73 | -------------------------------------------------------------------------------- /.rubocop.yml: -------------------------------------------------------------------------------- 1 | --- 2 | AllCops: 3 | Exclude: 4 | - vendor/**/* 5 | - test/**/* 6 | - metadata.rb 7 | - Berksfile 8 | - Guardfile 9 | Documentation: 10 | Enabled: false 11 | AlignParameters: 12 | Enabled: true 13 | Encoding: 14 | Enabled: true 15 | HashSyntax: 16 | Enabled: true 17 | LineLength: 18 | Enabled: false 19 | EmptyLinesAroundBlockBody: 20 | Enabled: false 21 | MethodLength: 22 | Max: 40 23 | NumericLiterals: 24 | MinDigits: 10 25 | Metrics/CyclomaticComplexity: 26 | Max: 10 27 | Metrics/PerceivedComplexity: 28 | Max: 10 29 | Metrics/AbcSize: 30 | Max: 29 31 | Style/DotPosition: 32 | EnforcedStyle: trailing 33 | Enabled: true 34 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | --- 2 | sudo: required 3 | language: ruby 4 | cache: bundler 5 | dist: trusty 6 | 7 | services: 8 | - docker 9 | 10 | before_install: 11 | - gem --version 12 | - bundle version 13 | 14 | matrix: 15 | include: 16 | # verify lint and unit 17 | - rvm: 2.3.1 18 | gemfile: Gemfile 19 | bundler_args: "--without integration guard tools" 20 | # integration tests 21 | - rvm: 2.3.1 22 | bundler_args: "--without guard tools" 23 | script: bundle exec rake test:integration OS='centos' 24 | gemfile: Gemfile 25 | - rvm: 2.3.1 26 | bundler_args: "--without guard tools" 27 | script: bundle exec rake test:integration OS='oracle' 28 | gemfile: Gemfile 29 | - rvm: 2.3.1 30 | bundler_args: "--without guard tools" 31 | script: bundle exec rake test:integration OS='ubuntu' 32 | gemfile: Gemfile 33 | - rvm: 2.3.1 34 | bundler_args: "--without guard tools" 35 | script: bundle exec rake test:integration OS='debian' 36 | gemfile: Gemfile 37 | -------------------------------------------------------------------------------- /Berksfile: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | 3 | source 'https://supermarket.getchef.com' 4 | 5 | metadata 6 | 7 | cookbook 'apt' 8 | cookbook 'chef-solo-search', git: 'https://github.com/edelight/chef-solo-search' 9 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | ## [1.0.0](https://github.com/dev-sec/chef-apache-hardening/tree/1.0.0) (2016-06-24) 4 | **Closed issues:** 5 | 6 | - Bad twiddle-wakka in metadata [\#19](https://github.com/dev-sec/chef-apache-hardening/issues/19) 7 | 8 | **Merged pull requests:** 9 | 10 | - switch to docker and use inspec for testing [\#24](https://github.com/dev-sec/chef-apache-hardening/pull/24) ([atomic111](https://github.com/atomic111)) 11 | - upgrade to Berkshelf 4 [\#23](https://github.com/dev-sec/chef-apache-hardening/pull/23) ([chris-rock](https://github.com/chris-rock)) 12 | - update common kitchen.yml platforms [\#22](https://github.com/dev-sec/chef-apache-hardening/pull/22) ([chris-rock](https://github.com/chris-rock)) 13 | - Added a missing dash [\#21](https://github.com/dev-sec/chef-apache-hardening/pull/21) ([efreesen](https://github.com/efreesen)) 14 | - closes \#19 [\#20](https://github.com/dev-sec/chef-apache-hardening/pull/20) ([chris-rock](https://github.com/chris-rock)) 15 | - update common Gemfile for chef11+12 [\#18](https://github.com/dev-sec/chef-apache-hardening/pull/18) ([arlimus](https://github.com/arlimus)) 16 | - common files: centos7 + rubocop [\#17](https://github.com/dev-sec/chef-apache-hardening/pull/17) ([arlimus](https://github.com/arlimus)) 17 | - update common kitchen.yml platforms [\#16](https://github.com/dev-sec/chef-apache-hardening/pull/16) ([arlimus](https://github.com/arlimus)) 18 | - update common readme badges [\#15](https://github.com/dev-sec/chef-apache-hardening/pull/15) ([arlimus](https://github.com/arlimus)) 19 | - updating common files [\#11](https://github.com/dev-sec/chef-apache-hardening/pull/11) ([arlimus](https://github.com/arlimus)) 20 | - update readme and add contributing section [\#10](https://github.com/dev-sec/chef-apache-hardening/pull/10) ([ehaselwanter](https://github.com/ehaselwanter)) 21 | - add some more specs for the hardening code [\#9](https://github.com/dev-sec/chef-apache-hardening/pull/9) ([ehaselwanter](https://github.com/ehaselwanter)) 22 | - add badges to readme [\#8](https://github.com/dev-sec/chef-apache-hardening/pull/8) ([chris-rock](https://github.com/chris-rock)) 23 | - add specs to apache cookbook [\#7](https://github.com/dev-sec/chef-apache-hardening/pull/7) ([ehaselwanter](https://github.com/ehaselwanter)) 24 | - fix alias conf according to gis requirements [\#6](https://github.com/dev-sec/chef-apache-hardening/pull/6) ([ehaselwanter](https://github.com/ehaselwanter)) 25 | - rubocop 0.27 is picky about the Berksfile [\#5](https://github.com/dev-sec/chef-apache-hardening/pull/5) ([ehaselwanter](https://github.com/ehaselwanter)) 26 | - remove o-rwx [\#4](https://github.com/dev-sec/chef-apache-hardening/pull/4) ([ehaselwanter](https://github.com/ehaselwanter)) 27 | - Update common [\#3](https://github.com/dev-sec/chef-apache-hardening/pull/3) ([arlimus](https://github.com/arlimus)) 28 | - fix reload issue. we need a restart action [\#2](https://github.com/dev-sec/chef-apache-hardening/pull/2) ([ehaselwanter](https://github.com/ehaselwanter)) 29 | - add the chef hardeing config [\#1](https://github.com/dev-sec/chef-apache-hardening/pull/1) ([ehaselwanter](https://github.com/ehaselwanter)) 30 | 31 | 32 | 33 | \* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)* -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributor Guideline 2 | 3 | This document provides an overview of how you can participat in improving this project or extending it. We are grateful for all your help: bug reports and fixes, code contributions, documentation or ideas. Feel free to join, we appreciate your support!! 4 | 5 | ## Communication 6 | 7 | ### GitHub repositories 8 | 9 | Much of the issues, goals and ideas are tracked in the respective projects in GitHub. Please use this channel to report bugs and post ideas. 10 | 11 | ### Trello 12 | 13 | The overall hardening project is organized publicly on Trello. Feel free to join and add tasks and ideas for the overall project. [https://trello.com/b/gL9v8N1q/dt-hardening](https://trello.com/b/gL9v8N1q/dt-hardening) 14 | 15 | ## git and GitHub 16 | 17 | In order to contribute code please: 18 | 19 | 1. Fork the project on GitHub 20 | 2. Clone the project 21 | 3. Add changes (and tests) 22 | 4. Commit and push 23 | 5. Create a merge-request 24 | 25 | To have your code merged, see the expectations listed below. 26 | 27 | You can find a well-written guide [here](https://help.github.com/articles/fork-a-repo). 28 | 29 | Please follow common commit best-practices. Be explicit, have a short summary, a well-written description and references. This is especially important for the merge-request. 30 | 31 | Some great guidelines can be found [here](https://wiki.openstack.org/wiki/GitCommitMessages) and [here](http://robots.thoughtbot.com/5-useful-tips-for-a-better-commit-message). 32 | 33 | 34 | ## Expectations 35 | 36 | ### Don't reinvent the wheel 37 | 38 | This hardening project doesn't intend to reinvent the configuration stack for services. Aim to use official configuration projects first and provide hardening as a layer on top. The goal is remove the need for a user to configure all aspects of services and maintain security configuration. This way, the user can still configure a service using the interface provided by the official project. 39 | 40 | * For Chef refer to the official [opscode community cookbooks](http://community.opscode.com/cookbooks). 41 | * For Puppet head to the [Puppet Forge](https://forge.puppetlabs.com/) and take a node of the Puppet supported modules. 42 | 43 | These projects are generally hosted on GitHub as well. 44 | 45 | In some cases, we in fact create the full rollout stack, but this is generally the exception ([os-hardening](https://github.com/TelekomLabs/chef-os-hardening), [nginx-hardening](https://github.com/TelekomLabs/chef-nginx-hardening)). 46 | 47 | 48 | ### Be explicit 49 | 50 | * Please avoid using nonsensical property and variable names 51 | * Use self-describing attribute names for user configuration 52 | * In case of failures, communicate what happened and why a failure occurs to the user. Make it easy to track the code or action that produced the error. Try to catch and handle errors if possible to provide improved failure messages. 53 | 54 | 55 | ### Add tests 56 | 57 | The security review of this project is done using integration tests. 58 | 59 | Whenever you add a new security configuration, please start by writing a test that checks for this configuration. For example: If you want to set a new attribute in a configuration file, write a test that expects the value to be set first. Then implement your change. 60 | 61 | You may add a new feature request by creating a test for whatever value you need. 62 | 63 | All tests will be reviewed internally for their validity and overall project direction. 64 | 65 | 66 | ### Document your code 67 | 68 | As code is more often read than written, please provide documentation in all projects. 69 | 70 | Adhere to the respective guidelines for documentation: 71 | 72 | * Chef generally documents code based explicit readme files. For code documentation please use [yard-chef](https://github.com/rightscale/yard-chef) 73 | * [Puppet module documentation](http://docs.puppetlabs.com/puppet/latest/reference/modules_documentation.html) 74 | 75 | 76 | ### Follow coding styles 77 | 78 | We generally include test for coding guidelines: 79 | 80 | * Chef follows [Foodcritic](http://acrmp.github.io/foodcritic/) 81 | * Puppet is checked with [puppet-lint](http://puppet-lint.com/checks/) 82 | 83 | Remember: Code is generally read much more often than written. 84 | 85 | 86 | ### Use Markdown 87 | 88 | Wherever possible, please refrain from any other formats and stick to simple markdown. 89 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | 3 | source 'https://rubygems.org' 4 | 5 | gem 'berkshelf', '~> 8.0' 6 | gem 'chef', '>= 12.0' 7 | gem 'inspec', '~> 5' 8 | 9 | group :test do 10 | gem 'rake' 11 | gem 'chefspec', '~> 9.3.0' 12 | gem 'foodcritic', '~> 16.0' 13 | gem 'thor-foodcritic' 14 | gem 'rubocop', '~> 1.76.0' 15 | gem 'coveralls', require: false 16 | gem 'minitest', '~> 5.5' 17 | gem 'simplecov', '~> 0.10' 18 | end 19 | 20 | group :development do 21 | gem 'guard' 22 | gem 'guard-rspec' 23 | gem 'guard-kitchen' 24 | gem 'guard-rubocop' 25 | gem 'guard-foodcritic' 26 | end 27 | 28 | group :integration do 29 | gem 'test-kitchen', '~> 3.0' 30 | gem 'kitchen-vagrant' 31 | gem 'kitchen-inspec' 32 | gem 'concurrent-ruby', '~> 1.0' 33 | gem 'kitchen-dokken' 34 | end 35 | 36 | group :tools do 37 | gem 'github_changelog_generator', '~> 1.16.0' 38 | end 39 | -------------------------------------------------------------------------------- /Guardfile: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | 3 | # Guardfile 4 | 5 | guard :rubocop do 6 | watch(/.+\.rb$/) 7 | watch(/(?:.+\/)?\.rubocop\.yml$/) { |m| File.dirname(m[0]) } 8 | end 9 | 10 | guard :foodcritic, cookbook_paths: '.', cli: '-f any --tags ~FC023' do 11 | watch(/attributes\/.+\.rb$/) 12 | watch(/providers\/.+\.rb$/) 13 | watch(/recipes\/.+\.rb$/) 14 | watch(/resources\/.+\.rb$/) 15 | watch(/metadata.rb/) 16 | end 17 | 18 | guard :rspec do 19 | watch(/^spec\/.+_spec\.rb$/) 20 | watch(/^(recipes)\/(.+)\.rb$/) { |m| "spec/#{m[1]}_spec.rb" } 21 | watch('spec/spec_helper.rb') { 'spec' } 22 | end 23 | 24 | guard :kitchen, all_on_start: false do 25 | watch(/test\/.+/) 26 | watch(/^recipes\/(.+)\.rb$/) 27 | watch(/^attributes\/(.+)\.rb$/) 28 | watch(/^files\/(.+)/) 29 | watch(/^templates\/(.+)/) 30 | watch(/^providers\/(.+)\.rb/) 31 | watch(/^resources\/(.+)\.rb/) 32 | end 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # apache-hardening (Chef cookbook) 2 | 3 | [![Supermarket](http://img.shields.io/cookbook/v/apache-hardening.svg)][1] 4 | [![Build Status](http://img.shields.io/travis/dev-sec/chef-apache-hardening.svg)][2] 5 | [![Code Coverage](http://img.shields.io/coveralls/dev-sec/chef-apache-hardening.svg)][3] 6 | [![Dependencies](http://img.shields.io/gemnasium/dev-sec/chef-apache-hardening.svg)][4] 7 | [![Gitter Chat](https://badges.gitter.im/Join%20Chat.svg)][5] 8 | 9 | ## Description 10 | 11 | This cookbook provides a secure overlay for apache configuration. 12 | 13 | ## Requirements 14 | 15 | * chef 16 | 17 | ### Platform 18 | 19 | - Debian 7, 8 20 | - Ubuntu 14.04, 16.04 21 | - CentOS 6.8, 7.2 22 | - OracleLinux 6.8, 7.2 23 | 24 | ## Usage 25 | 26 | A sample role may look like: 27 | 28 | ```json 29 | { 30 | "name": "apache", 31 | "default_attributes": { }, 32 | "override_attributes": { }, 33 | "json_class": "Chef::Role", 34 | "description": "Apache Hardened Server Test Role", 35 | "chef_type": "role", 36 | "run_list": [ 37 | "recipe[apt]", 38 | "recipe[apache2]", 39 | "recipe[apache-hardening]" 40 | ] 41 | } 42 | ``` 43 | 44 | ## Recipes 45 | 46 | ### apache-hardening::hardening (default) 47 | 48 | This recipe is an overlay recipe for the [apache2 cookbook](https://github.com/viverae-cookbooks/apache2) and applies `apache-hardening::hardening` 49 | 50 | Add the following to your runlist and customize security option attributes 51 | 52 | ``` 53 | "recipe[apache2]", 54 | "recipe[apache-hardening]" 55 | ``` 56 | 57 | This hardening recipe installs the hardening but expects an existing installation of Apache2. 58 | 59 | ## Security Options 60 | 61 | * `node['apache']['traceenable'] = 'Off'` 62 | This directive overrides the behavior of TRACE for both the core server and mod_proxy. 63 | See [http://httpd.apache.org/docs/2.2/mod/core.html#traceenable](http://httpd.apache.org/docs/2.2/mod/core.html#traceenable) for details 64 | Defaults to: `Off` 65 | 66 | * `node['apache_hardening']['allowed_http_methods'] = %w( GET POST )` 67 | A list of HTTP methods that should be allowed in the server. 68 | See [http://httpd.apache.org/docs/trunk/mod/mod_allowmethods.html](http://httpd.apache.org/docs/trunk/mod/mod_allowmethods.html) for details 69 | Defaults to: `GET POST` 70 | 71 | * `node['apache_hardening']['modules_to_disable'] = %w( cgi cgid )` 72 | This parameter sets a list of modules that should be disabled on the target server. 73 | See [http://httpd.apache.org/docs/current/mod/](http://httpd.apache.org/docs/current/mod/) for details 74 | Defaults to: `cgi cgid` 75 | 76 | ## Tests 77 | 78 | For local testing you can use vagrant or docker to run tests locally. You will have to install Virtualbox and Vagrant or docker on your system. See [Vagrant Downloads](http://downloads.vagrantup.com/) for a vagrant or [Docker Downloads](https://docs.docker.com/mac/) package suitable for your system. For all our tests we use `test-kitchen`. If you are not familiar with `test-kitchen` please have a look at [their guide](http://kitchen.ci/docs/getting-started). 79 | 80 | ``` 81 | # Install dependencies 82 | gem install bundler 83 | bundle install 84 | 85 | # Do lint checks 86 | bundle exec rake lint 87 | 88 | # fast test on one machine 89 | bundle exec kitchen test default-ubuntu-1404 90 | 91 | # test on all machines 92 | bundle exec kitchen test 93 | 94 | # for development 95 | bundle exec kitchen create default-ubuntu-1404 96 | bundle exec kitchen converge default-ubuntu-1404 97 | bundle exec kitchen verify default-ubuntu-1204 98 | ``` 99 | 100 | ## Contributors + Kudos 101 | 102 | * Dominik Richter [arlimus](https://github.com/arlimus) 103 | * Christoph Hartmann [chris-rock](https://github.com/chris-rock) 104 | * Patrick Muench [atomic111](https://github.com/atomic111) 105 | * Edmund Haselwanter [ehaselwanter](https://github.com/ehaselwanter) 106 | 107 | ## Contributing 108 | 109 | See [contributor guideline](CONTRIBUTING.md). 110 | 111 | ## License and Author 112 | 113 | * Author:: Deutsche Telekom AG 114 | 115 | Licensed under the Apache License, Version 2.0 (the "License"); 116 | you may not use this file except in compliance with the License. 117 | You may obtain a copy of the License at 118 | 119 | http://www.apache.org/licenses/LICENSE-2.0 120 | 121 | Unless required by applicable law or agreed to in writing, software 122 | distributed under the License is distributed on an "AS IS" BASIS, 123 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 124 | See the License for the specific language governing permissions and 125 | limitations under the License. 126 | 127 | [1]: https://supermarket.getchef.com/cookbooks/apache-hardening 128 | [2]: http://travis-ci.org/dev-sec/chef-apache-hardening 129 | [3]: https://coveralls.io/r/dev-sec/chef-apache-hardening 130 | [4]: https://gemnasium.com/dev-sec/chef-apache-hardening 131 | [5]: https://gitter.im/dev-sec/general 132 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env rake 2 | # encoding: utf-8 3 | 4 | require 'foodcritic' 5 | require 'rspec/core/rake_task' 6 | require 'rubocop/rake_task' 7 | 8 | # General tasks 9 | 10 | # Rubocop before rspec so we don't lint vendored cookbooks 11 | desc 'Run all tests except Kitchen (default task)' 12 | task default: [:lint, :spec] 13 | 14 | # Lint the cookbook 15 | desc 'Run all linters: rubocop and foodcritic' 16 | task lint: [:rubocop, :foodcritic] 17 | 18 | # Run the whole shebang 19 | desc 'Run all tests' 20 | task test: [:lint, :integration, :spec] 21 | 22 | # RSpec 23 | desc 'Run chefspec tests' 24 | task :spec do 25 | puts 'Running Chefspec tests' 26 | RSpec::Core::RakeTask.new(:spec) 27 | end 28 | 29 | # Foodcritic 30 | desc 'Run foodcritic lint checks' 31 | task :foodcritic do 32 | if Gem::Version.new('1.9.2') <= Gem::Version.new(RUBY_VERSION.dup) 33 | puts 'Running Foodcritic tests...' 34 | FoodCritic::Rake::LintTask.new do |t| 35 | t.options = { fail_tags: ['any'] } 36 | puts 'done.' 37 | end 38 | else 39 | puts "WARN: foodcritic run is skipped as Ruby #{RUBY_VERSION} is < 1.9.2." 40 | end 41 | end 42 | 43 | # Rubocop 44 | desc 'Run Rubocop lint checks' 45 | task :rubocop do 46 | RuboCop::RakeTask.new 47 | end 48 | 49 | # Automatically generate a changelog for this project. Only loaded if 50 | # the necessary gem is installed. 51 | 52 | desc 'Generate the changelog' 53 | task :changelog do 54 | version = File.read('metadata.rb')[/^version '(.*)'$/, 1] 55 | system "github_changelog_generator -u dev-sec -p chef-apache-hardening --future-release #{version}" 56 | end 57 | 58 | namespace :test do 59 | task :integration do 60 | concurrency = ENV['CONCURRENCY'] || 1 61 | os = ENV['OS'] || '' 62 | sh('sh', '-c', "bundle exec kitchen test -c #{concurrency} #{os}") 63 | end 64 | end 65 | -------------------------------------------------------------------------------- /attributes/default.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # Cookbook Name:: apache-hardening 4 | # Attributes:: default 5 | # 6 | # Copyright 2014, Edmund Haselwanter 7 | # Copyright 2014, Deutsche Telekom AG 8 | # 9 | # Licensed under the Apache License, Version 2.0 (the "License"); 10 | # you may not use this file except in compliance with the License. 11 | # You may obtain a copy of the License at 12 | # 13 | # http://www.apache.org/licenses/LICENSE-2.0 14 | # 15 | # Unless required by applicable law or agreed to in writing, software 16 | # distributed under the License is distributed on an "AS IS" BASIS, 17 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | # See the License for the specific language governing permissions and 19 | # limitations under the License. 20 | # 21 | 22 | include_attribute 'apache2' 23 | 24 | default['apache']['traceenable'] = 'Off' 25 | -------------------------------------------------------------------------------- /attributes/hardening.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # Cookbook Name:: apache-hardening 4 | # Attributes:: default 5 | # 6 | # Copyright 2014, Edmund Haselwanter 7 | # Copyright 2014, Deutsche Telekom AG 8 | # 9 | # Licensed under the Apache License, Version 2.0 (the "License"); 10 | # you may not use this file except in compliance with the License. 11 | # You may obtain a copy of the License at 12 | # 13 | # http://www.apache.org/licenses/LICENSE-2.0 14 | # 15 | # Unless required by applicable law or agreed to in writing, software 16 | # distributed under the License is distributed on an "AS IS" BASIS, 17 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | # See the License for the specific language governing permissions and 19 | # limitations under the License. 20 | # 21 | 22 | # security options 23 | 24 | default['apache_hardening']['allowed_http_methods'] = %w( GET POST ) 25 | default['apache_hardening']['modules_to_disable'] = %w( cgi cgid ) 26 | -------------------------------------------------------------------------------- /gemfile.chef-11: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | 3 | source 'https://rubygems.org' 4 | 5 | gem 'berkshelf', '~> 4.0' 6 | gem 'chef', '~> 11.18' 7 | 8 | group :test do 9 | gem 'rake' 10 | gem 'chefspec', '~> 4.1.1' 11 | gem 'foodcritic', '~> 3.0' 12 | gem 'thor-foodcritic' 13 | gem 'rubocop', '~> 0.28.0' 14 | gem 'coveralls', require: false 15 | end 16 | 17 | group :development do 18 | gem 'guard' 19 | gem 'guard-rspec' 20 | gem 'guard-kitchen' 21 | gem 'guard-rubocop' 22 | gem 'guard-foodcritic' 23 | end 24 | 25 | group :integration do 26 | gem 'test-kitchen', '~> 1.0' 27 | gem 'kitchen-vagrant' 28 | gem 'kitchen-inspec' 29 | gem 'kitchen-dokken' 30 | gem 'kitchen-sharedtests', '~> 0.2.0' 31 | end 32 | 33 | group :openstack do 34 | gem 'kitchen-openstack' 35 | end 36 | -------------------------------------------------------------------------------- /metadata.rb: -------------------------------------------------------------------------------- 1 | name 'apache-hardening' 2 | maintainer 'DevSec Hardening Framework Team' 3 | maintainer_email 'hello@dev-sec.io' 4 | license 'Apache v2.0' 5 | description 'Installs and configures a secure apache server' 6 | long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) 7 | version '1.0.0' 8 | 9 | depends 'apache2', '~> 3.2.2' 10 | 11 | recipe 'apache-hardening::default', 'calls hardening recipe' 12 | recipe 'apache-hardening::hardening', 'add hardening configuration apache server' 13 | 14 | supports 'amazon' 15 | supports 'redhat' 16 | supports 'centos' 17 | supports 'fedora' 18 | supports 'debian' 19 | supports 'ubuntu' 20 | supports 'oracle' 21 | -------------------------------------------------------------------------------- /recipes/default.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # Cookbook Name: apache-hardening 4 | # Recipe: default 5 | # 6 | # Copyright 2014, Edmund Haselwanter 7 | # Copyright 2014, Deutsche Telekom AG 8 | # 9 | # Licensed under the Apache License, Version 2.0 (the "License"); 10 | # you may not use this file except in compliance with the License. 11 | # You may obtain a copy of the License at 12 | # 13 | # http://www.apache.org/licenses/LICENSE-2.0 14 | # 15 | # Unless required by applicable law or agreed to in writing, software 16 | # distributed under the License is distributed on an "AS IS" BASIS, 17 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | # See the License for the specific language governing permissions and 19 | # limitations under the License. 20 | # 21 | 22 | include_recipe('apache-hardening::hardening') 23 | -------------------------------------------------------------------------------- /recipes/hardening.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # Cookbook Name: apache-hardening 4 | # Recipe: hardening.rb 5 | # 6 | # Copyright 2014, Edmund Haselwanter 7 | # Copyright 2014, Deutsche Telekom AG 8 | # 9 | # Licensed under the Apache License, Version 2.0 (the "License"); 10 | # you may not use this file except in compliance with the License. 11 | # You may obtain a copy of the License at 12 | # 13 | # http://www.apache.org/licenses/LICENSE-2.0 14 | # 15 | # Unless required by applicable law or agreed to in writing, software 16 | # distributed under the License is distributed on an "AS IS" BASIS, 17 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | # See the License for the specific language governing permissions and 19 | # limitations under the License. 20 | # 21 | 22 | template File.join(node['apache']['dir'], '/conf-enabled/', 'hardening.conf') do 23 | action :create 24 | source 'hardening.cnf.erb' 25 | owner 'root' 26 | group node['apache']['root_group'] 27 | mode '0640' 28 | notifies :restart, 'service[apache2]', :delayed 29 | end 30 | 31 | node['apache_hardening']['modules_to_disable'].each do |module_to_disable| 32 | apache_module module_to_disable do 33 | enable false 34 | notifies :restart, 'service[apache2]', :delayed 35 | end 36 | end 37 | 38 | begin 39 | r = resources(template: "#{node['apache']['dir']}/mods-available/alias.conf") 40 | r.cookbook('apache-hardening') 41 | rescue Chef::Exceptions::ResourceNotFound 42 | Chef::Log.info("ignoring update of alias.conf since it is not used #{node['apache']['dir']}/mods-available/alias.conf") 43 | end 44 | 45 | # change all the already created resource so we do not flap on o-rw 46 | run_context.resource_collection.each do |resource| 47 | resource.mode('0640') if resource.name =~ /#{node['apache']['dir']}/ && resource.mode == '0644' 48 | resource.mode('0750') if resource.name =~ /#{node['apache']['dir']}/ && resource.mode == '0755' 49 | resource.mode('0640') if resource.name == 'apache2.conf' 50 | end 51 | 52 | # change all the other files not defined as resources 53 | execute 'remove world readable files' do 54 | command "chmod -R o-rw #{node['apache']['dir']}" 55 | not_if "find #{node['apache']['dir']} -perm -o+r -type f -o -perm -o+w -type f | wc -l | egrep '^0$'" 56 | end 57 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json", 3 | "extends": [ 4 | "config:base", 5 | ":gitSignOff" 6 | ], 7 | "dependencyDashboard": true, 8 | "dependencyDashboardAutoclose": true, 9 | "packageRules": [ 10 | { 11 | "matchUpdateTypes": ["patch", "minor"], 12 | "automerge": true 13 | } 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | 3 | require 'chefspec' 4 | require 'chefspec/berkshelf' 5 | require 'coveralls' 6 | 7 | # coverage report 8 | Coveralls.wear! 9 | at_exit { ChefSpec::Coverage.report! } 10 | -------------------------------------------------------------------------------- /spec/unit/recipes/default_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | 3 | require 'spec_helper' 4 | 5 | describe 'apache-hardening::default' do 6 | 7 | before { allow_any_instance_of(Chef::Recipe).to receive(:search) } 8 | let(:runner) { ChefSpec::ServerRunner.new } 9 | let(:node) { runner.node } 10 | let(:chef_run) { runner.converge(described_recipe) } 11 | 12 | before do 13 | stub_command('/usr/sbin/apache2 -t') 14 | stub_command("find /etc/apache2 -perm -o+r -type f -o -perm -o+w -type f | wc -l | egrep '^0$'") 15 | end 16 | 17 | it 'includes apache-hardening::hardening recipe' do 18 | expect(chef_run).to include_recipe('apache-hardening::hardening') 19 | end 20 | 21 | end 22 | -------------------------------------------------------------------------------- /spec/unit/recipes/hardening_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | 3 | require 'spec_helper' 4 | 5 | describe 'apache-hardening::hardening' do 6 | 7 | before { allow_any_instance_of(Chef::Recipe).to receive(:search) } 8 | let(:runner) { ChefSpec::ServerRunner.new } 9 | let(:node) { runner.node } 10 | let(:chef_run) { runner.converge(described_recipe) } 11 | 12 | before do 13 | stub_command('/usr/sbin/apache2 -t') 14 | stub_command("find /etc/apache2 -perm -o+r -type f -o -perm -o+w -type f | wc -l | egrep '^0$'") 15 | end 16 | 17 | it 'creates hardening.conf with correct permissions' do 18 | 19 | expect(chef_run).to create_template(File.join(chef_run.node['apache']['dir'], '/conf-enabled/', 'hardening.conf')).with( 20 | user: 'root', 21 | group: chef_run.node['apache']['root_group'], 22 | mode: '0640' 23 | ) 24 | 25 | end 26 | 27 | # Since we cannot test the definition apache_module itself, we have to test for a side effect to happen 28 | # We check for the not present module file in mods_enabled 29 | it 'disables specified apache modules' do 30 | 31 | chef_run.node['apache_hardening']['modules_to_disable'].each do |module_to_disable| 32 | expect(chef_run).to_not create_file_if_missing("#{chef_run.node['apache']['dir']}/mods-enabled/#{module_to_disable}.load") 33 | end 34 | 35 | end 36 | 37 | it 'checks that the correct alias.conf.erb template is being used' do 38 | 39 | chef_run.run_context.resource_collection.each do |resource| 40 | 41 | next unless resource.name == "#{chef_run.node['apache']['dir']}/mods-available/alias.conf" 42 | 43 | expect(resource.cookbook).to eq('apache-hardening') 44 | 45 | end 46 | 47 | end 48 | 49 | it 'makes sure that it does not flap on o-rw' do 50 | 51 | chef_run.run_context.resource_collection.each do |resource| 52 | 53 | next unless (resource.respond_to? :mode) && !resource.mode.nil? 54 | 55 | expect(resource.mode).to eq('0750') if resource.name =~ /#{chef_run.node['apache']['dir']}/ && resource.mode[1].eql?('7') 56 | expect(resource.mode).to eq('0640') if resource.name =~ /#{chef_run.node['apache']['dir']}/ && resource.mode[1].eql?('6') 57 | expect(resource.mode).to eq('0640') if resource.name == 'apache2.conf' 58 | 59 | end 60 | 61 | end 62 | 63 | it 'executes "remove world readable files"' do 64 | 65 | stub_command("find /etc/apache2 -perm -o+r -type f -o -perm -o+w -type f | wc -l | egrep '^0$'").and_return(false) 66 | expect(chef_run).to run_execute('remove world readable files') 67 | 68 | end 69 | 70 | it 'does not execute "remove world readable files"' do 71 | 72 | stub_command("find /etc/apache2 -perm -o+r -type f -o -perm -o+w -type f | wc -l | egrep '^0$'").and_return(true) 73 | expect(chef_run).to_not run_execute('remove world readable files') 74 | 75 | end 76 | 77 | end 78 | -------------------------------------------------------------------------------- /templates/default/hardening.cnf.erb: -------------------------------------------------------------------------------- 1 | # Additional configuration for Apache. 2 | # 3 | # Generated by Chef 4 | # Generated by apache-hardening module 5 | 6 | 7 | > 8 | # http://httpd.apache.org/docs/2.4/upgrading.html 9 | <% if node['apache']['version'] > '2.2' -%> 10 | Require all granted 11 | <% else -%> 12 | Order Allow,Deny 13 | Deny from all 14 | <% end -%> 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /templates/default/mods/alias.conf.erb: -------------------------------------------------------------------------------- 1 | 2 | # 3 | # Aliases: Add here as many aliases as you need (with no limit). The format is 4 | # Alias fakename realname 5 | # 6 | # Note that if you include a trailing / on fakename then the server will 7 | # require it to be present in the URL. So "/icons" isn't aliased in this 8 | # example, only "/icons/". If the fakename is slash-terminated, then the 9 | # realname must also be slash terminated, and if the fakename omits the 10 | # trailing slash, the realname must also omit it. 11 | # 12 | # We include the /icons/ alias for FancyIndexed directory listings. If 13 | # you do not use FancyIndexing, you may comment this out. 14 | # 15 | Alias /icons/ "<%= node['apache']['icondir'] %>/" 16 | 17 | "> 18 | Options -Indexes -MultiViews -FollowSymLinks 19 | AllowOverride None 20 | <% if node['apache']['version'] == "2.4" -%> 21 | Require all granted 22 | <% else -%> 23 | Order allow,deny 24 | Allow from all 25 | <% end -%> 26 | 27 | 28 | --------------------------------------------------------------------------------