Credentials and Secrets
This project never accepts a Cloudflare credential directly on a custom resource or a Helm
value — every credential is a reference to an ordinary Kubernetes Secret that you create and
manage yourself. See Token Scopes for exactly which permissions
each credential needs.
Create the credential Secret
Section titled “Create the credential Secret”CloudflareGatewayConfiguration.spec.credentialSecretRef points at the Secret holding the
Cloudflare API token its controllers authenticate with:
kubectl create secret generic cloudflare-api-token \ --namespace cloudflare-gateway-controller-system \ --from-literal=api-token=<token>apiVersion: cfgateway.dreamfuselabs.com/v1alpha1kind: CloudflareGatewayConfigurationmetadata: name: tunnel-configspec: mode: tunnel accountID: "$ACCOUNT_ID" zoneAllowlist: ["$ZONE"] credentialSecretRef: namespace: cloudflare-gateway-controller-system name: cloudflare-api-token key: api-tokencredentialSecretRef carries its own namespace field, not just a name, because
CloudflareGatewayConfiguration is cluster-scoped — it has no namespace of its own to
implicitly resolve a bare Secret name against. The Secret’s data key defaults to api-token
if you omit key.
Updating the Secret’s value rotates the token the next time any of this configuration’s controllers reconcile (including the periodic background resync every Cloudflare-side resource runs) — no controller restart is needed.
DNS Mode needs a second token, in cert-manager’s namespace
Section titled “DNS Mode needs a second token, in cert-manager’s namespace”Tunnel Mode has no ACME/cert-manager dependency — the one Secret above is all you need.
cert-manager’s own Cloudflare DNS-01 solver, configured on your ClusterIssuer, resolves its
apiTokenSecretRef against cert-manager’s own cluster resource namespace — by default the
cert-manager namespace cert-manager itself runs in — never against the namespace of whatever
Certificate or Gateway consumes the issuer. This project’s own live testing confirmed it:
plan for two Secrets, one per consumer, holding two different tokens — cert-manager’s
copy is a separate token scoped to Zone / DNS: Edit plus Zone / Zone: Read (see
Token Scopes), not a copy of the
controller’s own token. Keeping the two separate isn’t about one being narrower than the
other — in DNS Mode the controller’s own token needs that exact same scope (see
Token Scopes’s DNS Mode table), and if you also use Access the
controller’s token is the broader one of the two. The reason to keep them separate is
independent rotation (see below) and blast-radius
limiting: each token can be rotated or revoked without touching the other’s access.
kubectl create secret generic cloudflare-api-token \ --namespace cert-manager \ --from-literal=api-token=<cert-manager-scoped-token>This isn’t a project-specific quirk — it’s how cert-manager’s Cloudflare DNS-01 solver works regardless of what’s driving it.
Identity provider client secrets
Section titled “Identity provider client secrets”A CloudflareAccessIdentityProvider in its managed arm (every type except OTP, which has no
credentials at all) references its OAuth client secret through spec.provider.clientSecretRef
— never inline in the spec:
apiVersion: v1kind: Secretmetadata: name: my-github-idp-client-secret namespace: cloudflare-gateway-controller-systemstringData: client-secret: <the OAuth client secret from your identity provider>---apiVersion: cfgateway.dreamfuselabs.com/v1alpha1kind: CloudflareAccessIdentityProvidermetadata: name: my-github-idpspec: configurationRef: name: tunnel-config provider: type: GitHub clientID: <the OAuth client ID> clientSecretRef: namespace: cloudflare-gateway-controller-system name: my-github-idp-client-secretclientSecretRef carries its own namespace for the same reason credentialSecretRef does —
CloudflareAccessIdentityProvider is cluster-scoped — and its data key defaults to
client-secret (a different default than credentialSecretRef’s api-token, since these are
two different kinds of credential). The controller reads this Secret, sends the value to
Cloudflare, and never persists it anywhere in the cluster.
Every other OAuth-adjacent field — clientID, a Google Workspace apps domain, an Entra
directory ID, an Okta account URL — is a plain spec field, not a Secret reference: none of
those values are secret, and putting them behind a Secret reference would make them
un-reviewable in Git for no security benefit.
Service token credentials
Section titled “Service token credentials”A CloudflareAccessServiceToken mints a non-interactive credential and writes it to a Secret
once, at creation time — Cloudflare’s API returns the token’s secret exactly once and
never again, so the controller stores it immediately and never re-fetches it.
This is the shape the controller itself writes — don’t create this Secret yourself. The
reconciler refuses to adopt a Secret of this name that already exists and isn’t
controller-owned (Accepted=False, Reason=[Conflicted](/reference/conditions/#conflicted), and no token minted), so applying this
YAML ahead of the CloudflareAccessServiceToken object blocks the object from reconciling
until you delete that Secret. The Secret always lands in the object’s own namespace, under a name that
defaults to the object’s own name (spec.secretName overrides that default if set), and
carries fixed keys. (default below matches the namespace the Access guide’s own
CloudflareAccessServiceToken example uses — not a requirement, just this
example’s own choice.)
apiVersion: v1kind: Secretmetadata: name: my-service-token namespace: defaultstringData: client-id: <CF-Access-Client-Id value> client-secret: <CF-Access-Client-Secret value>client-id and client-secret map directly to the CF-Access-Client-Id and
CF-Access-Client-Secret headers your application sends on each request to a
service-token-protected hostname. The controller owner-references this Secret to the
CloudflareAccessServiceToken object, so deleting the custom resource cascades to delete the
Secret — plan for that if you were relying on the credential surviving the object’s deletion.
GitOps-compatible secret management
Section titled “GitOps-compatible secret management”This project only ever reads an ordinary corev1.Secret by namespace, name, and key — it has
no opinion on how that Secret gets into the cluster, so any approach that ends up producing
one works, at a high level:
- Sealed Secrets or SOPS-encrypted manifests, decrypted at apply time — the simplest option for a single-cluster or low-tenant-count setup, since the encrypted form is safe to commit directly.
- External Secrets Operator, pointed at whatever secret store you already use (a cloud
provider’s secret manager, Vault, and so on), with its target Secret name matching what a
*SecretReffield above names. - HashiCorp Vault, injected directly via an agent sidecar or CSI provider.
Whichever mechanism you pick, never commit the Secret with the credential inlined in plaintext — commit only its shape (name, namespace, key), encrypted or sealed by your chosen tool. A credential committed in cleartext, even to a private repository, should be treated as compromised and rotated immediately; deleting it from the latest commit doesn’t remove it from Git history.
Rotating a credential without downtime
Section titled “Rotating a credential without downtime”Every credential above is read fresh at reconcile time, not cached for the controller’s lifetime, so rotation is a plain Secret update with no controller restart required:
- Create a new Cloudflare API token with the same scope as the one you’re replacing (see Token Scopes).
- Update the existing Secret’s value in place (
kubectl create secret ... --dry-run=client -o yaml | kubectl apply -f -, or your GitOps tool’s normal update path) rather than deleting and recreating the Secret object. - Confirm the affected
CloudflareGatewayConfiguration(orCloudflareAccessIdentityProvider, for a client-secret rotation) staysAccepted/Syncedafter its next reconcile. - Revoke the old token at Cloudflare once you’ve confirmed the new one is in use.
DNS Mode’s second Secret (above) holds a different token, on its own rotation schedule — the two Secrets aren’t linked, so rotating one doesn’t rotate the other.
RBAC: who should manage a CloudflareGatewayConfiguration
Section titled “RBAC: who should manage a CloudflareGatewayConfiguration”CloudflareGatewayConfiguration is a privileged object: it names the credential Secret every
controller for its mode authenticates with, plus the account and zone boundary
(zoneAllowlist) every referencing object is checked against. The risk is more direct than
“privileged object” suggests: the controller’s ClusterRole grants cluster-wide
get/list/watch/create/update/patch/delete on all Secrets, in every
namespace — nothing scopes that grant to a particular Secret or namespace, and there is no
admission webhook or ValidatingAdmissionPolicy narrowing it further. Kubernetes RBAC on the
two cluster-scoped kinds below is the only control this project has.
Concretely: anyone who can create a CloudflareGatewayConfiguration or a
CloudflareAccessIdentityProvider can make the controller read any Secret in any namespace
in the cluster, by pointing credentialSecretRef/clientSecretRef at a Secret they don’t
own — the controller reads it on their behalf with no ownership check. On the
identity-provider path, that value is then sent to Cloudflare as the OAuth client secret.
Restrict create/update on both kinds to the same operators you’d trust with the
underlying Cloudflare token itself — an ordinary application team in a shared cluster should
be able to reference an existing configuration (where namespaceSelector permits it), not
create or edit one.
CloudflareAccessServiceToken carries a different, narrower risk, and doesn’t belong in the
same sentence as the two kinds above: it has no *SecretRef field at all — the Secret it
writes is always created in its own namespace (see
Service token credentials) — but any namespace a shared
configuration’s namespaceSelector admits can mint an account-level Cloudflare Access
service token using that configuration’s credential. If account-level service-token minting
itself is sensitive in your environment, restrict namespaceSelector with that in mind, not
just Secret access.
The in-cluster boundary: zoneAllowlist and namespaceSelector
Section titled “The in-cluster boundary: zoneAllowlist and namespaceSelector”Scoping the token narrowly at Cloudflare (see Token Scopes) is
necessary but not sufficient on a shared cluster. CloudflareGatewayConfiguration carries two
further fields that bound what happens inside the cluster:
zoneAllowlistrestricts which zones this specific configuration may act on, independent of what the underlying token can reach.namespaceSelectorrestricts which namespaces may reference this configuration at all.
See Multi-Tenancy for the full model, including how these two fields combine to isolate tenants sharing one cluster.