Four Credential Types Can Belong to Four Different Owners
Four credentials are easy to mistake for one. A Zero Trust rollout says "the token" in meetings, then stores four secrets with different lifetimes. The Access service token authenticates a workload at the application edge. The tunnel token joins a connector to a remotely-managed tunnel. A credentials file proves a locally-managed tunnel's identity. The API token authorizes Terraform to change the account. Human identity-provider credentials are a separate family; they authenticate people, not these machine paths.
The API token is the control-plane key. It is account-scoped, limited by permission groups, and consumed by CI rather than an application. The secret is shown once, and a leak can edit every resource the policy allows. Platform automation rotates it.
The Access service token is an application credential. Access issues a Client ID and Client Secret, and the client sends both headers to a protected hostname. A Service Auth policy authorizes that pair, and the same token can be referenced by more than one policy. Scope it to one application path so one owner can rotate it.
The tunnel token is a join credential. It encodes the account, tunnel ID and secret, and anyone who holds it can run a connector for that tunnel. That is a network capability, not an application login. The network team owns it and the host team consumes it.
Connector credentials are a local-mode artifact. A locally-managed tunnel runs from a JSON file specific to one tunnel; the cert.pem account certificate used to create tunnels is account-wide. The certificate can list, create and delete every tunnel, so it is the most dangerous file here. The host owner controls the file and the network team controls the certificate.
The owners differ because the failure differs. A leaked service token reaches every application whose policy accepts it, a leaked tunnel token one network path, and a leaked API token the configuration that defines both. A leaked certificate can delete the tunnels themselves.
Figure 1 puts each credential beside its consumer and its revocation owner.
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','activationBorderColor':'#132440','signalColor':'#5a6e82','signalTextColor':'#132440','noteBkgColor':'#c4873b','noteTextColor':'#132440','noteBorderColor':'#132440','labelBoxBkgColor':'#a8dede','labelBoxBorderColor':'#132440','labelTextColor':'#132440','loopTextColor':'#132440','altBackground':'#f8f9fa','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart LR
API["API token
account scope and permission groups"] --> CI["Terraform and CI
control-plane calls"]
SVC["Access service token
Client ID plus Client Secret"] --> JOB["Machine client
one protected hostname"]
TUN["Tunnel token
account, tunnel and secret"] --> CFD["cloudflared replica
remote management"]
CRED["Connector credentials
tunnel JSON and account certificate"] --> CFDL["cloudflared replica
local management"]
CI --> OPS["Platform automation
rotates the API token"]
JOB --> APP["Application team
rotates the service token"]
CFD --> NET["Network team
rotates the tunnel token"]
CFDL --> HOST["Host team
reissues the credentials"]
OPS --> REC["Rotation record
owner, timestamp and proof"]
APP --> REC
NET --> REC
HOST --> REC
API -.->|"cannot pass an Access policy"| SVC
TUN -.->|"cannot edit DNS or Access"| API
classDef primary fill:#132440,color:#ffffff,stroke:#0b172b;
classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a;
classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f;
classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420;
classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f;
classDef owner fill:#f8f9fa,color:#132440,stroke:#5a6e82;
class API primary;
class SVC,CI,JOB,CFD secondary;
class TUN ok;
class CRED,CFDL warn;
class OPS,APP,NET,HOST,REC owner;
Figure 2 is the handover view, not the architecture view. The point is not the four boxes; it is that each row has a different consumer and a named owner. A rotation that closes one row must not require the credential in the next row.
The table is the handover document. It names issuer, consumer, blast radius and rotation owner, so work can be assigned without opening the dashboard.
| Credential | Issued by | Consumed by | Blast radius | Rotation owner |
|---|---|---|---|---|
| API token | Cloudflare account | Terraform or CI | Every resource the policy allows | Platform automation |
| Access service token | Access, bound by a Service Auth policy | A machine client at the edge | Every application whose policy accepts it | Application team |
| Tunnel token | Tunnel, from its ID and secret | A remotely-managed connector | One tunnel's routes and hostnames | Network team |
| Connector credentials | Connector CLI, per host | A locally-managed connector | One tunnel, or the whole account for the certificate | Host team, with the network team for the certificate |
Substitution is the first mistake. A service token cannot authenticate Terraform, an API token cannot pass an Access policy, and a certificate cannot serve traffic. Reusing one because it is already present collapses two blast radii.
Inspect the Selected Provider Schema Before Claiming Write-Only Safety
The schema is the only trustworthy claim about secret handling. Sensitive controls display; write_only controls persistence. The baseline is Terraform 1.17.1 with cloudflare/cloudflare 5.28.1. We dumped that installed schema and filtered the three secret-bearing resources; none exposes a write-only argument.
The service token secret is computed, sensitive and persisted. The schema marks client_secret computed and sensitive, with no write-only flag. Access returns it once at create or rotation, and the provider keeps the state copy because later reads cannot return it. An import therefore leaves the secret empty, and the only recovery is a rotation.
The tunnel secret is optional, sensitive and never refreshed. When set, tunnel_secret is used on create or update and not read back. The value sits in state, and a token refreshed in the dashboard is invisible to the next plan; the plan can be clean while state holds a credential that no longer starts a connector.
The API token value has the same shape. The provider marks value computed and sensitive, and preserves the old value on update. Editing policies changes permissions in place; it does not mint a new secret. Rotation is create-and-revoke, not an attribute edit.
The version fields are the rotation contract. The service token exposes client_secret_version and previous_client_secret_expires_at. Incrementing the version plans a new secret; the expiry controls how long the old one works. Neither is write-only, but together they make rotation reviewable.
The schema also explains the import gap. Import cannot recover a secret the API does not return. Terraform then manages a token whose secret it cannot use, and the first rotation is the only recovery.
Figure 3 follows the schema questions and the branches that decide whether a value survives in state.
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','activationBorderColor':'#132440','signalColor':'#5a6e82','signalTextColor':'#132440','noteBkgColor':'#c4873b','noteTextColor':'#132440','noteBorderColor':'#132440','labelBoxBkgColor':'#a8dede','labelBoxBorderColor':'#132440','labelTextColor':'#132440','loopTextColor':'#132440','altBackground':'#f8f9fa','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
A["terraform providers schema -json
Cloudflare provider 5.28.1"] --> B["Resource schema attributes"]
B --> C{"write_only is true?"}
C -- "yes" --> D["Terraform 1.11 or later omits
the value from plan and state"]
C -- "no" --> E{"sensitive is true?"}
E -- "no" --> F["Value is visible in plan,
state and output"]
E -- "yes" --> G["Value is redacted on screen"]
G --> H{"computed or optional?"}
H -- "computed" --> I["Returned once at create
or rotation"]
H -- "optional, no refresh" --> J["Supplied on create or update
and never read back"]
I --> K["Provider keeps the state copy
because reads cannot return it"]
J --> L["Out-of-band change is invisible
the next plan can be clean"]
K --> M["Import leaves the secret empty
rotate to regain a usable value"]
L --> M
F --> M
classDef primary fill:#132440,color:#ffffff,stroke:#0b172b;
classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a;
classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f;
classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420;
classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f;
class C,E,H primary;
class A,B,G,I secondary;
class D ok;
class F,M danger;
class J,K,L warn;
A write-only design would look different. It needs a write-only flag and Terraform 1.11 or later. The provider exposes no such flag for these fields, so protect the artifacts directly: encrypted backend, narrow access, short plan retention.
A retained secret is easier to audit and harder to defend. Because the value is in state, a rotation appears as a changed secret; because it is in state, a broad reader can take it. The state boundary is the credential boundary.
Keep Connector Startup and Logs from Becoming Secret Stores
A connector needs the secret at start, and every start path leaves copies. The safe question is not whether the token is hidden in the command, but who can read each copy and how long it lives.
The command-line flag is the most visible. The token appears in the service unit, the process list, and the status output operators paste into tickets. Cloudflare's own service example shows it in the start line. Use it for a one-off test, not a managed service.
The environment variable is quieter, not private. A process environment is readable by the same user and root, and container inspection exposes it. It also survives in unit files, shell profiles and orchestration specs. Avoiding the process list is progress, not privacy.
The token file is the supported improvement. A 2025.4.0 or later connector accepts --token-file, and the file can be root-owned with a restrictive mode. The path is visible; the content is not. The file still needs backup exclusion and a deletion step at host retirement.
A secret-manager fetch is only as good as its wrapper. The instance role can read the secret at boot, but a shell with tracing, a failed command that prints its arguments, or a crash log can copy it into the log pipeline. Fetch into a protected file, never echo it.
Debug logging turns headers into evidence. At debug level the connector records request and response headers, and Cloudflare warns this can expose sensitive data. A service token sent through that connector can land in a log line. Production stays at info or above, with redaction and short retention.
Logs still matter, so treat them as sensitive. The tunnel ID, connection events and origin errors are the useful evidence; the token is not. Centralize logs, restrict search, and alert on token-shaped strings.
The host boundary is the real boundary. Anyone who can read the unit file, environment, token file or process memory can run the tunnel. Permissions slow that down; they do not create a separate identity. Keep the connector host off the Terraform runner.
Figure 4 places the copies on both sides of the host boundary and names the surfaces that turn a copy into a leak.
Keep the account certificate off the connector. Remote mode needs a tunnel token, not a certificate that can manage every tunnel. That removes an account-wide secret from the fleet.
Plan Rotation with Overlap, Expiry and Emergency Ownership
A rotation plan is a set of timestamps with owners attached. New credential issued, consumers updated, old credential last accepted, old credential revoked. A missing timestamp turns rotation into an outage.
The service token has the cleanest overlap. Increment client_secret_version, set the previous-secret expiry to a bounded window, and apply. Both secrets work until the expiry. Update every consumer, prove the new secret, then move the expiry into the past.
The grace window is a deadline, not a safety net. Cloudflare offers one hour to thirty days, and the API accepts a timestamp. Choose the shortest window that covers the slowest consumer and put the deadline in the change record. Thirty days of grace is thirty days of exposure.
The token expiry must outlive the rotation. Duration is measured from creation or renewal, and the default is one year. If the next rotation is later, the token expires first. Set duration beyond the rotation interval plus grace, and alert a week before expiry.
The tunnel token rotates with a different failure mode. Changing tunnel_secret stops new connections with the old token but leaves existing connectors running. Reinstall half the replicas, confirm they join, wait for traffic to redistribute, then do the other half. The old token cannot be restored, so the untouched replica is the availability buffer.
A compromised tunnel token is not a graceful rotation. Refresh the secret and delete the tunnel's connections, which removes every connector using the old credential. Then reinstall each replica. Half-at-a-time is for scheduled rotation, not containment.
The API token needs two identities, not one edit. The provider preserves the token value across policy updates, so changing permissions does not rotate the secret. Create a second token with the same policy, switch CI, prove a plan, then revoke the first. Two names make the overlap explicit.
Connector credentials rotate by reissue. A local credentials file does not expire, and the account certificate lasts at least ten years unless revoked. Rotation means a new tunnel identity or a rewritten file, plus a restart. Deleting the certificate's API token revokes it and breaks every dependent workflow.
Emergency ownership is a separate row in the plan. The break-glass identity must not be the credential Terraform uses, and it must be able to revoke a token the automation cannot. Keep it sealed, give it two owners, and test it. An unused break-glass path is a hope, not a control.
Figure 5 lays the four rotations on one timeline; the overlap differs, but the last event is always a revocation.
The plan is incomplete without a revocation test. Each row ends with an old credential that must fail and a new credential that must work. The next section turns that into a rehearsal.
Prove Denial After Revocation and Continued Legitimate Access
The proof is two results against the same target. The old credential must be denied and the new one allowed. A dashboard screenshot of the new token is not evidence; a status code and a log entry are.
Use strict service token authentication in the lab. Strict mode returns a denial instead of a login redirect, so the result is unambiguous. New organizations default to it, and older ones can enable it.
The allowance test must use the real policy path. A request from the connector host proves the origin is alive, not that Access authorizes the token. Send it from the same client, to the same hostname, through the same policy.
The card below is a design-only rehearsal; no production secret or account identifier belongs in it.
Rehearse Zero Trust rotation
Status: design-only. Use a lab account, a disposable application, one tunnel with two replicas, and synthetic identities. No production secret appears in the trace, and every credential is revoked at the end.
Prerequisites. Terraform 1.17.1, provider 5.28.1, a lab zone, an Access application with a Service Auth policy, two service tokens, two connector hosts, and a break-glass account outside the Terraform identity. Enable strict service token authentication and confirm the application denies a wrong secret before rotating.
Steps.
- Record the baseline: the tunnel is healthy with two connections, the service token returns a successful response, and a wrong secret is denied. Save timestamps and status codes, never the secret.
- Rotate the service token by incrementing
client_secret_versionand setting a short previous-secret expiry. Apply, read the new secret into the client, and repeat the request. Both secrets should succeed during the window. - Move the expiry into the past. Repeat with the old secret, then the new one. The old must be denied and the new must still succeed. This is the first proof pair.
- Rotate the tunnel token by changing its secret. Read the new token through the tunnel token data source, reinstall one replica, and confirm it joins while the other replica keeps serving. Repeat an allowed request.
- Reinstall the second replica and confirm the connection count returns to two. From a scratch host, try to join with the old token and confirm the connection is refused. This is the second proof pair.
- Rotate the API token by creating a second token with the same policy, switching CI, and running a read-only plan. Revoke the first, call the API with it, and confirm a 401. Call with the second and confirm success. This is the third proof pair.
- Use the break-glass identity to revoke one credential the automation cannot reach, then rotate the break-glass credential. Record the owner, reason and time.
- Verify that a human Access login and a private Gateway request still work, so the rotation did not close the recovery path. Delete the lab application, tokens and tunnel.
| Check | Old credential | New credential | Evidence to keep |
|---|---|---|---|
| Service token during grace | Allowed | Allowed | Two Access log entries for the same path |
| Service token after expiry | Denied | Allowed | Denial code and timestamp |
| Tunnel token, new join | Refused | Connects | Connector log line and connection count |
| API token after revoke | 401 | 200 | API status codes, no token value |
| Human and private paths | Unchanged | Unchanged | Login result and origin response |
Expected observation. During grace both secrets return a successful response. After expiry the old is denied and the new still works. The refreshed tunnel refuses a new connection with the old token while the untouched replica keeps serving. The revoked API token returns 401, its replacement returns 200, and the human login path never changes.
Failure checks. If the old service secret still works, the timestamp did not apply or the client is reusing a session. If the new service secret is denied, the policy may reference a deleted token ID rather than the rotated Client ID. If the old tunnel token still joins, the test reused a cached connection. If a plan is clean after an out-of-band refresh, the state is stale.
Cost and cleanup. Two small hosts, one tunnel, two service tokens, one API token and one application. Stop the connectors before destroying the tunnel, revoke every token, delete the lab application and policy, and end the break-glass session.
Evidence to keep. Timestamps, status codes, sanitized log identifiers, tunnel connection counts, the rotation diff, and the name of the owner who revoked each credential. Never keep the secret, the raw token, or a screenshot that shows one.