Skip to content

feat(helm)!: camelCase keys and NetworkPolicies - #128

Merged
uniqueg merged 4 commits into
devfrom
feat/chart-network-policies
Oct 21, 2026
Merged

uniqueg merged 4 commits into
devfrom
feat/chart-network-policies

Conversation

@uniqueg

@uniqueg uniqueg commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Summary

Two chart changes decided for 0.3.0:

  1. feat(helm)!: use camelCase values keys: renames the values keys host_name to hostName and cloud_registry to cloudRegistry (Helm conventions) in the values, schema, templates, helpers, CI values, tests and docs. Rendering fails while an old key is set, naming the new key (in cloud-registry.validate); the legacy appName is rejected under both keys. The chart version needs no bump: it is derived from the release tag (version: 0.0.0 placeholder, release workflow chart_version).
  2. feat(helm): add NetworkPolicies (ingress only, no egress policy, as the app must reach MongoDB and the OIDC issuers/JWKS):
    • mongodb.networkPolicy.enabled: true (default): only the app's pods of the same release (chart selector labels) may connect to MongoDB on 27017.
    • cloudRegistry.networkPolicy.enabled: false (default, opt-in), cloudRegistry.networkPolicy.ingressFrom (NetworkPolicy peers, default namespaceSelector kubernetes.io/metadata.name: ingress-nginx): only those peers may connect to the app on 8080. Rendering fails without peers (an empty from would allow all sources); the schema only allows podSelector, namespaceSelector and ipBlock in peers.
    • Probes need no rule: connections from the pod's own node (kubelet) are always allowed (Kubernetes docs, "The two sorts of pod isolation").
    • deployment/README.md gets a "Network policies" section (what's protected, clusters without enforcement ignore the policies, kubectl exec is unaffected, how to enable the app policy and match ingressFrom to the ingress controller or OpenShift router, host-network controllers); docs/releases/0.3.0.md gets upgrade notes and breaking-change entries for the rename and the policies. The feat: grant roles on services to groups #105 TODO is unchanged.

Verification

  • coverage run --source cloud_registry -m pytest -W ignore::DeprecationWarning (Python 3.10): 696 passed; coverage report: 100 %
  • pytest (Python 3.12): 696 passed
  • helm lint deployment --strict -f deployment/ci/test-values.yaml, also with --set mongodb.auth.enabled=false --set mongodb.auth.existingSecret=: 0 charts failed (Helm 3.18.6)
  • helm template with the app policy enabled, with ingressFrom=null and []: renders / fails as expected
  • ruff check ., ruff format --check ., mypy, ast-grep scan, ast-grep test, semgrep --config .semgrep --error: no findings
  • After the Sourcery fixes (2534feb, d8bda8f): chart and config tests 152 passed, full suite 698 passed with 100 % coverage, helm lint passes
  • CI: all checks pass (static analysis, tests on 3.10 and 3.12, Helm chart, Docker Compose smoke test, Read the Docs, codecov patch and project)

Declined review findings

  • Ports 8080 and 27017 hard-coded in the policies (low): consistent with the Deployments, Services and probes; tests assert that the policy ports match the container ports.
  • Name --reset-then-reuse-values next to --reuse-values in the rename message and docs (low, cosmetic): rendering still fails safely with the rename message; the docs already explain why stored values bring the old keys back.
  • except: null (or selectors set to null) in ingressFrom peers is rejected by the schema, although Kubernetes treats null as unset (low): the error is clear and the fix is trivial for users.
  • Commit trailer should name another model (quality reviewer): the session's required attribution is the one used.

Open questions

None.

🤖 Generated with Claude Code

uniqueg and others added 2 commits October 21, 2026 14:31
Rename the chart's values keys that did not follow Helm's naming
conventions (camelCase, as in the other keys of the chart):
`host_name` is now `hostName`, `cloud_registry` is now `cloudRegistry`.
Templates, helpers, the values schema, the CI values, tests and docs
use the new keys.

Old keys would be ignored silently, so rendering fails while one is
set, naming the new key. The legacy `appName` is rejected under both
keys. The chart version is derived from the release tag, so it needs
no bump.

BREAKING CHANGE: values files must rename `host_name` to `hostName`
and `cloud_registry` to `cloudRegistry`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Restrict connections to the chart's pods (ingress only) with
NetworkPolicies, for clusters whose network plugin enforces them
(others ignore them):

- MongoDB (`mongodb.networkPolicy.enabled`, default `true`): only the
  app's pods of the same release may connect, on MongoDB's port,
  selected by the chart's labels.
- App (`cloudRegistry.networkPolicy.enabled`, default `false`): only
  the peers in `cloudRegistry.networkPolicy.ingressFrom` may connect,
  on the app's port; the default allows the namespace `ingress-nginx`.
  It is opt-in, as the peers must match the cluster's ingress
  controller. Rendering fails without peers, which would allow all
  sources.

Egress is not restricted: the app connects to MongoDB and to the token
issuers (OpenID Connect discovery, JWKS). The probes need no rule, as
connections from the pod's node are always allowed. The deployment
docs and the release notes describe the policies and how to set
`ingressFrom` or disable them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@sourcery-ai

sourcery-ai Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

The chart migrates its public values interface to hostName and cloudRegistry with safe rendering-time rejection of obsolete keys, adds configurable ingress-only NetworkPolicies for MongoDB and the app, and updates schemas, templates, documentation, CI values, and comprehensive Helm tests accordingly.

Sequence diagram for Helm rendering validation

sequenceDiagram
  participant Operator
  participant Helm
  participant Validate as cloud-registry.validate
  participant Templates
  Operator->>Helm: helm template or helm upgrade
  Helm->>Validate: render validation
  alt obsolete host_name or cloud_registry exists
    Validate-->>Helm: fail with renamed key message
    Helm-->>Operator: rendering fails
  else legacy appName exists
    Validate-->>Helm: fail with appName message
    Helm-->>Operator: rendering fails
  else values use hostName and cloudRegistry
    Validate->>Templates: continue rendering
    Templates-->>Helm: Kubernetes manifests
    Helm-->>Operator: rendered chart
  end
Loading

File-Level Changes

Change Details Files
Rename Helm values keys to camelCase with explicit migration failures.
  • Replace host_name with hostName and cloud_registry with cloudRegistry across defaults, schema, templates, tests, CI values, and documentation.
  • Update all chart references and validation/error messages to use the renamed keys.
  • Reject legacy keys during rendering and reject appName under both the legacy and renamed parent keys.
  • Keep the chart version placeholder unchanged while deriving release chart versions from tags.
deployment/Chart.yaml
deployment/README.md
deployment/ci/test-values.yaml
deployment/templates/NOTES.txt
deployment/templates/_helpers.tpl
deployment/templates/cloud-registry-configmap.yaml
deployment/templates/cloud-registry-deploy.yaml
deployment/templates/cloud-registry-ingress.yaml
deployment/templates/cloud-registry-route.yaml
deployment/values.schema.json
deployment/values.yaml
README.md
docs/releases/0.3.0.md
tests/test_chart.py
tests/test_config.py
Add ingress-only NetworkPolicies for MongoDB and the application.
  • Create an opt-out MongoDB policy that permits only same-release app pods on TCP 27017.
  • Create an opt-in app policy that permits configured ingressFrom peers on TCP 8080 while leaving egress unrestricted.
  • Validate that app peers are present and schema-restrict peer fields to supported Kubernetes selectors and IP blocks.
  • Use release/component selectors so policies target the intended pods and do not cross release boundaries.
  • Document enforcement behavior, probe handling, ingress-controller/OpenShift-router configuration, host-network controllers, and upgrade implications.
deployment/templates/mongo-networkpolicy.yaml
deployment/templates/cloud-registry-networkpolicy.yaml
deployment/values.schema.json
deployment/values.yaml
deployment/README.md
docs/releases/0.3.0.md
tests/test_chart.py
Expand Helm rendering tests to cover renamed values and NetworkPolicy behavior.
  • Update existing chart and configuration tests to exercise camelCase values.
  • Add failure coverage for legacy keys, removed appName, empty or malformed policy peers, and invalid policy types.
  • Assert default and enabled policy manifests, selectors, ports, ingress-only policy types, release isolation, and configurable peers.
tests/test_chart.py
tests/test_config.py

Possibly linked issues

  • #unknown: The PR implements listed review findings: camelCase Helm keys, optional app NetworkPolicy, default MongoDB NetworkPolicy, and release-note updates.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@codecov

codecov Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (753c6d9) to head (d8bda8f).
⚠️ Report is 2 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #128   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           10         9    -1     
  Lines          775       704   -71     
=========================================
- Hits           775       704   -71     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@uniqueg
uniqueg marked this pull request as ready for review October 21, 2026 12:43

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 3 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="deployment/templates/cloud-registry-networkpolicy.yaml" line_range="25-27" />
<code_context>
 ```yaml
-cloud_registry:
+cloudRegistry:
   ingress:
     annotations:
       nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
</code_context>
<issue_to_address>
**Existing policies broaden app access**

When another NetworkPolicy selects the app pods and allows additional ingress sources, kubernetes unions ingress permissions from every NetworkPolicy selecting these pods, so this rule does not block sources allowed by another policy; clients outside `ingressFrom` can still reach the app.

Clarify that NetworkPolicies are additive and advise checking all policies that select the app pods when relying on this restriction.
</issue_to_address>

### Comment 2
<location path="deployment/values.yaml" line_range="91" />
<code_context>
+      # than the default, which allows all pods of that namespace)
+      - namespaceSelector:
+          matchLabels:
+            kubernetes.io/metadata.name: ingress-nginx
+        podSelector:
+          matchLabels:
</code_context>
<issue_to_address>
**Ingress is blocked on older clusters**

When the app NetworkPolicy is enabled on a Kubernetes cluster older than v1.21 and its ingress namespace lacks the `kubernetes.io/metadata.name` label, the default `namespaceSelector` matches no namespace when the cluster does not automatically label namespaces with `kubernetes.io/metadata.name`; enabling the app policy then isolates the app from ingress-nginx and makes it unreachable through the Ingress.

Document and validate the minimum Kubernetes version for enabling this default, or provide a supported ingress namespace selector for clusters without the automatic label.
</issue_to_address>

### Comment 3
<location path="deployment/templates/cloud-registry-networkpolicy.yaml" line_range="27" />
<code_context>
+  - Ingress
+  ingress:
+  - from:
+      {{- toYaml $from | nindent 4 }}
+    ports:
+    - port: 8080
</code_context>
<issue_to_address>
**Malformed peers fail installation**

When the app policy is enabled and an `ingressFrom` entry has an invalid `NetworkPolicyPeer`, such as an `ipBlock` without `cidr` or combined with a selector, `toYaml` emits the peer unchanged, so Kubernetes rejects the NetworkPolicy and the Helm install or upgrade fails.

Validate `ingressFrom` entries as valid Kubernetes `NetworkPolicyPeer` values before rendering.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 3 findings to address first, and on clusters that enforce NetworkPolicies, MongoDB will accept connections only from this release’s app pods, which can interrupt backup jobs or other clients; enabling the app policy with peers that don’t match the cluster’s ingress controller can also make the app unreachable. Reverting restores the prior connectivity, but cannot undo downtime that occurred while the policies were active.

Blocking findings: deployment/templates/cloud-registry-networkpolicy.yaml:27, deployment/values.yaml:91, deployment/templates/cloud-registry-networkpolicy.yaml:27


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread deployment/values.yaml Resolved
uniqueg and others added 2 commits October 21, 2026 15:06
Address the review of the NetworkPolicies:

- The schema rejects `ipBlock` peers without `cidr`, with unknown
  fields or combined with selectors, which Kubernetes would reject at
  install time.
- The docs note that NetworkPolicies add up (other policies selecting
  the chart's pods can widen access) and that the default
  `ingressFrom` relies on the `kubernetes.io/metadata.name` label,
  set on all namespaces from Kubernetes 1.21.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reject empty `except` entries and unknown `ipBlock` fields (tested),
and say exactly what the schema checks of `ingressFrom` peers instead
of claiming it catches all peers Kubernetes would reject.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg
uniqueg merged commit 7d99c4e into dev Oct 21, 2026
11 checks passed
@uniqueg
uniqueg deleted the feat/chart-network-policies branch October 21, 2026 13:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant