Skip to content

feat(fcm): migrate to FCM v1, retire the legacy server-key path - #388

Open
geekbrother wants to merge 1 commit into
fix/ci-toolchain-driftfrom
feat/fcm-v1-migration
Open

geekbrother wants to merge 1 commit into
fix/ci-toolchain-driftfrom
feat/fcm-v1-migration

Conversation

@geekbrother

Copy link
Copy Markdown
Member

Migrates FCM to the v1 API and retires the legacy server-key path, which has been dead since Google decommissioned the legacy FCM HTTP API in June 2024. Probed directly:

POST https://fcm.googleapis.com/fcm/send  →  HTTP 404

Everything reached through that endpoint is dead — both the credential check in update_fcm and the sends in providers/fcm.rs. FCM v1 was already implemented end to end and is already preferred by provider selection whenever a tenant has v1 credentials, so what remained was retiring the legacy half instead of leaving it to fail silently.

What was broken

POST /:id/fcm "validated" a key with a dry-run send and mapped only FcmError::Unauthorized to failure. A 404 hits the _ => Ok(()) arm, so any string was accepted and stored — and a suspended tenant was restored on the strength of it. Tenant::providers() then advertised FCM for a tenant whose every send 404s.

Changes

  • POST /:id/fcm → 410 Gone, with a message pointing at /:id/fcm_v1. DELETE /:id/fcm still works, so a tenant carrying a stale legacy key can clear it.
  • Provider selection no longer builds a legacy provider for a tenant holding only a server key; it reports LegacyFcmApiRetired, and push_message suspends that tenant with "Legacy FCM credentials, migrate to FCM v1" so it stops being retried and shows up as needing action. Registering v1 credentials unsuspends it, exactly as before.
  • Tenant::providers() / Config::supported_providers() advertise FCM only when v1 credentials are present. A legacy-only tenant cannot receive anything, so claiming the provider was a lie.
  • Removed the unreachable legacy code: providers/fcm.rs, the Provider::Fcm variant, the fcm crate, and the error variants wrapping its types.
  • Single-tenant deployments configure FCM_V1_CREDENTIALS; FCM_API_KEY is gone from Config and the env examples.

Deliberately not done

The fcm_api_key column and its store methods are untouched, so existing rows stay readable and legacy-only tenants can be identified and told to migrate. No credential can be converted automatically — a v1 service account key has to come from the tenant. Dropping the column is a later, destructive cleanup.

Tests

The legacy tests asserting a key is accepted are replaced by one asserting it is refused and that no FCM provider is enabled. The enabled_providers and tenant_delete variants built on legacy registration are dropped — their v1 equivalents in fcm_v1.rs already cover that behaviour. tenant_update_fcm_bad, ignored in #386 because it could not pass while the dead API was consulted, is now this test. ECHO_TEST_FCM_KEY is no longer read by any test.

Verification

  • cargo clippy -D warnings for --tests, --features=multitenant --tests, --features functional_tests --tests, and --all-features --all-targets: clean
  • cargo fmt --check: clean
  • Functional suite against two real Postgres containers, CI's feature set, skipping only the APNs/FCM-v1 tests that need secrets: 25 passed, 0 failed, including the new rejection test and stores::tenant::tenant_fcm, which still exercises the legacy column

Note

Stacked on #386 (fix/ci-toolchain-drift), which unbreaks clippy and the container build. GitHub will retarget this to main once #386 merges. The one conflict during rebase was #386's #[ignore] stopgap, which this supersedes.

🤖 Generated with Claude Code

Google decommissioned the legacy FCM HTTP API in June 2024 — a POST to
fcm.googleapis.com/fcm/send answers 404 — so everything reached through it is
dead: both the credential check in update_fcm and the sends in
providers/fcm.rs. FCM v1 was already implemented end to end and is preferred
by provider selection whenever a tenant has v1 credentials; what remained was
retiring the legacy half rather than leaving it to fail silently.

- POST /:id/fcm returns 410 Gone with a message pointing at /:id/fcm_v1,
  instead of "validating" a key against the dead API, accepting any string
  because only a 401 mapped to failure, storing it, and restoring a suspended
  tenant on it. DELETE /:id/fcm still works so stale keys can be cleared.
- Provider selection no longer builds a legacy provider for a tenant that has
  only a server key; it reports LegacyFcmApiRetired, and push_message suspends
  that tenant with "migrate to FCM v1" so it stops being retried and shows up
  as needing action. Registering v1 credentials unsuspends it, as before.
- Tenant::providers() and Config::supported_providers() only advertise FCM when
  v1 credentials are present — a legacy-only tenant cannot receive anything, so
  claiming the provider was a lie.
- Removed the unreachable legacy provider, its Provider::Fcm variant, the fcm
  crate, and the error variants that wrapped its types.
- Single-tenant deployments configure FCM_V1_CREDENTIALS; FCM_API_KEY is gone
  from Config and the env examples.

The fcm_api_key column and its store methods are untouched: existing rows stay
readable so legacy-only tenants can be identified and told to migrate. No
credential can be converted automatically — a v1 service account key has to
come from the tenant.

Tests: the legacy tests that asserted a key is accepted are replaced by one
that asserts it is refused and that no FCM provider is enabled. The
enabled_providers and tenant_delete variants built on legacy registration are
dropped, their v1 equivalents already cover the behaviour, and
tenant_update_fcm_bad is no longer ignored — it is this new test.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant