Skip to content

Cloudflare ​

The cloudflare lease backend uses a parent API token to create a child token that expires on its own, and injects the child into fnox exec. By default the child inherits the parent's permissions; set policies to narrow them.

Config typecloudflare
ProducesCLOUDFLARE_API_TOKEN (configurable with env_var)
Max duration24 hours
RevocationYes; fnox deletes the child token
NeedsA parent token with the API Tokens: Edit permission

Quick start ​

toml
[providers.op]
type = "1password"
vault = "Development"

[secrets]
CLOUDFLARE_API_TOKEN = { provider = "op", value = "Cloudflare/api token", env = false }

[leases.cf]
type = "cloudflare"
duration = "1h"
sh
fnox exec -- sh -c 'curl -fsS -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" https://api.cloudflare.com/client/v4/zones'

The command sees the child token in CLOUDFLARE_API_TOKEN; the parent token stays out of its environment.

Bootstrap credentials ​

fnox reads the parent token from CLOUDFLARE_API_TOKEN, then CF_API_TOKEN. Store it as a secret with one of those names, as in the quick start, or export it. fnox lease create -i cf prompts for it when neither is set.

The parent needs API Tokens: Edit plus every permission the child should have. Cloudflare does not let a child token manage tokens, so the API Tokens permission groups are never passed on.

Configuration ​

FieldRequiredDefaultDescription
token_typeNo"user""user" creates the token under /user/tokens; "account" under /accounts/<account_id>/tokens.
account_idWith "account"noneAccount ID. Also replaces {account_id} in policy resource keys.
policiesNoparent's policiesPolicies for the child token. See Policies.
env_varNo"CLOUDFLARE_API_TOKEN"Variable that receives the child token.
durationNo"15m"Token lifetime, sent as expires_on. At most "24h".

Account-owned tokens are not tied to a person, which suits CI and shared setups. Child tokens are named fnox-lease-<label>, such as fnox-lease-fnox-exec-cf, so you can find them in the dashboard.

Policies ​

Without policies, fnox reads the parent token's policies, drops the API Tokens permission groups, and gives the child the rest. A parent that has only API Tokens permissions cannot be inherited from; configure policies instead.

Each policy has:

FieldRequiredDescription
effectNo"allow" (default) or "deny".
resourcesYesResource scope map, for example { "com.cloudflare.api.account.zone.*" = "*" }.
permission_groupsYesAt least one { id, name } table. name is optional and only for readability.
toml
[leases.cf]
type = "cloudflare"
account_id = "abc123def456"
duration = "2h"

[[leases.cf.policies]]
effect = "allow"
resources = { "com.cloudflare.api.account.{account_id}" = "*" }

[[leases.cf.policies.permission_groups]]
id = "e086da7e2179491d91ee5f35b3c14571"
name = "Workers Scripts Write"

Look up permission group IDs with the permission groups API:

sh
curl -s -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
  "https://api.cloudflare.com/client/v4/user/tokens/permission_groups" | jq '.result[] | {id, name}'

Troubleshooting ​

Cloudflare API token not found ​

Neither CLOUDFLARE_API_TOKEN nor CF_API_TOKEN is set when the lease is created. Under fnox exec, the lease is skipped with this warning unless a cached lease is still valid.

Parent token only has 'API Tokens' permissions ​

Inheritance left the child with nothing. Add the permissions the child needs to the parent token, or configure policies.

HTTP 401 or 403 ​

The parent token is invalid or lacks API Tokens: Edit. With token_type = "account", fnox verifies the parent against /accounts/<account_id>/tokens, so it must be valid for that account.

Resource key contains '{account_id}' placeholder ​

A policy uses {account_id} but account_id is not set. Set it on the lease.

See also ​

MIT LicenseCopyright © 2026jdx.dev