fix: configure network policies outside kyverno if possible (and stuff)

This commit is contained in:
2024-02-19 15:33:31 +01:00
parent b53088ca4e
commit 839a96dc39
9 changed files with 107 additions and 23 deletions
@@ -0,0 +1,63 @@
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: allow-namespace-traffic
annotations:
policies.kyverno.io/title: Generate NetworkPolicy to Existing Namespaces
policies.kyverno.io/subject: Namespace, NetworkPolicy
kyverno.io/kyverno-version: 1.7.0
policies.kyverno.io/minversion: 1.7.0
kyverno.io/kubernetes-version: "1.23"
policies.kyverno.io/description: >-
Allow all ingress/egress traffic within a namespace.
Allow egress to any pods in the cluster
Allow DNS with layer 7 inspection
spec:
generateExistingOnPolicyUpdate: true
rules:
- name: allow-namespace-traffic
match:
any:
- resources:
kinds:
- Namespace
generate:
synchronize: true
apiVersion: cilium.io/v2
kind: CiliumNetworkPolicy
name: allow-namespace-traffic
namespace: "{{request.object.metadata.name}}"
data:
metadata:
labels:
created-by: kyverno
spec:
endpointSelector: {}
description: "Allow all traffic within a namespace, allow dns, allow egress to all entities in cluster"
ingress:
- fromEndpoints:
- {}
- fromEndpoints:
- matchExpressions:
- key: io.kubernetes.pod.namespace
operator: Exists
egress:
- toEndpoints:
- matchExpressions:
- key: io.kubernetes.pod.namespace
operator: Exists
#authentication:
# mode: "required"
- toEndpoints:
- matchLabels:
io.kubernetes.pod.namespace: kube-system
k8s-app: kube-dns
toPorts:
- ports:
- port: "53"
protocol: UDP
rules:
dns:
- matchPattern: "*"
#authentication:
# mode: "required"
@@ -0,0 +1,44 @@
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
annotations:
policies.kyverno.io/category: Sample
policies.kyverno.io/description: 'Secrets like registry credentials often need
to exist in multiple Namespaces so Pods there have access. Manually duplicating
those Secrets is time consuming and error prone. This policy will copy a Secret
called `regcred` which exists in the `default` Namespace to new Namespaces when
they are created. It will also push updates to the copied Secrets should the
source Secret be changed. '
creationTimestamp: "2024-01-15T11:58:24Z"
name: sync-oceanbox-regcred
spec:
admission: true
background: true
generateExisting: true
rules:
- generate:
apiVersion: v1
clone:
# name: oceanbox-regcred
name: gitlab-pull-secret
namespace: default
kind: Secret
# name: oceanbox-regcred
name: gitlab-pull-secret
namespace: '{{request.object.metadata.name}}'
synchronize: true
exclude:
any:
- resources:
kinds:
- Namespace
names:
- "vcluster-*"
match:
any:
- resources:
kinds:
- Namespace
name: sync-oceanbox-regcred