Rolling out: monitor to enforce
For the backend lead and the console admin, working together. At the end of this page, your policy is in Enforce, your API refuses unattested requests on the endpoints you chose, the decision rests on measurements, and you know how to roll back.
There are two switches, and you flip them separately:
- The policy’s Mode, on the project’s Attestation page. In Enforce, the verifier issues no token to a device that fails a policy check.
- Your API’s rule, per endpoint. Nothing is refused until your API, or your gateway, refuses it. The SDKs never block a request; without a token they send it without the header.
Before you start
- A published policy in Monitor (recommended to start) mode. See Setting up apps and the policy.
- A production verifier serving it, scraped by Prometheus if you want the verifier’s metrics. See Staging and production and Operating the verifier.
- An API that verifies the
TrustPin-Attestationheader. See Verifying tokens in your API. - An app release with the SDK’s attestation module, in your users’ hands.
If you check tokens at a gateway, note that the gateway recipes refuse requests without the header, or with a token that fails verification, from the moment you deploy them. They let tokens with tp.result fail through. During monitor, they would refuse every app version without attestation: check tokens in the API instead, or adapt the recipe to log and pass.
1. Monitor: log every request
In monitor mode the verifier issues a token even when a policy check fails, with tp.result fail and the failed checks in tp.reasons. Two outcomes get no token in either mode: an app the policy doesn’t list (403 app_not_allowed), and forged evidence.
Log one line per request to a protected endpoint. Never log the token itself.
| Field | Source | Tells you |
|---|---|---|
| Endpoint | Your API | Where a refusal would land |
Outcome: missing, invalid, pass or fail | Header present? Verification passed? tp.result | What enforcing would refuse |
| Verification error | Your verification code | Expired tokens, wrong audience, binding mismatch, debug tokens |
tp.reasons | Token | Why a device fails the policy |
tp.plat, tp.app, tp.env, tp.ev | Token | Platform, app, environment and evidence of each result |
tp.mode, tp.pv | Token | The mode and policy version the token was issued under |
| App version | Your own header or User-Agent | Whether requests without the header come from app versions without attestation |
The checkAttestation middleware on the backend page logs these fields, one line per request, and the verification error on its attestation refused: line. Put it on every endpoint you plan to protect, and leave them all out of TRUSTPIN_ENDPOINT_MODES for now: every request goes through. Step 6 uses that setting to enforce endpoint by endpoint.
2. Measure
Measure per endpoint, over at least one full release cycle, so slow updaters show up.
From your API logs:
- the share of each outcome per endpoint:
missing,invalidandfailare what enforcing would refuse; failby reason code, platform and app;missingby app version: requests from versions without attestation shrink as users update, the rest come from devices that can’t attest or are still waiting for a token.
From the verifier’s metrics, for the fleet as a whole:
# Share of tokens issued with tp.result fail, over the last day
sum(increase(trustpin_attest_tokens_issued_total{mode="monitor",result="fail"}[1d]))
/ sum(increase(trustpin_attest_tokens_issued_total{mode="monitor"}[1d]))
# Attestations with a reason code, by platform and reason, over the last day
sum by (platform, reason) (
increase(trustpin_attest_attestations_total{reason!~"none|verdict_unavailable"}[1d])
)The reason label holds one reason per attestation, the first in alphabetical order; your API logs have all of them. The result label of trustpin_attest_attestations_total says whether the attestation got a token, so in monitor mode a policy failure counts as pass there, with its reason: filter on reason, not result. On the Grafana dashboard, the “Attestations with a reason, by reason and token outcome” panel shows each reason, split into token pass (a token was issued anyway: monitor mode, or an informational reason such as verdict_unavailable, in either mode) and token fail (refused).
Cost while you monitor: a device whose attestation failed keeps a key certificate for only one Access token lifetime, so it attests again, with an Apple or Google call, about once per access-token lifetime. Watch your Play Integrity quota (10,000 requests a day per Cloud project by default) if many Android devices fail.
3. Decide, or adjust
Move on only when you can answer yes to each question, per endpoint:
- Is every reason code explained? Use the table below. A reason you can’t explain is a policy or app problem to fix first.
- Are requests without the header accounted for? Most should come from app versions without attestation. Decide from which app version, or which date, you stop serving them on this endpoint.
- Has every active device been judged by the current policy? Device checks are evaluated at attestation only. After you tighten one, devices that passed before are judged again when their key certificate expires: wait one Key certificate lifetime (30 days by default) before trusting the numbers.
- Is the share that would be refused acceptable? Write the share you accept for each endpoint down before you look at the numbers, and compare.
Reason in fail results | Usually means | Typical action |
|---|---|---|
dev_environment | Builds run from Xcode reach this verifier | Expected on staging. See Prepare for enforce |
app_not_allowed (Android, with a token) | A listed package signed with a certificate the policy doesn’t list: often the Play app signing certificate is missing, or a re-signed copy of your app | Add your own missing certificate. Re-signed copies are what you want to refuse |
app_not_recognized, unlicensed | Android builds not installed from Google Play | Keep if you distribute only through Play; otherwise turn off Require an app recognized by Google Play or Require a licensed app |
device_integrity_insufficient, security_level_insufficient, verified_boot_failed, bootloader_unlocked, patch_level_too_old | Devices below the bar you set | Accept losing them, or relax that setting |
app_access_risk, play_protect_risk, device_activity_excessive | Optional Play Integrity verdicts | Check the share each one costs before enforcing it |
evidence_missing | Devices that can’t provide the evidence the policy requires, for example no Google Play under Play Integrity only | Consider Either |
app_identity_unverified | Key Attestation on a device with an unlocked bootloader | Expected for such devices |
To change the policy: on the Policy tab, Edit, change the settings, Save now (or Save changes on 4. Review), then Sign and publish. Each change reaches devices as described in When changes take effect. Then measure again.
4. Prepare for enforce
The policy is shared by every environment of the project, staging included, so decide per setting where development builds may still attest. While still in monitor mode:
- Debug tokens. Keep Allow debug tokens on if you test on simulators and emulators against staging: a verifier accepts debug tokens only when it also has
TRUSTPIN_DEBUG_TOKEN_HASHES. Make sure production verifiers have none (their/readyzanswersok, notdegraded), and that production APIs don’t setTRUSTPIN_ALLOW_DEBUG. - Builds run from Xcode. Accept development builds applies to every verifier. Turn it off, unless Xcode-run builds must keep attesting against staging; then leave it on and make production APIs refuse
tp.envdevelopment, next to thedebug tokencheck inverify.mjs. - Signing certificates. Remove the ones no build signs with any more. Keep the debug key only while debug builds on real devices test against staging.
- Sign and publish, then measure for another day: builds that relied on a removed setting now show up as
fail, not as passes.
5. Switch the policy to Enforce
- On the Policy tab, choose Edit, then 3. Mode and tokens, select Enforce, and choose Save now.
- Sign and publish. The dialog lists the change; tick the confirmation to publish.
What happens next, from the moment you publish:
| Who | What happens | When |
|---|---|---|
| Verifiers | Load the new version | Within their refresh interval, 5 minutes by default |
| Devices that passed | Nothing changes. Their new tokens carry tp.mode enforce | At their next renewal |
| Devices whose attestation failed | Their renewal is refused with 401 invalid_key_certificate; they attest again under the enforced policy. If they still fail, they get 403 attestation_failed and no token, wait the time the verifier sets (TRUSTPIN_REFUSAL_RETRY_AFTER, 10 minutes by default) before trying again, and send requests without the header meanwhile | Within one Access token lifetime |
Tokens already issued with tp.result fail | Stay valid until they expire. They carry tp.mode monitor; the verifier can’t recall them. For an immediate cut-off, your API refuses fail itself, as checkAttestation does on an endpoint in enforce | Gone within one Access token lifetime |
| Devices that passed under a laxer device check | Keep passing until their key certificate expires | Within one Key certificate lifetime |
Check:
- On the Status tab, Verifier checks, Check now reports
policy vN appliedwith the new version. The verifier also logspolicy updated, and itstrustpin_attest_policy_versionmetric changes. - Within one access-token lifetime,
trustpin_attest_tokens_issued_total{result="fail"}stops increasing, and new tokens in your logs carrytp.modeenforce. - The
missingshare in your logs grows by about thefailshare you measured. A much larger jump means something else changed: roll back and look.
6. Refuse in the API, one endpoint at a time
- Start with your most sensitive endpoint: set it to
enforcein the API’sTRUSTPIN_ENDPOINT_MODES, for example{"POST /transfer":"enforce"}, and restart the API. It now refusesmissing,invalidandfail. - Watch the refused count, errors and support tickets for that endpoint for a day or more.
- Move to the next endpoint.
Requests without the header never stop entirely: old app versions, devices that can’t attest, and attestation failures. For endpoints where refusing is too strong, choose something softer: rate-limit harder, require a second factor, or flag the session for review.
Rolling back
| What to undo | How | Takes effect |
|---|---|---|
| One endpoint | Remove it from TRUSTPIN_ENDPOINT_MODES and restart the API | At once. This is the fastest rollback, so try it first |
| The policy’s mode | Edit, 3. Mode and tokens, Monitor (recommended to start), Save now, then Sign and publish | Verifiers within 5 minutes. A device refused shortly before tries again once its wait is over (10 minutes by default, never more than 1 hour), then gets a token marked fail |
| A tightened setting | Relax it, then Sign and publish | As in the table below |
Verifiers never accept a lower policy version, so you can’t republish an older version: a rollback is a new version with the old settings.
When changes take effect
A new policy version first reaches each verifier within its refresh interval, 5 minutes by default. The table counts from then.
| Change | Takes effect on devices |
|---|---|
| Removing an app or a signing digest, turning off Accept development builds or Allow debug tokens, switching monitor to enforce | At each device’s next token renewal, so within one Access token lifetime. The renewal answers invalid_key_certificate, and the device attests again under the new policy |
| Tightening a device check: security level, verified boot, bootloader, patch level, Play Integrity verdicts | At each device’s next attestation only, so within one Key certificate lifetime (30 days by default) |
| Turning on Require token binding | At the next attestation or renewal: one without a binding is refused with 400 binding_required |
| Access token lifetime or Key certificate lifetime | Tokens and key certificates issued from then on; existing ones keep their expiry |
| Listing an app again, or relaxing a check | At the device’s next attempt. A device whose attestation failed in monitor mode attests again within one Access token lifetime. A device the verifier refused waits TRUSTPIN_REFUSAL_RETRY_AFTER (10 minutes by default) first |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| Requests are refused while the policy is in monitor mode | A gateway recipe refuses requests without the header, whatever the mode | Check tokens in the API during monitor, or make the recipe log and pass |
tp.result fail still appears after switching to enforce | Tokens issued before the switch, with tp.mode monitor | Wait one Access token lifetime, or refuse fail in the API |
| A tightened device check doesn’t show up | Device checks apply at the next attestation | Expect it within one Key certificate lifetime |
| Check now still reports the old policy version | The verifier hasn’t refreshed yet, or refuses the new version | Wait one refresh interval; then see the verifier’s log and Operating the verifier |
Next steps
- Operating the verifier: health, metrics, alerts and incidents, now that production depends on it
- Verifying tokens in your API, for assertions on sensitive operations