Skip to content

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.

CloudflareGatewayConfiguration.spec.credentialSecretRef points at the Secret holding the Cloudflare API token its controllers authenticate with:

Terminal window
kubectl create secret generic cloudflare-api-token \
--namespace cloudflare-gateway-controller-system \
--from-literal=api-token=<token>
apiVersion: cfgateway.dreamfuselabs.com/v1alpha1
kind: CloudflareGatewayConfiguration
metadata:
name: tunnel-config
spec:
mode: tunnel
accountID: "$ACCOUNT_ID"
zoneAllowlist: ["$ZONE"]
credentialSecretRef:
namespace: cloudflare-gateway-controller-system
name: cloudflare-api-token
key: api-token

credentialSecretRef 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.

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: v1
kind: Secret
metadata:
name: my-github-idp-client-secret
namespace: cloudflare-gateway-controller-system
stringData:
client-secret: <the OAuth client secret from your identity provider>
---
apiVersion: cfgateway.dreamfuselabs.com/v1alpha1
kind: CloudflareAccessIdentityProvider
metadata:
name: my-github-idp
spec:
configurationRef:
name: tunnel-config
provider:
type: GitHub
clientID: <the OAuth client ID>
clientSecretRef:
namespace: cloudflare-gateway-controller-system
name: my-github-idp-client-secret

clientSecretRef 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.

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: v1
kind: Secret
metadata:
name: my-service-token
namespace: default
stringData:
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.

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 *SecretRef field 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.

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:

  1. Create a new Cloudflare API token with the same scope as the one you’re replacing (see Token Scopes).
  2. 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.
  3. Confirm the affected CloudflareGatewayConfiguration (or CloudflareAccessIdentityProvider, for a client-secret rotation) stays Accepted/Synced after its next reconcile.
  4. 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:

  • zoneAllowlist restricts which zones this specific configuration may act on, independent of what the underlying token can reach.
  • namespaceSelector restricts 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.