Skip to content

Storage redirect middleware should sign S3 URLs for the new URL #4750

Closed

Description

@ehfd

Description

One key case of this purpose is where for image uploads, there is a preferred internal endpoint, and for image downloads, there is a separate external endpoint that is able to use signed URLs and redirects.

This means that for uploads, we are able to utilize the fast internal endpoint without any reverse proxies in between, going through the CNCF Distribution container or executable, and for downloads, we can use S3 signed URLs like currently.

The issue with the redirect middleware, currently, is that the signed URL is not compatible due to the hostname changing in the redirect, and downstream pullers fail.

This means that we need to choose between (1) a suboptimal upload by using the external S3 endpoint, where the container upload effectively passes through the reverse proxy twice (if CNCF Distribution is also behind the reverse proxy) and provides a massive bottleneck, or (2) the download having to always go through CNCF Distribution due to the combination of configuring REGISTRY_STORAGE_REDIRECT_DISABLED=true and solely using the internal S3 endpoint.

By signing the URL generated in storage redirect middleware, this problem can be completely solved and two different endpoints can be used, one for upload, and one for download and redirection with signed URLs.

This is a CNCF Distribution v3 issue.

Example of how this feature works:

For Ceph S3 (RGW) or MinIO combined with Kubernetes Ingress resources or other clustered environments, there are typically two ways to access the S3 endpoint.

The first is an internal Service, that exposes an internal HTTP endpoint (e.g., http://ceph-rgw.rook.svc.cluster.local). The second is an external HTTPS endpoint (e.g., https://s3-ceph.domain.tld) through an Ingress, terminated by HAProxy, Envoy, NGINX, etc.

Without separate endpoints, we are currently forced to either use (1) REGISTRY_STORAGE_REDIRECT_DISABLED=true and just use http://ceph-rgw.rook.svc.cluster.local for both uploads (faster and doesn't pass through the Ingress twice) and downloads (all downloads pass through Distribution and thus bottlenecked by the instance), or use (2) https://s3-ceph.domain.tld for both uploads (bottlenecked because the blob data goes through the Ingress twice) and downloads (fastest and least resource-intensive due to the redirect).

This feature solves this issue of choosing only one of the two flawed options by using the internal fast endpoint (http://ceph-rgw.rook.svc.cluster.local) for uploads and using the redirect to the external S3 endpoint (https://s3-ceph.domain.tld) for downloads, getting the best of both worlds.

Activity

  1. ehfd commented on Feb 5, 2026

    @ehfd
    Author

    tl;dr: S3 URL signing must be done AFTER the rewrite middleware, when both are enabled, because we want to use different upload and download S3 URL paths in certain cases.

    Implement For example, it can be used to rewrite the Blob Storage URL returned by the Azure Blob Storage driver to use Azure CDN. for S3, and make it compatible with signed URLs.

    In certain cases, you need a separate S3 upload endpoint (non-public, internal-only) without any reverse proxies or WAFs in between, and a separate S3 download endpoint (public, externally available) for signed URLs.

    Currently, the Docker/containerd client fails when I try to use https://distribution.github.io/distribution/storage-drivers/middleware/rewrite/. This is because the URL itself is the input for the signed key generation for the signed URL, and because the S3 signing happens before the rewrite, the blob access from the Docker/containerd client fails.

    Furthermore, the problem when we use the public endpoint for both upload and download is that the reverse proxy server (in k8s, for instance) gets congested because both S3 and CNCF Distribution are on the same reverse proxy interface, and the throughput fractions are reduced due to the same data passing multiple times.

  2. DARSHANR007 commented on May 19, 2026

    @DARSHANR007
    Contributor

    Hello,

    Is this issue still open? It looks interesting and I’d like to work on it.

    From what I understood, the fix would involve the following changes:

    1. Configuration Update

    Add an optional RedirectEndpoint field to the S3 storage driver configuration.

    This would allow the registry to store a separate public-facing domain instead of reusing the internal S3/backend endpoint.

    Example:

    storage:
      s3:
        bucket: example-bucket
        region: us-east-1
        endpoint: internal-s3.local
        redirectendpoint: cdn.example.com

    2. Middleware Changes

    Update the redirect/rewrite middleware logic.

    Before calling URLFor, the middleware can read the configured public redirect endpoint and pass it through the request context/options map.


    3. S3 Driver Changes

    Inside the S3 driver’s URLFor implementation:

    • Check whether the custom redirect hostname exists in the options map.
    • If present, overwrite:
    req.HTTPRequest.URL.Host

    with the public redirect hostname before signing the request.


    4. Request Signing

    After replacing the host, call the AWS SDK’s official .Presign() method.

    This ensures the generated HMAC-SHA256 signature is calculated using the public hostname rather than the internal backend endpoint.


    5. Redirect Flow

    Return the signed public URL back to the middleware.

    The middleware can then issue an HTTP 307 Temporary Redirect, allowing the container client to pull layers directly from the external endpoint using a valid signed URL.

    Let me know if this approach makes sense. I’d be happy to work on it.

  3. ehfd commented on May 19, 2026

    @ehfd
    Author

    @DARSHANR007
    If you could PR this, it would be awesome!

  4. DARSHANR007 commented on May 19, 2026

    @DARSHANR007
    Contributor

    yea ive PRed it on #4870

  5. ehfd commented on Jun 1, 2026

    @ehfd
    Author

    Merged in #4870.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions