Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
…nctions Eventarc delivers CloudEvents to Pub/Sub push endpoints marked with `?__GCP_CloudEventsMode=CE_PUBSUB_BINDING`. These are normally converted to HTTP binary content mode before reaching the function, but when an attribute can't be sent as an HTTP header (for example, a Firestore document ID with a trailing space in `ce-subject`), the request arrives as the raw Pub/Sub push envelope with the CloudEvent in binary content mode of the Google Cloud Pub/Sub protocol binding. FF treated these as plain Pub/Sub messages and delivered a `messagePublished` event instead. For the `cloudevent` signature type, decode these envelopes into the CloudEvent they carry. Only binary content mode is handled, and only when the query parameter is present and all required `ce-` attributes are set; all other Pub/Sub push requests are left unchanged.
dylayed
force-pushed
the
feat/ce-pubsub-binding
branch
from
September 25, 2026 23:17
53dd316 to
704c17b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Eventarc Firestore triggers push to
https://<service>?__GCP_CloudEventsMode=CE_PUBSUB_BINDING. Normally the request is converted to HTTP binary content mode (ce-*headers) before it reaches the function. When an attribute can't be sent as an HTTP header, it isn't converted: the function receives the raw Pub/Sub push envelope, with the CloudEvent in binary content mode of the Google Cloud Pub/Sub protocol binding (ce--prefixed attributes, data inmessage.data).The known trigger is a Firestore document ID with a trailing space, which puts a trailing space at the end of
ce-subjectandce-document(firebase/firebase-functions#1922). FF handles the envelope as a plain Pub/Sub message and delivers agoogle.cloud.pubsub.topic.v1.messagePublishedevent withsource: //pubsub.googleapis.com/. With firebase-functions 7.4.0 the handler now runs withparams: {}and a non-existent snapshot, and the event is acked.This adds a middleware, for the
cloudeventsignature type only, that decodes the envelope into the CloudEvent it carries and hands it to the existing structured-mode path. It's an alternative to #786, which spoofs HTTP headers and also matches unprefixedtype/sourceattributes.Scope
The middleware only applies when all of these hold. Everything else is left exactly as today:
__GCP_CloudEventsMode=CE_PUBSUB_BINDINGce-*HTTP headers (a binary-mode HTTP CloudEvent still takes precedence)ce-specversion,ce-id,ce-sourceandce-typeattributescontent-type: application/cloudevents...attribute)Data is decoded the way the HTTP body parsers in
server.tsdecode a binary-mode body:application/jsonis parsed (invalid JSON returns 400, likebodyParser.json),text/plainbecomes a string, and anything else, includingapplication/protobuf, stays aBuffer.datacontenttypecomes fromce-datacontenttype, falling back to thecontent-typeattribute.Not included, on purpose: structured content mode, and the
eventsignature type.Backward compatibility
CUSTOM_PUBSUB_<topic>) and send their ownce-*headers, so user messages withce-*attributes on those triggers are unaffected.CE_PUBSUB_BINDINGparameter, so they're unaffected.cloudeventfunction that gets aCE_PUBSUB_BINDINGenvelope now receives the real event instead of amessagePublishedwrapper.Testing
npm test: 120 passing (13 new intest/integration/cloud_event_pubsub_binding.ts);npm run checkclean.document.v1.writtentrigger → a firebase-functions 7.4.0onDocumentWrittenfunction, deployed withFUNCTION_SIGNATURE_TYPE=cloudevent(as the Firebase CLI does) and this branch packed in withnpm pack. Seven document IDs were tested: normal, internal space, leading space, trailing space,%,",é. All returned 200 and arrived as Firestore events. The trailing-space ID now getsparams.docId = "trailing-space "and the correct snapshot, where it previously got empty params and a missing document. The other six are unchanged.Unrelated issue found while testing: non-ASCII document IDs reach
paramsgarbled (é→é), because the header carries raw UTF-8 that Node reads as Latin-1. It's on the normal HTTP path and not touched here.