78 lines
3.1 KiB
YAML
78 lines
3.1 KiB
YAML
|
|
# Tenant isolation for `customer1` (audit finding F3 / A5-1, card t_fed52919).
|
||
|
|
#
|
||
|
|
# Two objects, two jobs:
|
||
|
|
# 1. `default-deny` (networking.k8s.io/v1) selects every pod in the namespace
|
||
|
|
# for BOTH directions and allows nothing. It is the only object here that
|
||
|
|
# creates a deny — a Kubernetes NetworkPolicy with `podSelector: {}` and no
|
||
|
|
# rules is an unambiguous deny-all in Cilium's k8s-policy path, and unlike a
|
||
|
|
# CiliumClusterwideNetworkPolicy with `endpointSelector: {}` it cannot
|
||
|
|
# accidentally select kube-system/Flux/CoreDNS.
|
||
|
|
# 2. `customer1-allow` (CiliumNetworkPolicy) re-adds exactly the traffic the
|
||
|
|
# tenant needs. Cilium unions all policies that select an endpoint, so the
|
||
|
|
# deny above plus this allow list is the effective policy.
|
||
|
|
#
|
||
|
|
# Why a CiliumNetworkPolicy for the allows: the sources to permit are Cilium
|
||
|
|
# *entities* (`ingress` = the Gateway listener proxy, `host` = the node/kubelet),
|
||
|
|
# which a stock NetworkPolicy cannot name.
|
||
|
|
#
|
||
|
|
# What this namespace is allowed to talk to — and nothing else:
|
||
|
|
# * its own pods (odoo/metabase -> pg:5432, the pg-backup CronJob -> pg),
|
||
|
|
# * kube-dns on 53.
|
||
|
|
# It gets NO internet egress (world) and NO API-server egress: the sandbox has
|
||
|
|
# no external dependency (backup.yaml: dumps stay on the local PVC, the Job has
|
||
|
|
# `automountServiceAccountToken: false`). If odoo/metabase are ever resumed and
|
||
|
|
# need an external service, add it here explicitly — that is the point.
|
||
|
|
apiVersion: networking.k8s.io/v1
|
||
|
|
kind: NetworkPolicy
|
||
|
|
metadata:
|
||
|
|
name: default-deny
|
||
|
|
namespace: customer1
|
||
|
|
spec:
|
||
|
|
podSelector: {}
|
||
|
|
policyTypes:
|
||
|
|
- Ingress
|
||
|
|
- Egress
|
||
|
|
---
|
||
|
|
apiVersion: cilium.io/v2
|
||
|
|
kind: CiliumNetworkPolicy
|
||
|
|
metadata:
|
||
|
|
name: customer1-allow
|
||
|
|
namespace: customer1
|
||
|
|
spec:
|
||
|
|
description: >-
|
||
|
|
Customer-1 tenant: gateway + kubelet ingress only, egress to own namespace
|
||
|
|
and cluster DNS only.
|
||
|
|
endpointSelector: {}
|
||
|
|
ingress:
|
||
|
|
# reserved:ingress Cilium Gateway/listener proxy on siriussec (8086/8087)
|
||
|
|
# reserved:host this node's kubelet probes / host-network datapath
|
||
|
|
# reserved:remote-node node-sourced traffic when the pod is on another node
|
||
|
|
# reserved:health cilium-health probes
|
||
|
|
- fromEntities:
|
||
|
|
- ingress
|
||
|
|
- host
|
||
|
|
- remote-node
|
||
|
|
- health
|
||
|
|
# Intra-namespace pod -> pod (app -> db, sidecars, the backup CronJob).
|
||
|
|
# Cilium enforces policy at BOTH ends, so this allow must exist in ingress as
|
||
|
|
# well as egress — measured on `piedmont`: with only the egress rule a pod
|
||
|
|
# could not reach its own Service (TimeoutError).
|
||
|
|
- fromEndpoints:
|
||
|
|
- matchLabels:
|
||
|
|
io.kubernetes.pod.namespace: customer1
|
||
|
|
egress:
|
||
|
|
# Cluster DNS (CoreDNS only).
|
||
|
|
- toEndpoints:
|
||
|
|
- matchLabels:
|
||
|
|
io.kubernetes.pod.namespace: kube-system
|
||
|
|
k8s-app: kube-dns
|
||
|
|
toPorts:
|
||
|
|
- ports:
|
||
|
|
- port: "53"
|
||
|
|
protocol: UDP
|
||
|
|
- port: "53"
|
||
|
|
protocol: TCP
|
||
|
|
# Intra-namespace only: odoo/metabase -> pg:5432 and the backup Job -> pg.
|
||
|
|
- toEndpoints:
|
||
|
|
- matchLabels:
|
||
|
|
io.kubernetes.pod.namespace: customer1
|