davidmontoyago/pulumi-cloudflare-free-edge-protection

GitHub: davidmontoyago/pulumi-cloudflare-free-edge-protection

基于Pulumi和Go开发的组件,通过自动化配置Cloudflare免费套餐,为任意云环境中的公开端点提供企业级的边缘安全与加速防护。

Stars: 0 | Forks: 1

# pulumi-cloudflare-free-edge-protection [![Develop](https://static.pigsec.cn/wp-content/uploads/repos/2026/05/40069a30fe070156.svg)](https://github.com/davidmontoyago/pulumi-cloudflare-free-edge-protection/actions/workflows/develop.yaml) [![Go 覆盖率](https://static.pigsec.cn/wp-content/uploads/repos/2026/05/42d38365dc070157.svg)](https://raw.githack.com/wiki/davidmontoyago/pulumi-cloudflare-free-edge-protection/coverage.html) [![Go 参考](https://pkg.go.dev/badge/github.com/davidmontoyago/pulumi-cloudflare-free-edge-protection.svg)](https://pkg.go.dev/github.com/davidmontoyago/pulumi-cloudflare-free-edge-protection) Pulumi 组件,用于在 Cloudflare 免费套餐下设置互联网级别的防护。通过 Cloudflare 的边缘基础设施保护任何云中的公共端点。 ## 功能 - 通过 Cloudflare 进行流量代理 - L4 和 L7 DDoS 防护 - 频率限制 - WAF 规则,用于拦截常见攻击模式 - TLS 强制执行 - 浏览器完整性检查 - 缓存 Web 资源 - 基于威胁分数的[请求质询](https://developers.cloudflare.com/cloudflare-challenges/) - 请求头转换,将真实客户端 IP 和地理位置标头传递给上游 ### 前置条件 - 一个 Cloudflare 免费套餐账户 - 一个在 Cloudflare 注册的域名 - Pulumi & Go ## 入门指南 ``` go get github.com/davidmontoyago/pulumi-cloudflare-free-edge-protection ``` #### GCP 集成 保护运行在 GCP 中的几个 Cloud Run 实例: ``` cloudflareEdgeProxy, err := cloudflare.NewEdgeProtection(ctx, "my-endpoint-edge-waf", &cloudflare.EdgeProtectionArgs{ Upstreams: []cloudflare.Upstream{ // DNS entries of the Domain Mapping config for each Cloud Run instance { DomainURL: "myfrontend.mydomain.dev", CanonicalNameURL: "ghs.googlehosted.com", }, { DomainURL: "mybackend.mydomain.dev", CanonicalNameURL: "ghs.googlehosted.com", }, }, CloudflareZone: cloudflare.Zone{ CloudflareAccountID: os.Getenv("CLOUDFLARE_ACCOUNT_ID"), Protected: true, }, // Required for GCP Cloud Run instances with Domain Mapping AlwaysUseHTTPS: pulumi.Bool(false), TLSEncryptionMode: pulumi.String("full"), }) if err != nil { return fmt.Errorf("failed to setup cloudflare protection: %w", err) } ``` ## 架构 ``` Internet │ ▼ CNAME record proxied through Cloudflare Global Network (Anycast Edge Servers) │ ▼ Upstream Cloud (e.g. for GCP, ghs.googlehosted.com) │ ▼ Internal Cloud DNS Resolution │ ▼ App Server Container (e.g. Cloud Run instance) ``` ### Cloudflare 免费套餐 - 不限流量的应用层 DDoS 防护 - 基于 IP 的频率限制 - 通过 WAF 防御高危和广泛存在的漏洞 - 仅检测并质询常见机器人 - 通用 SSL 证书 - 快速易用的 DNS - 全球 CDN 规则 - 70 条 Cloudflare 规则 - 5 条 WAF 规则 - 10 条转换规则 ### 上游安全 确保上游服务将 Cloudflare IP 列入允许名单,以仅允许来自边缘代理的流量。 ### 客户端 IP 和地理位置转发 为了使源站侧的客户端上下文处理更加明确,此组件创建了一个请求头转换规则,设置如下: - `X-Real-Client-IP: ` - `X-Real-Client-Country: ` - `X-Real-Client-Continent: ` - `X-Real-Client-City: ` - `X-Real-Client-Region: ` - `X-Real-Client-Region-Code: ` - `X-Real-Client-Postal-Code: ` - `X-Real-Client-Metro-Code: ` - `X-Real-Client-Lat: ` - `X-Real-Client-Lon: ` - `X-Real-Client-Timezone: ` 这些值派生自 Cloudflare 受信任的 `ip.src.*` 请求字段(其中 `ip.src` 等同于代理流量的 `CF-Connecting-IP`),而不是解析 `X-Forwarded-For`。 这种方法避免信任中间人提供的 `X-Forwarded-For` 链,同时保持配置与 Cloudflare 免费套餐兼容。 参见: - https://developers.cloudflare.com/dns/proxy-status
标签:AppImage, CDN, CISA项目, Cloudflare, DDoS防护, DevSecOps, DNS解析, EC2, EVTX分析, GCP集成, Go, IaC, MITRE ATT&CK, Pulumi, Ruby工具, TLS加密, WAF, Web应用防火墙, 上游代理, 云计算安全, 威胁防护, 开源项目, 日志审计, 流量代理, 缓存, 网络安全, 边缘计算, 隐私保护