Skip to content

feat(chart): add gateway helpers - #692

Merged
uniqueg merged 5 commits into
devfrom
feat/628-gateway-helpers
Nov 4, 2026
Merged

uniqueg merged 5 commits into
devfrom
feat/628-gateway-helpers

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

Summary

Moves what every gateway app needs from proTES's chart into foca-common, as options that apps turn on in their settings. extraEnv's guard came with #626.

  • plugins: true: the values plugins go into the overlay's section plugins, camelCase to snake_case; config and params of plugins, plugin identifiers and preset names stay as they are. A table holds the keys, and a test keeps it complete against FOCA's models.
  • backendsKey: tes: tes.backends goes into custom.tes.backends, and publicUrl or hostName into server.public_url. Rendering fails for backends set twice, for credentials it recognizes in entries, and for registries without a public URL.
  • requireAccessControl: true: the render-time checks of security settings. They count group_mapping, client_mapping and policies, as the app does.
  • Flower: foca-common.flowerDeployment, flowerService, flowerNetworkPolicy and flowerBrokerNetworkPolicy. Apps opt in by adding the template files. Unlike in proTES's chart, the NetworkPolicy and the unprivileged security contexts are defaults of the library, so that other apps don't need to bring them.

Left in proTES's chart, as they're specific to it or its upgrades: the checks of removed settings (service_list, middlewares, custom.access_control, storeLogs) and checkUpgrade. proTES switches later, in its own issue.

Also: backend lists' validation errors now leave out values (foca/plugins/backends/config.py).

Docs: docs/helm-chart.md (Settings, Templates, Values, Gateway apps, Flower). The chart stays at 0.5.0, which isn't released yet.

Closes #628

How it was verified

  • Local checks: ruff, mypy, docs build; pytest with own MongoDB: all pass, 100% coverage; chart tests with Helm 3.22.1 against the petstore chart with these settings: all pass. Default rendering of the petstore chart is byte-identical to the base (adversarial reviewer's diff).
  • CI: see the checks of this PR.

Not verified: a real install with these options and Flower against a cluster; the options against proTES's own chart tests, which comes with its switch; the UID of the Flower image (kept from proTES's chart).

Declined review findings

  • The check of access control re-implements part of FOCA's validation as a template: moved as the issue asks, and documented as the subset that catches a deployment that wouldn't start. Splitting it into smaller helpers isn't worth more template indirection.
  • Credentials in unusual shapes can't all be recognized: keys of available.<id>.config, or names that don't look like credentials. The app refuses unknown keys of entries at startup, but the ConfigMap exists by then. Documented as what it recognizes.
  • A public URL in the image's base config doesn't count for the check of registries, as charts can't read it; apps set it in the setting config. Documented.
  • Sourcery: empty or blank global audience in checkAccessControl: covered by the setting requireAudience.
  • Sourcery: empty top-level plugin settings dropped: they can't be told from app charts' defaults; documented, with config.plugins for this case.
  • Sourcery: checkPluginValues and checkBackends don't read settings.config: written by the app chart's author, not an operator's value.

Open questions

None.

🤖 Generated with Claude Code

uniqueg and others added 3 commits November 4, 2026 12:00
Options of the library chart for apps on the plugin engine, moved from
proTES's chart: plugin settings and backend lists from camelCase values
(settings `plugins` and `backendsKey`, with the public URL), render-time
checks of backends and of security settings (`requireAccessControl`),
and templates for Flower. Defaults render as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The check of access control also counts client_mapping and policies, as
the app does. Credentials in backend entries fail rendering, and
validation errors of backends leave out values. A public URL in the
settings counts for registries. Flower defaults to its NetworkPolicy and
to unprivileged security contexts, and its values are only checked by
its Deployment, so that apps with their own stay as they are. Keys with
an underscore stay as they are.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Errors of backend lists leave out values also through the list model.
The admin check reads policies by name, too. Credentials in backend
entries also fail in keys named like them, in a basic that is no map,
and in a URL with leading whitespace. Docs say what's a default.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg uniqueg added this to the v0.21.0 milestone Nov 4, 2026
@sourcery-ai

sourcery-ai Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Extends foca-common with opt-in gateway-app configuration and validation plus secure, reusable Flower resources, hardens backend error handling against credential leakage, and adds comprehensive tests, schemas, and documentation.

Sequence diagram for gateway configuration rendering and validation

