Implement Docker Bench Security tests as Bats test#147
Implement Docker Bench Security tests as Bats test#147alexei-led wants to merge 31 commits intodocker:masterfrom gaia-adm:bats
Conversation
…nning container, if needed
…nning container, if needed
|
Please sign your commits following these rules: $ git clone -b "bats" git@github.com:gaia-adm/docker-bench-security.git somewhere
$ cd somewhere
$ git rebase -i HEAD~24
editor opens
change each 'pick' to 'edit'
save the file and quit
$ git commit --amend -s --no-edit
$ git rebase --continue # and repeat the amend for each commit
$ git push -fAmmending updates the existing PR. You DO NOT need to open a new one. |
1 similar comment
|
Please sign your commits following these rules: $ git clone -b "bats" git@github.com:gaia-adm/docker-bench-security.git somewhere
$ cd somewhere
$ git rebase -i HEAD~24
editor opens
change each 'pick' to 'edit'
save the file and quit
$ git commit --amend -s --no-edit
$ git rebase --continue # and repeat the amend for each commit
$ git push -fAmmending updates the existing PR. You DO NOT need to open a new one. |
Signed-off-by: Alexei Ledenev <alexei.ledenev@hp.com>
|
Hi @alexei-led, and thanks for all this. |
README.md
Outdated
|
|
||
| [Bats](https://github.com/sstephenson/bats) is a [TAP](http://testanything.org/)-compliant testing framework for Bash. It provides a simple way to verify that the UNIX programs you write behave as expected. | ||
|
|
||
| All Docker Bench scipts are also available as Bats tests. Also container level (and image level) tests are automatically generated for all containers avaiable on host. It's possible to run all or only selected test(s), if you like. |
README.md
Outdated
| -v /etc:/etc --label docker_bench_security \ | ||
| docker-bench-tests | ||
| ``` | ||
| <<<<<<< HEAD |
|
@alexei-led I don't think we should be adding this functionality here. We're currently working on a new version of dockerbench here: https://github.com/diogomonica/actuary . Would love some help pushing it through the finish-line, and this is the exact kind of functionality that we're going towards. |
bats.Dockerfile
Outdated
|
|
||
| RUN curl -o "/tmp/v${BATS_VERSION}.tar.gz" -LS "https://github.com/sstephenson/bats/archive/v${BATS_VERSION}.tar.gz" && \ | ||
| tar -xvzf "/tmp/v${BATS_VERSION}.tar.gz" -C /tmp/ && \ | ||
| bash "/tmp/bats-${BATS_VERSION}/install.sh" /usr/local && \ |
There was a problem hiding this comment.
Since we're installing stuff, any way to verify what we've downloaded?
|
@diogomonica @alexei-led I'm leaving this open for the time being then. |
…egular bash file (ignored by git), see '0_config.example'
…ount whole /etc (in README.md example), but only required sub directoris (otherwise term does not work as expected in Alpine)
|
@konstruktoid Thank you for you comments. I've committed fixes, based on your review comments. Pls, take a look. |
|
@diogomonica Diego, I really like your new project (actuary) - it's definitely going into the right direction: machine readable output and execution of test subset. |
|
Hi @alexei-led, I'm writing most of Actuary's code at the moment. What you mention about containers has already been implemented. When you run a check that concerns containers, Actuary will print the container ID so you know which ones fail the test. Test results are standardized already. We use "Pass", "Fail", "Skip" (if something goes wrong, so the audit can continue) and "Info". "Info" is used exactly for manual inspection. For example test "1.4 Remove all non-essential services from the host" prints all of the host's open ports. We can't know beforehand what's essential and what's not, so we put this under "Info". You 're welcome (and everyone else of course) to test Actuary and report any issues you encounter or features you would like to see implemented :). Contributions are always welcome too! |
|
Hi @zuBux, thank you for replay. Actuary looks very promising, I will take a deeper look. WDYT, about allowing user to configure test parameters, to reduce required manual effort, for example: list of "trusted" users, max containers/host, required cgroups and etc? |
|
@alexei-led @zuBux I think we could allow parameters as part of the config. It should be used sparingly though, it makes things more complex. |
|
@alexei-led @diogomonica Yes, adding parameters to checks makes things a lot more complex. I tried this approach with drydock and my thoughts are:
Unless we find multiple tests which could benefit from this feature, I believe we should avoid it. Instead we should focus more on readable code and reusable functions so users can add their own tests if they want (maybe a custom section?) |
|
IMHO, any list or value, you present, to the user for further inspection, should and could be automated.
|
|
These are all good ideas, but I guess we 'll have to see if they truly add value after some time of testing. Also I think we should stop this conversation here, a PR of another project is not the place to do this :) |
Docker Bench Security scripts are very valuable, but there are some core problems with them.
So, I've forked the
docker-bench-securityand added Bats framework (very small footprint), couple of helper scripts and converted all tests into Bats format (some tests code was reduced drastically too)Content:
bats_testsfolder that contains Bats tests and templatesbats_tests\test_helper:bats-assertandbats-supportrun_test.sh- generates Bats tests from templates (for all containers on host) and executes specified (or all tests), it can produce a timestamp(ed) test result file in TAP format (wit-rflag)generate_tests.sh- a helper script that automatically creates valid Bats tests from predefined templates for all containers on Docker hostbats.Dockerfile- Dockerfile that generates Docker image with all aboveI did this change for our own need. We would like to be able to run Docker Security Bench tests on every machine in our Docker cluster. These tests run automatically when:
We also have a small service that collects all test results from all hosts and send them to another service (test analytics).