GCP命令读取所有用户的权限

是否可以列出GCP中用户的所有权限?

我知道有此命令:

  

gcloud projects get-iam-policy“ project-ID”

,但是我只能看到我在IAM控制台中设置的IAM角色。例如,我看不到IAM角色

  

BigQuery数据查看器

我已经在BigQuery页面上的数据集上为用户设置了

theresa88520 回答:GCP命令读取所有用户的权限

  

在GCP中是否可以列出用户的所有权限?

在Google Cloud Platform中,没有单个命令可以执行此操作。通过角色的权限分配给资源。组织,文件夹,项目,数据库,存储对象,KMS密钥等可以分配有IAM权限。您必须扫描(检查IAM权限)每个资源,以确定IAM成员帐户拥有的权限总数。

这些功能既是Google Cloud授权,安全性还是审计的强项和弱项。如果了解得很好,这些功能将非常强大。

,

您可以通过使用标记“ --flatten”,“ --format”和“ {{3}”来调整ConcurrentModificationException的输出来列出与用户或服务帐户相关联的角色。 }':

gcloud projects get-iam-policy

在我的测试场景中,输出如下:

gcloud projects get-iam-policy <YOUR GCP PROJECT>  \
--flatten="bindings[].members" \
--format="table(bindings.role)" \
--filter="bindings.members:<THE USER OR SERVICE ACCOUNT>"
,

当我们考虑用户的权限时,想到某种主表说“用户X具有所有THESE权限”是错误的。相反,我们需要重新调整思维方向,以不同的角度思考。想想要保护的事物(资源),然后我们可以说“此资源(Z)允许用户X执行Y”。

在GCP中,我们也不分配权限,而是分配权限的角色。

回到您的询问,这意味着我们无法列出用户的所有权限,因为用户没有“拥有”权限,而是用户拥有相对于资源的角色。

想象一下您的文件系统上一个名为“ A”的文件,用户X可以读取但不能写入该文件。现在,假设您的文件系统上有一个名为“ B”的文件,用户X可以写入但不能读取。我们不能正确地说用户X同时具有“读取”和“写入”权限。尽管有些文件用户可以读取,而有些文件可以写入,但这并不是说用户可以读写所有文件。

要得出结论……对于任何给定的资源集,您都可以询问该资源,哪些用户在该资源上扮演什么角色。

我们有一个API,可用于确定用户是否可以对给定资源执行命名操作……请参见:Testing permissions

,

您可以使用此代码在组织下的IAM策略内搜索“ foo@bar.com”:

invisible(lapply(c("tidyverse","matrixStats","RANN","microbenchmark","compiler"),require,character.only=TRUE))

enableJIT(3)

# faster column scaling (modified from https://www.r-bloggers.com/author/strictlystat/)
colScale <- function(x,center = TRUE,scale = TRUE,rows = NULL,cols = NULL) {
    if (!is.null(rows) && !is.null(cols)) {x <- x[rows,cols,drop = FALSE]
    } else if (!is.null(rows)) {x <- x[rows,drop = FALSE]
    } else if (!is.null(cols)) x <- x[,drop = FALSE]
    cm <- colMeans(x,na.rm = TRUE)
    if (scale) csd <- matrixStats::colSds(x,center = cm,na.rm = TRUE) else
        csd <- rep(1,length = length(cm))
    if (!center) cm <- rep(0,length = length(cm))
    x <- t((t(x) - cm) / csd)
    return(x)
}

# your posted version (mostly):
oldv <- function(){
    iris.scaled <- iris %>% 
        mutate_if(is.numeric,scale)
    iris.nn2 <- nn2(iris.scaled[1:4])
    distance.index <- iris.nn2$nn.idx[,-1]
    target = iris.scaled$Species
    category_neighbours <- matrix(target[distance.index[,]],nrow = nrow(distance.index),ncol = ncol(distance.index))
    class <- apply(category_neighbours,1,function(x) {
        x1 <- table(x)
        names(x1)[which.max(x1)]})
    cbind(iris,class)
}

## my version:
myv <- function(){
    iris.scaled <- colScale(data.matrix(iris[,1:(dim(iris)[2]-1)]))
    iris.nn2 <- nn2(iris.scaled)

    # set self neighbors to NA
    iris.nn2$nn.idx[iris.nn2$nn.idx - seq_len(dim(iris.nn2$nn.idx)[1]) == 0] <- NA

    # match up categories
    category_neighbours <- matrix(iris$Species[iris.nn2$nn.idx[,nrow = dim(iris.nn2$nn.idx)[1],ncol = dim(iris.nn2$nn.idx)[2])

    # turn category_neighbours into numeric for tabulate
    cn <- matrix(as.numeric(factor(category_neighbours,exclude=NULL)),ncol = dim(iris.nn2$nn.idx)[2])
    cnl <- levels(factor(category_neighbours,exclude = NULL))

    # tabulate frequencies and match up with factor levels
    class <- apply(cn,function(x) {
        cnl[which.max(tabulate(x,nbins=length(cnl))[!is.na(cnl)])]})
    cbind(iris,class)
}

microbenchmark(oldv(),myv(),times=100L)
#> Unit: milliseconds
#>    expr       min        lq      mean    median        uq      max neval cld
#>  oldv() 11.015986 11.679337 12.806252 12.064935 12.745082 33.89201   100   b
#>   myv()  2.430544  2.551342  3.020262  2.612714  2.691179 22.41435   100  a

您可以将范围更改为项目或文件夹。

文档:https://cloud.google.com/asset-inventory/docs/searching-iam-policies

尽管它不涵盖所有政策:https://cloud.google.com/asset-inventory/docs/supported-asset-types#searchable_asset_types

更多详细信息可以在另一篇文章中找到:How to list,find,or search iam policies across services (APIs),resource types,and projects in google cloud platform (GCP)?

,

我创建了这个小脚本。它提供了诸如成员 ID、分配给它的角色和项目名称等详细信息

for list in `gcloud projects list | awk 'NR>1 {print $1}'`; do gcloud projects get-iam-policy $list --flatten="bindings[].members" --format="table(bindings.members,bindings.role,$list)"; done;
本文链接:https://www.f2er.com/2912021.html

大家都在问