Add skeleton NetworkPolicy templates to Gitaly and Praefect
What does this MR do?
Adds a skeleton NetworkPolicy template to the Gitaly and Praefect subcharts, in the shape Webservice, Sidekiq, GitLab Shell and KAS already use. It renders a policy named <fullname>-v1 that carries the rules from ingress.rules and egress.rules, and each direction has its own enabled flag.
- It is off by default and ships no rules, so a default install renders nothing.
- Only the cluster's network plugin (CNI) enforces it, and the docs say so.
- The Gitaly policy renders only when
global.gitaly.enabledis set, and one selector covers both plain and Praefect-managed Gitaly pods.
flowchart LR
C["webservice, sidekiq,<br/>gitlab-shell, kas, toolbox"] -->|"8075/8076"| P["Praefect"]
P -->|"8075/8076"| G1["Gitaly node 1"]
P -->|"8075/8076"| G2["Gitaly node 2"]
G2 <-->|"replication, 8075/8076"| G1
P -->|"5432"| DB[("PostgreSQL")]
X["pod outside the list"] -.->|"blocked by policy"| PValues example
The Praefect chart page has a full example for Gitaly behind Praefect, and the Gitaly chart page has one for Gitaly alone.
Proof
This branch's chart on k3s with its NetworkPolicy controller enforcing, Praefect with two Gitaly nodes, and the docs example applied:
| Check | Policies off (control) | Policies on |
|---|---|---|
| HTTP and SSH push through Praefect | pass | pass |
praefect dataloss: both replicas up to date |
pass | pass |
Pod outside the allow list, in the release namespace or another, to Praefect and Gitaly 8075 |
open | blocked |
helm template with defaults, with and without Praefect |
no NetworkPolicy |
How to test
bundle exec rspec spec/configuration/gitaly_spec.rb spec/configuration/praefect_spec.rb -e networkpolicy # 18 examples, 0 failures
helm template test . -f <values that render> --set global.praefect.enabled=true > out.yaml && grep -c 'kind: NetworkPolicy' out.yaml # 0
# add --set gitlab.gitaly.networkpolicy.enabled=true --set gitlab.praefect.networkpolicy.enabled=true for 2On a cluster, apply the docs example and restart the Webservice, Sidekiq, GitLab Shell, KAS, Toolbox, and Praefect pods, because some plugins do not re-check open connections. Then clone, push and run praefect dataloss.
An AI coding assistant wrote this change. The assistant also checked each claim against the chart source, and the Praefect example against a Praefect with two Gitaly nodes on a k3s test VM that enforces NetworkPolicy, and ran the Gitaly and Praefect specs, markdownlint and Vale on the changed files.
Related issues
Related to #6438
Related to gitlab-org/gitlab#634058
Related to #5197
Author checklist
For general guidance, please follow our Contributing guide.
Required
For anything in this list which will not be completed, please provide a reason in the MR discussion.
- Merge Request Title and Description are up to date, accurate, and descriptive.
- MR targeting the appropriate branch.
- MR has a green pipeline.
- Documentation created/updated.
- Tests added/updated.
- Have you validated that your change works end-to-end on a real cluster deployment?
- See Proof.
- Equivalent MR/issue for omnibus-gitlab opened.
- N/A: chart-only template.
- When ready for review, MR is marked as ready (not a draft) and assigned to a reviewer.
Reviewers checklist
- As soon as you begin reviewing, select Start a review on your first comment so the MR shows Reviewer started review.
- MR has a green pipeline on https://gitlab.com/gitlab-org/charts/gitlab.
- Consider downstream impact to the Operator, as per evaluating impact from changes to GitLab chart.
- Off by default, so the default render is unchanged.