Skip to content

fix(chart): honour per-issuer audiences - #641

Merged
uniqueg merged 3 commits into
devfrom
fix/chart-issuer-audience
Nov 3, 2026
Merged

uniqueg merged 3 commits into
devfrom
fix/chart-issuer-audience

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Closes #604

Summary

foca-common.checkAudience looked only at security.auth.audience, so the chart refused configurations that FOCA accepts. It now passes if each of security.auth.issuers has 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, and verify_audience: false still 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.0 isn't tagged yet (latest tag chart-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/tests with Helm 3.22.1, the version of CI: 264 passed
  • helm lint --strict charts/foca-common: passes
  • ruff check, ruff format, mkdocs build --strict: pass
  • Kind install: CI only
  • New tests failed before the fix.

🤖 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:

  • Align Helm chart audience validation with FOCA by accepting valid per-issuer audiences while continuing to reject invalid configured audiences.

Enhancements:

  • Support global audiences as fallbacks for issuers without their own and preserve the requirement for a global audience when issuer definitions are absent.
  • Document per-issuer audience handling and migration guidance for Helm chart users.

Documentation:

  • Update Helm chart reference and migration documentation to describe per-issuer audiences.

Tests:

  • Add coverage for valid and invalid global and per-issuer audience configurations, including disabled audience validation.

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
@uniqueg uniqueg added this to the v0.20.0 milestone Nov 3, 2026
@uniqueg uniqueg added the type: bug Something isn't working label Nov 3, 2026
@sourcery-ai

sourcery-ai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Updates 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 validation

flowchart 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
Loading

File-Level Changes

Change Details Files
Align Helm audience validation with FOCA's per-issuer semantics.
  • Add reusable validation for non-empty lists of non-blank client IDs.
  • Accept a valid global audience or valid audiences on every configured issuer.
  • Require a global audience when issuers are omitted, while treating an empty issuer list as removal of base issuers.
  • Reject invalid configured audiences even when validation is disabled, while preserving the opt-out for missing audience requirements.
charts/foca-common/templates/_helpers.tpl
Expand regression coverage for audience combinations and validation behavior.
  • Cover accepted global, per-issuer, mixed, empty, and base-configuration issuer cases.
  • Cover invalid issuer and global audiences.
  • Verify invalid issuer audiences fail with verify_audience disabled and missing audiences remain allowed when disabled.
charts/foca-common/tests/test_templates.py
Document per-issuer audience support and migration behavior.
  • Update Helm chart option documentation to describe global and issuer-specific audiences.
  • Add migration guidance for configurations using issuer-specific audiences.
docs/helm-chart.md
docs/migration-0.20.md

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

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

codecov Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (f521cd3) to head (914ffa1).

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #641   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           56        56           
  Lines         7119      7119           
=========================================
  Hits          7119      7119           
Flag Coverage Δ
test_unit 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 3, 2026 06:45

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


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

Comment thread docs/migration-0.20.md Resolved
@uniqueg
uniqueg merged commit 8b22ad7 into dev Nov 3, 2026
56 checks passed
@uniqueg
uniqueg deleted the fix/chart-issuer-audience branch November 3, 2026 07:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(chart): honour per-issuer audiences

1 participant