google-cloud-platform - 在没有任何组织级别权限的情况下获取 GCP 中给定项目的资产/资源列表
问题描述
我一直在探索的一个选项如下。
在阅读文档https://cloud.google.com/security-command-center/docs/how-to-api-list-assets#listing_all_assets时,发现我们可以使用 Security Command Center API 获取所有资产的列表。
以下是文档中提供的代码。
static ImmutableList<ListAssetsResult> listAssets(OrganizationName organizationName) {
try (SecurityCenterClient client = SecurityCenterClient.create()) {
// Start setting up a request for to search for all assets in an organization.
// OrganizationName organizationName = OrganizationName.of(/*organizationId=*/"123234324");
ListAssetsRequest.Builder request =
ListAssetsRequest.newBuilder().setParent(organizationName.toString());
// Call the API.
ListAssetsPagedResponse response = client.listAssets(request.build());
// This creates one list for all assets. If your organization has a large number of assets
// this can cause out of memory issues. You can process them incrementally by returning
// the Iterable returned response.iterateAll() directly.
ImmutableList<ListAssetsResult> results = ImmutableList.copyOf(response.iterateAll());
System.out.println("All assets:");
System.out.println(results);
return results;
} catch (IOException e) {
throw new RuntimeException("Couldn't create client.", e);
}
}
在安全命令中心运行命令会返回错误“PERMISSION_DENIED: Permission 'securitycenter.assets.list' denied on resource 'organizations/{organization-id}' (or resource may not exist)”作为响应。
根据以下文档https://cloud.google.com/security-command-center/docs/access-control,需要在 ORGANIZATION LEVEL 设置权限“securitycenter.assets.list”,这是有问题的。
我正在寻找一个选项来绕过上述问题,我不需要组织级别的权限或任何其他可以帮助我完成此任务的 API。
解决方案
要使用 Security Command Center,您的项目需要成为组织的一部分。您还需要组织级别的权限。您的目标无法在项目级别实现。
推荐阅读
- azure - 是否可以使用内置 blob 触发器为每个新 blob 触发逻辑应用?
- c++ - 了解将对象插入向量时的构造、复制和销毁
- python - 在 .csv 中切片和编辑日期
- java - 玩 Mapping 忽略 RawSQL Ebean
- python - 根据两个索引减去两个多索引数据帧
- git - 如何从分离的头中删除已删除的提交?
- r - 在 Shiny 中启用数据帧的某些部分的关键字?
- dax - 除了 DAX Studio,您还可以在哪里编写 DAX 查询?
- ios - 我正在使用 mobileVLCKit。如何在 iOS 上设置 VLCMediaPlayer 的静音/取消静音?
- python - 我如何在 scrapy 的 itemloader 中传递一个列表?