Listing all projects and folders in your hierarchy  |  Resource Manager Documentation  |  Google Cloud (2024)

Resources in Google Cloud are organized into ahierarchy, with each node (Organizations,Folders, Projects, and so forth) having a reference to its parent. You can usethat reference as a key filter term for scans to improve the consistency ofresource searches.

You can grant users permissions usingcustom roles. These roles operate on theprinciple of least privilege, and generally provide only the minimum necessarypermissions required to do a particular task.

This scheme can be useful for isolating different user groups. For example:

  • A large company with departments that shouldn't be able to inspect theresources of their peers.
  • Contractors who are given permissions to a specific Project, but no otherresources.

As a result of their restricted permissions, however, custom roles may causemany resources in your hierarchy to be omitted when executing a list operation.When performing searches as a user that has been granted a custom role, it canbe difficult to tell why certain resources are not appearing.

To avoid this scenario, this page discusses the best practices for listing allof the resources managed by the Cloud Resource Manager API in your resource hierarchy. Youcan use this guidance to configure custom audit checks, or to create your ownuser experience on top of the Cloud Resource Manager API.

List all resource nodes

When you scan your resource hierarchy to list every resource, you need stronglyconsistent results. If your scan misses resources or provides outdated results,it can be hard to tell that something has gone wrong. To make sure that youalways get the most accurate and complete results, use a service account andperform a scan in the following way:

  1. Grant a service account the list and get permissions for Organizations,Folders, and Projects on the Organization resource.
  2. If you are listing Project and Folder resources, specify the parent resourcein the filter string.
  3. Run theprojects.list() methodwith this service account for each type of resource you want to find, andfor any intermediate resources such as Folders.

Example to list all resource nodes

The following pseudocode demonstrates how to list every resource node in yourOrganizations:

organizations = organizations.search()projects = emptyList()parentsToList = queueOf(organizations)while (parent = parentsToList.pop()) { // TODO: Iterate over paginated results as needed. // TODO: Handle PERMISSION_DENIED appropriately. projects.addAll(projects.list(parent.type, parent.id)) parentsToList.addAll(folders.list(parent))}

When building a custom user experience, you may also want to mix in searchresults and load the parent resources as needed (while also catching thePERMISSION_DENIED exception).

Reduce latency on gcloud projects list

If your gcloud projects list query fails or takes too long, the number ofGoogle Cloud projects to return might be too large. To fix this, apply thefilter and page-size flags to your gcloud projects list command.

To learn more about the flags you can add to your gcloud projects list command,see gcloud projects list.

Exclude Apps Script projects example

The most common cause of query failures or latency is a high number of AppsScript projects within an organization. The following command shows how to excludeApps Script projects from the projects list and limit the number of resourcesreturned per page.

gcloud projects list --filter="NOT parent.id: 'APPS_SCRIPT_FOLDER_ID' "--page-size='30'

Get the Apps Script folder ID

To find your Apps Script folder ID, take the following steps.

  1. In the toolbar of the Google Cloud console, clickSearch for resources, docs, products, and more and type apps-script.

    Go to Google Cloud console

  2. Under Resources select the apps-script folder.

  3. Under Folder ID copy the folder ID.

Search resources

If your scan is intended to search for a resource that was created some timeago, you can perform a faster scan that has eventual consistency rather thanstrong consistency. Note that this search method may omit some resources fromthe search result, particularly any resources that have been changed recently.To search for resources:

  1. Use a service account that has the get permission for the resource you aresearching for.
  2. Run theprojects.search()method with this service account.

Troubleshooting omitted resources

If you are developing a scanning tool, we recommend that you use list andget permissions granted at the Organization level. This avoids issues causedby the user having partial permissions, which results in some resources beingomitted from the list.

If you are designing a custom user experience that checks user permissions,there is no easy solution. If a user does not have Organization-levelpermissions, they will need certain permissions on every resource for it toappear. If a user is missing permissions on a resource somewhere in thehierarchy, some resources may not appear.

If a user has the list permission but not the get permission for aparticular resource, that resource won't be visible at all in theGoogle Cloud console. However, the resource will be returned in a search using theAPI or Google Cloud CLI that specifies the resource's parent. This disparitybetween the Google Cloud console and other methods is a common source of confusionwhen trying to scan the resource hierarchy.

The following diagrams demonstrate some common configurations of permissions,and how they change what resources are visible to a user running a search.

Listing all projects and folders in your hierarchy | Resource Manager Documentation | Google Cloud (1)

In this example, all required permissions are granted in the Organizationresource. Therefore, the entire hierarchy is visible when performing a list orsearch.

Listing all projects and folders in your hierarchy | Resource Manager Documentation | Google Cloud (2)

The user in this example has all required permissions except forresourcemanager.organizations.get, but they are granted those permissions atthe Folder level. This permissions gap gives them full visibility on list orsearch of that part of the hierarchy, but not the other half.

Listing all projects and folders in your hierarchy | Resource Manager Documentation | Google Cloud (3)

This example shows the experience of a user with only theresourcemanager.projects.get permission granted at the Folder resource level.They are able to see the Projects underneath that Folder in the hierarchy, butonly by searching. Using the list functionality will not return any results.

Listing all projects and folders in your hierarchy | Resource Manager Documentation | Google Cloud (4)

This example shows the same issue as above, where the granted permissions onlyallow a user to find their Folder resources by searching. Using the listfunctionality will not return any results.

Listing all projects and folders in your hierarchy | Resource Manager Documentation | Google Cloud (5)

The user in this example has a mix of permissions throughout their Organization.They can list folders from the Organization level, which allows them to findthem with searches that specify the parent resource throughout the hierarchy.They can list Project resources for one Folder, but not the other, and they haveresourcemanager.projects.get permission on one Project at the bottom of thehierarchy.

The result is that they aren't able to return the Projects on the left side ofthis resource hierarchy. They can list the Projects on the right side only byusing a search that specifies the parent resource, and only one Project isvisible when viewed in the Google Cloud console.

Listing all projects and folders in your hierarchy | Resource Manager Documentation | Google Cloud (6)

In this example, the user can get the Organization resource and list Projectresources by specifying the parent throughout the hierarchy. However, they donot have permission to list or search any of the intermediate Folders. TheirProjects are searchable if the user happens to know the ID of its parentFolder. The Folders are not visible at all to this user, and so they will not beable to discover the ID if they don't already have it. The only resource thatwill appear in the Google Cloud console is the Organization.

When designing your custom user experience, it's important to be aware ofsituations similar to the above. You can use a combination of listing andsearching to render the resource hierarchy. You should also consider how tocommunicate to users that they are missing permissions that would allow them tosee the whole resource hierarchy.

Listing all projects and folders in your hierarchy  |  Resource Manager Documentation  |  Google Cloud (2024)
Top Articles
Did Cynthia Just Throw The Most Important Fight Of Her Pokemon Career?
POLYGRAPH TECHNIQUE - PAST AND PRESENT
Funny Roblox Id Codes 2023
Hometown Pizza Sheridan Menu
Kem Minnick Playboy
Po Box 7250 Sioux Falls Sd
Canary im Test: Ein All-in-One Überwachungssystem? - HouseControllers
Western Union Mexico Rate
Ingles Weekly Ad Lilburn Ga
oklahoma city for sale "new tulsa" - craigslist
Botanist Workbench Rs3
OSRS Fishing Training Guide: Quick Methods To Reach Level 99 - Rune Fanatics
Ventura Craigs List
Kris Carolla Obituary
Waive Upgrade Fee
Jscc Jweb
Brutál jó vegán torta! – Kókusz-málna-csoki trió
5808 W 110Th St Overland Park Ks 66211 Directions
Https E24 Ultipro Com
Nioh 2: Divine Gear [Hands-on Experience]
Calmspirits Clapper
Echo & the Bunnymen - Lips Like Sugar Lyrics
Seattle Rpz
The ULTIMATE 2023 Sedona Vortex Guide
Nutrislice Menus
Transfer and Pay with Wells Fargo Online®
E22 Ultipro Desktop Version
Amazing deals for DKoldies on Goodshop!
Costco Great Oaks Gas Price
Kashchey Vodka
Wsop Hunters Club
Culver's Flavor Of The Day Taylor Dr
Craigslist Personals Jonesboro
Jail View Sumter
Directions To Nearest T Mobile Store
Foodsmart Jonesboro Ar Weekly Ad
Malluvilla In Malayalam Movies Download
Die wichtigsten E-Nummern
Elanco Rebates.com 2022
Flaky Fish Meat Rdr2
Orangetheory Northville Michigan
Whitehall Preparatory And Fitness Academy Calendar
Hellgirl000
Valls family wants to build a hotel near Versailles Restaurant
Sechrest Davis Funeral Home High Point Nc
Rescare Training Online
Euro area international trade in goods surplus €21.2 bn
Every Type of Sentinel in the Marvel Universe
Barback Salary in 2024: Comprehensive Guide | OysterLink
Research Tome Neltharus
Acellus Grading Scale
Obituary Roger Schaefer Update 2020
Latest Posts
Article information

Author: Maia Crooks Jr

Last Updated:

Views: 6093

Rating: 4.2 / 5 (43 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Maia Crooks Jr

Birthday: 1997-09-21

Address: 93119 Joseph Street, Peggyfurt, NC 11582

Phone: +2983088926881

Job: Principal Design Liaison

Hobby: Web surfing, Skiing, role-playing games, Sketching, Polo, Sewing, Genealogy

Introduction: My name is Maia Crooks Jr, I am a homely, joyous, shiny, successful, hilarious, thoughtful, joyous person who loves writing and wants to share my knowledge and understanding with you.