Skip to content
AnswerWell geo Documentation

Research · 7 min read · Answerwell

Cloud Workload Security: API Policies, Proxy Enforcement, and Request Validation

How Cloudflare Cloud Workload Security intercepts cloud API calls with workloads, Rego policies, and a local proxy before changes reach your provider.

This page summarises Cloudflare documentation on Cloud Workload Security (CWS): a control plane in the Cloudflare dashboard plus a CWS proxy you run in your environment. Together they let you allow approved cloud API operations and block risky ones—such as making an R2 bucket public—before the request reaches the cloud provider.

Cloud Workload Security (CWS) helps you prevent risky cloud changes. Apply policy controls to API requests before they reach your cloud provider.

— Cloudflare, Cloud Workload Security

CWS requires a Zero Trust subscription; the Zero Trust Free plan is sufficient. The feature is in Beta; manage resources after selecting your account in the dashboard (Platform).

When to use Cloud Workload Security (CWS) for cloud API guardrails

Section titled “When to use Cloud Workload Security (CWS) for cloud API guardrails”

Teams adopt CWS when automation, CI/CD, or operators can call cloud APIs that change security posture (storage access, networking, identity). The proxy sits on the client path: SDKs, CLIs, and apps must route HTTPS API traffic through it and trust its TLS interception CA. Creating a deployment in the dashboard does not redirect traffic by itself (Traffic requirements).

Typical goals:

  • Block specific API operations while allowing read-only or safer variants.
  • Apply stricter policies in production than in non-production using workloads.
  • Enforce destination limits with domain ACLs separate from request-body checks.

How CWS works: dashboard config and the CWS proxy

Section titled “How CWS works: dashboard config and the CWS proxy”

You manage CWS in the Cloudflare dashboard. A proxy process loads a deployment configuration, refreshes it on a poll interval (minimum 30 seconds), evaluates requests routed through it, and logs decisions (How it works, Configuration refresh).

You manage CWS resources in the Cloudflare dashboard. A proxy you run in your environment loads a deployment’s configuration and evaluates requests routed through it.

— Cloudflare, Cloud Workload Security

The proxy needs:

  • A deployment ID and account ID in config.yaml.
  • Cloudflare API credentials (API token with Cloud Workload Security Deployment permission, or Global API Key mode)—used only to load configuration, not to act as the client’s cloud identity (Request authentication).
  • A CA certificate and private key for TLS interception; clients trust ca_cert only (TLS certificates and trust).

Install the cws-proxy package via APT or DNF (Get started). Validate local settings with:

cws-proxy --config config.yaml --config-test

Successful validation prints CWS proxy configuration is valid; that check does not verify API access or credentials (Validate a configuration).

Wait for remote_config_loaded and action_mapper_loaded in logs before sending traffic (Validate and start the proxy).

Proxy deployment options: local machine, CI/CD, and shared hosts

Section titled “Proxy deployment options: local machine, CI/CD, and shared hosts”
Pattern Use when
Local machine Same Linux host runs proxy and client for a first guardrail test
CI/CD runner Pipeline jobs need guardrails on deployment scripts
Application host or container A long-lived app issues cloud API calls
Shared proxy host Many clients share one listen_addr on a private IP

For a shared proxy, set proxy.listen_addr to an address clients can reach; 127.0.0.1 only works inside the same network namespace (Traffic requirements).

CWS entities: workloads, policies, policy sets, and deployments

Section titled “CWS entities: workloads, policies, policy sets, and deployments”

CWS ties scope to checks through named resources (Request Validation).

Entity Role
Workload Reusable Wirefilter filter that selects a group of requests (e.g. Cloudflare API, production accounts) (Workloads)
Policy Policy filter plus Rego with a Boolean valid rule under policy. (Policies)
Policy set Groups policies; includes/excludes workloads; per-policy Enforce toggles blocking (Policy sets)
Deployment Configuration the proxy loads: attached policy sets, optional domain ACL and Basic Auth, Default mode, On error action (Deployments)
Rego module Shared logic under lib. imported by policies (Rego modules)

Workloads select requests, policies check them, and policy sets group those checks for a deployment.

— Cloudflare, Cloud Workload Security

Target security profiles with workloads for production vs non-production

Section titled “Target security profiles with workloads for production vs non-production”

Create separate policy sets for production and non-production. Attach matching workloads (AWS accounts, OUs, or Cloudflare accounts) to each set, then attach both sets to the same deployment (Target security profiles with workloads, Create a workload).

Request validation: how CWS decides allow or block

Section titled “Request validation: how CWS decides allow or block”

Request Validation describes the decision chain:

  1. The deployment selects which policy sets run.
  2. For each set, the request must match an included workload and not match an excluded workload. An empty inclusion list imposes no inclusion restriction (Create a policy set).
  3. Within that scope, each policy filter must match. A workload match does not bypass the policy filter (Policy filter).
  4. Each matching policy runs Rego; valid == true passes that policy’s check.
  5. Enforce and Default mode determine the final outcome.
Condition Effect
Matching policy, valid true That check passes; another enforcing policy may still block
Matching policy, valid false, Enforce on Block the request
Matching policy, valid false, Enforce off Record failure; no block from that policy
No policy matches Apply deployment Default mode (Default allow or Default block)

A false Rego result is a failed check, not an unmatched request.

— Cloudflare, Configure policies

Domain ACLs control which destinations a deployment may connect to. An ACL allow permits the connection but does not skip workload or policy checks (Related controls). Basic Auth credentials can feed filters; they are separate from the proxy’s deployment API token (Manage traffic scope).

Write CWS policies: Wirefilter filters and Rego valid rules

Section titled “Write CWS policies: Wirefilter filters and Rego valid rules”

Both Filters and Rego source are required when you create a policy. The filter narrows request scope; Rego must declare package policy.<name> and a Boolean rule valid.

Example filter for R2 API traffic:

application.name == "Cloudflare" and application.service == "r2"

Example read-only Rego (permits only GET):

package policy.r2_read_only
default valid := false
valid if {
input.http.request.method == "GET"
}

Use input.http.request.body for parsed body fields (Create a policy). The Get started walkthrough blocks public R2 access with a filter on r2-put-bucket-public-policy and Rego that allows only enabled == false.

Reuse logic via Rego modules (lib. packages), Rego metadata (data.metadata.*), and tenant structures for AWS or Cloudflare hierarchies.

Attach policy sets to a deployment and choose Default mode

Section titled “Attach policy sets to a deployment and choose Default mode”

In the dashboard: create workloads and policies, group them in a policy set (attach workloads, attach policies, set Enforce), then attach the set to a deployment. Default allow permits requests outside every policy filter; Default block denies them. After saving, allow a configuration refresh interval before testing through the proxy.

Domain ACLs and traffic scope alongside request policies

Section titled “Domain ACLs and traffic scope alongside request policies”

Manage traffic scope covers:

  • Domain ACLs — per-domain Allow or Block, plus a default action. Use example.com for an exact host; .example.com matches the parent and subdomains (Create a domain ACL).
  • Basic Auth credentials — usernames with rotatable secrets; usable in filters, not a substitute for cloud provider auth.

Attach a domain ACL on the deployment’s Domain ACL field. A CONNECT denied by ACL (domain_acl_denied_connect) happens before request-policy evaluation (Domain ACL blocks the connection).

Common mistakes when CWS does not block or connect

Section titled “Common mistakes when CWS does not block or connect”
Symptom Likely cause
Risky API call succeeds Client bypasses proxy (NO_PROXY), wrong deployment ID, Enforce off, or filter/workload mismatch (Client bypasses the proxy, Policy is not attached, in scope, or enforcing)
Certificate errors Client missing NODE_EXTRA_CA_CERTS (or equivalent); expired or mismatched CA/key (Client does not trust the proxy CA)
Proxy never loads config Empty CWS_DEPLOYMENT_TOKEN in the proxy process environment; wrong account or deployment ID (Token environment variable is missing or empty)
Dashboard change has no effect Poll interval not elapsed; refresh failed and proxy kept old config—restart after local config.yaml changes (Proxy has not refreshed the intended deployment)
HTTP 403 with unclear source Distinguish CWS.Error, domain ACL, and upstream_status: 403 from the cloud provider (CWS rejects the request, Cloud provider rejects an allowed request)

For JSON logs, inspect request.outcome, request.policy_sets, and request.outcome_reason on the handling proxy process (Read proxy logs). Deeper setup and config.yaml fields are in Proxy configuration; first end-to-end test in Get started.

  1. Confirm the account has Zero Trust and open Cloud Workload Security in the dashboard; verify the deployment lists the expected policy sets and Enforce state.
  2. On the proxy host, run cws-proxy --config config.yaml --config-test, start the proxy, and confirm remote_config_loaded and action_mapper_loaded in logs (Troubleshooting).
  3. From a client configured to use the proxy and CA trust (as in Route the CLI through the proxy), send one request that should pass and one that should fail; for the R2 guardrail pattern, expect 403 and a CWS.Error on the blocked call (Verify the guardrail).
  4. Read proxy JSON logs for request.policy_sets and request.outcome on those requests (Read proxy logs).
  5. You can check automatically in Answerwell (our tool): https://answerwell.org/workspace

If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact statement you are asking about.