Make Cloud Run Service Public

Learn how to make a Google Cloud Run service publicly accessible using Node.js and the HTTP REST API. This guide covers setting IAM permissions, configuring service visibility, and deploying with gcloud and direct API calls.

generate service account token
import { GoogleAuth } from 'google-auth-library'; const auth = new GoogleAuth({ keyFile: 'me.json', scopes: ['https://www.googleapis.com/auth/cloud-platform'] }); const client = await auth.getClient(); const token = await client.getAccessToken(); console.log('Access Token:', token);
using the service account token, make a service publically accessible
(async()=>{ // // requires service account token // // var token = ''; var project = ''; var service = ''; //list service details var url = `https://run.googleapis.com/v1/projects/${project}/locations/us-central1/services/${service}:getIamPolicy'; var headers = { authorization : `Bearer ${token}`, 'content-type' : 'application/json' }; var res = await fetch(url,{headers}); var json = await res.json(); console.json(json); //make public var json = { policy : { bindings : [ { role : 'roles/run.invoker', members : ['allUsers'] } ] } }; var url = `https://run.googleapis.com/v1/projects/${project}/locations/us-central1/services/${service}:setIamPolicy'; var headers = { authorization : `Bearer ${token}`, 'content-type' : 'application/json' }; var body = JSON.stringify(json); var res = await fetch(url,{headers,method:'post',body}); var json = await res.json(); console.json(json); })();