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

undefined method `downcase' for nil:NilClass #32

Closed
kidbrax opened this issue May 5, 2017 · 8 comments
Closed

undefined method `downcase' for nil:NilClass #32

kidbrax opened this issue May 5, 2017 · 8 comments
Labels

Comments

@kidbrax
Copy link

kidbrax commented May 5, 2017

When executing this profile, I get this:

/usr/local/bundle/gems/inspec-1.23.0/lib/resources/docker.rb:32:in `block (2 levels) in <class:DockerContainerFilter>': undefined method `downcase' for nil:NilClass (NoMethodError)
	from /usr/local/bundle/gems/inspec-1.23.0/lib/utils/filter.rb:63:in `instance_eval'
	from /usr/local/bundle/gems/inspec-1.23.0/lib/utils/filter.rb:63:in `block in where'
	from /usr/local/bundle/gems/inspec-1.23.0/lib/utils/filter.rb:63:in `each'
	from /usr/local/bundle/gems/inspec-1.23.0/lib/utils/filter.rb:63:in `find_all'
	from /usr/local/bundle/gems/inspec-1.23.0/lib/utils/filter.rb:63:in `where'
	from /usr/local/bundle/gems/inspec-1.23.0/lib/resources/docker.rb:32:in `block in <class:DockerContainerFilter>'
	from /usr/local/bundle/gems/inspec-1.23.0/lib/utils/filter.rb:204:in `block in create_connector'
	from /usr/local/bundle/gems/inspec-1.23.0/lib/utils/filter.rb:178:in `call'
	from /usr/local/bundle/gems/inspec-1.23.0/lib/utils/filter.rb:178:in `block (2 levels) in connect'
	from cis-docker-benchmark-master/controls/container_images.rb:50:in `block in load_with_context'
	from /usr/local/bundle/gems/inspec-1.23.0/lib/inspec/rule.rb:51:in `instance_eval'
	from /usr/local/bundle/gems/inspec-1.23.0/lib/inspec/rule.rb:51:in `initialize'
	from /usr/local/bundle/gems/inspec-1.23.0/lib/inspec/control_eval_context.rb:71:in `new'
	from /usr/local/bundle/gems/inspec-1.23.0/lib/inspec/control_eval_context.rb:71:in `block (2 levels) in create'
	from cis-docker-benchmark-master/controls/container_images.rb:37:in `load_with_context'
	from /usr/local/bundle/gems/inspec-1.23.0/lib/inspec/profile_context.rb:146:in `instance_eval'
	from /usr/local/bundle/gems/inspec-1.23.0/lib/inspec/profile_context.rb:146:in `load_with_context'
	from /usr/local/bundle/gems/inspec-1.23.0/lib/inspec/profile_context.rb:130:in `load_control_file'
	from /usr/local/bundle/gems/inspec-1.23.0/lib/inspec/profile.rb:149:in `block in collect_tests'
	from /usr/local/bundle/gems/inspec-1.23.0/lib/inspec/profile.rb:146:in `each'
	from /usr/local/bundle/gems/inspec-1.23.0/lib/inspec/profile.rb:146:in `collect_tests'
	from /usr/local/bundle/gems/inspec-1.23.0/lib/inspec/dependencies/dependency_set.rb:65:in `block in each'
	from /usr/local/bundle/gems/inspec-1.23.0/lib/inspec/dependencies/dependency_set.rb:64:in `each'
	from /usr/local/bundle/gems/inspec-1.23.0/lib/inspec/dependencies/dependency_set.rb:64:in `each'
	from /usr/local/bundle/gems/inspec-1.23.0/lib/inspec/profile.rb:144:in `collect_tests'
	from /usr/local/bundle/gems/inspec-1.23.0/lib/inspec/runner.rb:90:in `block in load'
	from /usr/local/bundle/gems/inspec-1.23.0/lib/inspec/runner.rb:79:in `each'
	from /usr/local/bundle/gems/inspec-1.23.0/lib/inspec/runner.rb:79:in `load'
	from /usr/local/bundle/gems/inspec-1.23.0/lib/inspec/runner.rb:100:in `run'
	from /usr/local/bundle/gems/inspec-1.23.0/lib/inspec/base_cli.rb:83:in `run_tests'
	from /usr/local/bundle/gems/inspec-1.23.0/lib/inspec/cli.rb:166:in `exec'
	from /usr/local/bundle/gems/thor-0.19.4/lib/thor/command.rb:27:in `run'
	from /usr/local/bundle/gems/thor-0.19.4/lib/thor/invocation.rb:126:in `invoke_command'
	from /usr/local/bundle/gems/thor-0.19.4/lib/thor.rb:369:in `dispatch'
	from /usr/local/bundle/gems/thor-0.19.4/lib/thor/base.rb:444:in `start'
	from /usr/local/bundle/gems/inspec-1.23.0/bin/inspec:12:in `<top (required)>'
	from /usr/local/bundle/bin/inspec:17:in `load'
	from /usr/local/bundle/bin/inspec:17:in `<main>'
@chris-rock
Copy link
Member

Can you open the inspec shell via inspec shell and run docker.containers.running?.ids?

@chris-rock
Copy link
Member

Seems to be a bug in inspec

@kidbrax
Copy link
Author

kidbrax commented May 5, 2017

Sure, this is what I get:

Welcome to the interactive InSpec Shell
To find out how to use it, type: help

You are currently running on:

    OS platform:  amazon
    OS family:  amazon
    OS release: 2016.09

inspec> docker
=> Docker Host
inspec> docker.containers
=> #<Inspec::Resources::DockerContainerFilter:0x0000000233f480 @containers=[{}]>
inspec> docker.containers.running?
=> #<Inspec::Resources::DockerContainerFilter:0x0000000221d610> with status downcase start_with? "up"
inspec> docker.containers.running?.ids
=> []

@jdel
Copy link

jdel commented May 8, 2017

I am running into the same issue with a docker container I built based on chef/inspec where I just add the docker client:

Dockerfile

FROM chef/inspec:1.23.0

RUN apk add --update docker \
 && rm -rf /usr/bin/docker-* /usr/bin/dockerd \
 && rm -rf /var/cache/apk/*

I am running the container and bind mount my docker socket and get the same error as described:

docker run -ti --rm --name inspec -v /var/run/docker.sock:/var/run/docker.sock:ro jdel/inspec exec https://github.com/dev-sec/cis-docker-benchmark
[2017-05-03T15:41:40+00:00] WARN: URL target https://github.com/dev-sec/cis-docker-benchmark transformed to https://github.com/dev-sec/cis-docker-benchmark/archive/master.tar.gz. Consider using the git fetcher
/usr/local/bundle/gems/inspec-1.23.0/lib/resources/docker.rb:32:in `block (2 levels) in <class:DockerContainerFilter>': undefined method `downcase' for nil:NilClass (NoMethodError)
[...]

Below is the result from docker run -ti --rm --name inspec -v /var/run/docker.sock:/var/run/docker.sock:ro jdel/inspec shell with the troubleshooting commands you requested:
I have a different output than @kidbrax

Welcome to the interactive InSpec Shell
To find out how to use it, type: help

You are currently running on:

    OS platform:  alpine
    OS family:  alpine
    OS release: 3.4.6

inspec> docker
=> Docker Host
inspec> docker.containers
=> #<Inspec::Resources::DockerContainerFilter:0x005648f99aa298 @containers=[{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}]>
inspec> docker.containers.running?
NoMethodError: undefined method `downcase' for nil:NilClass
from /usr/local/bundle/gems/inspec-1.23.0/lib/resources/docker.rb:32:in `block (2 levels) in <class:DockerContainerFilter>'
inspec> docker.containers.running?.ids?
NoMethodError: undefined method `downcase' for nil:NilClass
from /usr/local/bundle/gems/inspec-1.23.0/lib/resources/docker.rb:32:in `block (2 levels) in <class:DockerContainerFilter>'

If I run docker run -ti --rm --name inspec -v /var/run/docker.sock:/var/run/docker.sock:ro --entrypoint /bin/sh jdel/inspec I can then do a docker ps and see my containers running (4 of them).

To me this looks like a bug in docker.containers.running?

I have tried inspec 1.21, 1.22, and 1.23 with no success.

@chris-rock
Copy link
Member

@jdel Thank you, I agree that this looks like a bug in docker.containers.running? Can you please open an issue in https://github.com/chef/inspec/issues ?

@kidbrax
Copy link
Author

kidbrax commented May 9, 2017

I have submitted an issue to inspec, inspec/inspec#1788

@chris-rock chris-rock added the bug label Jun 25, 2017
@chris-rock
Copy link
Member

Based on the inspec implementation, our baseline works only with Docker 1.13+

@chris-rock
Copy link
Member

I opened PR #35 to document the required docker version in our Readme. Since InSpec is keeping track of that, we can lower the required version if InSpec supports more. I am going to close this issue now. Please reopen if it required

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

No branches or pull requests

3 participants