Repository navigation
fix(chart): honour per-issuer audiences - #641
Conversation
checkAudience only looked at security.auth.audience, so the chart refused configurations that FOCA accepts: each issuer with an audience of its own. Accept those, require the global audience if any issuer lacks one, and refuse invalid audiences of issuers, as FOCA does. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqMUX3EU35poH13xMgG
Reviewer's GuideUpdates the Helm chart's audience validation to match FOCA by supporting valid per-issuer audiences, retaining correct global-audience and base-config issuer handling, and preserving validation opt-out semantics. Adds comprehensive regression tests and documents the new behavior. Flow diagram for Helm audience validationflowchart TD
A[Helm renders chart with requireAudience] --> B{verify_audience is false?}
B -->|Yes| C[Skip required global or issuer coverage check]
B -->|No| D[Validate configured audiences]
D --> E{Any configured issuer audience invalid?}
E -->|Yes| F[Fail rendering]
E -->|No| G{Global audience valid?}
G -->|Yes| H[Render successfully]
G -->|No| I{Every issuer has its own valid audience?}
I -->|Yes| H
I -->|No| J{Issuers omitted from overlay?}
J -->|Yes| F
J -->|No| F
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Accept an explicit empty list of issuers, which removes those of the base config, and refuse invalid audiences of issuers also with verify_audience: false, as FOCA validates them in any case. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqMUX3EU35poH13xMgG
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #641 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 56 56
Lines 7119 7119
=========================================
Hits 7119 7119
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 4 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="charts/foca-common/templates/_helpers.tpl" line_range="378" />
<code_context>
+{{- fail "the audience of each of config.security.auth.issuers must list non-blank client IDs, if set" -}}
+{{- end -}}
+{{- end -}}
+{{- if and $verifyAudience (or (not $valid) (and $needsGlobal (not $hasAudience))) -}}
+{{- fail "config.security.auth.audience must list the client IDs of the apps calling this app (e.g., its front end), whose tokens are accepted, unless each of config.security.auth.issuers has an audience of its own; or set config.security.auth.verify_audience to false to accept tokens for any audience (not recommended)" -}}
{{- end -}}
</code_context>
<issue_to_address>
**Invalid audiences pass chart validation**
When `verify_audience` is false and `config.security.auth.audience` is set to an invalid value, `checkAudience` gates `$valid` on `$verifyAudience`, so Helm accepts the invalid configured audience and FOCA rejects some such values during startup.
Check `$valid` whenever a global audience is configured, independently of `$verifyAudience`, while keeping the missing-global-audience check conditional on verification being enabled.
</issue_to_address>
### Comment 2
<location path="charts/foca-common/templates/_helpers.tpl" line_range="370-375" />
<code_context>
+{{- $issuers = ternary $issuers (list) (kindIs "slice" $issuers) -}}
+{{- range $issuer := $issuers -}}
+{{- /* Plain URLs have no settings of their own */ -}}
+{{- $own := index (ternary $issuer (dict) (kindIs "map" $issuer)) "audience" -}}
+{{- if kindIs "invalid" $own -}}
+{{- $needsGlobal = true -}}
+{{- else if not (include "foca-common.isAudience" $own) -}}
+{{- /* FOCA refuses these whatever verify_audience says */ -}}
+{{- fail "the audience of each of config.security.auth.issuers must list non-blank client IDs, if set" -}}
+{{- end -}}
+{{- end -}}
</code_context>
<issue_to_address>
**Malformed issuers pass audience check**
When `config.security.auth.issuers` contains a map with a valid audience but no non-empty issuer, `checkAudience` treats any map with a valid `audience` as a configured issuer, so a map missing its required `issuer` passes without a global audience; FOCA then rejects the config at startup and the pod fails.
Validate that each issuer map has a non-empty string `issuer` before counting its audience toward the requirement.
</issue_to_address>
### Comment 3
<location path="charts/foca-common/templates/_helpers.tpl" line_range="378" />
<code_context>
+{{- fail "the audience of each of config.security.auth.issuers must list non-blank client IDs, if set" -}}
+{{- end -}}
+{{- end -}}
+{{- if and $verifyAudience (or (not $valid) (and $needsGlobal (not $hasAudience))) -}}
+{{- fail "config.security.auth.audience must list the client IDs of the apps calling this app (e.g., its front end), whose tokens are accepted, unless each of config.security.auth.issuers has an audience of its own; or set config.security.auth.verify_audience to false to accept tokens for any audience (not recommended)" -}}
{{- end -}}
</code_context>
<issue_to_address>
**Unused audience blocks rendering**
When the global audience is blank while all configured issuers have valid audiences of their own, or there are no issuers, `checkAudience` fails even when every issuer has a valid audience of its own (or the issuer list is empty), so Helm refuses configurations that FOCA accepts.
Only require a valid global audience when at least one issuer needs it, matching FOCA’s validation behavior.
</issue_to_address>
### Comment 4
<location path="docs/migration-0.20.md" line_range="117-119" />
<code_context>
the config overlay sets `config.plugins.defaults.store.key_secret`, as
it is a ConfigMap.
+
+### Audiences of issuers in Helm charts
+
+With foca-common 0.4.0 or later, `requireAudience` accepts configurations in
+which each of `config.security.auth.issuers` has an `audience` of its own,
+without `config.security.auth.audience`, as FOCA does. Apps that computed
</code_context>
<issue_to_address>
**Chart changelog entry**
The issue asks for both documentation and a chart changelog update. The diff adds a migration-guide section but no chart changelog entry.
</issue_to_address>Linked issues
#604 fix(chart): honour per-issuer audiences · 2 of 3 met
| # | Requirement | Status | Notes |
|---|---|---|---|
| 1 | Accept a valid global audience or valid audiences for every issuer; refuse missing or blank audiences unless validation is disabled. | ✅ Met | The helper checks issuer audiences, falls back to the global audience where needed, and preserves the validation opt-out. |
| 2 | Add chart tests for global and per-issuer audiences, an issuer without an audience, and verify_audience: false. | ✅ Met | The tests cover those cases, including that an issuer without its own or a global audience fails. |
| 3 | Update the docs and chart changelog. | 🟡 Partly met | The Helm docs and migration guide are updated, but the diff includes no chart changelog entry. |
Sourcery assessment
Needs a human reviewer. 3 findings to address first, and the chart now allows rendering without a global audience when it considers every issuer to have its own. If that coverage check accepts an issuer that lacks an effective audience, tokens could be accepted under a weaker auth policy; reverting would not undo any access or data exposure that already occurred.
Blocking findings: charts/foca-common/templates/_helpers.tpl:378, charts/foca-common/templates/_helpers.tpl:375, charts/foca-common/templates/_helpers.tpl:378
Closes #604
Summary
foca-common.checkAudiencelooked only atsecurity.auth.audience, so the chart refused configurations that FOCA accepts. It now passes if each ofsecurity.auth.issuershas a valid audience of its own, or the global audience is valid. Blank or invalid audiences stay refused, also those of issuers and a global one no issuer needs, andverify_audience: falsestill opts out. Without any issuers in the overlay, the global audience stays required, as the overlay may not list those of the app's base config.Chart version: stays 0.4.0, as
chart-v0.4.0isn't tagged yet (latest tagchart-v0.3.0), and the repo's rule is one version for all changes up to the next chart release.Docs:
docs/helm-chart.md,docs/migration-0.20.md. The repo has no chart changelog, so the migration guide takes that part of the issue's acceptance criteria.Verification
pytest charts/foca-common/testswith Helm 3.22.1, the version of CI: 264 passedhelm lint --strict charts/foca-common: passesruff check,ruff format,mkdocs build --strict: pass🤖 Generated with Claude Code
https://claude.ai/code/session_011FSoqMUX3EU35poH13xMgG
Summary by Sourcery
Update Helm audience validation to honor valid per-issuer audiences consistently with FOCA.
Bug Fixes:
Enhancements:
Documentation:
Tests: