Use the Conformity Knowledge Base AI to help improve your Cloud Posture

Check for Publicly Accessible Cloud Run Services

Trend Cloud One™ – Conformity is a continuous assurance tool that provides peace of mind for your cloud infrastructure, delivering over 1000 automated best practice checks.

Risk Level: High (not acceptable risk)

Identify any publicly accessible Cloud Run services within your GCP account and update their IAM policy in order to protect against unauthorized users that are sending requests to invoke these services. To deny access from anonymous and public users, remove the bindings for allUsers and allAuthenticatedUsers members from your service's IAM policy. allUsers is a special member identifier that represents any user on the Internet, including authenticated and unauthenticated users, while the allAuthenticatedUsers is an identifier that represents any user or service account that can sign in to Google Cloud Platform (GCP) with a Google account.

Security
Reliability
Cost
optimisation
Performance
efficiency
Operational
excellence

Misconfigured access permissions are a common security vulnerability that involves Google Cloud resources. Granting permissions to allUsers and allAuthenticatedUsers members can allow anyone to invoke your services. To prevent sensitive data leaks, data loss, and unexpected charges on your GCP bill, ensure that anonymous and/or public access to your Cloud Run services is not allowed.


Audit

To determine if there are any publicly accessible Cloud Run services available within your GCP account, perform the following operations:

Using GCP Console

01 Sign in to the Google Cloud Management Console.

02 Select the Google Cloud Platform (GCP) project that you want to examine from the console top navigation bar.

03 Navigate to Cloud Run console available at https://console.cloud.google.com/run/.

04 Select the SERVICES tab to view the Cloud Run services deployed for the selected GCP project.

05 Select the Cloud Run service that you want to examine and choose PERMISSIONS to access the permissions defined for selected service. The panel with the service permissions opens.

06 Toggle the Expand button (right arrow icon) available next to each role name listed in the Role / Principal section to show the principal(s) defined for each role. Check for any allUsers and allAuthenticatedUsers principals. If the Role / Principal list contains roles with allUsers and/or allAuthenticatedUsers principals, the selected Cloud Run service is considered publicly accessible.

07 Repeat steps no. 5 and 6 for each Cloud Run service created for the selected GCP project.

08 Repeat steps no. 2 - 7 for each project deployed within your Google Cloud account.

Using GCP CLI

01 Run projects list command (Windows/macOS/Linux) with custom output filters to list the ID of each project available in your Google Cloud Platform (GCP) account:

gcloud projects list
	--format="value(projectId)"

02 The command output should return the requested GCP project IDs:

PROJECT_ID
cc-bigdata-project-123123
cc-iot-app-project-112233

03 Run services list command (Windows/macOS/Linux) with the ID of the GCP project that you want to examine as the identifier parameter and custom output filters to describe the name and the region of each Cloud Run service deployed within the selected project:

gcloud run services list
	--project cc-bigdata-project-123123
	--format="(NAME,REGION)"

04 The command output should return the requested service names and the associated regions:

NAME: cc-project5-service
REGION: us-central1

NAME: cc-stream-service
REGION: us-central1

NAME: cc-container-service
REGION: us-central1

05 Run services get-iam-policy command (Windows/macOS/Linux) with the name of the Cloud Run service that you want to examine as the identifier parameter, to describe names of the IAM members (principals) defined in the invoker policy associated with the selected service:

gcloud run services get-iam-policy cc-project5-service
	--project cc-bigdata-project-123123
	--region us-central1
	--format=json | jq '.bindings[].members[]'

06 The command output should return the name of the associated IAM members:

"allAuthenticatedUsers"
"allUsers"

If the list of IAM members returned by the run services get-iam-policy command output includes "allUsers" and/or "allAuthenticatedUsers", as shown in the example above, the selected Cloud Run service is considered publicly accessible.

07 Repeat steps no. 5 and 6 for each Cloud Run service created for the selected GCP project.

08 Repeat steps no. 3 – 7 for each GCP project deployed in your Google Cloud account.

Remediation / Resolution

