1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-29 10:55:05 +00:00

add disallow_host_network_hostport.yaml

This commit is contained in:
Shuting Zhao 2019-10-08 21:51:35 -07:00
parent 0c0a9a69a6
commit ce41e4a99d
8 changed files with 55 additions and 23 deletions

View file

@ -1,16 +1,16 @@
apiVersion: kyverno.io/v1alpha1
kind: ClusterPolicy
metadata:
name: validate-host-network-port
name: validate-host-network-hostport
spec:
rules:
- name: validate-host-network-port
- name: validate-host-network-hostport
match:
resources:
kinds:
- Pod
validate:
message: "Host network and port are not allowed"
message: "hostNetwork and hostPort are not allowed"
pattern:
spec:
hostNetwork: false

View file

@ -89,7 +89,7 @@ func Test_validate_host_path(t *testing.T) {
}
func Test_validate_host_network_port(t *testing.T) {
testScenario(t, "test/scenarios/test/scenario_validate_host_network_port.yaml")
testScenario(t, "test/scenarios/test/scenario_validate_disallow_host_network_hostport.yaml")
}
func Test_validate_hostPID_hostIPC(t *testing.T) {

View file

@ -0,0 +1,20 @@
apiVersion: kyverno.io/v1alpha1
kind: ClusterPolicy
metadata:
name: validate-host-network-hostport
spec:
rules:
- name: validate-host-network-hostport
match:
resources:
kinds:
- Pod
validate:
message: "hostNetwork and hostPort are not allowed"
pattern:
spec:
hostNetwork: false
containers:
- name: "*"
ports:
- hostPort: null

View file

@ -0,0 +1,12 @@
apiVersion: v1
kind: Pod
metadata:
name: nginx-host-network
spec:
hostNetwork: false
containers:
- name: nginx-host-network
image: nginx
ports:
- containerPort: 80
hostPort: 80

View file

@ -1,7 +1,7 @@
# file path relative to project root
input:
policy: samples/best_practices/deny_runasrootuser.yaml
resource: test/manifest/resource_validate_deny_runasrootuser.yaml
resource: test/manifest/deny_runasrootuser.yaml
expected:
validation:
policyresponse:

View file

@ -0,0 +1,18 @@
# file path relative to project root
input:
policy: samples/best_practices/disallow_host_network_hostport.yaml
resource: test/manifest/disallow_host_network_hostport.yaml.yaml
expected:
validation:
policyresponse:
policy: validate-host-network-hostport
resource:
kind: Pod
apiVersion: v1
namespace: ''
name: "nginx-host-network"
rules:
- name: validate-host-network-hostport
type: Validation
message: "Validation rule 'validate-host-network-hostport' failed at '/spec/containers/0/ports/0/hostPort/' for resource Pod//nginx-host-network. hostNetwork and hostPort are not allowed"
success: false

View file

@ -1,18 +0,0 @@
# file path relative to project root
input:
policy: examples/best_practices/policy_validate_host_network_port.yaml
resource: examples/best_practices/resources/resource_validate_host_netwok_port.yaml
expected:
validation:
policyresponse:
policy: validate-host-network-port
resource:
kind: Pod
apiVersion: v1
namespace: ''
name: "nginx-host-network"
rules:
- name: validate-host-network-port
type: Validation
message: "Validation rule 'validate-host-network-port' failed at '/spec/containers/0/ports/0/hostPort/' for resource Pod//nginx-host-network. Host network and port are not allowed"
success: false