Skip to content

feat(chart)!: audiences per token client - #338

Merged
uniqueg merged 5 commits into
devfrom
feat/token-clients-audiences
Nov 23, 2026
Merged

uniqueg merged 5 commits into
devfrom
feat/token-clients-audiences

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Summary

Chart side of audiences per service client, matching elixir-cloud-aai/tesk-api#220 (tesk-api#215). Merge together with tesk-api#220, so that the dev heads stay compatible.

  • auth.tokenClients.clients is a map from client ID to the client's settings: audiences (a non-empty list) or allowAnyAudience: true, not both (proposal of the issue: per client, default false). The chart renders one JSON variable, TESK_API_AUTHORISATION_SERVICE_CLIENTS_CLIENTS, normalised to what tesk-api 2.1.0 accepts: {"audiences": [...]} or {"allowAnyAudience": true} per client, with IDs and audiences trimmed, allowAnyAudience as a JSON boolean (also from "true"), a non-true allowAnyAudience left out, and null clients left out (null removes a key in Helm).
  • …_CLIENT_IDS and …_AUDIENCE are never rendered. The shared auth.tokenClients.audience and allowAnyAudience and clients as a list are removed. The schema lets them through, and the chart fails with a hint to the upgrade notes when they hold values that mean something (a non-empty audience, allowAnyAudience: true, or a non-empty list), also when the setting is off. The defaults of chart 0.4.0 pass, because helm upgrade --reuse-values renders with the old release's defaults. This follows the chart's existing pattern for removed keys ($defs/removed, tesk.checkRemovedValues). The issue asked for a schema failure with a hint, but Helm's schema errors can't carry one.
  • With the setting on, the chart refuses what tesk-api 2.1.0 refuses at startup: no client, blank or duplicate client IDs (after trimming), a client without audiences (unless allowAnyAudience: true), a blank audience, or both fields. The schema checks the structure: per-client additionalProperties: false, non-blank IDs and audiences, and booleans.
  • With the setting on and tesk-api before 2.1.0 (tesk.image.tag as a version, by default appVersion, still 2.0.0 on dev), the chart fails instead of starting a tesk-api that doesn't start (2.0.0) or ignores the setting (earlier). This replaces the notes' warning for tesk-api before 2.0.0. Tags that aren't versions (e.g. dev) aren't checked.
  • allowAnyAudience stays opt-in for testing (decision d21 of the maintainer, 2026-11-23): kept for testing and for setting up federations while the audiences at an IdP that one doesn't control are being sorted out. The values.yaml comments, the schema description, the configuration reference, the deployment guide ("Tokens of services") and the upgrade notes say what it does (accepts that client's tokens whatever their aud), the risk (every token that the trusted issuer issues to that client ID is accepted, also tokens meant for other services, so a token leaked from or replayed by another service works here), and that production should list audiences; tesk-api#220 logs a warning at startup for each such client.
  • Docs: upgrade notes ("Audiences per client of tokenClients", with the conversion, rollback and rollout notes), the deployment guide ("Tokens of services") and the configuration reference. values.yaml comments are updated too.

Closes #336

Verification

  • pytest (all tests, Helm v3.22.1 as in CI, REQUIRE_HELM=1): 1274 passed. The token client tests are rewritten for the map form: rendering and normalisation, JSON escaping, values files with numeric IDs, every template refusal, schema refusals, the removed forms with their hint (also when off), the 0.4.0 defaults passing, the link target in the upgrade notes, and the version gate, both with explicit tags and with the default appVersion.
  • helm lint charts/tesk --strict: OK.
  • mkdocs build --strict: OK.
  • pre-commit run --all-files: all hooks pass. actionlint was skipped locally because of a missing local shellcheck; no workflow is changed.
  • No end-to-end run against tesk-api#220. The chart's kind install (chart-install) uses the default values (tesk-api appVersion 2.0.0, auth.mode: noauth, token clients off), so it doesn't touch this setting and stays green. tesk-api pushes images only from dev, so no image with fix: default to taskmaster and filer v0.10.6 #220 exists until it merges, and a local build of fix: default to taskmaster and filer v0.10.6 #220 was blocked by the sandbox's proxy. The rendered JSON is checked against fix: default to taskmaster and filer v0.10.6 #220's parser rules (ServiceClientTokenServices.clients) in the unit tests. Proposed follow-up: once appVersion is 2.1.0, add a kind case with auth.tokenClients on that checks tesk-api starts.
  • CI: all checks pass, CI passed green, also both kind installs (they don't exercise token clients, see above).
  • d21 docs change (ee20d8f, light lane: comments, schema description and docs only): pytest tests/test_chart.py (Helm v3.22.1): 1033 passed; mkdocs build --strict: OK; pre-commit run --all-files: all hooks pass; CI on ee20d8f: all 25 checks pass.

Reviews: two rounds of adversarial-reviewer and quality-reviewer. Fixed:

  • --reuse-values upgrades from 0.4.0 failed on that chart's defaults (medium).
  • A test of the default appVersion was missing (medium).
  • The docs didn't give the upgrade order (medium).
  • Stale wording in the docs and schema (medium).
  • Unquoted numeric or boolean client IDs, which Helm rewrites, are now documented (low).
  • The old enum is back on the removed allowAnyAudience (low).
  • Test and comment nits (low).

Declined review findings

  • Exact agreement of whitespace trimming with Java's String.strip (adversarial, low). Go and Java differ only in rare characters (e.g. NBSP, U+001C). Either way such a value is refused, by the chart or at tesk-api's startup, never accepted wrongly. This is noted in the template comment.

Open questions

None.

🤖 Generated with Claude Code

https://claude.ai/code/session_011FSoqN5w1v5t1QRTKU7ad5

Summary by Sourcery

Adopt per-client token audiences in the chart and enforce compatibility with tesk-api 2.1.0 and later.

New Features:

  • Support configuring token clients with per-client audiences or explicit any-audience access, rendered as the JSON configuration expected by tesk-api 2.1.0.

Bug Fixes:

  • Prevent deployments from silently using removed token-client settings or incompatible tesk-api versions.
  • Reject invalid, ambiguous, blank, duplicate, or incomplete token-client configurations before deployment.

Enhancements:

  • Normalize client IDs and audiences while omitting null clients and non-true any-audience flags.
  • Replace legacy token-client environment variables with the consolidated client configuration variable.
  • Add comprehensive validation for legacy values, API compatibility, rendering, normalization, and JSON escaping.

Documentation:

  • Update configuration, deployment, values, and upgrade documentation for per-client audiences, migration, rollout, and rollback behavior.

Tests:

  • Rewrite and expand chart tests for per-client token configuration, schema and template failures, legacy-value migration hints, and tesk-api version gating.

uniqueg and others added 4 commits November 23, 2026 08:03
auth.tokenClients.clients is now a map from client ID to the client's
settings, audiences or allowAnyAudience: true (not both), and the chart
passes them on to tesk-api as one JSON variable,
TESK_API_AUTHORISATION_SERVICE_CLIENTS_CLIENTS (tesk-api#215, #220).
The shared audience and allowAnyAudience and the list of client IDs
are removed: the schema lets them through, and the chart fails with a
hint to the upgrade notes, also with the setting off, as tesk-api 2.1.0
doesn't start with the variables they stood for.

The chart refuses what tesk-api 2.1.0 refuses at startup (blank or
duplicate client IDs after trimming, clients without audiences, blank
audiences, both fields) and fails with the setting on and tesk-api
before 2.1.0, which replaces the warning of the notes for tesk-api
before 2.0.0.

Closes #336

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_011FSoqN5w1v5t1QRTKU7ad5
Upgrade notes with the conversion from the form of chart 0.4.0, the
deployment guide's "Tokens of services" and the configuration
reference.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_011FSoqN5w1v5t1QRTKU7ad5
`helm upgrade --reuse-values` renders with the old release's defaults,
so the defaults of chart 0.4.0 (an empty audience, allowAnyAudience
false, an empty list of clients) no longer fail; only values that mean
something do. Also test the default appVersion against the version
gate, document how Helm changes unquoted numeric client IDs, give the
upgrade order, and fix review nits in comments and docs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_011FSoqN5w1v5t1QRTKU7ad5
Give the removed shared allowAnyAudience its old enum again, so that
values that were never valid don't pass unnoticed, say in the schema
and docs that the defaults of chart 0.4.0 pass, and simplify the tests
of the default appVersion and the empty list.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_011FSoqN5w1v5t1QRTKU7ad5
@uniqueg uniqueg self-assigned this Nov 23, 2026
@sourcery-ai

sourcery-ai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Configuration

Update token-client configuration to use per-client audiences, validate legacy values and API-version compatibility, and render the normalized client map expected by tesk-api 2.1.0.

  • charts/tesk/templates/_helpers.tpl L850-869, L875-897, L902-936 (+2 small edits)
  • charts/tesk/templates/common/tesk-deployment.yaml L253-254
  • charts/tesk/values.schema.json L81-111, L755-765 (+2 small edits)
  • charts/tesk/values.yaml L318-326, L335 (removed lines), L338-355

Documentation

Document the per-client configuration, its security implications, and the upgrade, rollout, and rollback steps.

  • docs/configuration.md L139-145
  • docs/deployment.md L537-543, L550-579, L585-607 (+1 small edits)
  • docs/upgrading.md L15-82

Tests

Replace the shared-audience tests with coverage for rendering, normalization, validation, legacy-value migration, and API-version gating.

  • tests/test_chart.py L2191-2216, L2239-2305, L2370-2538 (+24 small edits)

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 23, 2026 •

Copy link
Copy Markdown

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #338   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            2         2           
  Lines          422       422           
=========================================
  Hits           422       422           

☔ 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 23, 2026 07:36
@sourcery-ai

sourcery-ai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Linked issues

Checked at commit ee20d8f

#336 tokenClients: audiences per client · 2 of 6 met

# Requirement Status Notes
1 Use a per-client map with audiences or allowAnyAudience settings, validating each client's settings. ✅ Met The schema validates each client's fields and disallows extra settings; the template also rejects missing audiences, blank IDs or audiences, duplicate trimmed IDs, and conflicting settings when enabled.
2 Have the old list form and shared audience fail schema validation with a hint to the upgrade notes. 🟡 Partly met The schema permits legacy values so the template can give an upgrade hint; it rejects meaningful legacy values there, including when token clients are off, while chart 0.4.0 defaults pass.
3 Render the new tesk-api environment configuration for the per-client settings. ✅ Met The chart renders the normalized client map as TESK_API_AUTHORISATION_SERVICE_CLIENTS_CLIENTS and does not render the former client-ID or shared-audience variables.
4 Accept each client's token at its own audience and refuse it at another client's audience. ❌ Not addressed This diff changes the chart configuration but contains no tesk-api implementation of the per-client audience check.
5 Update upgrade notes in the chart and tesk-api, the configuration reference, and the deployment guide. 🟡 Partly met The chart's upgrade notes, configuration reference, and deployment guide are updated; the tesk-api upgrade notes are not included in this diff.
6 Test the chart rendering and refusals, and test tesk-api's per-client acceptance and cross-client refusal. 🟡 Partly met The chart tests cover rendering, normalization, schema and template refusals, legacy values, and version gating; tesk-api tests are not included in this diff.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/tesk/templates/_helpers.tpl" line_range="902" />
<code_context>
-{{- range (default list $tokenClients.clients) -}}
-{{- with trim (toString .) -}}
-{{- $clients = append $clients . -}}
+{{- if include "tesk.apiBefore" (dict "root" . "version" "2.1.0") -}}
+{{- fail (printf "auth.tokenClients needs tesk-api 2.1.0 or later, not %s (tesk.image.tag): tesk-api 2.0.0 reads the clients in another form and doesn't start without it, and earlier versions ignore the setting. Upgrade tesk-api, or turn auth.tokenClients off; see %s" (include "tesk.apiImageTag" .) $upgrading) -}}
 {{- end -}}
</code_context>
<issue_to_address>
**Digest pins bypass API version gate**

When `auth.tokenClients.enabled` is true and `tesk.image.tag` names a 2.1.0-or-later version but its digest identifies an older tesk-api image, `tesk.apiBefore` compares the version text before `@` and ignores the digest, while the deployment pulls the image identified by that digest. A tag such as `2.1.0@sha256:<digest-of-2.0.0>` therefore passes this check but runs an incompatible API, so token clients can prevent startup or be ignored.

Treat digest-pinned images as unverifiable by this version gate, or otherwise require a trusted version indication that cannot disagree with the pinned image.
</issue_to_address>

### Comment 2
<location path="charts/tesk/templates/_helpers.tpl" line_range="881-897" />
<code_context>
+renders with the old release's defaults, and the chart never renders the
+variables of tesk-api 2.0.0 */ -}}
+{{- $removed := list -}}
+{{- if include "tesk.isSet" $tokenClients.audience -}}
+{{- $removed = append $removed "auth.tokenClients.audience" -}}
+{{- end -}}
+{{- if eq (toString $tokenClients.allowAnyAudience) "true" -}}
+{{- $removed = append $removed "auth.tokenClients.allowAnyAudience" -}}
</code_context>
<issue_to_address>
**Schema permits legacy values**

The issue asks for the old list form and shared `audience` to fail schema validation with a hint. This change instead allows those forms through the schema and rejects meaningful values later in the template; the schema also permits client settings with missing or empty audiences.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 1 finding to address first, and if the client-to-audience mapping is wrong, tokens may be accepted for a client they were not meant to authorize, allowing that client to create tasks on the cluster. Reverting restores the previous checks, but cannot undo tasks or other actions taken while the incorrect authorization was active.

Blocking findings: charts/tesk/templates/_helpers.tpl:902


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

Comment thread charts/tesk/templates/_helpers.tpl Resolved
Comment thread charts/tesk/templates/_helpers.tpl Resolved
@uniqueg uniqueg mentioned this pull request Nov 23, 2026
6 tasks
Say what allowAnyAudience does, that any token issued to the client
is accepted (also one leaked from or replayed by another service),
that it is meant for testing and setting up federations, and that
production should list audiences (decision d21).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_011FSoqN5w1v5t1QRTKU7ad5
@uniqueg
uniqueg merged commit 2878bcf into dev Nov 23, 2026
34 checks passed
@uniqueg
uniqueg deleted the feat/token-clients-audiences branch November 23, 2026 22:40
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.

tokenClients: audiences per client

1 participant