Skip to Content
App AttestationRolling out: monitor to enforce

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

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.

FieldSourceTells you
EndpointYour APIWhere a refusal would land
Outcome: missing, invalid, pass or failHeader present? Verification passed? tp.resultWhat enforcing would refuse
Verification errorYour verification codeExpired tokens, wrong audience, binding mismatch, debug tokens
tp.reasonsTokenWhy a device fails the policy
tp.plat, tp.app, tp.env, tp.evTokenPlatform, app, environment and evidence of each result
tp.mode, tp.pvTokenThe mode and policy version the token was issued under
App versionYour own header or User-AgentWhether 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, invalid and fail are what enforcing would refuse;
  • fail by reason code, platform and app;
  • missing by 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:

  1. Is every reason code explained? Use the table below. A reason you can’t explain is a policy or app problem to fix first.
  2. 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.
  3. 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.
  4. 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 resultsUsually meansTypical action
dev_environmentBuilds run from Xcode reach this verifierExpected 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 appAdd your own missing certificate. Re-signed copies are what you want to refuse
app_not_recognized, unlicensedAndroid builds not installed from Google PlayKeep 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_oldDevices below the bar you setAccept losing them, or relax that setting
app_access_risk, play_protect_risk, device_activity_excessiveOptional Play Integrity verdictsCheck the share each one costs before enforcing it
evidence_missingDevices that can’t provide the evidence the policy requires, for example no Google Play under Play Integrity onlyConsider Either
app_identity_unverifiedKey Attestation on a device with an unlocked bootloaderExpected 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:

  1. 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 /readyz answers ok, not degraded), and that production APIs don’t set TRUSTPIN_ALLOW_DEBUG.
  2. 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.env development, next to the debug token check in verify.mjs.
  3. 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.
  4. 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

  1. On the Policy tab, choose Edit, then 3. Mode and tokens, select Enforce, and choose Save now.
  2. Sign and publish. The dialog lists the change; tick the confirmation to publish.

What happens next, from the moment you publish:

WhoWhat happensWhen
VerifiersLoad the new versionWithin their refresh interval, 5 minutes by default
Devices that passedNothing changes. Their new tokens carry tp.mode enforceAt their next renewal
Devices whose attestation failedTheir 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 meanwhileWithin one Access token lifetime
Tokens already issued with tp.result failStay 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 enforceGone within one Access token lifetime
Devices that passed under a laxer device checkKeep passing until their key certificate expiresWithin one Key certificate lifetime

Check:

  • On the Status tab, Verifier checks, Check now reports policy vN applied with the new version. The verifier also logs policy updated, and its trustpin_attest_policy_version metric changes.
  • Within one access-token lifetime, trustpin_attest_tokens_issued_total{result="fail"} stops increasing, and new tokens in your logs carry tp.mode enforce.
  • The missing share in your logs grows by about the fail share you measured. A much larger jump means something else changed: roll back and look.

6. Refuse in the API, one endpoint at a time

  1. Start with your most sensitive endpoint: set it to enforce in the API’s TRUSTPIN_ENDPOINT_MODES, for example {"POST /transfer":"enforce"}, and restart the API. It now refuses missing, invalid and fail.
  2. Watch the refused count, errors and support tickets for that endpoint for a day or more.
  3. 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 undoHowTakes effect
One endpointRemove it from TRUSTPIN_ENDPOINT_MODES and restart the APIAt once. This is the fastest rollback, so try it first
The policy’s modeEdit, 3. Mode and tokens, Monitor (recommended to start), Save now, then Sign and publishVerifiers 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 settingRelax it, then Sign and publishAs 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.

ChangeTakes effect on devices
Removing an app or a signing digest, turning off Accept development builds or Allow debug tokens, switching monitor to enforceAt 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 verdictsAt each device’s next attestation only, so within one Key certificate lifetime (30 days by default)
Turning on Require token bindingAt the next attestation or renewal: one without a binding is refused with 400 binding_required
Access token lifetime or Key certificate lifetimeTokens and key certificates issued from then on; existing ones keep their expiry
Listing an app again, or relaxing a checkAt 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

SymptomLikely causeFix
Requests are refused while the policy is in monitor modeA gateway recipe refuses requests without the header, whatever the modeCheck tokens in the API during monitor, or make the recipe log and pass
tp.result fail still appears after switching to enforceTokens issued before the switch, with tp.mode monitorWait one Access token lifetime, or refuse fail in the API
A tightened device check doesn’t show upDevice checks apply at the next attestationExpect it within one Key certificate lifetime
Check now still reports the old policy versionThe verifier hasn’t refreshed yet, or refuses the new versionWait one refresh interval; then see the verifier’s log and Operating the verifier

Next steps