siderolabs / omni

SaaS-simple deployment of Kubernetes - on your own hardware.
Other
522 stars 31 forks source link

[feature] Add cache-control header to head requests #324

Closed selfuryon closed 3 months ago

selfuryon commented 3 months ago

Problem Description

Hey! I faced with issue using Cloudflare as a proxy for Omni. Omni frontend uses this workflow to download the image from the backend:

  1. Check/trigger the creation of the image via a HEAD request to the /image/xxx route
  2. Download the image via GET request

The problem is here, that Cloudflare caches all requests, and they convert HEAD request to GET request by default, which broke the authentication because payload contains the method too.

Solution

Cloudflare (and others I believe) support no caching behavior based on standard headers in the request, so we can just add the header Cache-Control: no-store to our HEAD request to bypass caching in CF.

Alternative Solutions

Currently, I bypass the caching by using Cloudflare caching rules with exceptions for all /image URIs, but it isn't very flexible.

Notes

I will prepare PR to resolve this issue