Skip to content

feat: set the tesk-api CORS origins in the chart - #310

Merged
uniqueg merged 14 commits into
devfrom
feat/307-cors-origins
Nov 16, 2026
Merged

uniqueg merged 14 commits into
devfrom
feat/307-cors-origins

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Closes #307

Stacked on #309 (branched from build/308-tesk-api-2.0.0, which is merged in): until #309 is merged, this diff also shows its commits. Review the commits feat: set the tesk-api CORS origins in the chart, fix: refuse origins that tesk-api refuses, fix: match tesk-api's CORS origin rules and docs: list IPv6 CORS origins in the short form (the merge of #309 at 6225b88 only adapts the CORS notes tests to its taskmaster check); after #309 is merged, dev needs to be merged into this branch.

Summary

tesk-api 2.0.0 answers cross-origin requests of the origins in TESK_API_CORS_ALLOWED_ORIGINS (elixir-cloud-aai/tesk-api#195). The chart gets a value for it:

  • tesk.cors.allowedOrigins (list, default []) in values.yaml, documented like auth.serviceInfoPublic, and in values.schema.json.
  • templates/common/tesk-deployment.yaml sets TESK_API_CORS_ALLOWED_ORIGINS to the list joined with ,, only when the list isn't empty (also tesk.cors: null and allowedOrigins: null leave it out).
  • The schema refuses origins that tesk-api 2.0.0 refuses at startup (which would leave the API down after an upgrade, with the default Recreate strategy): only http/https (any case), an ASCII host name without _ (optionally with a trailing dot), an IPv4 address as four decimal numbers or a well-formed bracketed IPv6 address, and a port from 1 to 65535 without leading zeros and other than the default; no wildcards, paths, user info or commas. Checked against a copy of tesk-api's CorsConfig validation on 46 origins: the same verdict for all but IPv6 zone IDs and single-label hosts starting with a digit, which the chart refuses on purpose (documented).
  • The notes of helm install/helm upgrade warn if origins are set with tesk-api before 2.0.0, which ignores them.
  • Docs: deployment guide (new section "Browser clients (CORS)", including that IPv6 origins must be in the short, lower-case form that browsers send), configuration reference, upgrade notes. They name 2.0.0 as the first tesk-api release with the setting: feat: set the tesk-api CORS origins in the chart #307 says "the first release after 2.0.0", but tesk-api#195 is part of 2.0.0 (see its release notes), and this was checked on kind.

How it was verified

  • helm lint charts/tesk --strict (Helm 3.22.1): passed.
  • REQUIRE_HELM=1 pytest tests/test_chart.py: 737 passed (with build: use tesk-api 2.0.0 in the chart #309 merged in) (new: test_cors_allowed_origins, test_cors_allowed_origins_invalid with 30 invalid origins, test_cors_unknown_key, test_notes_cors_old_api, test_notes_cors_unset_old_api; written first and failing before the change).
  • coverage run -m pytest --ignore=tests/test_chart.py: 175 passed, 100% coverage.
  • pre-commit run --all-files: passed.
  • mkdocs build --strict: passed; anchors deployment/#browser-clients-cors and tesk-api/configuration/#cross-origin-requests-cors exist.
  • kind (v0.33.0), tesk-api 2.0.0 with allowedOrigins: [https://client.example.org, http://localhost:3000], cluster deleted afterwards: preflight OPTIONS /tasks from https://client.example.org → 200 with Access-Control-Allow-Origin: https://client.example.org; GET /tasks from http://localhost:3000 → 200 with that origin; from https://evil.example.org → 403 without CORS headers; without Origin → 200.
  • CI: all checks passed at 37af2a3 (CI passed, Chart, Chart install on kind, Docs, Lint, Test, Release readiness, CodeQL, Codecov, Read the Docs preview, Sourcery).
  • Sourcery: 3 findings. Two were about build: use tesk-api 2.0.0 in the chart #309's code (old API with new taskmaster; tags with leading zeros), fixed there in 6225b88 and merged in. One (origins in other case, with a trailing slash or as expanded IPv6) answered: Spring compares origins case-insensitively and ignores a trailing /; expanded IPv6 never matches what browsers send, now documented instead of canonicalized in a template.

Declined review findings

Two review rounds (adversarial and quality); fixed: origins that the first schema let through but tesk-api refuses at startup (default ports, leading zeros, _, malformed IPv4/IPv6, other schemes), the CORS section as a list, a separate test for notes without origins. Declined:

  • Quality review: the link tesk-api/configuration.md#cross-origin-requests-cors points to docs that are pulled in at build time; the strict build with the pinned tesk-api v2.0.0 docs resolves it, so it stays.
  • The chart refuses IPv6 zone IDs (browsers don't send them) and single-label hosts that start with a digit (e.g. 3com), which tesk-api accepts: matching tesk-api there would need a much more complex pattern for no practical gain.

Open questions

None.

🤖 Generated with Claude Code

Summary by Sourcery

Configure and validate browser CORS origins in the tesk Helm chart for tesk-api 2.0.0 and later.

New Features:

  • Add configurable CORS allowed origins to the Helm chart and pass them to tesk-api 2.0.0 and later.

Bug Fixes:

  • Prevent deployments from accepting CORS origins that tesk-api would reject at startup.

Enhancements:

  • Warn during Helm installation and upgrades when CORS origins are configured with an older tesk-api image.
  • Document CORS configuration, browser origin requirements, IPv6 formatting, token considerations, and upgrade behavior.

Documentation:

  • Add CORS guidance to the deployment, configuration, and upgrade documentation.

Tests:

  • Add chart tests covering CORS rendering, validation, unknown keys, and compatibility warnings.

uniqueg and others added 10 commits November 16, 2026 12:33
The chart's appVersion (the default tag of the API's image) is 2.0.0,
and the taskmaster and filer images default to 0.12.0. One helm upgrade
brings both in the order they need, as the API's Deployment uses the
Recreate strategy (#305).

The notes warn about auth.tokenClients for tesk-api before 2.0.0, the
first release with the setting (was: before 1.2.1-0). The chart's
service info reports TES 1.1.0 for tesk-api 2.0.0 and later (and for
tags that aren't versions), and TES 1.0.0 before, as tesk-api 2.0.0
implements TES 1.1.

Refs #308

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Pull the docs of tesk-api v2.0.0 and tesk-core v0.12.0 into the site,
so that the links of the tesk-api 2.0.0 release notes (upgrading/#to-200,
"Tokens of services") resolve. Add upgrade notes for the new default
images: pinned tags and the upgrade order, the hardened filer pods on
clusters that refuse the RuntimeDefault seccomp profile, the service
info's TES version, and the API changes for clients. The configuration
reference and the deployment guide name the new defaults.

Refs #308

Co-Authored-By: Claude Opus 5.5 <[email protected]>
tesk.apiBefore replaces four copies of the version check of the API's
tag (notes and service info). Docs: /v3/api-docs of tesk-api 2.0.0,
the tokenClients requirement in the configuration reference, one place
for the filer's seccomp advice; test_default_images checks the
rendered image.

Refs #308

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- tesk.filer.podSecurityContext and tesk.filer.securityContext replace
  the taskmaster's defaults for the filer pods (FILER_POD_SECURITY_CONTEXT
  and FILER_SECURITY_CONTEXT), e.g. on clusters that refuse pods asking
  for the RuntimeDefault seccomp profile; null keeps the defaults.
- The FTP secret's name also goes to the taskmasters as
  TESK_FTP_SECRET_NAME, so that filer jobs of taskmaster 0.12.0
  reference it instead of holding the credentials.
- The notes warn about taskmaster 0.12.0 or later with tesk-api before
  2.0.0, which reports wrong task states.

Docs: upgrade notes, configuration reference, deployment guide.

Refs #308

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Add pre-release cases to the notes test for taskmaster 0.12.0 with an
older tesk-api, parametrize the filer security context test on JSON
values, and read tesk.apiBefore the same way everywhere. Docs: rewrap
lines, note that Helm merges the filer's security contexts across
values files, and the ignore_error exception with taskmaster 0.11.0.

Refs #308

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The value tesk.cors.allowedOrigins (a list, default empty) becomes
TESK_API_CORS_ALLOWED_ORIGINS of tesk-api 2.0.0, joined by commas, only
when it isn't empty. The schema refuses wildcards, paths, user info,
commas and origins without a scheme, which tesk-api would refuse at
startup; the notes warn if origins are set with tesk-api before 2.0.0,
which ignores them. Docs: deployment guide (Browser clients (CORS)),
configuration reference, upgrade notes.

Closes #307

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Tags that look like versions but aren't SemVer (e.g. 1.2.3- or
0.12.0-foo..bar) made semverCompare fail the render. The API and
taskmaster checks now accept only SemVer pre-release and build parts,
and treat other tags as tags that aren't versions. Docs: the taskmaster
checks the filer's security contexts and falls back to its defaults.

Refs #308

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The schema now accepts only http(s) origins with an ASCII host name, an
IPv4 address as four decimal numbers or a bracketed IPv6 address, and a
port from 1 to 65535 without leading zeros and other than the default:
tesk-api 2.0.0 stops at startup on other origins, which left the API
down after an upgrade with the Recreate strategy. Docs: the CORS section
as a list; a test of its own for notes without origins.

Refs #307

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The schema now checks IPv6 literals as such (malformed ones such as
[1] or [::1::2] stopped tesk-api at startup), and accepts what tesk-api
accepts: schemes in any case, host names with a trailing dot. It stays
stricter for IPv6 zone IDs and single-label hosts that start with a
digit, as the docs say.

Refs #307

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg uniqueg self-assigned this Nov 16, 2026
@sourcery-ai

sourcery-ai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Configuration

Define and validate tesk.cors.allowedOrigins as a list of browser origins, defaulting to empty and refusing values that tesk-api would reject at startup.

  • charts/tesk/values.schema.json L313-345
  • charts/tesk/values.yaml L176-189

Pass nonempty origins to tesk-api as TESK_API_CORS_ALLOWED_ORIGINS, and warn when the configured API version is too old to honor them.

  • charts/tesk/templates/_helpers.tpl L407-414
  • charts/tesk/templates/common/tesk-deployment.yaml L229-235

Documentation

Explain how to configure browser-client CORS, the origin validation rules, token implications, and the minimum supported API version.

  • docs/configuration.md L69
  • docs/deployment.md L603-649
  • docs/upgrading.md L87-94

Tests

Test origin rendering and schema rejection, unknown CORS keys, and version-dependent install notes.

  • tests/test_chart.py L1267-1420

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

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (69e48fe) to head (35a2a15).

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #310   +/-   ##
=========================================
  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 16, 2026 14:30
@sourcery-ai

sourcery-ai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Linked issues

Checked at commit 35a2a15

#307 feat: set the tesk-api CORS origins in the chart · 3 of 3 met

# Requirement Status Notes
1 Add tesk.cors.allowedOrigins with default [], documentation, and schema validation. ✅ Met The value and default are in values.yaml; the chart schema validates it, and the configuration reference documents it.
2 Set TESK_API_CORS_ALLOWED_ORIGINS to the comma-joined list only when it is non-empty. ✅ Met The deployment template joins and sets the value only when origins are present; tests also cover empty and null values.
3 Test both cases and document which tesk-api release supports the setting. ✅ Met Tests cover unset/empty and configured origins; the deployment and configuration docs identify tesk-api 2.0.0 as the supported starting release.

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

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

## Individual Comments

### Comment 1
<location path="charts/tesk/values.yaml" line_range="50" />
<code_context>
     image:
       repository: docker.io/elixircloud/tesk-core-taskmaster
-      tag: 0.11.0
+      tag: 0.12.0
   # Image of the filer (tesk-core), which stages the inputs and outputs; its
   # tag must be the same release as the taskmaster's (the installation
</code_context>
<issue_to_address>
**Tasks get incorrect statuses**

When an existing release pins `tesk.image.tag` below 2.0.0 but leaves its taskmaster and filer image tags unset when upgrading, the chart deploys taskmaster 0.12.0 with the pinned older API, which treats filer jobs as executor jobs and reports incorrect task states that are persisted for tasks.

Fail chart rendering for this incompatible API/taskmaster combination, or otherwise keep the new taskmaster default from being deployed with an older pinned API.

Also at `charts/tesk/templates/_helpers.tpl:394-401`.
</issue_to_address>

### Comment 2
<location path="charts/tesk/templates/_helpers.tpl" line_range="104" />
<code_context>
+`version` (X.Y.Z) */ -}}
+{{- define "tesk.apiBefore" -}}
+{{- $apiTag := include "tesk.apiImageTag" .root | trimPrefix "v" -}}
+{{- if and (regexMatch "^[0-9]+\\.[0-9]+(\\.[0-9]+)?(-[0-9A-Za-z-]+(\\.[0-9A-Za-z-]+)*)?(\\+[0-9A-Za-z-]+(\\.[0-9A-Za-z-]+)*)?$" $apiTag) (semverCompare (printf "<%s-0" .version) $apiTag) -}}
+true
+{{- end -}}
</code_context>
<issue_to_address>
**Helm rendering rejects image tags**

When an API or taskmaster image tag has a leading-zero version component or numeric prerelease identifier, the tag regexes admit these strings, then `semverCompare` rejects `$apiTag` or `$taskmasterTag`; Helm aborts rendering, so installs, upgrades, and template rendering fail.

Make both tag regexes admit only SemVer strings `semverCompare` can parse, and treat invalid tags as unchecked.

Also at `charts/tesk/templates/_helpers.tpl:394`.
</issue_to_address>

### Comment 3
<location path="charts/tesk/templates/common/tesk-deployment.yaml" line_range="232" />
<code_context>
+        origins) */}}
+        {{- with dig "cors" "allowedOrigins" list $tesk }}
+        - name: TESK_API_CORS_ALLOWED_ORIGINS
+          value: {{ join "," . | quote }}
+        {{- end }}
         {{- if .Values.transfer.enabled }}
