Skip to content

Commit

Permalink
update test scenarios
Browse files Browse the repository at this point in the history
Signed-off-by: Jaehyun Nam <[email protected]>
  • Loading branch information
nam-jaehyun committed Apr 27, 2022
1 parent 89a420b commit 441a380
Show file tree
Hide file tree
Showing 31 changed files with 370 additions and 6 deletions.
2 changes: 1 addition & 1 deletion examples/multiubuntu/build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ FROM ubuntu:18.04

RUN apt-get update

RUN apt-get install -y net-tools iputils-ping telnet ssh tcpdump nmap dsniff
RUN apt-get install -y net-tools iputils-ping telnet ssh tcpdump nmap dsniff arping
RUN apt-get install -y curl iperf3 netperf ethtool python-scapy python-pip
RUN apt-get install -y iptables bridge-utils apache2 vim

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ spec:
# multiubuntu_test_03

# test
# $ ping -c 1 127.0.0.1
# ping: socket: Operation not permitted
# $ arping -c 1 127.0.0.1
# arping: libnet_init(LIBNET_LINK, <null>): libnet_open_link(): UID/EUID 0 or capability CAP_NET_RAW required
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ spec:
recursive: true
- dir: /proc/ # required to change root to user1 (coarse-grained way)
recursive: true
- dir: /lib/ # used by root and user1
recursive: true
- dir: /sys/ # used by root and user1
recursive: true
- dir: /pts/ # used by root and user1
recursive: true
action:
Allow

Expand Down
7 changes: 7 additions & 0 deletions tests/host_scenarios/kubearmor-dev-next_test_01/cmd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
source: kubearmor-dev
cmd: diff --help
result: failed
---
operation: Process
condition: diff
action: Block
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: security.kubearmor.com/v1
kind: KubeArmorHostPolicy
metadata:
name: hsp-kubearmor-dev-next-proc-path-block
spec:
nodeSelector:
matchLabels:
kubernetes.io/hostname: kubearmor-dev-next
severity: 5
process:
matchPaths:
- path: /usr/bin/diff
action:
Block

# kubearmor-dev-next_test_01

# test
# $ diff --help
# -bash: /usr/bin/diff: Permission denied

# expectation
# anyone cannot execute /usr/bin/diff
7 changes: 7 additions & 0 deletions tests/host_scenarios/kubearmor-dev-next_test_02/cmd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
source: kubearmor-dev
cmd: cat /etc/passwd
result: passed
---
operation: File
condition: /etc/passwd
action: Audit
7 changes: 7 additions & 0 deletions tests/host_scenarios/kubearmor-dev-next_test_02/cmd2
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
source: kubearmor-dev
cmd: head -n 1 /etc/passwd
result: passed
---
operation: File
condition: /etc/passwd
action: Audit
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apiVersion: security.kubearmor.com/v1
kind: KubeArmorHostPolicy
metadata:
name: hsp-kubearmor-dev-next-file-path-audit
spec:
nodeSelector:
matchLabels:
kubernetes.io/hostname: kubearmor-dev-next
severity: 5
file:
matchPaths:
- path: /etc/passwd
action:
Audit

# kubearmor-dev-next_test_02

# test
# $ cat /etc/passwd
# ...
# $ head /etc/passwd
# ...

# expectation
# anyone can access /etc/passwd, but the access would be audited
7 changes: 7 additions & 0 deletions tests/host_scenarios/kubearmor-dev-next_test_03/cmd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
source: kubearmor-dev
cmd: cat /etc/hostname
result: failed
---
operation: File
condition: /etc/hostname
action: Block
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: security.kubearmor.com/v1
kind: KubeArmorHostPolicy
metadata:
name: hsp-kubearmor-dev-next-file-path-block
spec:
nodeSelector:
matchLabels:
kubernetes.io/hostname: kubearmor-dev-next
severity: 5
file:
matchPaths:
- path: /etc/hostname
action:
Block

# kubearmor-dev-next_test_03

# test
# $ cat /etc/hostname
# cat: /etc/hostname: Permission denied

# expectation
# anyone cannot access /etc/hostname
7 changes: 7 additions & 0 deletions tests/host_scenarios/kubearmor-dev-next_test_04/cmd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
source: kubearmor-dev
cmd: bash -c date
result: failed
---
operation: Process
condition: date
action: Block
7 changes: 7 additions & 0 deletions tests/host_scenarios/kubearmor-dev-next_test_04/cmd2
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
source: kubearmor-dev
cmd: bash -c ls
result: passed
---
operation: Process
condition: ls
action: Block
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apiVersion: security.kubearmor.com/v1
kind: KubeArmorHostPolicy
metadata:
name: hsp-kubearmor-dev-next-proc-path-block-fromsource
spec:
nodeSelector:
matchLabels:
kubernetes.io/hostname: kubearmor-dev-next
severity: 5
process:
matchPaths:
- path: /bin/date
fromSource:
- path: /bin/bash # ubuntu
- path: /usr/bin/date
fromSource:
- path: /usr/bin/bash # centos
action:
Block

# kubearmor-dev-next_test_04

# test
# (/home/vagrant/selinux-test/) $ bash -c date
# bash: 1: date: Permission denied
# (/home/vagrant/selinux-test/) $ bash -c ls
# ls ...

