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

Use Labels for Resource Management

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: Low (generally tolerable level of risk)

Ensure that user-defined labels are being used to tag, collect, and organize Cloud Run services within your Google Cloud Platform (GCP) projects. User-defined labels are a lightweight and efficient way to group together related or associated cloud resources.

Security
Reliability
Performance
efficiency
Cost
optimisation

As your Google Cloud Platform (GCP) projects grow increasingly complex, effective management strategies become essential. User-defined labels can significantly enhance visibility and organization across your Google Cloud resources. By strategically labeling your Cloud Run services, you can streamline organization, simplify search queries, and optimize resource management. This lightweight yet powerful approach allows you to group related services, such as production, staging, and development environments, for efficient identification and control.


Audit

To determine if your Cloud Run services are labeled for better resource management, 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 LABELS to view the labels defined for selected service. The panel with the service labels opens.

06 Review the Labels for \ panel to determine if any user-defined labels are configured for the selected resource. If there are no user-defined labels listed on this panel, the selected Cloud Run service is not labeled with user-defined labels for resource management.

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 ID(s):

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: tm-stream-service
REGION: us-central1

NAME: tm-vertex-service
REGION: us-central1

05 Run services describe command (Windows/macOS/Linux) with the name of the Cloud Run service that you want to examine as the identifier parameter, to describe the user-defined labels configured for the selected service:

gcloud run services describe cc-project5-service
	--region=us-central1
	--format="yaml(metadata.labels)"

06 The command output should return the requested resource labels:

metadata:
	labels:
		cloud.googleapis.com/location: us-central1

Check the services describe command output to identify the labels defined for the selected resource. Labels that contain cloud.googleapis.com are reserved labels added by Cloud Run service. If the command output returns only reserved labels, as shown in the example above, the selected Cloud Run service is not labeled with user-defined labels for resource management.

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 ensure that all your Cloud Run services are labeled with user-defined labels for better resource management, 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 LABELS. The panel with the service labels opens.

06 In the Labels for \ panel, choose ADD LABEL, and use the Key and Value text fields to define your own labels for the selected service. You can use labels such as: environment (e.g., prod, test, dev), team (e.g., frontend, backend, secops), purpose (e.g., API), billing (e.g., project5, engineering), version (e.g., v1.5, v2.1) or owner (e.g., john-doe, team-lead). Choose SAVE to apply the changes. Adding labels will deploy a new revision of the service.

07 Repeat steps no. 4 and 5 for each Cloud Run service that you want to configure, available within the selected project.

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

Using GCP CLI

01 Run services update command (Windows/macOS/Linux) with the name of the Cloud Run service that you want to configure as the identifier parameter, to set labels for the selected service. Use the --update-labels command parameter to supply your own labels. If the specified label exists, its value is modified. Otherwise, a new label is created. You can use labels such as: environment (e.g., prod, test, dev), team (e.g., frontend, backend, secops), purpose (e.g., API), billing (e.g., project5, engineering), version (e.g., v1.5, v2.1) or owner (e.g., john-doe, team-lead). Adding labels will deploy a new revision of the service:

gcloud run services update cc-project5-service
	--region=us-central1
	--update-labels environment=prod,team=engineering

02 The command output should return the build information available for the redeployed service:

OK Deploying... Done.
	OK Creating Revision...
	OK Routing traffic...
Done.

Service [cc-project5-service] revision [cc-project5-service-00003-abc] has been deployed and is serving 100 percent of traffic.
Service URL: https://cc-project5-service-123456789012.us-central1.run.app

03 Repeat steps no. 1 and 2 for each Cloud Run service that you want to configure, available in the selected project.

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

References

Publication date Nov 20, 2024