Reputation: 3161
I have a Cloud Run service on a GCP project with access point URL https://reporting-intake-service-XXX-uc.a.run.app
. And the service itself uses Pub/Sub to push a message.
Update: I have confirmed the issue is with the Pub/Sub invocation in the service and NOT the access to the service itself.
FROM python:3
WORKDIR /app
COPY . .
RUN pip install -r requirements.txt
CMD python3 intake.py
import logging
from flask import Flask, request
from google.cloud import pubsub_v1
app = Flask(__name__)
@app.route("/", methods=["POST"])
def intake():
try:
report = request.data
publish_message(report)
return "Thanks"
except Exception as e:
logging.error(e)
return "ERROR"
def publish_message(report):
publisher = pubsub_v1.PublisherClient()
future = publisher.publish("projects/my-project/topics/reporting", report)
logging.info(future.result())
if __name__ == "__main__":
app.run(port=8080, host="0.0.0.0", debug=True)
status = StatusCode.PERMISSION_DENIED
details = "User not authorized to perform this action."
Running a VM with service account permissions:
The command to test:
curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $(gcloud auth print-identity-token)" -d "{'\id\': \'ThIS IS SOME DATA\'}" https://reporting-intake-service-XXX-uc.a.run.app
Response:
ERROR
https://cloud.google.com/run/docs/authenticating/service-to-service#acquire-token
https://cloud.google.com/run/docs/authenticating/service-to-service#set-up-sa
Upvotes: 1
Views: 1457
Reputation: 3161
Okay I solved it.
It turns out the Cloud Run service was made with the default Compute service account ###[email protected]
.
Cloud Run > click on service > REVISIONS > SECURITY
The IAM principle attached to ###[email protected]
was deleted (by me for security purposes). So the underlying service I created on Cloud Run did not have access to PubSub.
I spent way too much time on this sh*t.
To be clear this is under the "Require authentication" schema.
Upvotes: 1