Skip to content

feat(cloudflare): add cloudflare-mode option to choose which store to upload cert - #54

Open
claneys wants to merge 4 commits into
robertlestak:mainfrom
claneys:feat/cloudflare-leaf-only
Open

feat(cloudflare): add cloudflare-mode option to choose which store to upload cert#54
claneys wants to merge 4 commits into
robertlestak:mainfrom
claneys:feat/cloudflare-leaf-only

Conversation

@claneys

@claneys claneys commented Sep 4, 2026

Copy link
Copy Markdown

The certificate was being pushed to Cloudflare's custom_certificates endpoint, which holds edge certificates served to visitors and requires a chain Cloudflare can bundle against its public trust store. Ours is issued by the internal ca, so every sync failed with "certificate chain cannot be bundled using Cloudflare's trust store" — dropping the CA from the payload did not help, since the leaf itself is privately issued.

Fix errors 2100:

cert-manager-sync-789c5c7cb4-mx87z cert-manager-sync {"action":"HandleSecret","error":"store cloudflare sync failed: failed to create certificate in Cloudflare (zone: 056fb04345110094502307b2223df090): POST \"https://api.cloudflare.com/client/v4/zones/056fb04345110094502307b2223df090/custom_certificates\": 400 Bad Request {\"success\":false,\"errors\":[{\"code\":2100,\"message\":\"The certificate chain you uploaded cannot be bundled using Cloudflare's trust store. Please check your input and try again.\"}],\"messages\":[],\"result\":null}","level":"error","msg":"sync error details","name":"core-gateway-cloudfront-origin-mtls-client-cert","namespace":"kgateway-cdn","resourceVersion":"957966679","time":"2026-09-04T12:40:35Z"}

Some CA bundles are rejected by Cloudflare's custom_certificates trust
store validation ("certificate chain cannot be bundled"). Add a
per-secret leaf-only annotation to upload only the leaf certificate
instead of the full chain.
The custom_certificates endpoint uploads edge certificates, which
Cloudflare bundles against its public trust store. Syncing an origin
mTLS client certificate issued by an internal CA there always fails
with "certificate chain cannot be bundled using Cloudflare's trust
store", whether or not the CA is included.

Add a cloudflare-mode annotation selecting the target store.
"origin-pull" uses the origin_tls_client_auth endpoint, which is the
one meant for client certificates Cloudflare presents to the origin:
it takes the leaf and the private key only, and accepts a private
issuing CA. That endpoint has no update method, so a renewal uploads
the new certificate and removes the one it replaced.

Replaces the leaf-only flag, which could not fix this: a leaf issued
by a private CA is rejected by custom_certificates all the same.
@claneys claneys changed the title feat(cloudflare): add leaf-only option to skip CA bundling feat(cloudflare): add cloudflare-mode option to choose which store to upload cert Sep 4, 2026
The origin-pull mode uploads a zone-level client certificate, which
applies to every hostname in the zone. Zones that need a different
client certificate per hostname have no way to express that.

Add an origin-pull-hostname mode that uploads to the per-hostname
endpoint and associates the certificate with the hostnames listed in a
new cloudflare-hostnames annotation. Associating a hostname is what puts
the certificate in use, so it runs before the replaced certificate is
removed; if the association fails, the freshly uploaded certificate is
deleted so retries do not pile up unused certificates.

Both mode and hostnames are validated together: the mode requires a
non-empty list, and the list is rejected in any other mode rather than
being silently ignored.
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