Skip to content

kflare v0.3.0

Choose a tag to compare

@github-actions github-actions released this 29 Oct 22:52
· 69 commits to main since this release
97b5037

The fourth alpha release of kflare: the API is still v1alpha1, and it needs Kubernetes 1.34 or newer. Five more kinds
are now generated by kflare's code generator, on Cloudflare's generated Go SDK, as the Rules products' kinds already
were: the three security rule kinds, WAFCustomRule, RateLimitRule and ManagedRuleset, so that every rule kind is
generated, and R2Bucket and WorkerRoute, the first of the kinds written before the generator to move onto it.
The rule kinds' fields take the names of Cloudflare's API, so manifests written for v0.2 change: read
Upgrading from v0.2.1 before upgrading. It is a minor release because of that change.
R2Bucket and WorkerRoute apply manifests unchanged, but behave differently in the ways their sections list. The
other kinds written before the generator (Zone, DNSRecord, Tunnel, TunnelConfiguration, WorkerScript and
IPList) are unchanged: they move onto it in later releases, whose notes list their changes the same way. The chart
also gains an Artifact Hub page with its license, CRDs and security report.

helm upgrade kflare oci://ghcr.io/jonathangraniero/charts/kflare --version 0.3.0 -n kflare-system \
  --values kflare-values.yaml

The image is ghcr.io/jonathangraniero/kflare:0.3.0, for linux/amd64 and linux/arm64. The deploy guide's
Verifying a release checks both signatures before you install. To install kflare
for the first time, follow the README's quickstart.

Upgrading from v0.2.1

The chart's values and the controller's permissions are v0.2.1's, and so are the other CRDs but R2Bucket's and
WorkerRoute's, whose manifests need no change. Only the WAFCustomRule, RateLimitRule and ManagedRuleset
resources do; if this lists none, they need nothing:

kubectl get wafcustomrules,ratelimitrules,managedrulesets -A

Check your R2Buckets before upgrading as well. spec.storageClass defaults to Standard, and kflare now sets a
bucket's storage class: a bucket whose class was set to InfrequentAccess outside kflare goes back to Standard
unless its R2Bucket says InfrequentAccess. Pause such an R2Bucket before upgrading
(kubectl annotate r2bucket <name> kflare.dev/paused=true), apply its manifest with storageClass: InfrequentAccess
after the chart, then remove the annotation (kubectl annotate r2bucket <name> kflare.dev/paused-). An alert on a
WorkerRoute's PatternOutsideZone reason needs changing too (WorkerRoute).

For the three rule kinds:

  1. Rewrite their manifests in the new shape, from the sections below, each with a manifest before and after. Keep
    them back for now: the v0.2.1 CRDs refuse the new fields (unknown field "spec.ratelimit")
  2. Pause each WAFCustomRule with a blockResponse, with kubectl annotate wafcustomrule <name> kflare.dev/paused=true. Upgraded, such a rule loses its response, and kflare would write it again without one
  3. Upgrade the chart, which upgrades the CRDs. If you manage the CRDs yourself (crds.enabled=false), apply
    config/crd/bases from v0.3.0 first
  4. Apply the rewritten manifests right away, then remove the annotations from step 2, with
    kubectl annotate wafcustomrule <name> kflare.dev/paused-. With Argo CD or Flux, sync them after the chart

Between steps 3 and 4, a stored resource has lost its old fields: the API server drops the fields the new CRD does not
know when it reads the resource. The RateLimitRule and WAFCustomRule sections below say what kflare does with
their Cloudflare rules until you apply the new shape. Until then a change to the resource's spec is refused
(spec.id: Required value), but one to its metadata or status is not, so it can still be paused, report its status
and be deleted.

ManagedRuleset

  • rulesetID is now id, the API's name for the ruleset an execute rule runs. A ManagedRuleset stored with
    rulesetID has no id after the upgrade, and cannot be updated until it gets one: apply your ManagedRuleset
    manifests with id right after upgrading
  • id can change in place, which updates the deployment's rule to run the other ruleset; it was immutable
  • The category and rule overrides are sent in the spec's order rather than sorted. Cloudflare keeps that order, so
    reordering them in the spec writes the rule again
  • An empty overrides.categories or overrides.rules is refused: leave it out
  • For Go clients: ManagedRulesetCategoryOverride and ManagedRulesetRuleOverride are now
    ManagedRulesetOverridesCategory and ManagedRulesetOverridesRule, and an override's action is a string

Before:

spec:
  zoneRef:
    name: example-zone
  rulesetID: 77454fe2d30c4220b5701f6fdfb893ba
  expression: "true"
  overrides:
    categories:
      - category: wordpress
        action: log

After:

spec:
  zoneRef:
    name: example-zone
  id: 77454fe2d30c4220b5701f6fdfb893ba
  expression: "true"
  overrides:
    categories:
      - category: wordpress
        action: log

RateLimitRule

  • The rate limit moves under ratelimit, the API's name for it: characteristics, period, requestsPerPeriod,
    mitigationTimeout, countingExpression and requestsToOrigin. blockResponse is now response. A
    RateLimitRule stored with the old fields has no rate limit after the upgrade, and cannot be updated until it gets
    one: apply your RateLimitRule manifests in the new shape right after upgrading. Until then its Cloudflare rule is
    left as it was
  • Nothing defaults any more: set action (was block), ratelimit.characteristics (was [ip.src]),
    ratelimit.period (was 10), ratelimit.mitigationTimeout (was the period; 0 throttles, on Enterprise plans) and
    response.statusCode (was 429)
  • ratelimit.characteristics must list cf.colo.id, which kflare no longer adds for you, and at least one other
    field. They are sent sorted
  • For Go clients: RateLimitRuleBlockResponse is now RateLimitRuleResponse, the rate limit is a
    RateLimitRuleRatelimit, its characteristics are []string, and its integers are int64, the optional ones
    pointers

Before:

spec:
  zoneRef:
    name: example-zone
  expression: 'starts_with(http.request.uri.path, "/api/")'
  requestsPerPeriod: 100
  blockResponse:
    contentType: application/json
    content: '{"error":"rate limited"}'

After:

spec:
  zoneRef:
    name: example-zone
  expression: 'starts_with(http.request.uri.path, "/api/")'
  action: block
  ratelimit:
    characteristics: [cf.colo.id, ip.src]
    period: 10
    requestsPerPeriod: 100
    mitigationTimeout: 10
  response:
    statusCode: 429
    contentType: application/json
    content: '{"error":"rate limited"}'

WAFCustomRule

  • A skip rule's parameters move to the spec's root, as the API names them: skip.remainingRules: true is now
    ruleset: current, and skip.phases and skip.products are phases and products. skip.log is now
    logging.enabled
    , and blockResponse is now response
  • A WAFCustomRule stored with the old fields loses them after the upgrade:
    • A skip rule then has no parameters, which Cloudflare refuses (20115): kflare reports TerminalError and leaves
      the Cloudflare rule as it was until you apply the manifest in the new shape
    • A block rule with a blockResponse becomes a plain block rule, and kflare writes its Cloudflare rule again
      without the response. Pause such rules (kflare.dev/paused: "true") before upgrading, apply them in the new
      shape, then remove the annotation
  • Nothing defaults any more: set response.statusCode (was 403). A skip rule without logging still logs its
    matches, Cloudflare's default, which kflare no longer sends itself
  • New: phase: current skips the rest of the phase, the custom rulesets that run later in it included. It combines
    with products, but not with phases or ruleset
  • For Go clients: WAFCustomRuleSkip, WAFCustomRuleSkipPhase, WAFCustomRuleSkipProduct and
    WAFCustomRuleBlockResponse are gone. The phases and products are []string, the response is a
    WAFCustomRuleResponse whose statusCode is an int64, and logging is a WAFCustomRuleLogging

Before:

spec:
  zoneRef:
    name: example-zone
  expression: 'http.request.uri.path eq "/healthz"'
  action: skip
  skip:
    remainingRules: true
    phases: [http_ratelimit]
    log: false
---
spec:
  zoneRef:
    name: example-zone
  expression: 'http.request.uri.path wildcard "/admin*"'
  action: block
  blockResponse:
    contentType: text/plain
    content: Blocked

After:

spec:
  zoneRef:
    name: example-zone
  expression: 'http.request.uri.path eq "/healthz"'
  action: skip
  ruleset: current
  phases: [http_ratelimit]
  logging:
    enabled: false
---
spec:
  zoneRef:
    name: example-zone
  expression: 'http.request.uri.path wildcard "/admin*"'
  action: block
  response:
    statusCode: 403
    contentType: text/plain
    content: Blocked

R2Bucket

  • jurisdiction: default, eu or us keep the bucket's objects in that jurisdiction (fedramp and
    fedramp-high need a FedRAMP account). Each jurisdiction has buckets of its own, so two R2Buckets can name buckets
    of the same name in different jurisdictions. It defaults to default, the only jurisdiction kflare reached before,
    and cannot change
  • storageClass: Standard or InfrequentAccess, the class of objects uploaded to the bucket without one of
    their own, changed in place. It defaults to Standard, so a bucket whose class was set to InfrequentAccess
    outside kflare is set back to Standard
    unless its R2Bucket says InfrequentAccess
  • A WorkerScript does not bind an R2Bucket outside the default jurisdiction yet: it reports
    R2BucketJurisdictionUnsupported (it still uploads through the legacy SDK, whose binding has no jurisdiction)
  • Status: cloudflareMetadata.bucketName records the bucket kflare created or adopted, and creationDate is
    Cloudflare's timestamp as a string. kubectl get r2buckets shows the jurisdiction, the bucket and its location
  • The claim label stays kflare.dev/r2-bucket-name, so an upgraded R2Bucket keeps its bucket
  • For Go clients: R2BucketNameLabel is now R2BucketIDLabel, and R2BucketCloudflareMetadata.CreationDate a
    string

Before and after: a v0.2.1 manifest, such as

spec:
  accountRef:
    name: example-account
  name: example-assets
  locationHint: weur

reads back with the defaults:

spec:
  accountRef:
    name: example-account
  name: example-assets
  locationHint: weur
  jurisdiction: default
  storageClass: Standard

WorkerRoute

  • The spec and status are unchanged: zoneRef, pattern and an optional workerScriptRef, and routeID, zoneID
    and script in status.cloudflareMetadata. A v0.2.1 manifest applies and reads back as it is
  • A pattern outside the zone is reported as Cloudflare's refusal: TerminalError, with Cloudflare's message
    ("Route pattern must include zone name: example.com", 10022), where kflare reported PatternOutsideZone before
    calling Cloudflare. An alert on PatternOutsideZone needs changing
  • A claim on a route counts only from a WorkerRoute whose Zone is for the same Cloudflare zone, through any Zone
  • The sample in config/samples is generated: one route, kept on deletion. The exclusion route it showed is a
    WorkerRoute without workerScriptRef, as before

Generated kinds

  • A claim on a KVNamespace's, D1Database's or R2Bucket's Cloudflare object counts only from a resource that uses
    the same Cloudflare account, through any CloudflareAccount, and on a WorkerRoute's from one in the same
    Cloudflare zone, through any Zone. One whose CloudflareAccount or Zone is gone no longer keeps another
    resource from adopting the object

The Helm chart

  • The chart's Artifact Hub page lists its license, its CRDs with an example of each, each release's changes, and
    the controller image, which Artifact Hub now scans for its security report. It found no image before: it renders a
    chart for Kubernetes 1.29 to find them, which the chart refuses
    (#90)

The controller

  • A Ready condition no longer ends in a blank message when Cloudflare's error holds only spaces: it names the HTTP
    status, as it does for an error without a message. Found by the new fuzz tests
    (#108)

Known limitations

v0.2.0's, unchanged: ARCHITECTURE.md explains each.