sequenceDiagram
    participant Helm
    participant Common as foca-common
    participant ConfigMap
    participant FOCA
    Helm->>Common: checkSettings
    Common->>Common: checkPluginValues
    Common->>Common: checkBackends
    Common->>Common: checkAccessControl
    Common->>Common: gatewayConfig
    Common->>ConfigMap: render config overlay
    ConfigMap->>FOCA: FOCA_CONFIG_OVERLAY
    FOCA->>FOCA: validate application configuration
Loading

File-Level Changes

Change Details Files
Add opt-in gateway configuration generation and render-time validation to the common Helm library chart.
  • Translate plugin values from camelCase to FOCA’s snake_case schema while preserving plugin identifiers, presets, config, and params.
  • Render backend lists and public URLs under the expected FOCA config paths, with duplicate, malformed, credential, and registry URL checks.
  • Validate access-control settings, issuer configuration, group mappings, policies, and admin-role coverage when required.
  • Add schema coverage and tests that keep chart key mappings aligned with FOCA models.
charts/foca-common/templates/_gateway.tpl
charts/foca-common/templates/_configmap.tpl
charts/foca-common/templates/_helpers.tpl
charts/foca-common/app-values.schema.json
examples/petstore/chart/values.schema.json
charts/foca-common/tests/test_templates.py
tests/test_chart_gateway_keys.py
Provide reusable, secure-by-default Flower resources for Celery-enabled applications.
  • Add opt-in Deployment and ClusterIP Service helpers backed by broker and Flower secrets.
  • Default Flower to unprivileged security contexts, a read-only root filesystem, a writable temporary volume, and no ingress peers.
  • Add optional Flower-to-broker and Flower ingress NetworkPolicies with validation for required values and resource-name collisions.
  • Document integration through app-provided template files and values.
charts/foca-common/templates/_flower.tpl
docs/helm-chart.md
charts/foca-common/Chart.yaml
charts/foca-common/tests/test_templates.py
Prevent backend validation errors from exposing credential values.
  • Enable hidden input values in backend Pydantic models and the outer backend-list model.
  • Add regression coverage for URL and credential-shaped backend entries.
foca/plugins/backends/config.py
tests/plugins/test_plugin_backends.py
Expand Helm chart documentation and generated values schemas for the new gateway and Flower options.
  • Document gateway settings, generated overlay behavior, validation boundaries, backend key conversion, and access-control requirements.
  • Document Flower configuration, secret requirements, network exposure, security defaults, and optional templates.
  • Update chart value schemas without changing the unreleased chart version.
docs/helm-chart.md
charts/foca-common/app-values.schema.json
examples/petstore/chart/values.schema.json

Possibly linked issues


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 Nov 4, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (20f46f9) to head (43d6d74).

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #692   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           65        65           
  Lines         8510      8511    +1     
=========================================
+ Hits          8510      8511    +1     
Flag Coverage Δ
test_unit 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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 November 4, 2026 11:33

@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 8 issues

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

## Individual Comments

### Comment 1
<location path="charts/foca-common/templates/_gateway.tpl" line_range="272" />
<code_context>
+values. Call with the root context.
+*/}}
+{{- define "foca-common.checkAccessControl" -}}
+{{- $config := .Values.config | default dict -}}
+{{- $mapping := dict -}}
+{{- $requireAdmin := "true" -}}
</code_context>
<issue_to_address>
**Access control can be disabled**

When an app's settings override `security.access_control.enabled` or `enforce` to false while the root config passes, `checkAccessControl` reads only `.Values.config`, while `configOverlay` merges `.settings.config`; rendering succeeds and the app starts without enforced access control.

Validate the effective merged config, including `.settings.config`, in `checkAccessControl`.

Also at `charts/foca-common/templates/_gateway.tpl:97`, `charts/foca-common/templates/_gateway.tpl:161`.
</issue_to_address>

### Comment 2
<location path="charts/foca-common/templates/_gateway.tpl" line_range="179" />
<code_context>
+{{- end -}}
+{{- range $entry := $backends -}}
+{{- if kindIs "map" $entry -}}
+{{- if and (kindIs "string" (get $entry "url")) (regexMatch "://[^/?#]*@" (get $entry "url")) -}}
+{{- fail (printf "the url of an entry of %s.backends must not hold credentials, which would be readable in the ConfigMap: use auth and basic.usernameEnv and basic.passwordEnv" $key) -}}
+{{- end -}}
</code_context>
<issue_to_address>
**Credentials remain readable in ConfigMaps**

When a backend URL contains credentials in its query or fragment, or `publicUrl` contains credentials, `checkBackends` checks only URL authority user-info and leaves `publicUrl` unchecked, while the original values reach the ConfigMap; readers of it can access the credentials.

Reject credentials in every component of backend URLs and in `publicUrl` before rendering the ConfigMap.

Also at `charts/foca-common/templates/_gateway.tpl:115`.
</issue_to_address>

### Comment 3
<location path="charts/foca-common/templates/_gateway.tpl" line_range="183-184" />
<code_context>
+{{- fail (printf "the url of an entry of %s.backends must not hold credentials, which would be readable in the ConfigMap: use auth and basic.usernameEnv and basic.passwordEnv" $key) -}}
+{{- end -}}
+{{- range $name := keys $entry | sortAlpha -}}
+{{- if and (regexMatch "(?i)password|secret|token|credential" $name) (not (hasSuffix "_env" $name)) -}}
+{{- fail (printf "an entry of %s.backends must not hold credentials (%s), which would be readable in the ConfigMap: use auth and basic.usernameEnv and basic.passwordEnv" $key $name) -}}
+{{- end -}}
+{{- end -}}
</code_context>
<issue_to_address>
**Credential-like keys bypass validation**

When a backend entry contains a secret value under an unknown credential-like key ending in `_env`, such as `token_env`, the `_env` suffix exemption lets a credential value under a key such as `token_env` pass `checkBackends`; `backendsConfig` then renders it into the ConfigMap. FOCA rejects the unknown field only after that ConfigMap has exposed the value.

Limit the `_env` exemption to validated credential environment-variable fields, rather than exempting arbitrary entry keys.
</issue_to_address>

### Comment 4
<location path="charts/foca-common/templates/_gateway.tpl" line_range="177" />
<code_context>
+{{- $backends = concat $backends (get $section "backends") -}}
+{{- end -}}
+{{- end -}}
+{{- range $entry := $backends -}}
+{{- if kindIs "map" $entry -}}
+{{- if and (kindIs "string" (get $entry "url")) (regexMatch "://[^/?#]*@" (get $entry "url")) -}}
</code_context>
<issue_to_address>
**Malformed backends bypass credential checks**

When `config.custom.<backendsKey>.backends` is a non-list value containing credential-bearing data, `config.custom.<backendsKey>.backends` is scanned only when it is a list, so a non-list value containing credential-bearing entries is left in the generated ConfigMap without triggering the credential check. The app then rejects the malformed config at startup, but the credentials have already been rendered into a readable ConfigMap.

Validate that configured backends are a list when present, and reject malformed values before emitting the ConfigMap.
</issue_to_address>

### Comment 5
<location path="charts/foca-common/templates/_gateway.tpl" line_range="391-397" />
<code_context>
+{{- /* `security` and `auth` are maps here, as the issuers are set */ -}}
+{{- $globalAudience := get (get $security "auth") "audience" -}}
+{{- if and (hasKey (get $security "auth") "audience") (not (kindIs "invalid" $globalAudience)) -}}
+{{- $strings := kindIs "slice" $globalAudience -}}
+{{- range $client := ternary $globalAudience (list) $strings -}}
+{{- if not (kindIs "string" $client) -}}
+{{- $strings = false -}}
+{{- end -}}
+{{- end -}}
+{{- if not $strings -}}
+{{- fail "config.security.auth.audience must list the accepted audiences (strings, e.g., client IDs), or be null" -}}
+{{- end -}}
</code_context>
<issue_to_address>
**Invalid audiences pass chart validation**

When `requireAccessControl` is enabled and a trusted issuer relies on an empty or blank global audience for audience validation, `checkAccessControl` accepts empty lists and blank strings because it checks only that entries are strings; Helm renders the deployment, then FOCA rejects the audience at startup.

Reject empty global audiences and any audience containing a blank string when they are used for issuer audience validation.
</issue_to_address>

### Comment 6
<location path="charts/foca-common/templates/_flower.tpl" line_range="97-105" />
<code_context>
+        imagePullPolicy: {{ $flower.imagePullPolicy | default "Always" }}
+        command: ["celery", "flower", "--port=5555"]
+        env:
+        - name: CELERY_BROKER_URL
+          valueFrom:
+            secretKeyRef:
+              name: {{ $root.Values.broker.existingSecret | quote }}
+              key: broker-url
+        - name: FLOWER_BASIC_AUTH
+          valueFrom:
+            secretKeyRef:
+              name: {{ $flower.existingSecret | quote }}
+              key: basic-auth
+        ports:
</code_context>
<issue_to_address>
**Rotated Flower secrets stay stale**

When data in `flower.existingSecret` or `broker.existingSecret` is rotated while the Flower pod is running, the Deployment has no checksum or other rollout trigger for either Secret. Kubernetes does not refresh environment variables in an already-running container when Secret data changes, so Flower keeps using the old broker URL or basic-auth credentials until its pod is restarted.

Add a Flower secret-rollout mechanism, such as a checksum annotation for both referenced Secrets.
</issue_to_address>

### Comment 7
<location path="charts/foca-common/templates/_gateway.tpl" line_range="77" />
<code_context>
+{{- $plugins := dict -}}
+{{- $keys := include "foca-common.pluginKeys" . | fromJson -}}
+{{- range $key, $value := .Values.plugins | default dict -}}
+{{- if $value -}}
+{{- $converted := dict -}}
+{{- if has $key (list "available" "presets") -}}
</code_context>
<issue_to_address>
**Explicit plugin settings disappear**

When a top-level plugin setting is false or `plugins.pipeline` is explicitly empty, `pluginsConfig` and `checkPluginValues` skip falsey values, so the overlay drops explicit settings and conflict checks miss duplicates; the caller gets the base or default plugin behavior instead.

Distinguish absent plugin keys from false or empty values in both overlay generation and conflict validation.

Also at `charts/foca-common/templates/_gateway.tpl:78`, `charts/foca-common/templates/_gateway.tpl:102-103`.
</issue_to_address>

### Comment 8
<location path="charts/foca-common/templates/_gateway.tpl" line_range="407" />
<code_context>
+{{- if ne $claimGroups (trim $claimGroups) -}}
+{{- fail "config.security.access_control.claim_groups must be the name of a claim, without surrounding whitespace" -}}
+{{- end -}}
+{{- $groupMappingSet = not (kindIs "invalid" $mapping) -}}
+{{- if kindIs "invalid" $mapping -}}
+{{- $mapping = dict -}}
</code_context>
<issue_to_address>
**Group admin grants are ignored**

When `requireAccessControl` is enabled, `group_mapping` is omitted, and a `group:` policy grants `admin`, `$mapping` starts as an empty map, so `checkAccessControl` treats the omitted mapping as set and ignores the grant unless `keep_group_subjects` is true; Helm rejects a config FOCA accepts.

Track whether `group_mapping` was actually supplied before defaulting it to an empty map.

Also at `charts/foca-common/templates/_gateway.tpl:421`.
</issue_to_address>

Linked issues

#628 feat(chart): add gateway helpers · 6 of 6 met

# Requirement Status Notes
1 Render plugin settings from camelCase values as FOCA’s snake_case config ✅ Met The gateway helpers convert plugin setting keys and preserve the specified config, params, plugin identifiers, and preset names.
2 Add render-time checks of backend lists ✅ Met The helpers validate backend placement and entries, including credentials and registry public URLs.
3 Add render-time checks of security settings ✅ Met With requireAccessControl enabled, the helper checks access-control enforcement, issuers, group claims, and admin grants.
4 Provide Flower for the worker ✅ Met Optional Flower Deployment, Service, and network policies are provided, with tests covering defaults and configuration.
5 Add chart tests for each helper and keep defaults unchanged for apps that do not use the plugin engine ✅ Met The chart tests cover the gateway options and Flower helpers, and verify gateway values have no effect when the settings are off.
6 Document the changes on the Helm chart page ✅ Met The Helm chart page documents the gateway settings, Flower integration, and their templates and values.

Sourcery assessment

Needs a human reviewer. 8 findings to address first, and when enabled, Flower can display task arguments and connect to the Celery broker; if its NetworkPolicy admits unintended peers, reverting removes future access but cannot undo task data already viewed. The backend settings are also rendered into a ConfigMap, so credentials missed by the chart’s checks could be exposed and would need to be rotated.

Blocking findings: charts/foca-common/templates/_gateway.tpl:272, charts/foca-common/templates/_gateway.tpl:179, charts/foca-common/templates/_gateway.tpl:184, charts/foca-common/templates/_gateway.tpl:177, charts/foca-common/templates/_gateway.tpl:397, and 3 more


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

uniqueg and others added 2 commits November 4, 2026 13:05
Check access control on the overlay, with the settings of the app, and
count rules of groups if no group mapping is set, as the app does.

Refuse credentials in the query or fragment of backend URLs and in the
public URL, in keys ending in _env unless they can name a variable, and
malformed lists of backends, whose credentials wouldn't be recognized.

Roll Flower's pods with rolloutOnSecrets, as those of the app.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg
uniqueg merged commit f69ceb6 into dev Nov 4, 2026
60 of 83 checks passed
@uniqueg
uniqueg deleted the feat/628-gateway-helpers branch November 4, 2026 12:19
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.

feat(chart): add gateway helpers

1 participant