Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apache_conf resource seems to be using incorrect paths to amalgamate apache config (only Centos/RHEL?) #1013

Closed
davidcpell opened this issue Sep 2, 2016 · 3 comments · Fixed by #1014
Milestone

Comments

@davidcpell
Copy link
Contributor

Description

The Compliance tests I'm writing make heavy use of the apache_conf resource to validate httpd configuration. As I understand it, the resource builds a hash accessible via apache_conf.params by gathering all .conf and .load files in the files in apache/httpd config directory and combining them.

The problem is that the resource seems to be using incorrect paths and is therefore failing to find anything but my standard /etc/httpd/conf/httpd.conf file.

Here is an example of a simple test:

control 'WA000-WWA022' do
  impact 0.2 # review
  title 'The KeepAlive directive must be enabled.' 

  describe apache_conf do 
    its('KeepAlive') { should cmp 'On' }
  end
end

When I run $ chef exec kitchen verify, I can see this output in stdout:

find_files(): exit 1 from `find /etc/httpd/conf/etc/httpd/mods-enabled/*.load -maxdepth 1 -type f`
find_files(): exit 1 from `find /etc/httpd/conf/etc/httpd/mods-enabled/*.conf -maxdepth 1 -type f`
find_files(): exit 1 from `find /etc/httpd/conf/etc/httpd/ports.conf -maxdepth 1 -type f`
find_files(): exit 1 from `find /etc/httpd/conf/etc/httpd/conf-enabled/*.conf -maxdepth 1 -type f`
find_files(): exit 1 from `find /etc/httpd/conf/etc/httpd/sites-enabled/*.conf -maxdepth 1 -type f`
find_files(): exit 1 from `find /etc/httpd/conf/etc/httpd/mods-enabled/*.load -maxdepth 1 -type f`
find_files(): exit 1 from `find /etc/httpd/conf/etc/httpd/mods-enabled/*.conf -maxdepth 1 -type f`
find_files(): exit 1 from `find /etc/httpd/conf/etc/httpd/ports.conf -maxdepth 1 -type f`
find_files(): exit 1 from `find /etc/httpd/conf/etc/httpd/conf-enabled/*.conf -maxdepth 1 -type f`
find_files(): exit 1 from `find /etc/httpd/conf/etc/httpd/sites-enabled/*.conf -maxdepth 1 -type f`
find_files(): exit 1 from `find /etc/httpd/conf/etc/httpd/mods-enabled/*.load -maxdepth 1 -type f`
find_files(): exit 1 from `find /etc/httpd/conf/etc/httpd/mods-enabled/*.conf -maxdepth 1 -type f`
find_files(): exit 1 from `find /etc/httpd/conf/etc/httpd/ports.conf -maxdepth 1 -type f`
find_files(): exit 1 from `find /etc/httpd/conf/etc/httpd/conf-enabled/*.conf -maxdepth 1 -type f`
find_files(): exit 1 from `find /etc/httpd/conf/etc/httpd/sites-enabled/*.conf -maxdepth 1 -type f`
find_files(): exit 1 from `find /etc/httpd/conf/etc/httpd/mods-enabled/*.load -maxdepth 1 -type f`
find_files(): exit 1 from `find /etc/httpd/conf/etc/httpd/mods-enabled/*.conf -maxdepth 1 -type f`
find_files(): exit 1 from `find /etc/httpd/conf/etc/httpd/ports.conf -maxdepth 1 -type f`
find_files(): exit 1 from `find /etc/httpd/conf/etc/httpd/conf-enabled/*.conf -maxdepth 1 -type f`
find_files(): exit 1 from `find /etc/httpd/conf/etc/httpd/sites-enabled/*.conf -maxdepth 1 -type f`

As you can see, it's failing to find any files, and the find path looks odd: /etc/httpd/conf/etc/httpd/sites-enabled. The standard path to sites-enabled is /etc/httpd/sites-enabled, same with mods-enabled etc.

Perplexed, I generated a new dummy cookbook to start from scratch and use Centos 7.2 for good measure. All I changed was installing Apache via package 'httpd' in the default recipe, which will grab version 2.4 for Centos 7. Added a similar test using apache_conf and got the following output:

find_files(): exit 1 from `find /etc/httpd/conf/conf.modules.d/*.conf -maxdepth 1 -type f`
find_files(): exit 1 from `find /etc/httpd/conf/conf.d/*.conf -maxdepth 1 -type f`

Something seems off, as my default conf.d and conf.modules.d are in /etc/httpd, not /etc/httpd/conf.

Still curious, I added Ubuntu 14.04 to the platforms in my dummy cookbook's kitchen config, installed apache2 and didn't get any failure outputs when running the test.

InSpec and Platform Version

Tested on:
Windows 7 Enterprise, SP1
ChefDK 0.17.17
kitchen 1.11.1
apache 2.2 installed with community/supermarket apache2 cookbook
Virtual Box + Centos 6.7 for running tests

Replication Case

  1. $ chef generate cookbook test
  2. Add package 'httpd' to default recipe
  3. Use centos-6.7 and/or centos-7.2 as platforms in kitchen.yml
  4. Add a test to test/recipes/default_test.rb that uses apache_conf
  5. $ kitchen verify

