Skip to content

fix(helm): refuse NetworkPolicy peers the kubernetes api would refuse - #3500

Merged
freeqaz merged 3 commits into
mainfrom
fix-fe3-chart-peers
Oct 24, 2026
Merged

freeqaz merged 3 commits into
mainfrom
fix-fe3-chart-peers

Conversation

@freeqaz

@freeqaz freeqaz commented Oct 24, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Two chart values become NetworkPolicy peers almost verbatim:

  • gatewayRouting.sandbox.ingressPeers checked only matchLabels; ipBlock.cidr, ipBlock.except and matchExpressions were pasted with toYaml.
  • openshellGit.clients checked only that both selectors carried matchLabels, not their keys or values.

helm template therefore rendered, for example, ipBlock.cidr: 10.0.0.0/33, operator: Equals with key bad key!, or matchLabels: {kubernetes.io/metadata.name: "openshell system"}. The Kubernetes API (ValidateLabelSelector, ParseCIDR) refuses each one when Helm applies the NetworkPolicy, after other objects of the release have already changed. An unknown key such as podSelectors was rendered as written. Finding 2336.

Change

  • New shared helpers in templates/_network-policies.tpl:
    • openclaw.networkPolicy.peer: the peer must be either ipBlock or selectors, with no unknown fields. A field set to null counts as unset, as the API server reads it.
    • openclaw.networkPolicy.selector: matchLabels goes through the existing openclaw.networkPolicy.matchLabels. For matchExpressions it checks the key, the operator (In/NotIn/Exists/DoesNotExist) and that the values fit the operator.
    • openclaw.networkPolicy.cidr: the IPv4/IPv6 parser that gatewayRouting.remoteNodeCidrs already used, moved out so it can be shared. It produces the same messages for that field.
    • openclaw.networkPolicy.labelKey: split out of the matchLabels helper.
  • gateway-routing.yaml and openshell-git.yaml run each peer through openclaw.networkPolicy.peer. The rendered YAML does not change for valid input.
  • Docs: a one-sentence note in docs/guides/deploy/native-admin.md and a breaking-change notice.
  • egressAuthority.clients has the same gap but belongs to the credential proxy listener, so it is left for a separate change.

Verification

  • New test "NetworkPolicy peers from values are refused before install" in tests/integration/production-kubernetes-packaging.test.mjs:
    • It fails on main with "Missing expected rejection".
    • With the fix it passes. It covers 9 invalid ingress-peer shapes and 2 invalid openshellGit.clients shapes, plus valid controls: 0.0.0.0/0 with except, ::/0, and matchExpressions using NotIn and Exists.
  • The test matches each refusal on Helm's stderr, not the error message (which also carries the --set command line), and checks that valid peers, including a null sibling field, render exactly as written.
  • Whole file: 104 pass, 0 fail; pinned 20/20 at 2 CPUs on a remote test VM on the final head.
  • Internal review: approve-with-nits. Applied: stderr assertions (the operator case had passed for the wrong reason), null fields read as unset, more unknown-field and value cases, a --set-string hint for non-string expression values, leading-zero octets named in the notice. Mutants for the operator, unknown ipBlock field and null-field checks are caught. This includes the existing remoteNodeCidrs and peer-label tests, which exercise the moved CIDR parser and label-key helper.
  • tests/integration/installation-change-preflight.test.mjs: 7 pass. eslint and prettier are clean on the touched files.

Risks

  • Low. The only newly refused values are ones the API server would refuse anyway, plus unknown peer keys. Unknown keys are the one case that may have applied before, depending on field validation, so there is a notice.
  • ipBlock.except containment inside cidr is not checked.
  • This PR and fix(openshell): check sandbox policy settings at controller startup #3499 both add an entry at the top of breaking-changes.md. Whichever lands second needs a trivial merge of main.

gatewayRouting.sandbox.ingressPeers checked only matchLabels and
openshellGit.clients only that both selectors were present; ipBlock CIDRs,
matchExpressions and unknown keys were pasted with toYaml, so an invalid peer
failed when Helm applied the NetworkPolicy, after other release objects had
changed.

A shared openclaw.networkPolicy.peer helper now checks each peer: ipBlock or
selectors, CIDRs (the remoteNodeCidrs parser, moved into a shared helper),
matchLabels (existing helper), matchExpressions key/operator/values, and no
unknown fields. egressAuthority.clients is left as is (Credential Proxy area).
Finding 2336.
@freeqaz
freeqaz requested a review from a team as a code owner October 24, 2026 18:02
@clawsweeper

clawsweeper Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review in progress

ClawSweeper is reviewing this revision. This supersedes any previous blocked status.

View the workflow run.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 24, 2026
Review follow-ups: a peer field set to null (ipBlock: null next to selectors)
is unset for the API server, so the peer helper no longer refuses it, and a
peer whose fields are all null is refused. matchExpressions values that are
not strings get a --set-string hint. The test now matches each refusal on
Helm's stderr (the error message also carries the --set command line, which
let the operator case pass for the wrong reason), covers unknown ipBlock and
selector fields, invalid and non-string expression values and the null
shapes, and checks that valid peers render as written.
# Conflicts:
#	docs/guides/deploy/breaking-changes.md
@freeqaz
freeqaz merged commit ba258f5 into main Oct 24, 2026
41 checks passed
@freeqaz
freeqaz deleted the fix-fe3-chart-peers branch October 24, 2026 18:37
freeqaz added a commit that referenced this pull request Oct 24, 2026
…ession refusals (#3508)

Test-only: pins eleven NetworkPolicy peer refusals from #3500 (CIDRs, label keys and match expressions).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant