Repository navigation
feat(chart): add gateway helpers - #692
Conversation
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]>
Reviewer's GuideExtends 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 validationsequenceDiagram
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
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. 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
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:
|
There was a problem hiding this comment.
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
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]>
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 valuespluginsgo into the overlay's sectionplugins, camelCase to snake_case;configandparamsof 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.backendsgoes intocustom.tes.backends, andpublicUrlorhostNameintoserver.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 countgroup_mapping,client_mappingandpolicies, as the app does.foca-common.flowerDeployment,flowerService,flowerNetworkPolicyandflowerBrokerNetworkPolicy. 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) andcheckUpgrade. 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
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
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.config. Documented.checkAccessControl: covered by the settingrequireAudience.config.pluginsfor this case.checkPluginValuesandcheckBackendsdon't readsettings.config: written by the app chart's author, not an operator's value.Open questions
None.
🤖 Generated with Claude Code