</code_context>
<issue_to_address>
**Browser requests fail CORS**

When an allowed origin has uppercase scheme or host characters, a trailing slash, an expanded IPv6 literal, or another spelling the browser serializes differently, the chart joins the configured origins unchanged, and tesk-api compares them exactly with the browser’s serialized `Origin`; the values do not match, so the browser blocks the API response.

Canonicalize each configured origin to the browser’s serialized form before passing the joined values to tesk-api.

Also at `tests/test_chart.py:1285`, `tests/test_chart.py:1287`, `tests/test_chart.py:1302-1305`, `charts/tesk/templates/common/tesk-deployment.yaml:233`.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 3 findings to address first, and the chart now deploys a new API/taskmaster pair, and task runs may create states and outputs that a rollback cannot undo if their behavior is wrong. When configured, the CORS origins also let browsers at those origins read API responses using a user's token; reverting removes the headers, but cannot undo data already exposed.

Blocking findings: charts/tesk/values.yaml:50, charts/tesk/templates/_helpers.tpl:104, charts/tesk/templates/common/tesk-deployment.yaml:232


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

Comment thread charts/tesk/values.yaml Resolved
Comment thread charts/tesk/templates/_helpers.tpl Resolved
uniqueg and others added 3 commits November 16, 2026 15:49
Taskmaster 0.12.0 and later with tesk-api before 2.0.0 report wrong
task states, e.g. after an upgrade with values that pin an older
tesk.image.tag but not the taskmaster. The installation now fails for
such a pair instead of the notes warning about it.

The version checks accept only SemVer that semverCompare reads as
written (no leading zeros in numbers and numeric pre-release parts), so
tags such as 01.2.3 or 1.2.3-01 count as tags that aren't versions.

Refs #308

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The CORS notes tests now pin taskmaster and filer 0.11.0 for older
tesk-api tags, which the chart refuses with taskmaster 0.12.0.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
tesk-api compares origins as text, so a long-form IPv6 origin passes
its startup check but never matches the short form that browsers send.

Refs #307

Co-Authored-By: Claude Opus 5.5 <[email protected]>
dev only adds the squash of #309, already merged here (tree of
6225b88 equals dev), so the branch tree is kept.
@uniqueg
uniqueg merged commit ab9769c into dev Nov 16, 2026
23 checks passed
@uniqueg
uniqueg deleted the feat/307-cors-origins branch November 16, 2026 15:45
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: set the tesk-api CORS origins in the chart

1 participant