feat(lab9): falco custom rules + conftest hardening policies + bonus … - #9
Merged
Conversation
…cryptominer detection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
feat(lab9): falco custom rules + conftest hardening policies + bonus cryptominer detection
Goal
Deploy Falco (modern eBPF) for runtime threat detection with custom rules, and write Conftest/Rego policies to gate Kubernetes manifests at CI time.
Changes
labs/lab9/falco/rules/custom-rules.yaml— added custom rule "Write to /tmp by container" (detects writes to/tmpinside containers, priority WARNING, tags[container, drift])labs/lab9/falco/rules/cryptominer-rules.yaml— added bonus rule "Possible Cryptominer Activity" combining two indicators (known miner/nc process names viaproc.name, and outbound connections to common mining-pool ports viafd.rport), priority CRITICALlabs/lab9/policies/extra/hardening.rego— added 4 Conftest deny rules:runAsNonRootmust be true,allowPrivilegeEscalationmust be false,capabilities.dropmust includeALL, andresources.limits.memorymust be setsubmissions/lab9.md— full writeup with captured alerts, policy file, Conftest test output, and tuning/reflection discussionTesting
Falco baseline alerts
docker run -d --name lab9-target alpine:3.20 sleep 1d
docker run -d --name falco --privileged
-v /proc:/host/proc:ro -v /boot:/host/boot:ro
-v /lib/modules:/host/lib/modules:ro -v /usr:/host/usr:ro
-v /var/run/docker.sock:/host/var/run/docker.sock
-v "$(pwd)/labs/lab9/falco/rules":/etc/falco/rules.d:ro
falcosecurity/falco:0.43.1 falco -U -o json_output=true -o time_format_iso_8601=true
docker exec -it lab9-target /bin/sh -lc 'echo "shell-in-container test"'
docker exec --user 0 lab9-target /bin/sh -lc 'echo "test" > /tmp/my-write.txt'
grep '^{' labs/lab9/falco/logs/falco.log | jq -c '.rule' | sort -u
-> "Terminal shell in container"
-> "Write to /tmp by container"
Bonus: cryptominer detection
docker exec lab9-target /bin/sh -c 'nc -zv 8.8.8.8 3333 2>&1 || true'
grep '^{' labs/lab9/falco/logs/falco.log | jq -c 'select(.rule == "Possible Cryptominer Activity")'
-> fires with proc=nc cmdline="nc -zv 8.8.8.8 3333"
Conftest policy tests
conftest test labs/lab9/manifests/good-pod.yaml --policy labs/lab9/policies/extra/
-> 4 tests, 4 passed, 0 failures
conftest test labs/lab9/manifests/bad-pod-runasroot.yaml --policy labs/lab9/policies/extra/
-> FAIL: DENY: Pod must have runAsNonRoot = true (4 tests, 3 passed, 1 failure)
conftest test labs/lab9/manifests/bad-pod-no-resources.yaml --policy labs/lab9/policies/extra/
-> FAIL: DENY: Container 'app' must have memory limits (4 tests, 3 passed, 1 failure)
Artifacts & Screenshots
submissions/lab9.mdlabs/lab9/falco/rules/custom-rules.yamllabs/lab9/falco/rules/cryptominer-rules.yamllabs/lab9/policies/extra/hardening.regoChecklist
feat(labN): <topic>stylesubmissions/lab9.md