Skip to content

Commit

Permalink
add default posture block test case based fromsourceallow
Browse files Browse the repository at this point in the history
Modified test script to accomodate DefaultPosture logs

Signed-off-by: daemon1024 <[email protected]>
  • Loading branch information
daemon1024 committed Mar 21, 2022
1 parent 3f239bf commit 64140bf
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 4 deletions.
1 change: 1 addition & 0 deletions KubeArmor/enforcer/appArmorProfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,7 @@ func (ae *AppArmorEnforcer) GenerateProfileBody(securityPolicies []tp.SecurityPo

// Resolve conflicts
ae.ResolvedProcessWhiteListConflicts(&processWhiteList, fromSources, &fusionProcessWhiteList)

// body

profileBody := ""
Expand Down
7 changes: 7 additions & 0 deletions tests/scenarios/github_test_12/cmd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
source: ubuntu-1-deployment
cmd: curl 142.250.193.46
result: passed
---
operation: Network
condition: SOCK_STREAM
action: Allow
7 changes: 7 additions & 0 deletions tests/scenarios/github_test_12/cmd2
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
source: ubuntu-1-deployment
cmd: curl google.com
result: failed
---
operation: Network
condition: SOCK_DGRAM
action: Block
7 changes: 7 additions & 0 deletions tests/scenarios/github_test_12/cmd3
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
source: ubuntu-1-deployment
cmd: wget --tries=1 142.250.193.46
result: failed
---
operation: Network
condition: SOCK_STREAM
action: Block
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: security.kubearmor.com/v1
kind: KubeArmorPolicy
metadata:
name: ksp-ubuntu-1-net-tcp-from-source-allow-curl
namespace: github
spec:
severity: 8
selector:
matchLabels:
container: ubuntu-1
network:
matchProtocols:
- protocol: tcp
fromSource:
- path: /usr/bin/curl
action:
Allow
2 changes: 1 addition & 1 deletion tests/test-scenarios-github.sh
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ function should_find_blocked_log() {
fi

if [[ $6 -eq 0 ]]; then
audit_log=$($CAT_LOG | grep -E "$1.*policyName.*\"$2\".*$match_type.*$3.*resource.*$4.*$5" | tail -n 1 | grep -v Passed)
audit_log=$($CAT_LOG | grep -E "$1.*policyName.*\"$2|DefaultPosture\".*$match_type.*$3.*resource.*$4.*$5" | tail -n 1 | grep -v Passed)
else
audit_log=$($CAT_LOG | grep -E "$1.*policyName.*\"NativePolicy\".*$match_type.*$3.*resource.*$4.*$5" | tail -n 1 | grep -v Passed)
fi
Expand Down
4 changes: 2 additions & 2 deletions tests/test-scenarios-in-runtime.sh
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ function should_find_blocked_log() {

if [[ $KUBEARMOR = "kubearmor"* ]]; then
if [[ $6 -eq 0 ]]; then
audit_log=$(kubectl -n kube-system exec $KUBEARMOR -- grep -E "$1.*policyName.*\"$2\".*$match_type.*$3.*resource.*$4.*$5" $ARMOR_LOG | tail -n 1 | grep -v Passed)
audit_log=$(kubectl -n kube-system exec $KUBEARMOR -- grep -E "$1.*policyName.*\"$2|DefaultPosture\".*$match_type.*$3.*resource.*$4.*$5" $ARMOR_LOG | tail -n 1 | grep -v Passed)
else
audit_log=$(kubectl -n kube-system exec $KUBEARMOR -- grep -E "$1.*policyName.*\"NativePolicy\".*$match_type.*$3.*resource.*$4.*$5" $ARMOR_LOG | tail -n 1 | grep -v Passed)
fi
Expand All @@ -222,7 +222,7 @@ function should_find_blocked_log() {
fi
else # local
if [[ $6 -eq 0 ]]; then
audit_log=$(grep -E "$1.*policyName.*\"$2\".*$match_type.*$3.*resource.*$4.*$5" $ARMOR_LOG | tail -n 1 | grep -v Passed)
audit_log=$(grep -E "$1.*policyName.*\"$2|DefaultPosture\".*$match_type.*$3.*resource.*$4.*$5" $ARMOR_LOG | tail -n 1 | grep -v Passed)
else
audit_log=$(grep -E "$1.*policyName.*\"NativePolicy\".*$match_type.*$3.*resource.*$4.*$5" $ARMOR_LOG | tail -n 1 | grep -v Passed)
fi
Expand Down
2 changes: 1 addition & 1 deletion tests/test-scenarios-local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ function should_find_blocked_log() {
fi

if [[ $6 -eq 0 ]]; then
audit_log=$(grep -E "$1.*policyName.*\"$2\".*$match_type.*$3.*resource.*$4.*$5" $ARMOR_LOG | tail -n 1 | grep -v Passed)
audit_log=$(grep -E "$1.*policyName.*\"$2|DefaultPosture\".*$match_type.*$3.*resource.*$4.*$5" $ARMOR_LOG | tail -n 1 | grep -v Passed)
else
audit_log=$(grep -E "$1.*policyName.*\"NativePolicy\".*$match_type.*$3.*resource.*$4.*$5" $ARMOR_LOG | tail -n 1 | grep -v Passed)
fi
Expand Down

0 comments on commit 64140bf

Please sign in to comment.