Stacktrace

See stdout content pasted above.

@chris-rock chris-rock added this to the 0.33.0 milestone Sep 4, 2016
@davidcpell
Copy link
Contributor Author

davidcpell commented Sep 6, 2016

@chris-rock @jeremymv2 I just upgraded to 0.33.0 but am still having this issue with the apache_conf resource:

$ chef exec gem list inspec
inspec (0.33.0)

$ chef exec inspec version
0.33.0

$ chef exec kitchen verify apache-centos-67
-----> Starting Kitchen (v1.11.1)
-----> Verifying <apache-centos-67>...
       Use `C:/Users/c5249136/code/chef/cookbooks/stig/test/recipes/apache` for testing
find_files(): exit 1 from `find /etc/httpd/etc/httpd/mods-enabled/*.load -maxdepth 1 -type f`
find_files(): exit 1 from `find /etc/httpd/etc/httpd/mods-enabled/*.conf -maxdepth 1 -type f`
find_files(): exit 1 from `find /etc/httpd/etc/httpd/ports.conf -maxdepth 1 -type f`
find_files(): exit 1 from `find /etc/httpd/etc/httpd/conf-enabled/*.conf -maxdepth 1 -type f`
find_files(): exit 1 from `find /etc/httpd/etc/httpd/sites-enabled/*.conf -maxdepth 1 -type f`
find_files(): exit 1 from `find /etc/httpd/etc/httpd/mods-enabled/*.load -maxdepth 1 -type f`
find_files(): exit 1 from `find /etc/httpd/etc/httpd/mods-enabled/*.conf -maxdepth 1 -type f`
find_files(): exit 1 from `find /etc/httpd/etc/httpd/ports.conf -maxdepth 1 -type f`
find_files(): exit 1 from `find /etc/httpd/etc/httpd/conf-enabled/*.conf -maxdepth 1 -type f`
find_files(): exit 1 from `find /etc/httpd/etc/httpd/sites-enabled/*.conf -maxdepth 1 -type f`
find_files(): exit 1 from `find /etc/httpd/etc/httpd/mods-enabled/*.load -maxdepth 1 -type f`
find_files(): exit 1 from `find /etc/httpd/etc/httpd/mods-enabled/*.conf -maxdepth 1 -type f`
find_files(): exit 1 from `find /etc/httpd/etc/httpd/ports.conf -maxdepth 1 -type f`
find_files(): exit 1 from `find /etc/httpd/etc/httpd/conf-enabled/*.conf -maxdepth 1 -type f`
find_files(): exit 1 from `find /etc/httpd/etc/httpd/sites-enabled/*.conf -maxdepth 1 -type f`
find_files(): exit 1 from `find /etc/httpd/etc/httpd/mods-enabled/*.load -maxdepth 1 -type f`
find_files(): exit 1 from `find /etc/httpd/etc/httpd/mods-enabled/*.conf -maxdepth 1 -type f`
find_files(): exit 1 from `find /etc/httpd/etc/httpd/ports.conf -maxdepth 1 -type f`
find_files(): exit 1 from `find /etc/httpd/etc/httpd/conf-enabled/*.conf -maxdepth 1 -type f`
find_files(): exit 1 from `find /etc/httpd/etc/httpd/sites-enabled/*.conf -maxdepth 1 -type f`

This was after uninstalling 0.29.0 with the following command:

$ chef exec gem uninstall -i C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0 inspec --version 0.29.0

It looks like the conf part of the lookup path is gone but /etc/httpd is still doubled.

davidcpell added a commit to davidcpell/inspec that referenced this issue Sep 9, 2016
If the path is absolute, just use what was passed, otherwise build an
absolute path using `@conf_dir`.

Fixes inspec#1013

I've got what seemed to me to be the necessary ingredients for a
successful unit test. I added the mock file and referenced it in
`helper.rb` both in the commands hash and files hash. Using
`binding.pry` I saw that the path was valid when it got sent through the
`mockfile` lamda, but the test is erroring when it gets to
`ApacheConf#read_content` at line 79 where `read_file(to_read[0])` is
called. Apparently at that point it can't find the file.

Could someone with more familiarity with the mocking system tell me what
I'm missing there? :)
chris-rock pushed a commit that referenced this issue Sep 20, 2016
If the path is absolute, just use what was passed, otherwise build an
absolute path using `@conf_dir`.

Fixes #1013

I've got what seemed to me to be the necessary ingredients for a
successful unit test. I added the mock file and referenced it in
`helper.rb` both in the commands hash and files hash. Using
`binding.pry` I saw that the path was valid when it got sent through the
`mockfile` lamda, but the test is erroring when it gets to
`ApacheConf#read_content` at line 79 where `read_file(to_read[0])` is
called. Apparently at that point it can't find the file.

Could someone with more familiarity with the mocking system tell me what
I'm missing there? :)
davidcpell added a commit to davidcpell/inspec that referenced this issue Sep 20, 2016
If the path is absolute, just use what was passed, otherwise build an
absolute path using `@conf_dir`.

Fixes inspec#1013
@monoranjang
Copy link

Is this issue resolved

@davidcpell
Copy link
Contributor Author

Yes, a PR was merged to address it on Sep 9, 2016.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants