简体   繁体   English

我如何导出(到文件)所有在 GCP 组织中每个项目具有特定角色的人?

[英]How do I export(to a file) all people with a certain role per project in an organization in GCP?

I have inherited a project and am basically trying to get all owners per project from the more than 100 projects into a nice little list so that I can use them for further role planning outside of GCP.我继承了一个项目,基本上是在尝试将 100 多个项目中的每个项目的所有所有者放入一个漂亮的小列表中,以便我可以使用它们在 GCP 之外进行进一步的角色规划。 There are projects that have more than 30 owners and I need to start managing roles.有超过 30 个所有者的项目,我需要开始管理角色。

They are managed in the projects directly and are not populated by CI or any other service.它们直接在项目中管理,不由 CI 或任何其他服务填充。

Thank you谢谢

What have you tried so far?你试过什么了?

There's a lot of questions I can ask for more detail and understanding but making assumptions, I'd make a script that iterates over all Projects, iterate over all People with Role.有很多问题我可以要求更多的细节和理解,但做出假设,我会制作一个遍历所有项目的脚本,遍历所有具有角色的人。

There's GUI, CLI, API, etc ways to access the information.有 GUI、CLI、API 等方式来访问信息。 For a simple script, CLI is the simplest.对于简单的脚本,CLI 是最简单的。

To show all projects: gcloud projects list显示所有项目: gcloud projects list

To list all users in the project (with their roles) gcloud projects get-iam-policy <project_name>列出项目中的所有用户(及其角色) gcloud projects get-iam-policy <project_name>

Hope this helps!希望这可以帮助!

    for PROJECT in `gcloud projects list --format="value(projectId)"`
do
   printf "Project: %s\n" ${PROJECT} >> Testfile1.txt
   gcloud projects get-iam-policy ${PROJECT} --flatten="bindings[].members[]" --filter="bindings.role=roles/owner" --format="value(bindings.members)" >> Testfile1.txt 
   printf "\n"
   printf "\n"    
done

Gets the job done.完成工作。 Iterates through all projects and exports project-id and name of all "owners" to a file called "Testfile1.txt".遍历所有项目并将所有“所有者”的项目 ID 和名称导出到名为“Testfile1.txt”的文件中。 It is not pretty but it works.它不漂亮,但它有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 每个项目的 GCP / GKE 导出到 bigquery 的成本 - GCP / GKE export cost to bigquery per project 如何在 GCP 中为 secret 赋予角色? - How do I give a role to secret in GCP? 如何在 Prometheus 中从我的 GCP 组织导出 SLO? - How to export SLO's from my GCP organization in Prometheus? 如何在我的 GCP 组织中获取所有外部 IP 地址? - How can I get all External IP Addresses in my GCP organization? 如何创建仅在特定时间段内有效的具有分配角色的 GCP 服务帐户? - How can I create a GCP service account with assigned role that will only be valid for a certain period of time? 如何列出 GCP 中属于特定组织的所有项目 - How to list all projects in GCP that belongs to a specific organization 如何将 GCP 项目从一个组织迁移到另一个组织 - How to migrate a GCP Project from one organization to other GCP-IAM - 如何授予对组织中所有服务帐户的访问权限? - GCP-IAM - How to grant access to all service account in organization? Ingress (GCP Load balancer) - 如何为每个路由设置不同的请求超时 - Ingress (GCP Load balancer) - how do I set different request timeouts per route 小型组织是否应该在 GCP 中拥有多个所有者角色? - Should a small organization have more than one Owner role in GCP?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM