1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-06 16:06:56 +00:00
kyverno/samples/AddDefaultNetworkPolicy.md

41 lines
1.2 KiB
Markdown
Raw Normal View History

2019-10-23 14:06:03 -07:00
# Default deny all ingress traffic
2019-11-10 21:27:50 -08:00
By default, Kubernetes allows communications across all pods within a cluster. Network policies and, a CNI that supports network policies, must be used to restrict communinications.
2019-10-23 15:36:37 -07:00
2019-11-10 21:27:50 -08:00
A default `NetworkPolicy` should be configured for each namespace to default deny all ingress 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.
2019-10-23 14:06:03 -07:00
## Policy YAML
2019-11-10 21:34:22 -08:00
[add_network_policy.yaml](best_practices/add_network_policy.yaml)
2019-10-23 14:06:03 -07:00
````yaml
2019-11-13 13:56:20 -08:00
apiVersion: kyverno.io/v1
2019-10-23 14:06:03 -07:00
kind: ClusterPolicy
metadata:
2019-11-10 21:27:50 -08:00
name: add-networkpolicy
2019-10-23 14:06:03 -07:00
spec:
rules:
2019-12-10 09:51:15 -08:00
- name: default-deny-ingress
2019-10-23 14:06:03 -07:00
match:
resources:
kinds:
- Namespace
name: "*"
exclude:
namespaces:
- "kube-system"
- "default"
- "kube-public"
- "kyverno"
2019-10-23 14:06:03 -07:00
generate:
kind: NetworkPolicy
name: default-deny-ingress
593 feature (#594) * initial commit * background policy validation * correct message * skip non-background policy process for add/update * add Generate Request CR * generate Request Generator Initial * test generate request CR generation * initial commit gr generator * generate controller initial framework * add crd for generate request * gr cleanup controller initial commit * cleanup controller initial * generate mid-commit * generate rule processing * create PV on generate error * embed resource type * testing phase 1- generate resources with variable substitution * fix tests * comment broken test #586 * add printer column for state * return if existing resource for clone * set resync time to 2 mins & remove resource version check in update handler for gr * generate events for reporting * fix logs * initial commit * fix trailing quote in patch * remove comments * initial condition (equal & notequal) * initial support for conditions * initial support fo conditions in generate * support precondition checks * cleanup * re-evaluate GR on namespace update using dynamic informers * add status for generated resources * display loaded variable SA * support delete cleanup of generate request main resources * fix log * remove namespace from SA username * support multiple variables per statement for scalar values * fix fail variables * add check for userInfo * validation checks for conditions * update policy * refactor logs * code review * add openapispec for clusterpolicy preconditions * Update documentation * CR fixes * documentation * CR fixes * update variable * fix logs * update policy * pre-defined variables (serviceAccountName & serviceAccountNamespace) * update test
2020-01-07 15:13:57 -08:00
namespace: "{{request.object.metadata.name}}"
2019-10-23 14:06:03 -07:00
data:
spec:
# select all pods in the namespace
podSelector: {}
policyTypes:
- Ingress
2019-10-23 14:06:03 -07:00
````