Repository navigation
feat(chart): check ingress-nginx body size - #787
Conversation
The Ingress of foca-common fails to render if its annotation nginx.ingress.kubernetes.io/proxy-body-size is below the app's limit (config.server.max_content_length), as ingress-nginx would answer the requests in between with its own 413 page instead of the app's problem details. The error names the value to set. Sizes are those of nginx (bytes, or with the suffix k, m or g; 0 for no limit), with at most 9 digits and no leading zeros, so that Sprig neither reads them as octal nor overflows. The library adds no annotation: without one, or without an app limit, nothing is checked. Ported from prowes.checkProxyBodySize (prowes#163). Refs #785 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The Settings and Templates tables and the maxContentLength helper's comment said that the library doesn't use the app's limit; the Ingress now checks ingress-nginx's annotation against it. Adds tests for the limit from the app's settings and for numeric annotations, which the schema refuses. Refs #785 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideImplementationAdd a helper that validates an explicitly configured ingress-nginx body-size annotation against the app limit, and invoke it while rendering the Ingress.
DocumentationExplain the body-size check and its accepted formats, behavior, and remediation in the chart guide and release notes.
TestsCover accepted, undersized, and invalid annotation values, including app settings and certificate annotations.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Refs #785 Co-Authored-By: Claude Opus 5.5 <[email protected]>
test_chart_version_not_hard_coded refuses the current chart version in the docs; the release notes say which version adds the check. Refs #785 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #787 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 75 75
Lines 10025 10025
=========================================
Hits 10025 10025
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Linked issuesChecked at commit 434e4c5 #785 feat(chart): check ingress-nginx body size against the app limit · 5 of 5 met
|
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="charts/foca-common/templates/_ingress.tpl" line_range="87" />
<code_context>
+{{- $name := "nginx.ingress.kubernetes.io/proxy-body-size" -}}
+{{- if hasKey .annotations $name -}}
+{{- $size := toString (index .annotations $name) -}}
+{{- if not (regexMatch "^(0|[1-9][0-9]{0,8})[kKmMgG]?$" $size) -}}
+{{- fail (printf "%s.ingress.annotations: %s must be a size of ingress-nginx (at most 9 digits without leading zeros, bytes or with the suffix k, m or g, e.g., 10m; \"0\" for no limit), not %q" $key $name $size) -}}
+{{- end -}}
</code_context>
<issue_to_address>
**Gigabyte body limits are rejected**
When the `proxy-body-size` annotation uses a `g` or `G` suffix, `checkProxyBodySize` accepts and converts the suffix, but the annotation reaches ingress-nginx unchanged; NGINX rejects the generated configuration, so the intended limit is not applied and requests above the controller's existing limit receive 413 responses.
Reject `g` and `G` suffixes in the validation and remove the gigabyte conversion factor.
</issue_to_address>
### Comment 2
<location path="charts/foca-common/templates/_ingress.tpl" line_range="87-88" />
<code_context>
+{{- $name := "nginx.ingress.kubernetes.io/proxy-body-size" -}}
+{{- if hasKey .annotations $name -}}
+{{- $size := toString (index .annotations $name) -}}
+{{- if not (regexMatch "^(0|[1-9][0-9]{0,8})[kKmMgG]?$" $size) -}}
+{{- fail (printf "%s.ingress.annotations: %s must be a size of ingress-nginx (at most 9 digits without leading zeros, bytes or with the suffix k, m or g, e.g., 10m; \"0\" for no limit), not %q" $key $name $size) -}}
+{{- end -}}
+{{- $number := regexFind "^[0-9]+" $size -}}
</code_context>
<issue_to_address>
**Skip validation without app limit**
The issue says nothing is checked without an app limit. The helper validates the annotation's syntax before determining whether an app limit exists, so a malformed value still fails rendering in that case.
</issue_to_address>Sourcery assessment
Approval pending. 2 findings to address first.
Blocking findings: charts/foca-common/templates/_ingress.tpl:87, charts/foca-common/templates/_ingress.tpl:88
Without an app limit, only the comparison is skipped: a value that is not a size of ingress-nginx still fails to render, as nginx would refuse it, too. The docs said nothing was checked then. Refs #785 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
Moves proWES's body-size check (
prowes.checkProxyBodySize, prowes#163) into the library chart, as proposed in #785:foca-common.ingressnow fails to render if the Ingress's annotationnginx.ingress.kubernetes.io/proxy-body-sizeis belowfoca-common.maxContentLength(the app'sconfig.server.max_content_length), as ingress-nginx would answer the requests in between with its own413page instead of the app's problem details. The error names the value to set (set it to <n>m or more).k,morg(either case);0= no limit. At most 9 digits and no leading zeros, so that Sprig neither reads010mas octal nor overflows; anything else fails with "must be a size of ingress-nginx".null), or without an app limit, nothing is checked. The check runs on the merged annotations, so it is unaffected by the cert-manager annotations ofingress.https.<valuesKey>.ingress.annotations, so proWES's tests keep passing once it drops its own copy (follow-up drafted for proWES).docs/helm-chart.md; chart release notesdocs/releases/chart/0.6.0.md. The chart version stays 0.6.0: it is unreleased (latest tagchart-v0.5.0), and the repo's convention is one version for all changes up to the next release.Verification
pytest charts/foca-common/tests(Helm v3.18.6) -> 467 passed.pytest tests/test_version_mentions.py tests/test_chart_gateway_keys.py-> 307 passed (the first CI run caught a hard-coded chart version in the docs, fixed in ff2782a).helm lint --strictofcharts/foca-common, the petstore chart with everyci/*-values.yaml, and the gateway chart: all pass.ruff check/ruff format --check charts/foca-common/tests: pass. (mypy's configured paths don't includecharts/.)pytest charts/foca-common/tests tests/test_version_mentions.py-> 553 passed;helm lint --strict charts/foca-commonpasses.tests/utils/test_http.py::test_address_fallback_bounded, Python 3.12 only; 5248 other tests passed there).Declined review findings
Adversarial (low): for app limits of about a petabyte or more, the hint "set it to m or more" can name a value with more than 9 digits (which the check refuses), and near the int64 maximum the rounding overflows; pass/fail stays correct. Declined: unrealistic limits, and the hint is only a hint.
Quality (medium): a numeric (unquoted) annotation would be read as, e.g.,
2e+07. Declined as a template change: the app values schema already refuses numbers ("got number, want null or string"); a test now pins that.Quality (low): more rounding/boundary cases. Declined: the boundaries (
10485759,10239K,11m,1025m) are covered.Sourcery (medium): reject the
gsuffix. Declined: nginx'sclient_max_body_sizeis an offset (ngx_parse_offset), which acceptsg/G.Sourcery (medium): skip the format check without an app limit. Kept the check (a malformed size breaks nginx's config anyway); fixed the docs, which said nothing was checked then (434e4c5).
Fixed from review: stale "the library doesn't use maxContentLength" in the helper comment and the Settings table; the Templates table now says that
foca-common.ingresscan fail; tests for the limit from the app's settings; release notes list the change under Breaking changes (renders that passed before can fail).Open questions
None.
Closes #785
🤖 Generated with Claude Code
Summary by Sourcery
Add ingress-nginx body-size validation to prevent requests from being rejected by the ingress controller before reaching the application.
New Features:
Enhancements:
Documentation:
Tests: