2023-09-15 18:18:46 +02:00
|
|
|
---
|
2022-05-25 19:56:22 +05:30
|
|
|
apiVersion: kyverno.io/v1
|
|
|
|
kind: ClusterPolicy
|
|
|
|
metadata:
|
|
|
|
annotations:
|
|
|
|
policies.kyverno.io/category: Multi-Tenancy
|
2023-09-15 18:18:46 +02:00
|
|
|
policies.kyverno.io/description: 'By default, Kubernetes allows communications
|
|
|
|
across all Pods within a cluster. The NetworkPolicy resource and a CNI plug-in
|
|
|
|
that supports NetworkPolicy must be used to restrict communications. A default
|
|
|
|
NetworkPolicy should be configured for each Namespace to default deny all ingress
|
|
|
|
and egress traffic to the Pods in the Namespace. Application teams can then
|
|
|
|
configure additional NetworkPolicy resources to allow desired traffic to application
|
|
|
|
Pods from select sources. This policy will create a new NetworkPolicy resource
|
|
|
|
named `default-deny` which will deny all traffic anytime a new Namespace is
|
|
|
|
created. '
|
2022-05-25 19:56:22 +05:30
|
|
|
policies.kyverno.io/subject: NetworkPolicy
|
2023-09-15 18:18:46 +02:00
|
|
|
policies.kyverno.io/title: Add Network Policy
|
|
|
|
name: add-networkpolicy
|
2022-05-25 19:56:22 +05:30
|
|
|
spec:
|
2023-09-15 18:18:46 +02:00
|
|
|
admission: true
|
|
|
|
background: true
|
2022-05-25 19:56:22 +05:30
|
|
|
rules:
|
2023-09-15 18:18:46 +02:00
|
|
|
- generate:
|
2022-05-25 19:56:22 +05:30
|
|
|
apiVersion: networking.k8s.io/v1
|
|
|
|
data:
|
|
|
|
spec:
|
|
|
|
podSelector: {}
|
|
|
|
policyTypes:
|
|
|
|
- Ingress
|
2023-09-15 18:18:46 +02:00
|
|
|
- Egress
|
|
|
|
kind: NetworkPolicy
|
|
|
|
name: default-deny
|
|
|
|
namespace: '{{request.object.metadata.name}}'
|
|
|
|
synchronize: true
|
|
|
|
match:
|
|
|
|
any:
|
|
|
|
- resources:
|
|
|
|
kinds:
|
|
|
|
- Namespace
|
|
|
|
name: default-deny
|