Add encrypted content to mobile push notifications
What does this MR do and why?
Adds encrypted content to mobile push notifications: the to-do content travels sealed between the instance and the device, so Apple and any relay never see it. The instance holds the plaintext and the key, so this is not end-to-end encryption; the API doc has a threat-model section saying what is and is not protected.
Today a full payload carries a to-do's title, subtitle and body in clear text through APNs. With this change a device can register a 32-byte content_key; for such a device the alert is the generic "You have a new to-do" with mutable-content set, and the real content rides sealed under that key (AES-256-GCM) in the gitlab.content envelope, which the GitLab mobile app's notification service extension opens on the phone. Apple never sees to-do content.
mobile_device_push_subscriptions.content_key(jsonb,encrypts), thecontent_keyregistration parameter (validated as base64 of 32 bytes) andcontent_key: missing | presentin the registration response. The app sends its key only after amissinganswer, never on the cold-start heartbeat, so the key is not re-sent on every launch. The parameter is already masked byconfig.filter_parameters(/key$/).Gitlab::MobilePush::EncryptedContentseals the version-2 envelope{alg: "A256GCM", v: 2, iat, ciphertext}with the additional authenticated datagitlab-mobile-push/2\n<device token>\n<iat>: a captured payload opens neither on another device nor, as the app enforces, after a 3900 s window.- A device changing hands drops the previous owner's
content_keyandpayload_mode(RegisterServiceresets them before applying the registration), so a reassigned device starts withcontent_key: missing. - Key rotation:
content_key_registered_atis stamped when the key changes, a key older than 90 days is reportedmissingso the app replaces it (it keeps sealing pushes until then; re-sending the same key does not renew it), andgitlab:mobile_push:clear_content_keys[username]forgets stored keys for incident response. Payloadgains theencryptedmode (MobileDevicePushSubscription#effective_payload_mode:id_onlywhen the user chose identifiers only,encryptedwith a key,fullotherwise);ApnsClienttakes the per-devicegitlabobject throughPayload#gitlab_data_for(subscription).fullandid_onlypayloads are unchanged.
The app side (key exchange, Keychain storage, the extension's AAD and freshness checks) ships in GitLab Mobile. Two app changes follow from the rotation design and land there before the feature flag is enabled: minting a fresh key on every missing answer, and keeping the previous key for the 3900 s envelope window and trying it when the current key does not open an envelope.
References
- The GitLab mobile app's extension that opens the envelope:
ios/NotificationService/NotificationService.swiftin https://gitlab.com/mvanremmerden/gitlab-mobile - Push subscriptions API: !248023 (merged), delivery: !248026 (merged)
Screenshots or screen recordings
No UI change.
How to set up and validate locally
- In the Rails console enable the flags:
Feature.enable(:mobile_push_registration_api); Feature.enable(:mobile_push_notifications_dispatch); Feature.enable(:mobile_push_notifications). - Register a device with a key:
curl --request POST --header "PRIVATE-TOKEN: <token>" --data "device_token=$(openssl rand -hex 32)" --data "content_key=$(openssl rand -base64 32)" http://gdk.test:3000/api/v4/user/push_subscriptions— the response carries"content_key": "present"; repeat withoutcontent_keyand it still reportspresent. - In the Rails console:
sub = Notifications::MobileDevicePushSubscription.last; todo = Todo.last; Gitlab::MobilePush::Payload.new(todo, mode: sub.effective_payload_mode).gitlab_data_for(sub)— thecontentenvelope withalg,v: 2,iatand a base64ciphertext, andtitle/bodynil on the payload.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Database review
Two migrations on mobile_device_push_subscriptions, a small table: content_key (jsonb, nullable) with the check constraint octet_length(content_key::text) <= 1024, and content_key_registered_at (timestamptz, nullable).
clear_content_keys runs only from the operator Rake task gitlab:mobile_push:clear_content_keys[username]. It batches by id with each_batch (1,000 rows); only the update_all in each batch filters on content_key. Without a username:
SELECT "mobile_device_push_subscriptions"."id" FROM "mobile_device_push_subscriptions" ORDER BY "mobile_device_push_subscriptions"."id" ASC LIMIT 1;
SELECT "mobile_device_push_subscriptions"."id" FROM "mobile_device_push_subscriptions" WHERE "mobile_device_push_subscriptions"."id" >= 1 ORDER BY "mobile_device_push_subscriptions"."id" ASC LIMIT 1 OFFSET 1000;
UPDATE "mobile_device_push_subscriptions" SET "content_key" = NULL, "content_key_registered_at" = NULL WHERE "mobile_device_push_subscriptions"."id" >= 1 AND "mobile_device_push_subscriptions"."id" < 1001 AND "mobile_device_push_subscriptions"."content_key" IS NOT NULL;With a username, each statement also filters on user_id, which index_mobile_device_push_subscriptions_on_user_id serves:
SELECT "mobile_device_push_subscriptions"."id" FROM "mobile_device_push_subscriptions" WHERE "mobile_device_push_subscriptions"."user_id" = 1 ORDER BY "mobile_device_push_subscriptions"."id" ASC LIMIT 1;
SELECT "mobile_device_push_subscriptions"."id" FROM "mobile_device_push_subscriptions" WHERE "mobile_device_push_subscriptions"."user_id" = 1 AND "mobile_device_push_subscriptions"."id" >= 1 ORDER BY "mobile_device_push_subscriptions"."id" ASC LIMIT 1 OFFSET 1000;
UPDATE "mobile_device_push_subscriptions" SET "content_key" = NULL, "content_key_registered_at" = NULL WHERE "mobile_device_push_subscriptions"."user_id" = 1 AND "mobile_device_push_subscriptions"."id" >= 1 AND "mobile_device_push_subscriptions"."id" < 1001 AND "mobile_device_push_subscriptions"."content_key" IS NOT NULL;