Skip to content

Repository files navigation

Cloudflare Zero Trust Operator

Logo

A Kubernetes Operator for Cloudflare Zero Trust: Tunnels, Access, Gateway, Device, DNS, R2, and Rules Management

Documentation (English) » | 文档 (中文) »

Examples · Report Bug · Request Feature

GitHub licenseGitHub releaseGo Report CardCITestLint

Note: This project is currently in Alpha (v0.34.x). This is NOT an official Cloudflare product. It uses the Cloudflare API and cloudflared to automate Zero Trust configuration on Kubernetes.

This project is a fork of adyanth/cloudflare-operator with extended Zero Trust features and improvements.

Overview

The Cloudflare Zero Trust Operator provides Kubernetes-native management of Cloudflare Zero Trust resources. Built with kubebuilder and controller-runtime, it enables declarative configuration of tunnels, access policies, gateway rules, device settings, R2 storage, and zone rules through Custom Resource Definitions (CRDs).

Features

CategoryFeatures
Tunnel ManagementCreate/manage Cloudflare Tunnels, automatic cloudflared deployments, Service binding with DNS
Private NetworkVirtual Networks, Network Routes, Private Service exposure via WARP
Access ControlZero Trust Applications, Access Groups, Reusable Access Policies, Inline Policy Rules, Identity Providers, Service Tokens
Gateway & SecurityGateway Rules (DNS/HTTP/L4), Gateway Lists, Browser Isolation
Device ManagementSplit Tunnel configuration, Fallback Domains, Device Posture Rules
DNS & ConnectivityDNS Record management, WARP Connectors for site-to-site
Domain ManagementZone settings (SSL/TLS, Cache, Security), Origin CA Certificates
R2 StorageR2 Buckets, Custom Domains, Event Notifications
Rules EngineZone Rulesets, Transform Rules (URL/Header), Redirect Rules
Cloudflare PagesPages Projects (build config, resource bindings), Custom Domains, Deployment management (create, retry, rollback)
RegistrarDomain Registration management (Enterprise)
Kubernetes IntegrationNative Ingress support, Gateway API support (Gateway, HTTPRoute, TCPRoute, UDPRoute)

Architecture

This operator uses a Three-Layer Architecture for simplicity and reliability:

flowchart TB
subgraph Internet["Internet"]
Users["Users / WARP Clients"]
end
subgraph Cloudflare["Cloudflare Edge"]
Edge["Cloudflare Edge Network"]
API["Cloudflare API"]
end
subgraph K8s["Kubernetes Cluster"]
subgraph Layer1["Layer 1: K8s CRD"]
OneToOne["1:1 Resources<br/>(DNSRecord, AccessApp, R2Bucket, PagesDeployment, etc.)"]
Aggregate["Aggregate Resources<br/>(Tunnel, ClusterTunnel, Ingress, HTTPRoute)"]
end
subgraph Layer2["Layer 2: Controllers"]
Direct["Direct Controllers<br/>(Call CF API directly, write status to CRD)"]
ConfigAgg["Config Aggregation<br/>(Write to ConfigMap, TunnelConfig Controller syncs)"]
end
subgraph Layer3["Layer 3: Cloudflare API Client"]
CFClient["Connection Pool, Rate Limiting<br/>Auto Retry, Error Handling"]
end
subgraph Managed["Managed Resources"]
Deployment["cloudflared Deployment"]
ConfigMap["Tunnel ConfigMap"]
end
subgraph App["Applications"]
Service["Services"]
Pod["Pods"]
end
end
OneToOne -.->|watch| Direct
Aggregate -.->|watch| ConfigAgg
Direct -->|"API calls"| API
Direct -->|"status"| OneToOne
ConfigAgg -->|write| ConfigMap
ConfigMap -.->|watch| Direct
Direct -->|"tunnel config"| API
Direct -->|creates| Deployment
Deployment -->|proxy| Service
Service --> Pod
Users -->|HTTPS/WARP| Edge
Edge <-->|tunnel| Deployment
style Layer2 fill:#9f9,stroke:#333,stroke-width:2px
style CFClient fill:#f9f,stroke:#333,stroke-width:2px
Loading

Architecture Benefits

FeatureBenefit
Direct Status WritesControllers write directly to CRD.Status, no intermediate layers
Independent InformersEach CRD has its own Controller + Informer, no event interference
ConfigMap AggregationTunnel config uses ConfigMap for multi-source aggregation (Ingress, TunnelBinding, etc.)
Hash DetectionSkip sync when config unchanged, reducing API usage
Simple Data FlowL1 CRD → L2 Controller → L3 CF API, easy to trace and debug

Note: See Three-Layer Architecture Design for detailed documentation.

Quick Start

Prerequisites

  • Kubernetes cluster v1.28+
  • Cloudflare account with Zero Trust enabled
  • Cloudflare API Token (Create Token)

Installation

Option 1: Full Installation (Recommended for new users)

# All-in-one: CRDs + Namespace + RBAC + Operator (without webhook)
kubectl apply -f https://github.com/StringKe/cloudflare-operator/releases/latest/download/cloudflare-operator-full-no-webhook.yaml
# Verify installation
kubectl get pods -n cloudflare-operator-system

Option 2: Modular Installation (Recommended for production)

# Step 1: Install CRDs (cluster-admin required)
kubectl apply -f https://github.com/StringKe/cloudflare-operator/releases/latest/download/cloudflare-operator-crds.yaml
# Step 2: Create namespace
kubectl apply -f https://github.com/StringKe/cloudflare-operator/releases/latest/download/cloudflare-operator-namespace.yaml
# Step 3: Install operator (RBAC + Deployment)
kubectl apply -f https://github.com/StringKe/cloudflare-operator/releases/latest/download/cloudflare-operator-no-webhook.yaml
# Verify installation
kubectl get pods -n cloudflare-operator-system

Available Installation Files

FileContentsUse Case
cloudflare-operator-full.yamlCRDs + Namespace + RBAC + Operator + WebhookFull installation with cert-manager
cloudflare-operator-full-no-webhook.yamlCRDs + Namespace + RBAC + OperatorFull installation without webhook
cloudflare-operator-crds.yamlCRDs onlyModular: install CRDs separately
cloudflare-operator-namespace.yamlNamespace onlyModular: create namespace
cloudflare-operator.yamlRBAC + Operator + WebhookModular: operator with webhook
cloudflare-operator-no-webhook.yamlRBAC + OperatorModular: operator without webhook

Create a Tunnel

# 1. Create API credentials secretapiVersion: v1kind: Secretmetadata:
name: cloudflare-credentialstype: OpaquestringData:
CLOUDFLARE_API_TOKEN: "<your-api-token>"
---
# 2. Create tunnelapiVersion: networking.cloudflare-operator.io/v1alpha2kind: Tunnelmetadata:
name: my-tunnelspec:
newTunnel:
name: k8s-tunnelcloudflare:
accountId: "<your-account-id>"domain: example.comsecret: cloudflare-credentials

Expose a Service

apiVersion: networking.cfargotunnel.com/v1alpha1kind: TunnelBindingmetadata:
name: web-bindingsubjects:
- kind: Servicename: web-appspec:
fqdn: app.example.comprotocol: httptunnelRef:
kind: Tunnelname: my-tunnel

CRD Reference

Credentials & Configuration

CRDAPI VersionScopeDescription
CloudflareCredentialsnetworking.cloudflare-operator.io/v1alpha2ClusterCloudflare API credentials management
CloudflareDomainnetworking.cloudflare-operator.io/v1alpha2ClusterZone settings (SSL/TLS, Cache, Security, WAF)

Tunnel Management

CRDAPI VersionScopeDescription
Tunnelnetworking.cloudflare-operator.io/v1alpha2NamespacedCloudflare Tunnel with managed cloudflared
ClusterTunnelnetworking.cloudflare-operator.io/v1alpha2ClusterCluster-wide Cloudflare Tunnel
TunnelBindingnetworking.cfargotunnel.com/v1alpha1NamespacedBind Services to Tunnels with DNS

Private Network Access

CRDAPI VersionScopeDescription
VirtualNetworknetworking.cloudflare-operator.io/v1alpha2ClusterCloudflare virtual network for isolation
NetworkRoutenetworking.cloudflare-operator.io/v1alpha2ClusterRoute CIDR through tunnel
PrivateServicenetworking.cloudflare-operator.io/v1alpha2NamespacedExpose Service via private IP

Access Control

CRDAPI VersionScopeDescription
AccessApplicationnetworking.cloudflare-operator.io/v1alpha2NamespacedZero Trust application with inline policy rules
AccessGroupnetworking.cloudflare-operator.io/v1alpha2ClusterAccess policy group
AccessPolicynetworking.cloudflare-operator.io/v1alpha2ClusterReusable access policy (referenced by applications)
AccessIdentityProvidernetworking.cloudflare-operator.io/v1alpha2ClusterIdentity provider config
AccessServiceTokennetworking.cloudflare-operator.io/v1alpha2NamespacedService token for M2M

Gateway & Security

CRDAPI VersionScopeDescription
GatewayRulenetworking.cloudflare-operator.io/v1alpha2ClusterGateway policy rule
GatewayListnetworking.cloudflare-operator.io/v1alpha2ClusterList for gateway rules
GatewayConfigurationnetworking.cloudflare-operator.io/v1alpha2ClusterGlobal gateway settings

Device Management

CRDAPI VersionScopeDescription
DeviceSettingsPolicynetworking.cloudflare-operator.io/v1alpha2ClusterWARP client settings
DevicePostureRulenetworking.cloudflare-operator.io/v1alpha2ClusterDevice posture check

DNS & Connectivity

CRDAPI VersionScopeDescription
DNSRecordnetworking.cloudflare-operator.io/v1alpha2NamespacedDNS record management
WARPConnectornetworking.cloudflare-operator.io/v1alpha2NamespacedWARP connector deployment
AccessTunnelnetworking.cloudflare-operator.io/v1alpha2NamespacedAccess tunnel configuration

SSL/TLS & Certificates

CRDAPI VersionScopeDescription
OriginCACertificatenetworking.cloudflare-operator.io/v1alpha2NamespacedCloudflare Origin CA certificate with K8s Secret

R2 Storage

CRDAPI VersionScopeDescription
R2Bucketnetworking.cloudflare-operator.io/v1alpha2NamespacedR2 storage bucket with lifecycle rules
R2BucketDomainnetworking.cloudflare-operator.io/v1alpha2NamespacedCustom domain for R2 bucket
R2BucketNotificationnetworking.cloudflare-operator.io/v1alpha2NamespacedEvent notifications for R2 bucket

Rules Engine

CRDAPI VersionScopeDescription
ZoneRulesetnetworking.cloudflare-operator.io/v1alpha2NamespacedZone ruleset (WAF, rate limiting, etc.)
TransformRulenetworking.cloudflare-operator.io/v1alpha2NamespacedURL rewrite & header modification
RedirectRulenetworking.cloudflare-operator.io/v1alpha2NamespacedURL redirect rules

Cloudflare Pages

CRDAPI VersionScopeDescription
PagesProjectnetworking.cloudflare-operator.io/v1alpha2NamespacedPages project with build config and bindings
PagesDomainnetworking.cloudflare-operator.io/v1alpha2NamespacedCustom domain for Pages project
PagesDeploymentnetworking.cloudflare-operator.io/v1alpha2NamespacedPages deployment (create, retry, rollback)

Registrar (Enterprise)

CRDAPI VersionScopeDescription
DomainRegistrationnetworking.cloudflare-operator.io/v1alpha2ClusterDomain registration settings

Kubernetes Integration

CRDAPI VersionScopeDescription
TunnelIngressClassConfignetworking.cloudflare-operator.io/v1alpha2ClusterConfig for Ingress integration
TunnelGatewayClassConfignetworking.cloudflare-operator.io/v1alpha2ClusterConfig for Gateway API integration

Note: The operator also supports native Kubernetes Ingress and Gateway API (Gateway, HTTPRoute, TCPRoute, UDPRoute) resources when configured with the appropriate IngressClass or GatewayClass.

Examples

See the examples directory for comprehensive usage examples:

  • Basic - Credentials, Tunnels, DNS, Service Binding
  • Private Network - Virtual Networks, Routes, Private Services
  • Zero Trust - Access Apps, Groups, Policies, Identity Providers
  • Gateway - Gateway Rules, Lists
  • Device - Device Policies, Posture Rules
  • Pages - Pages Projects, Domains, Deployments
  • Scenarios - Complete real-world scenarios

Documentation

LanguageLink
Englishdocs/en/README.md
中文docs/zh/README.md

Documentation includes:

  • Installation Guide
  • API Token Permissions
  • Complete CRD Reference
  • Troubleshooting Guide
  • Migration Guide (v1alpha1 → v1alpha2)

API Token Permissions

FeaturePermissionScope
TunnelsAccount:Cloudflare Tunnel:EditAccount
DNSZone:DNS:EditZone
AccessAccount:Access: Apps and Policies:EditAccount
Access Groups & IdPAccount:Access: Organizations, Identity Providers, and Groups:EditAccount
Service TokensAccount:Access: Service Tokens:EditAccount
Device PostureAccount:Access: Device Posture:EditAccount
GatewayAccount:Zero Trust:EditAccount
Zone SettingsZone:Zone Settings:EditZone
SSL/TLSZone:SSL and Certificates:EditZone
R2Account:Workers R2 Storage:EditAccount
PagesAccount:Cloudflare Pages:EditAccount
RulesZone:Zone Rulesets:EditZone
RegistrarAccount:Registrar:EditAccount

For detailed per-CRD permission requirements, see Configuration Guide.

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

Acknowledgements

This project is forked from adyanth/cloudflare-operator. We extend our gratitude to @adyanth and all original contributors for their excellent work on the initial implementation.

What's Different

This fork extends the original project with:

  • Complete Zero Trust resource support (Access, Gateway, Device management)
  • v1alpha2 API with improved resource management
  • Native Kubernetes Ingress and Gateway API integration
  • R2 Storage management (buckets, custom domains, notifications)
  • Cloudflare Pages support (projects, custom domains, advanced deployments with retry/rollback)
  • Zone settings and rules engine (SSL/TLS, Cache, WAF, Transform/Redirect rules)
  • Origin CA certificate integration
  • Domain registration management (Enterprise)
  • Three-layer architecture for simplicity and reliability (simplified from six-layer)
  • Reusable Access Policies and inline include/exclude/require rules
  • NetworkRoute adoption with cross-VNet search support
  • Enhanced error handling and status reporting
  • Comprehensive documentation and examples

License

Apache License 2.0 - See LICENSE for details.

About

Kubernetes Operator for Cloudflare Zero Trust - Tunnels, Access, Gateway & Device Management (Fork of adyanth/cloudflare-operator)

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages