1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-31 03:45:17 +00:00

update disallow_default_namespace and disallow_host_network_port and disallow_host_pid_ipc

This commit is contained in:
Jim Bugwadia 2019-11-10 15:50:18 -08:00
parent 170e2a5179
commit 20736e5e81
9 changed files with 43 additions and 46 deletions

View file

@ -41,15 +41,15 @@ func Test_validate_disallow_automoutingapicred_pass(t *testing.T) {
} }
func Test_validate_disallow_default_namespace(t *testing.T) { func Test_validate_disallow_default_namespace(t *testing.T) {
testScenario(t, "test/scenarios/samples/best_practices/scenario_validate_disallow_default_namespace.yaml") testScenario(t, "test/scenarios/samples/best_practices/disallow_default_namespace.yaml")
} }
func Test_validate_host_network_port(t *testing.T) { func Test_validate_host_network_port(t *testing.T) {
testScenario(t, "test/scenarios/samples/best_practices/disallow_host_network_port.yaml") testScenario(t, "test/scenarios/samples/best_practices/disallow_host_network_port.yaml")
} }
func Test_validate_hostPID_hostIPC(t *testing.T) { func Test_validate_host_PID_IPC(t *testing.T) {
testScenario(t, "test/scenarios/samples/best_practices/scenario_validate_disallow_hostpid_hostipc.yaml") testScenario(t, "test/scenarios/samples/best_practices/disallow_host_pid_ipc.yaml")
} }
func Test_validate_ro_rootfs(t *testing.T) { func Test_validate_ro_rootfs(t *testing.T) {

View file

@ -1,6 +1,6 @@
# Disallow use of default namespace # Disallow use of default namespace
Kubernetes namespaces provide a way to segment and isolate cluster resources across multiple applictaions and users. It is recommended that each workload be isolated in its own namespace and that use of the default namespace be not allowed. Kubernetes namespaces are an optional feature that provide a way to segment and isolate cluster resources across multiple applications and users. As a best practice, workloads should be isolated with namespaces. Namespaces should be required and the default (empty) namespace should not be used.
## Policy YAML ## Policy YAML
@ -10,20 +10,20 @@ Kubernetes namespaces provide a way to segment and isolate cluster resources acr
apiVersion: kyverno.io/v1alpha1 apiVersion: kyverno.io/v1alpha1
kind: ClusterPolicy kind: ClusterPolicy
metadata: metadata:
name: validate-namespace name: disallow-default-namespace
spec: spec:
rules: rules:
- name: check-default-namespace - name: validate-namespace
match: match:
resources: resources:
kinds: kinds:
- Pod - Pod
validate: validate:
message: "Using 'default' namespace is restricted" message: "Using 'default' namespace is not allowed"
pattern: pattern:
metadata: metadata:
namespace: "!default" namespace: "!default"
- name: check-namespace-exist - name: require-namespace
match: match:
resources: resources:
kinds: kinds:

View file

@ -6,13 +6,13 @@ To avoid pod container from having visibility to host process space, validate th
## Policy YAML ## Policy YAML
[disallow_hostpid_hostipc.yaml](best_practices/disallow_hostpid_hostipc.yaml) [disallow_host_pid_ipc.yaml](best_practices/disallow_host_pid_ipc.yaml)
````yaml ````yaml
apiVersion: kyverno.io/v1alpha1 apiVersion: kyverno.io/v1alpha1
kind: ClusterPolicy kind: ClusterPolicy
metadata: metadata:
name: validate-host-pid-ipc name: disallow-host-pid-ipc
annotations: annotations:
policies.kyverno.io/category: Security policies.kyverno.io/category: Security
policies.kyverno.io/description: Sharing the host's PID namespace allows visibility of process policies.kyverno.io/description: Sharing the host's PID namespace allows visibility of process
@ -20,9 +20,9 @@ metadata:
the container process to communicate with processes on the host. To avoid pod container from the container process to communicate with processes on the host. To avoid pod container from
having visibility to host process space, validate that 'hostPID' and 'hostIPC' are set to 'false'. having visibility to host process space, validate that 'hostPID' and 'hostIPC' are set to 'false'.
spec: spec:
validationFailureAction: enforce validationFailureAction: audit
rules: rules:
- name: validate-host-pid-ipc - name: validate-hostPID-hostIPC
match: match:
resources: resources:
kinds: kinds:

View file

@ -44,14 +44,14 @@ These policies are highly recommended.
6. [Disallow docker socket bind mount](DisallowDockerSockMount.md) 6. [Disallow docker socket bind mount](DisallowDockerSockMount.md)
7. [Disallow `hostNetwork` and `hostPort`](DisallowHostNetworkPort.md) 7. [Disallow `hostNetwork` and `hostPort`](DisallowHostNetworkPort.md)
8. [Disallow `hostPID` and `hostIPC`](DisallowHostPIDIPC.md) 8. [Disallow `hostPID` and `hostIPC`](DisallowHostPIDIPC.md)
9. [Disallow unknown image registries](DisallowUnknownRegistries.md) 9. [Disallow use of default namespace](DisallowDefaultNamespace.md)
10. [Disallow latest image tag](DisallowLatestTag.md) 10. [Disallow latest image tag](DisallowLatestTag.md)
11. [Disallow use of default namespace](DisallowDefaultNamespace.md) 11. [Disallow Helm Tiller](DisallowHelmTiller.md)
12. [Require namespace limits and quotas](RequireNSLimitsQuotas.md) 12. [Restrict image registries](DisallowUnknownRegistries.md)
13. [Require pod resource requests and limits](RequirePodRequestsLimits.md) 13. [Require namespace limits and quotas](RequireNSLimitsQuotas.md)
14. [Require pod `livenessProbe` and `readinessProbe`](RequirePodProbes.md) 14. [Require pod resource requests and limits](RequirePodRequestsLimits.md)
15. [Default deny all ingress traffic](DefaultDenyAllIngress.md) 15. [Require pod `livenessProbe` and `readinessProbe`](RequirePodProbes.md)
16. [Disallow Helm Tiller](DisallowHelmTiller.md) 16. [Default deny all ingress traffic](DefaultDenyAllIngress.md)
17. [Add `safe-to-evict` for pods with `emptyDir` and `hostPath` volumes](AddSafeToEvict.md) 17. [Add `safe-to-evict` for pods with `emptyDir` and `hostPath` volumes](AddSafeToEvict.md)
## Additional Policies ## Additional Policies
@ -62,4 +62,4 @@ The policies provide additional best practices and are worthy of close considera
19. [Limit automount of Service Account credentials](DisallowAutomountSACredentials.md) 19. [Limit automount of Service Account credentials](DisallowAutomountSACredentials.md)
20. [Configure Linux Capabilities](AssignLinuxCapabilities.md) 20. [Configure Linux Capabilities](AssignLinuxCapabilities.md)
21. [Limit Kernel parameter access](ConfigureKernelParmeters.md) 21. [Limit Kernel parameter access](ConfigureKernelParmeters.md)
22. [Restrict ingress class](KnownIngressClass.md) 22. [Restrict ingress classes](KnownIngressClass.md)

View file

@ -1,24 +1,26 @@
apiVersion: kyverno.io/v1alpha1 apiVersion: kyverno.io/v1alpha1
kind: ClusterPolicy kind: ClusterPolicy
metadata: metadata:
name: validate-namespace name: disallow-default-namespace
annotations: policies.kyverno.io/category: Isolation
policies.kyverno.io/category: Workload Isolation policies.kyverno.io/description: Kubernetes namespaces are an optional feature
policies.kyverno.io/description: With many users spread across multiple teams, restricting that provide a way to segment and isolate cluster resources across multiple
use of the default namespace and subdividing the cluster by namesoace isolates workloads. applications and users. As a best practice, workloads should be isolated with
namespaces. Namespaces should be required and the default (empty) namespace
should not be used.
spec: spec:
rules: rules:
- name: check-default-namespace - name: validate-namespace
match: match:
resources: resources:
kinds: kinds:
- Pod - Pod
validate: validate:
message: "Using 'default' namespace is restricted" message: "Using 'default' namespace is not allowed"
pattern: pattern:
metadata: metadata:
namespace: "!default" namespace: "!default"
- name: check-namespace-exist - name: require-namespace
match: match:
resources: resources:
kinds: kinds:
@ -28,3 +30,4 @@ spec:
pattern: pattern:
metadata: metadata:
namespace: "?*" namespace: "?*"

View file

@ -1,11 +1,7 @@
apiVersion: kyverno.io/v1alpha1 apiVersion: kyverno.io/v1alpha1
kind: ClusterPolicy kind: ClusterPolicy
metadata: metadata:
name: validate-host-network-hostport name: disallow-host-network-port
annotations:
policies.kyverno.io/category: Security
policies.kyverno.io/description: Using 'hostPort' and 'hostNetwork' allows pods to share
the host network stack, allowing potential snooping of network traffic from an application pod.
spec: spec:
rules: rules:
- name: validate-host-network-port - name: validate-host-network-port
@ -14,11 +10,11 @@ spec:
kinds: kinds:
- Pod - Pod
validate: validate:
message: "Defining hostNetwork and hostPort are not allowed" message: "Using host networking is not allowed"
pattern: pattern:
spec: spec:
(hostNetwork): false (hostNetwork): false
containers: containers:
- name: "*" - name: "*"
ports: ports:
- hostPort: null - hostPort: null

View file

@ -1,7 +1,7 @@
apiVersion: kyverno.io/v1alpha1 apiVersion: kyverno.io/v1alpha1
kind: ClusterPolicy kind: ClusterPolicy
metadata: metadata:
name: validate-host-pid-ipc name: disallow-host-pid-ipc
annotations: annotations:
policies.kyverno.io/category: Security policies.kyverno.io/category: Security
policies.kyverno.io/description: Sharing the host's PID namespace allows visibility of process policies.kyverno.io/description: Sharing the host's PID namespace allows visibility of process
@ -11,7 +11,7 @@ metadata:
spec: spec:
validationFailureAction: audit validationFailureAction: audit
rules: rules:
- name: validate-host-pid-ipc - name: validate-hostPID-hostIPC
match: match:
resources: resources:
kinds: kinds:

View file

@ -5,7 +5,7 @@ input:
expected: expected:
validation: validation:
policyresponse: policyresponse:
policy: validate-namespace policy: disallow-default-namespace
resource: resource:
kind: Pod kind: Pod
apiVersion: v1 apiVersion: v1
@ -14,12 +14,10 @@ expected:
namespace: 'default' namespace: 'default'
name: myapp-pod name: myapp-pod
rules: rules:
- name: check-default-namespace - name: validate-namespace
type: Validation type: Validation
message: "Validation error: Using 'default' namespace is restricted\nValidation rule 'check-default-namespace' failed at path '/metadata/namespace/'."
success: false success: false
- name: check-namespace-exist - name: require-namespace
type: Validation type: Validation
message: "Validation rule 'check-namespace-exist' succeeded."
success: true success: true

View file

@ -1,17 +1,17 @@
# file path relative to project root # file path relative to project root
input: input:
policy: samples/best_practices/disallow_hostpid_hostipc.yaml policy: samples/best_practices/disallow_host_pid_ipc.yaml
resource: test/resources/disallow_hostpid_hostipc.yaml resource: test/resources/disallow_hostpid_hostipc.yaml
expected: expected:
validation: validation:
policyresponse: policyresponse:
policy: validate-host-pid-ipc policy: disallow-host-pid-ipc
resource: resource:
kind: Pod kind: Pod
apiVersion: v1 apiVersion: v1
namespace: '' namespace: ''
name: "nginx-with-hostpid" name: "nginx-with-hostpid"
rules: rules:
- name: validate-host-pid-ipc - name: validate-hostPID-hostIPC
type: Validation type: Validation
success: false success: false