Skip to content

CH-155 Allow CORS across *.domain at the ingress - #905

Open
filippomc wants to merge 1 commit into
developfrom
feature/CH-155-CORS
Open

filippomc wants to merge 1 commit into
developfrom
feature/CH-155-CORS

Conversation

@filippomc

@filippomc filippomc commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Closes CH-155

Implemented solution

Applications served on different subdomains of a deployment can now call each other with credentials (cookies, Authorization) without going through the use_services /proxy/<service> path. CORS is handled once at the ingress, for every application.

New opt-in values. The default is off, so existing deployments render exactly as before:

ingress:
  cors:
    enabled: true
    allowMethods: [GET, PUT, POST, DELETE, PATCH, OPTIONS]
    allowHeaders: [DNT, Keep-Alive, User-Agent, X-Requested-With, If-Modified-Since, Cache-Control, Content-Type, Range, Authorization, X-CSRFToken]
    exposeHeaders: []

The allowed origins are <domain> and *.<domain>, over https when tls is set and http otherwise. Credentials are always allowed.

  • nginx (ingress.yaml): enable-cors, cors-allow-origin, cors-allow-credentials, cors-allow-methods, cors-allow-headers and, when set, cors-expose-headers are added to both the application Ingress and the use_services -proxy Ingress.
    • ingress-nginx needs a scheme in wildcard origins, so the value is https://*.<domain>,https://<domain> rather than the bare *.<domain> sketched in the issue.
    • Its wildcard matches a single label, so nested application hosts (a subdomain or alias containing a dot, e.g. instance.app.<domain>) are appended to the list one by one.
  • traefik (traefik-middlewares.yaml): a ch-cors headers Middleware with accessControlAllowOriginListRegex: ^https://([A-Za-z0-9-]+\.)*<domain>$ (any depth), appended to router.middlewares on both Ingresses.

For allowed origins the ingress answers the preflight requests itself, and its headers replace the ones set by gatekeepers or applications (ingress-nginx sets them with more_set_headers). Requests from other origins get no CORS headers from the ingress, so an application's own CORS handling still applies to them. The gatekeepers' existing cors-origins: *.<domain> configuration is left as it is.

Security note: when enabled, every *.<domain> host is trusted by every application: a script on any subdomain page can read the authenticated responses of all of them. The new section in docs/ingress-domains-proxies.md says so, and advises against enabling it where a subdomain serves untrusted content (e.g. user notebooks).

How to test this PR

  1. Unit test: pytest tools/deployment-cli-tools/tests/test_helm.py -k ingress_cors. It renders the chart with helm template and checks that:
    • nothing is added by default;
    • with enabled: true, the nginx annotations are on both the application and the proxy Ingress, including a nested alias, for TLS and non-TLS;
    • with ingressClass: traefik, the ch-cors Middleware exists, is referenced by both Ingresses, and its regex accepts the domain and its subdomains while refusing http:// origins and lookalike domains;
    • turning it off again removes the Middleware and its reference.
  2. Render a deployment: set ingress.cors.enabled: true in deployment-configuration/values-template.yaml, run harness-deployment, then helm template deployment/helm. Every generated Ingress should carry the nginx.ingress.kubernetes.io/*cors* annotations (or reference ch-cors with traefik).
  3. On a deployed environment, with <app> any application subdomain:
# Preflight answered by the ingress: 204, Access-Control-Allow-Origin: https://www.<domain>, Access-Control-Allow-Credentials: true
curl -si -X OPTIONS https://<app>.<domain>/ -H 'Origin: https://www.<domain>' -H 'Access-Control-Request-Method: POST' | grep -i '^HTTP\|^access-control'

# Actual request: exactly one Access-Control-Allow-Origin, equal to the origin (check a gatekeeper-secured app too)
curl -si https://<app>.<domain>/ -H 'Origin: https://www.<domain>' | grep -i '^access-control\|^vary'

# Foreign origin: no CORS headers from the ingress
curl -si https://<app>.<domain>/ -H 'Origin: https://example.com' | grep -i '^access-control'

What has been verified so far: the tools/deployment-cli-tools/tests suite passes locally (294 tests) and the lint check is clean. A downstream project's chart was generated and rendered for an nginx and a traefik environment: every generated Ingress got the CORS configuration, and the nginx values pass ingress-nginx's annotation validation patterns, which were reproduced from its source rather than run against the controller. Step 3 has not been run on a cluster yet.

Sanity checks:

  • The pull request is explicitly linked to the relevant issue(s)
  • The issue is well described: clearly states the problem and the general proposed solution(s)
  • In this PR it is explicitly stated how to test the current change
  • The issue seta the scope and the type of issue (bug, story, task, etc.)
  • The relevant components are indicated in the issue (if any)
  • All the automated test checks are passing
  • All the linked issues are included in one Sprint
  • All the linked issues are in the Review state
  • All the linked issues are assigned

Breaking changes (select one):

  • The present changes do not change the preexisting api in any way
  • This PR and the issue are tagged as a breaking-change and the migration procedure is well described above

Possible deployment updates issues (select one):

  • There is no reason why deployments based on CloudHarness may break after the current update
  • This PR and the issue are tagged as alert:deployment

Test coverage (select one):

  • Tests for the relevant cases are included in this pr
  • The changes included in this pr are out of the current test coverage scope

Documentation (select one):

  • The documentation has been updated to match the current changes
  • The changes included in this PR are out of the current documentation scope

Nice to have (if relevant):

  • Screenshots of the changes
  • Explanatory video/animated gif

🤖 Generated with Claude Code

@filippomc
filippomc requested a review from aranega November 26, 2026 18:46
New opt-in `ingress.cors` (enabled, allowMethods, allowHeaders,
exposeHeaders) lets every application accept credentialed cross-origin
requests from the deployment's own hosts (<domain> and *.<domain>).

- nginx: enable-cors annotations on the application and use_services
  proxy ingresses. The nginx wildcard matches one label, so nested
  application hosts (e.g. instance.app.<domain>) are listed explicitly.
- traefik: ch-cors headers middleware matching any subdomain depth,
  appended to the router middlewares.

The ingress answers preflights and its headers replace those set by
gatekeepers or applications for the allowed origins.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant