Skip to content

Commit a22f01d

Browse files
authored
feat: allow dynamic list of ingress rules (#21)
The control NetworkPolicy only ever allowed traffic from the ingress-nginx namespace, with no way to add more. In clusters that deny pod-to-pod traffic by default, that leaves no way to permit other legitimate callers, such as PgDog pods reaching the control plane's API. Add networkPolicy.extraIngress, a list of NetworkPolicyIngressRule entries appended to the control NetworkPolicy's ingress rules verbatim, alongside the existing ingress-nginx rule.
1 parent 0f030c4 commit a22f01d

4 files changed

Lines changed: 70 additions & 0 deletions

File tree

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ The PgDog deployment contains the following components:
4848
| ConfigMap | Configuration for the control plane. |
4949
| Secret | Secret that stores the key used to encrypt authentication cookies. |
5050
| Service account, Cluster role, Cluster role bindings | Service account with RBAC to access select Kube APIs. See [RBAC](#rbac) for more details. |
51+
| NetworkPolicy | Optional; restricts ingress/egress traffic. See [NetworkPolicy](#networkpolicy) for more details. |
5152

5253
In addition to installing the PgDog control plane, this chart will deploy a Redis deployment (with one replica). The control plane uses Redis for storing
5354
metrics. The Redis deployment has the following components:
@@ -293,6 +294,37 @@ In the above example, the dashboard can see workloads in every namespace, but it
293294

294295
If your cluster manages RBAC out-of-band (a platform team's controller, GitOps, an admission policy), set `control.rbac.create: false`. The chart then renders no ServiceAccount, no ClusterRole/Binding, and no Role/Bindings, and the deployment runs the pod with `automountServiceAccountToken: false`. The dashboard still serves the UI, but every Kubernetes-backed view will be empty until you bind an externally-managed ServiceAccount with equivalent permissions to the pod yourself.
295296

297+
## NetworkPolicy
298+
299+
When `networkPolicy.enabled` is `true`, the chart renders a `NetworkPolicy` for the control pod and one for Redis, restricting traffic to what the control plane actually needs:
300+
301+
- Ingress on `control.port` from the `ingress-nginx` namespace only.
302+
- Egress to Redis, to `kube-system` for DNS, and to the public internet on 5432 (Postgres) and 443 (HTTPS, e.g. the AWS/CloudWatch/RDS APIs), excluding RFC1918 private ranges.
303+
- Redis accepts ingress only from the control pod and allows no egress.
304+
305+
In clusters that deny pod-to-pod traffic by default, the built-in ingress-nginx rule alone often isn't enough — for example, PgDog pods calling the control plane's API need their own rule. Use `networkPolicy.extraIngress` to add any number of additional ingress rules to the control `NetworkPolicy`:
306+
307+
```yaml
308+
networkPolicy:
309+
enabled: true
310+
extraIngress:
311+
- from:
312+
- namespaceSelector:
313+
matchLabels:
314+
kubernetes.io/metadata.name: pgdog
315+
podSelector:
316+
matchLabels:
317+
app.kubernetes.io/name: pgdog
318+
ports:
319+
- protocol: TCP
320+
port: 8080
321+
```
322+
323+
| Option | Description |
324+
|-|-|
325+
| `networkPolicy.enabled` | Render the control and Redis `NetworkPolicy` resources (bool, default `false`). |
326+
| `networkPolicy.extraIngress` | Additional ingress rules appended to the control `NetworkPolicy`, on top of the built-in ingress-nginx rule. Each entry follows the standard `NetworkPolicyIngressRule` schema (`from`/`ports`) and is passed through verbatim (list, default `[]`). |
327+
296328
## AWS access (EKS / IRSA)
297329

298330
The control plane reads RDS topology and CloudWatch metrics so the dashboard can show your databases alongside the PgDog workloads. To do that in EKS without baking long-lived keys into the cluster, the recommended path is **IRSA** (IAM Roles for Service Accounts).

templates/networkpolicy.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ spec:
2020
ports:
2121
- protocol: TCP
2222
port: {{ .Values.control.port }}
23+
{{- with .Values.networkPolicy.extraIngress }}
24+
{{- toYaml . | nindent 2 }}
25+
{{- end }}
2326
egress:
2427
- to:
2528
- podSelector:

test/values-networkpolicy.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
networkPolicy:
2+
enabled: true
3+
extraIngress:
4+
- from:
5+
- namespaceSelector:
6+
matchLabels:
7+
kubernetes.io/metadata.name: pgdog
8+
podSelector:
9+
matchLabels:
10+
app.kubernetes.io/name: pgdog
11+
ports:
12+
- protocol: TCP
13+
port: 8080
14+
- from:
15+
- ipBlock:
16+
cidr: 10.0.0.0/16

values.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,25 @@ redis:
191191

192192
networkPolicy:
193193
enabled: false
194+
# extraIngress appends additional ingress rules to the control
195+
# NetworkPolicy, on top of the built-in rule allowing traffic from the
196+
# ingress-nginx namespace. Each entry follows the standard
197+
# NetworkPolicyIngressRule schema (from/ports) and is passed through
198+
# verbatim. Useful in clusters that deny pod-to-pod traffic by default,
199+
# e.g. to allow pgdog pods to reach the control API.
200+
# Example:
201+
# extraIngress:
202+
# - from:
203+
# - namespaceSelector:
204+
# matchLabels:
205+
# kubernetes.io/metadata.name: pgdog
206+
# podSelector:
207+
# matchLabels:
208+
# app.kubernetes.io/name: pgdog
209+
# ports:
210+
# - protocol: TCP
211+
# port: 8080
212+
extraIngress: []
194213

195214
ingress:
196215
enabled: true

0 commit comments

Comments
 (0)