Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GCP - Verify ownership of a cloud function https endpoint for a PubSub push

Pretty sure there's no way to do this but would be great to reach out to see if anyone else has any ideas.

What I'm trying to do is this:

  • I have 2 microservices hosted on Google Cloud Platform as cloud functions
  • My first microservices does stuff and fires a PubSub message with topic [x]
  • I'd like to set my second microservice up as a push subscriber to the topic [x]. I know I can do this by deploying the 2nd cloud function with a subscription trigger but I don't want to do this as there's no decent way to acknowledge/reject the message (see this post: Google Cloud Functions to only Ack Pub/Sub on success).
  • Therefore I've deployed my 2nd function as having a HTTP trigger. I've then tried to configure the push subscription in the GCP console to this endpoint URL. Of course, this isn't working because the https://[cloud-subdomain].cloudfunctions.net/ isn't a verified domain.

I guess it's just not possible to do what I'm trying to and instead need to create my 2nd microservice in app engine or elsewhere where i can verify a domain.

Thanks in advance!

like image 822
Louzoid Avatar asked Jul 05 '17 08:07

Louzoid


People also ask

What is push endpoint in Pubsub?

When Pub/Sub delivers a message to a push endpoint, Pub/Sub sends the message in the body of a POST request. The body of the request is a JSON object and the message data is in the message. data field. The message data is base64-encoded.

How do you trigger a cloud function in Pubsub?

For Cloud Functions (1st gen): In the Trigger type field, select Cloud Pub/Sub. In the Select a Cloud Pub/Sub topic field, select a topic for the trigger to monitor. Messages published to this topic will trigger calls to your function.

Does Pub/Sub use HTTP?

The Pub/Sub server sends each message as an HTTPS request to the subscriber client at a pre-configured endpoint.


1 Answers

Site Verification using HTML tag method

Not just domain registrar based verification, you can verify your site using any of the methods listed here. I agree most of these will not work with Cloud Functions, but it is possible to get HTML Tag based verification working in matter of minutes with Cloud functions.

You will need to add the given meta attribute in the HTML response just before the body attribute.

Example:

<meta name="google-site-verification" content="VERIFICATION_TAG" />

Also, Google verifies the domain periodically (even after initial success) and hence you will have to continue returning this response as long as you want to have the URL verified.

How long does verification last?

Google periodically checks if your verification is valid in a way appropriate to your verification method (for example, by checking for the presence of an HTML tag on your site). If verification can no longer be confirmed, your permissions on that property will expire after a certain grace period.

Implement retry mechanism within your Cloud function

This is same as the option explained in the other answer you linked, and IMO simpler. Take currentRetryAttempt as one parameter of the request and increment this value every time you queue up a retry request recursively back to the same function when you're timing out. You will need to check currentRetryAttempt against a maxRetriesAllowed value before queuing up a new retry request.

It does not impose any restrictions on the responses from your Cloud function unlike the previous option.

like image 57
Tuxdude Avatar answered Oct 17 '22 20:10

Tuxdude