# expectation
# (/usr)/bin/bash cannot execute (/usr)/bin/date
# (/usr)/bin/bash can execute any others
7 changes: 7 additions & 0 deletions tests/host_scenarios/kubearmor-dev-next_test_05/cmd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
source: kubearmor-dev
cmd: bash -c date
result: passed
---
operation: Process
condition: date
action: Allow
7 changes: 7 additions & 0 deletions tests/host_scenarios/kubearmor-dev-next_test_05/cmd2
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
source: kubearmor-dev
cmd: bash -c ls
result: failed
---
operation: Process
condition: ls
action: Allow
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apiVersion: security.kubearmor.com/v1
kind: KubeArmorHostPolicy
metadata:
name: hsp-kubearmor-dev-next-proc-path-allow-fromsource
spec:
nodeSelector:
matchLabels:
kubernetes.io/hostname: kubearmor-dev-next
severity: 5
process:
matchPaths:
- path: /bin/date
fromSource:
- path: /bin/bash # ubuntu
- path: /usr/bin/date
fromSource:
- path: /usr/bin/bash # centos
action:
Allow

# kubearmor-dev-next_test_05

# test
# $ bash -c date
# ...
# $ bash -c ls
# bash: /usr/bin/ls: Permission denied

# expectation
# (/usr)/bin/bash can only execute (/usr)/bin/date
# (/usr)/bin/bash cannot execute any others
7 changes: 7 additions & 0 deletions tests/host_scenarios/kubearmor-dev-next_test_06/cmd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
source: kubearmor-dev
cmd: head -n 1 /etc/hostname
result: failed
---
operation: File
condition: /etc/hostname
action: Block
7 changes: 7 additions & 0 deletions tests/host_scenarios/kubearmor-dev-next_test_06/cmd2
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
source: kubearmor-dev
cmd: head -n 1 /etc/hosts
result: passed
---
operation: File
condition: /etc/hosts
action: Block
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
apiVersion: security.kubearmor.com/v1
kind: KubeArmorHostPolicy
metadata:
name: hsp-kubearmor-dev-next-file-path-block-fromsource
spec:
nodeSelector:
matchLabels:
kubernetes.io/hostname: kubearmor-dev-next
severity: 5
file:
matchPaths:
- path: /etc/hostname
fromSource:
- path: /usr/bin/head
action:
Block

# kubearmor-dev-next_test_06

# test
# $ head /etc/hostname
# head: cannot open '/etc/hostname' for reading: Permission denied
# $ head /etc/hosts
# ...

# expectation
# /usr/bin/head cannot access /etc/hostname
# /usr/bin/head can access any others
7 changes: 7 additions & 0 deletions tests/host_scenarios/kubearmor-dev-next_test_07/cmd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
source: kubearmor-dev
cmd: head -n 1 /etc/hostname
result: passed
---
operation: File
condition: /etc/hostname
action: Allow
7 changes: 7 additions & 0 deletions tests/host_scenarios/kubearmor-dev-next_test_07/cmd2
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
source: kubearmor-dev
cmd: head -n 1 /etc/hosts
result: failed
---
operation: File
condition: /etc/hosts
action: Allow
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
apiVersion: security.kubearmor.com/v1
kind: KubeArmorHostPolicy
metadata:
name: hsp-kubearmor-dev-next-file-path-allow-fromsource
spec:
nodeSelector:
matchLabels:
kubernetes.io/hostname: kubearmor-dev-next
severity: 5
file:
matchPaths:
- path: /etc/hostname
fromSource:
- path: /usr/bin/head
action:
Allow

# kubearmor-dev-next_test_07

# test
# $ head /etc/hostname
# kubearmor-dev
# $ head /etc/hosts
# head: /etc/hosts: Permission denied

# expectation
# /usr/bin/head can only access /etc/hostname
# /usr/bin/head cannot access any others
7 changes: 7 additions & 0 deletions tests/host_scenarios/kubearmor-dev-next_test_08/cmd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
source: kubearmor-dev
cmd: head -n 1 /etc/default/useradd
result: passed
---
operation: File
condition: /etc/default/useradd
action: Allow
7 changes: 7 additions & 0 deletions tests/host_scenarios/kubearmor-dev-next_test_08/cmd2
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
source: kubearmor-dev
cmd: head -n 1 /etc/hostname
result: failed
---
operation: File
condition: /etc/hostname
action: Allow
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apiVersion: security.kubearmor.com/v1
kind: KubeArmorHostPolicy
metadata:
name: hsp-kubearmor-dev-next-file-dir-allow-fromsource
spec:
nodeSelector:
matchLabels:
kubernetes.io/hostname: kubearmor-dev-next
severity: 5
file:
matchDirectories:
- dir: /etc/default/
recursive: true
fromSource:
- path: /usr/bin/head
action:
Allow

# kubearmor-dev-next_test_08

# test
# $ head /etc/default/useradd
# Default values for useradd(8) ...
# $ head /etc/hostname
# head: /etc/hostname: Permission denied

# expectation
# /usr/bin/head can only access /etc/default/*
# /usr/bin/head cannot access any others
7 changes: 7 additions & 0 deletions tests/host_scenarios/kubearmor-dev-next_test_09/cmd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
source: kubearmor-dev
cmd: head -n 1 /etc/default/useradd
result: failed
---
operation: File
condition: /etc/default/useradd
action: Block
7 changes: 7 additions & 0 deletions tests/host_scenarios/kubearmor-dev-next_test_09/cmd2
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
source: kubearmor-dev
cmd: head -n 1 /etc/hostname
result: passed
---
operation: File
condition: /etc/hostname
action: Block
Loading

0 comments on commit 441a380

Please sign in to comment.