-
Notifications
You must be signed in to change notification settings - Fork 92
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
Use native severspec functions to check uid and gid of files #134
Conversation
This is a valid fix but took about about an hour diving into this because I noticed some unexpected behavior with this control that I don't know if its a regression or not. The symbol syntax should behave the same as the string syntax, as long as the file actually exists. i.e when running against a docker an ubuntu:{focal, jammy} based container, none of the cis-dil-benchmark/controls/1_4_secure_boot_settings.rb Lines 30 to 44 in ab97de3
but what I'm seeing when testing locally is that all of the files are being tested rather than just one of the files (both in container and VM), which I don't think is the desired behavior
@spencer-cdw can you provide some more detail about your testing environment (OS version, path of actual grub conf file, etc) as well as CLI output? $ cat /etc/os-release
PRETTY_NAME="Ubuntu 22.04.1 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.1 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.co
$ cinc-auditor version
5.18.14
$ cinc-auditor exec https://github.com/dev-sec/cis-dil-benchmark --controls=cis-dil-benchmark-1.4.1
[2022-11-03T01:47:03+00:00] WARN: URL target https://github.com/dev-sec/cis-dil-benchmark transformed to https://github.com/dev-sec/cis-dil-benchmark/archive/master.tar.gz. Consider using the git fetcher
[2022-11-03T01:47:05+00:00] WARN: Cannot find a UUID for your node.
Profile: CIS Distribution Independent Linux Benchmark Profile (cis-dil-benchmark)
Version: 0.4.13
Target: local://
Target ID:
× cis-dil-benchmark-1.4.1: Ensure permissions on bootloader config are configured (21 failed)
× File /boot/grub/grub.conf is expected to exist
expected File /boot/grub/grub.conf to exist
✔ File /boot/grub/grub.conf is expected not to be readable by group
✔ File /boot/grub/grub.conf is expected not to be writable by group
✔ File /boot/grub/grub.conf is expected not to be executable by group
✔ File /boot/grub/grub.conf is expected not to be readable by other
✔ File /boot/grub/grub.conf is expected not to be writable by other
✔ File /boot/grub/grub.conf is expected not to be executable by other
× File /boot/grub/grub.conf gid is expected to cmp == 0
expected: 0
got:
(compared using `cmp` matcher)
× File /boot/grub/grub.conf uid is expected to cmp == 0
expected: 0
got:
(compared using `cmp` matcher)
× File /boot/grub/grub.cfg is expected to exist
expected File /boot/grub/grub.cfg to exist
✔ File /boot/grub/grub.cfg is expected not to be readable by group
✔ File /boot/grub/grub.cfg is expected not to be writable by group
✔ File /boot/grub/grub.cfg is expected not to be executable by group
✔ File /boot/grub/grub.cfg is expected not to be readable by other
✔ File /boot/grub/grub.cfg is expected not to be writable by other
✔ File /boot/grub/grub.cfg is expected not to be executable by other
× File /boot/grub/grub.cfg gid is expected to cmp == 0
expected: 0
got:
(compared using `cmp` matcher)
× File /boot/grub/grub.cfg uid is expected to cmp == 0
expected: 0
got:
(compared using `cmp` matcher)
× File /boot/grub/menu.lst is expected to exist
expected File /boot/grub/menu.lst to exist
✔ File /boot/grub/menu.lst is expected not to be readable by group
✔ File /boot/grub/menu.lst is expected not to be writable by group
✔ File /boot/grub/menu.lst is expected not to be executable by group
✔ File /boot/grub/menu.lst is expected not to be readable by other
✔ File /boot/grub/menu.lst is expected not to be writable by other
✔ File /boot/grub/menu.lst is expected not to be executable by other
× File /boot/grub/menu.lst gid is expected to cmp == 0
expected: 0
got:
(compared using `cmp` matcher)
× File /boot/grub/menu.lst uid is expected to cmp == 0
expected: 0
got:
(compared using `cmp` matcher)
× File /boot/boot/grub/grub.conf is expected to exist
expected File /boot/boot/grub/grub.conf to exist
✔ File /boot/boot/grub/grub.conf is expected not to be readable by group
✔ File /boot/boot/grub/grub.conf is expected not to be writable by group
✔ File /boot/boot/grub/grub.conf is expected not to be executable by group
✔ File /boot/boot/grub/grub.conf is expected not to be readable by other
✔ File /boot/boot/grub/grub.conf is expected not to be writable by other
✔ File /boot/boot/grub/grub.conf is expected not to be executable by other
× File /boot/boot/grub/grub.conf gid is expected to cmp == 0
expected: 0
got:
(compared using `cmp` matcher)
× File /boot/boot/grub/grub.conf uid is expected to cmp == 0
expected: 0
got:
(compared using `cmp` matcher)
× File /boot/boot/grub/grub.cfg is expected to exist
expected File /boot/boot/grub/grub.cfg to exist
✔ File /boot/boot/grub/grub.cfg is expected not to be readable by group
✔ File /boot/boot/grub/grub.cfg is expected not to be writable by group
✔ File /boot/boot/grub/grub.cfg is expected not to be executable by group
✔ File /boot/boot/grub/grub.cfg is expected not to be readable by other
✔ File /boot/boot/grub/grub.cfg is expected not to be writable by other
✔ File /boot/boot/grub/grub.cfg is expected not to be executable by other
× File /boot/boot/grub/grub.cfg gid is expected to cmp == 0
expected: 0
got:
(compared using `cmp` matcher)
× File /boot/boot/grub/grub.cfg uid is expected to cmp == 0
expected: 0
got:
(compared using `cmp` matcher)
× File /boot/boot/grub/menu.lst is expected to exist
expected File /boot/boot/grub/menu.lst to exist
✔ File /boot/boot/grub/menu.lst is expected not to be readable by group
✔ File /boot/boot/grub/menu.lst is expected not to be writable by group
✔ File /boot/boot/grub/menu.lst is expected not to be executable by group
✔ File /boot/boot/grub/menu.lst is expected not to be readable by other
✔ File /boot/boot/grub/menu.lst is expected not to be writable by other
✔ File /boot/boot/grub/menu.lst is expected not to be executable by other
× File /boot/boot/grub/menu.lst gid is expected to cmp == 0
expected: 0
got:
(compared using `cmp` matcher)
× File /boot/boot/grub/menu.lst uid is expected to cmp == 0
expected: 0
got:
(compared using `cmp` matcher)
× File /boot/grub2/grub.cfg is expected to exist
expected File /boot/grub2/grub.cfg to exist
✔ File /boot/grub2/grub.cfg is expected not to be readable by group
✔ File /boot/grub2/grub.cfg is expected not to be writable by group
✔ File /boot/grub2/grub.cfg is expected not to be executable by group
✔ File /boot/grub2/grub.cfg is expected not to be readable by other
✔ File /boot/grub2/grub.cfg is expected not to be writable by other
✔ File /boot/grub2/grub.cfg is expected not to be executable by other
× File /boot/grub2/grub.cfg gid is expected to cmp == 0
expected: 0
got:
(compared using `cmp` matcher)
× File /boot/grub2/grub.cfg uid is expected to cmp == 0
expected: 0
got:
(compared using `cmp` matcher)
Profile Summary: 0 successful controls, 1 control failure, 0 controls skipped
Test Summary: 42 successful, 21 failures, 0 skipped
|
I think I would like to use the specialized inspec functions for this, like in our other baselines: it { should be_owned_by sshd_custom_user }
it { should be_grouped_into os.darwin? ? 'wheel' : sshd_custom_user } see: https://serverspec.org/resource_types.html#file Would you like to change this on all occasions? |
Certainly. I've just pushed an update to the branch that refactors all of them. |
Additional information on my environment. I have a docker container with packer/inspec/ansible installed
Packer is building 18.04/20.04/22.04 ubuntu images on aws/gcp/azure Running I am seeing the same behavior where the |
The new syntax is working: I've created a new issue to look more into the |
Signed-off-by: Spencer Owen <[email protected]>
Signed-off-by: Spencer Owen <[email protected]>
Signed-off-by: Spencer Owen <[email protected]>
In the past I've either used the
@schurzi is there a special function for determine Do you know of a way to list all of the supported functions for a specific resource? I've always just kind of just trial and error'd things based of the class methods. $ cinc-auditor shell
Welcome to the interactive InSpec Shell
To find out how to use it, type: help
You are currently running on:
Name: ubuntu
Families: debian, linux, unix, os
Release: 22.04
Arch: x86_64
inspec> file('/etc/os-release').class.superclass.instance_methods(false).sort
=> [:allowed?,
:basename,
:block_device?,
:character_device?,
:contain,
:content,
:directory?,
:executable?,
:exist?,
:file,
:file?,
:file_version,
:gid,
:group,
:grouped_into?,
:immutable?,
:link_path,
:linked_to?,
:md5sum,
:mode,
:mode?,
:more_permissive_than?,
:mount_options,
:mounted?,
:mtime,
:owned_by?,
:owner,
:path,
:pipe?,
:product_version,
:readable?,
:selinux_label,
:setgid?,
:setuid?,
:sgid,
:sha256sum,
:shallow_link_path,
:size,
:socket?,
:source,
:source_path,
:sticky,
:sticky?,
:suid,
:symlink?,
:to_s,
:type,
:uid,
:version?,
:writable?]
inspec> |
Signed-off-by: Spencer Owen <[email protected]>
I was able to filter the extra tests by adding the following: describe.one do
grub_conf.locations.each do |f|
next unless file(f).exist?
describe file(f) do The only potential problem is that the entire control is considered skipped if none of the files in additional environment setup if grub conf file doesn't exist (i.e. docker container) FROM ubuntu:jammy as base
RUN : \
&& set -eu \
&& apt-get -q update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
ca-certificates \
curl \
git \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
&& :
FROM base as cinc-auditor-bin
ARG CINC_AUDITOR_VER=5.18.14
WORKDIR /workspace
RUN : \
&& set -eu \
# only here to avoid error message from inspec
&& git init \
&& . /etc/os-release \
&& curl \
--fail-early \
--silent \
--show-error \
--location \
--remote-name \
"http://downloads.cinc.sh/files/stable/cinc-auditor/${CINC_AUDITOR_VER}/${ID}/${VERSION_ID}/cinc-auditor_${CINC_AUDITOR_VER}-1_$(dpkg --print-architecture).deb" \
&& dpkg -i "cinc-auditor_${CINC_AUDITOR_VER}-1_$(dpkg --print-architecture).deb" \
&& rm *.deb \
# this is only needed for the container
&& mkdir -p /boot/grub \
&& touch /boot/grub/grub.cfg && chmod go-r /boot/grub/grub.cfg \
&& : build$ docker build -t ubuntu/cinc-auditor . --target cinc-auditor-bin
...
<build output>
... run$ docker run -it ubuntu/cinc-auditor bash -c 'cinc-auditor exec https://github.com/deric4/cis-dil-benchmark.git --controls=cis-dil-benchmark-1.4.1'
[2022-11-04T12:05:57+00:00] WARN: Cannot find a UUID for your node.
Profile: CIS Distribution Independent Linux Benchmark Profile (cis-dil-benchmark)
Version: 0.4.13
Target: local://
Target ID:
✔ cis-dil-benchmark-1.4.1: Ensure permissions on bootloader config are configured
✔ File /boot/grub/grub.cfg is expected to exist
✔ File /boot/grub/grub.cfg is expected not to be readable by group
✔ File /boot/grub/grub.cfg is expected not to be writable by group
✔ File /boot/grub/grub.cfg is expected not to be executable by group
✔ File /boot/grub/grub.cfg is expected not to be readable by other
✔ File /boot/grub/grub.cfg is expected not to be writable by other
✔ File /boot/grub/grub.cfg is expected not to be executable by other
✔ File /boot/grub/grub.cfg gid is expected to cmp == 0
✔ File /boot/grub/grub.cfg uid is expected to cmp == 0
Profile Summary: 1 successful control, 0 control failures, 0 controls skipped
Test Summary: 9 successful, 0 failures, 0 skipped |
@deric4 Great reproduction case. I reproduced your test. I also removed the following line from the docker container and confirmed that 0 tests were executed.
|
I linked the
I always use the documentation site I linked. Your way of listing the instance methods is also valid and very creative. :D @spencer-cdw I'd like to merge this now as is. We should solve the other problems in separate issues/PRs. Is the current state complete from your point of view? |
Yes, Before if a file didn't exist, it would fail with error
Now if a file doesn't exist, it fails with error
This is a cleaner failure (in my opinion) and uses the built in Note: There was 1 instance where a check was literally looking to see if the root users I think this is good to merge as is. We can figure out why some tests aren't being skipped in this related issue #136 and #137 Because that behavior/bug is the same both before and after this change, I feel confident that this isn't introducing any regressions. |
Signed-off-by: Spencer Owen <[email protected]>
CIS Check 1.4.1 throws the following error
There are 10 instances in this repo where a file gid/uid should == 0.
In 9 of those instances, the string syntax is used
This is the only instace where the symbol syntax is used
Similar comparison such as
1.5.2
uses a string and works as expectedhttps://github.com/dev-sec/cis-dil-benchmark/blob/master/controls/5_1_configure_cron.rb#L73-L74