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

Add CIS Agent for automated CIS compliance checking #2881

Merged
merged 27 commits into from
Jun 21, 2023

Conversation

stmcginnis
Copy link
Contributor

@stmcginnis stmcginnis commented Mar 10, 2023

Issue number:

Closes #2731

Description of changes:

This adds tooling to be able to run Bottlerocket CIS compliance checks.

This is made up of three parts:

  • Add command line that can check the various system settings and report the results
  • Wire up apiserver to be able to call this CLI and get its results
  • Wire up apiclient as the user interface for someone to get compliance status from a running system

Testing done:

  • Built and deployed image, verified level 1 and level 2 checks were performed correctly with the bloodhound CLI.

Removed from this PR, but just for the sake of showing test coverage, also did:

  • Tested apiserver endpoint by using apiclient raw -m GET -u /cis-report and apiclient raw -m GET -u /cis-report?level=2&format=json.
  • Test apiclient interface.
    • Ran apiclient and verified help output contained information about new subcommand.
    • Ran apiclient cisreport and verified default level 1 text report was output.
    • Ran apiclient cisreport -l 2 and verified level 2 report generated.
    • Ran apiclient cisreport -f json and verified json report generated. Ran through jq to view pretty-print view.
    • Ran apiclient cisreport -f invalid and verified error message returned.

Terms of contribution:

By submitting this pull request, I agree that this contribution is dual-licensed under the terms of both the Apache License, version 2.0, and the MIT license.

@stmcginnis stmcginnis marked this pull request as draft March 10, 2023 23:47
@stmcginnis
Copy link
Contributor Author

stmcginnis commented Mar 10, 2023

This is already quite large, so I've broken each checker into separate commits to try to make it a little easier to review.

We may want to consider merging this one first to get the CLI on the system, then have a separate PR for the API plumbing just to keep things simple. For now, marking as draft until we decide on an approach.

API wiring was relatively small, so just included it here.

@stmcginnis stmcginnis marked this pull request as ready for review March 15, 2023 15:49
Copy link
Contributor

@arnaldo2792 arnaldo2792 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still going through it but here are a few things that caught my eye.

sources/bloodhound/src/main.rs Outdated Show resolved Hide resolved
sources/bloodhound/src/main.rs Show resolved Hide resolved
sources/bloodhound/src/main.rs Show resolved Hide resolved
sources/bloodhound/src/main.rs Outdated Show resolved Hide resolved
sources/bloodhound/src/main.rs Show resolved Hide resolved
sources/bloodhound/src/main.rs Outdated Show resolved Hide resolved
sources/bloodhound/src/main.rs Outdated Show resolved Hide resolved
@stmcginnis stmcginnis force-pushed the cis-agent branch 2 times, most recently from e98bff1 to 4a0cd1f Compare March 18, 2023 16:15
@stmcginnis
Copy link
Contributor Author

Improved report information by adding a metadata file to be included in the checkers directory. This gives a little more flexibility if we want to have multiple types of compliance checks by just pointing bloodhound at a different checks directory where it can discover metadata about the checks being performed.

jpculp
jpculp previously requested changes Mar 23, 2023
sources/bloodhound/Cargo.toml Outdated Show resolved Hide resolved
@stmcginnis
Copy link
Contributor Author

Force pushed a refactoring of the code to make it better organized.

@stmcginnis stmcginnis force-pushed the cis-agent branch 2 times, most recently from 446505c to a0e4f32 Compare March 28, 2023 22:33
@stmcginnis
Copy link
Contributor Author

And a couple more force-pushes to get rid of commits that are already in develop but GitHub somehow thinks they are new. :/

@jpculp jpculp dismissed their stale review March 29, 2023 23:15

Chrono feature setting was resolved.

sources/api/apiclient/README.md Outdated Show resolved Hide resolved
sources/api/apiclient/src/cisreport.rs Outdated Show resolved Hide resolved
sources/api/apiserver/src/server/mod.rs Outdated Show resolved Hide resolved
sources/bloodhound/README.md Outdated Show resolved Hide resolved
sources/bloodhound/src/args.rs Outdated Show resolved Hide resolved
sources/bloodhound/src/lib.rs Outdated Show resolved Hide resolved
sources/bloodhound/src/bin/bottlerocket-checks/checks.rs Outdated Show resolved Hide resolved
sources/bloodhound/src/bin/bottlerocket-checks/checks.rs Outdated Show resolved Hide resolved
sources/bloodhound/src/bin/bottlerocket-checks/checks.rs Outdated Show resolved Hide resolved
@stmcginnis
Copy link
Contributor Author

Removed apiclient and apiserver commits for now to keep this smaller and to work through some of the suggestions there.

sources/bloodhound/src/output.rs Show resolved Hide resolved
packages/os/Cargo.toml Show resolved Hide resolved
sources/bloodhound/src/lib.rs Show resolved Hide resolved
sources/bloodhound/src/lib.rs Show resolved Hide resolved
sources/bloodhound/src/lib.rs Show resolved Hide resolved
sources/bloodhound/src/lib.rs Show resolved Hide resolved
sources/bloodhound/src/results.rs Show resolved Hide resolved
sources/bloodhound/src/lib.rs Show resolved Hide resolved
sources/bloodhound/src/bin/bottlerocket-checks/checks.rs Outdated Show resolved Hide resolved
sources/bloodhound/src/lib.rs Show resolved Hide resolved
sources/bloodhound/README.md Outdated Show resolved Hide resolved
sources/bloodhound/src/lib.rs Outdated Show resolved Hide resolved
sources/bloodhound/src/lib.rs Outdated Show resolved Hide resolved
sources/bloodhound/src/args.rs Outdated Show resolved Hide resolved
sources/bloodhound/src/main.rs Show resolved Hide resolved
sources/bloodhound/src/bin/bottlerocket-checks/checks.rs Outdated Show resolved Hide resolved
sources/bloodhound/src/bin/bottlerocket-checks/checks.rs Outdated Show resolved Hide resolved
sources/bloodhound/src/bin/bottlerocket-checks/checks.rs Outdated Show resolved Hide resolved
This adds the 1.1.1.1 check for the UDF module.

Signed-off-by: Sean McGinnis <[email protected]>
This adds the 1.3.1 benchmark to ensure dm-verity is in use.

Signed-off-by: Sean McGinnis <[email protected]>
This adds a check for CIS 1.4.1 to verify setuid core dumps are
disabled.

Signed-off-by: Sean McGinnis <[email protected]>
This adds a CIS check for 1.4.2 to verify ASLR is enabled.

Signed-off-by: Sean McGinnis <[email protected]>
This adds CIS check 1.4.3 to verify unprivileged eBPF is disabled.

Signed-off-by: Sean McGinnis <[email protected]>
This add CIS check 1.4.4 to verify user namespaces are disabled.

Signed-off-by: Sean McGinnis <[email protected]>
This adds CIS 1.5.1 to verify selinux enforcement.

Signed-off-by: Sean McGinnis <[email protected]>
This adds CIS 1.5.2 to verify kernel lockdown mode is enabled.

Signed-off-by: Sean McGinnis <[email protected]>
This adds CIS 2.1.1.1 to verify ntp is configured.

Signed-off-by: Sean McGinnis <[email protected]>
This adds CIS 3.1.1 to verify send_redirects are disabled.

Signed-off-by: Sean McGinnis <[email protected]>
Adds CIS 3.2.1 to verify source routed packets are disabled.

Signed-off-by: Sean McGinnis <[email protected]>
This adds CIS 3.2.2 to verify ICMP redirects are not accepted.

Signed-off-by: Sean McGinnis <[email protected]>
This adds CIS 3.2.3 to verify secure ICMP redirects are not accepted.

Signed-off-by: Sean McGinnis <[email protected]>
This add CIS 3.2.4 to verify suspicious packets are logged.

Signed-off-by: Sean McGinnis <[email protected]>
This adds CIS 3.2.5 to verify broadcast ICMP requests are ignored.

Signed-off-by: Sean McGinnis <[email protected]>
Adds CIS 3.2.6 to verify bogus ICMP responses are ignored.

Signed-off-by: Sean McGinnis <[email protected]>
Adds CIS 3.2.7 to verify TCP SYN cookies are enabled.

Signed-off-by: Sean McGinnis <[email protected]>
This adds CIS 3.3.1 to verify SCTP is disabled.

Signed-off-by: Sean McGinnis <[email protected]>
This adds CIS 3.4.1.1 to verify default deny firewall policy.

Signed-off-by: Sean McGinnis <[email protected]>
Adds CIS 3.4.1.2 to verify IPv4 loopback traffic policy.

Signed-off-by: Sean McGinnis <[email protected]>
This adds CIS 3.4.2.1 to verify IPv6 default deny firewall policy.

Signed-off-by: Sean McGinnis <[email protected]>
Adds CIS 3.4.2.2 to verify IPv6 koopback traffic is configured.

Signed-off-by: Sean McGinnis <[email protected]>
Adds CIS 4.1.1.1 to verify journald configuration.

Signed-off-by: Sean McGinnis <[email protected]>
This adds CIS 4.1.2 to verify file permissions on journal files.

Signed-off-by: Sean McGinnis <[email protected]>
sources/bloodhound/src/output.rs Show resolved Hide resolved
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 this pull request may close these issues.

Add CIS benchmark agent for easy compliance reporting
5 participants