To remove the allUsers and/or allAuthenticatedUsers IAM member bindings from the associated invoker policy in order to restrict anonymous and/or public access to your Cloud Run services, perform the following operations:

Using GCP Console

01 Sign in to the Google Cloud Management Console.

02 Select the Google Cloud Platform (GCP) project that you want to access from the console top navigation bar.

03 Navigate to Cloud Run console available at https://console.cloud.google.com/run/.

04 Select the SERVICES tab to access the Cloud Run services deployed for the selected GCP project.

05 Select the Cloud Run service that you want to configure and choose PERMISSIONS to access the permissions defined for selected service. The panel with the service permissions opens.

06 Toggle the Expand button (right arrow icon) available next to each role name listed in the Role / Principal section to show the principal(s) defined for each role.

01 Identify and remove all allUsers and allAuthenticatedUsers principals from the role bindings configured for the selected service by using the Delete button (bin icon) available next to each principal.

07 Inside the Remove role from principal? confirmation box, choose REMOVE to remove the allUsers and/or allAuthenticatedUsers role bindings.

08 Access to invoke Cloud Run services can be granted to specific, trusted users, groups, or service accounts that require it, following the Principle of Least Privilege (POLP). To assign the Cloud Run Invoker role (roles/run.invoker) to a Cloud Run service, perform the following actions:

  1. Select the Cloud Run service that you want to configure and choose PERMISSIONS. Once the panel with the service permissions opens, choose ADD PRINCIPAL.
  2. For Add principals, enter the name of the trusted member/principal in the New principals box.
  3. For Assign roles, use the Select a role dropdown box to search and select the Cloud Run Invoker role.
  4. Choose SAVE to apply the changes.

09 Repeat steps no. 5 - 9 for each Cloud Run service that you want to configure, available within the selected project.

10 Repeat steps no. 2 – 10 for each project deployed in your Google Cloud account.

Using GCP CLI

01 Run services remove-iam-policy-binding command (OSX/Linux/UNIX) with the name of the publicly accessible Cloud Run service that you want to configure as the identifier parameter, to remove the allUsers binding from the invoker policy associated with the selected service:

gcloud run services remove-iam-policy-binding cc-project5-service
	--region='us-central1'
	--member='allUsers'
	--role='roles/run.invoker'

02 The command output should return the information available for the updated policy:

Updated IAM policy for service [cc-project5-service].
	bindings:
	- members:
		- serviceAccount:<service-account-name>
		role: roles/run.invoker
	etag: ABCD1234ABCD
	version: 1

03 Run services remove-iam-policy-binding command (OSX/Linux/UNIX) with the name of the publicly accessible service that you want to configure as the identifier parameter, to remove the allAuthenticatedUsers binding from the invoker policy associated with the selected service:

gcloud run services remove-iam-policy-binding cc-project5-service
	--region='us-central1'
	--member='allAuthenticatedUsers'
	--role='roles/run.invoker'

04 The command output should return the information available for the updated policy:

Updated IAM policy for service [cc-project5-service].
bindings:
- members:
	- serviceAccount:<service-account-name>
	role: roles/run.invoker
etag: ABCDABCDABCD
version: 1

05 Access to invoke Cloud Run services can be granted to specific, trusted users, groups, or service accounts that require it, following the Principle of Least Privilege (POLP). To assign the Cloud Run Invoker role (roles/run.invoker) to your Cloud Run service, run the services add-iam-policy-binding command (OSX/Linux/UNIX). This command adds an invoker role policy binding that allows the specified, trusted member/principal to invoke your service. Trusted principals can be are users, groups, domains, or service accounts:

gcloud run services add-iam-policy-binding cc-project5-service
	--region="us-central1"
	--member='user:user@domain.com'
	--role='roles/run.invoker'

06 The command output should return the information available for the new role policy binding:

bindings:
- members:
	- allUsers
	- user:user@domain.com
	role: roles/run.invoker
etag: 1234ABCD1234
version: 1

07 Repeat steps no. 1 - 6 for each Cloud Run service created for the selected GCP project.

08 Repeat steps no. 1 – 7 for each GCP project deployed in your Google Cloud account.

References

Publication date Oct 23, 2023