Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google cloud storage 如何查看gcloud shell上的实例信息_Google Cloud Storage_Gcloud - Fatal编程技术网

Google cloud storage 如何查看gcloud shell上的实例信息

Google cloud storage 如何查看gcloud shell上的实例信息,google-cloud-storage,gcloud,Google Cloud Storage,Gcloud,我想检查实例信息,特别是存储,无论是只读的、完整的还是通过gcloud shell读/写的,可能有更好更直接的方法,但这里有一种方法可以在任何地方使用,无论GCE与否。gcloud可以使用实例的凭据打印访问令牌,如下所示: $> gcloud auth print-access-token ya29.GlxcBCtxyP3xW1JwKL62vh4h_8W0vqH9awoCXgcYkOguBP2DKc4JxgHpX6HHuaaaaaaaaaaaaa 然后,您可以直接使用Google的OAu

我想检查实例信息,特别是存储,无论是只读的、完整的还是通过gcloud shell读/写的,可能有更好更直接的方法,但这里有一种方法可以在任何地方使用,无论GCE与否。gcloud可以使用实例的凭据打印访问令牌,如下所示:

$> gcloud auth print-access-token
ya29.GlxcBCtxyP3xW1JwKL62vh4h_8W0vqH9awoCXgcYkOguBP2DKc4JxgHpX6HHuaaaaaaaaaaaaa
然后,您可以直接使用Google的OAuth API查询该访问令牌的范围:

$> curl 'https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=ya29.GlxcBCtxyP3xW1JwKL62vh4h_8W0vqH9awoCXgcYkOguBP2DKc4JxgHpX6HHuaaaaaaaaaaaaa'
{
  "issued_to": "something.apps.googleusercontent.com",
  "audience": "something.apps.googleusercontent.com",
  "user_id": "1234567890",
  "scope": "https://www.googleapis.com/auth/cloud-platform https://www.googleapis.com/auth/cloudkms https://www.googleapis.com/auth/appengine.admin https://www.googleapis.com/auth/compute https://www.googleapis.com/auth/plus.me",
  "expires_in": 3578,
  "email": "some@email.com",
  "verified_email": true,
  "access_type": "offline"
}
因此,获取作用域列表的完整命令可能如下所示(假设您安装了HTTPie和jq):


也许有更好、更直接的方法,但这里有一种方法可以在任何地方使用,不管GCE与否。gcloud可以使用实例的凭据打印访问令牌,如下所示:

$> gcloud auth print-access-token
ya29.GlxcBCtxyP3xW1JwKL62vh4h_8W0vqH9awoCXgcYkOguBP2DKc4JxgHpX6HHuaaaaaaaaaaaaa
然后,您可以直接使用Google的OAuth API查询该访问令牌的范围:

$> curl 'https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=ya29.GlxcBCtxyP3xW1JwKL62vh4h_8W0vqH9awoCXgcYkOguBP2DKc4JxgHpX6HHuaaaaaaaaaaaaa'
{
  "issued_to": "something.apps.googleusercontent.com",
  "audience": "something.apps.googleusercontent.com",
  "user_id": "1234567890",
  "scope": "https://www.googleapis.com/auth/cloud-platform https://www.googleapis.com/auth/cloudkms https://www.googleapis.com/auth/appengine.admin https://www.googleapis.com/auth/compute https://www.googleapis.com/auth/plus.me",
  "expires_in": 3578,
  "email": "some@email.com",
  "verified_email": true,
  "access_type": "offline"
}
因此,获取作用域列表的完整命令可能如下所示(假设您安装了HTTPie和jq):


您不需要在实例上获取此信息。如果你跑

gcloud compute instances describe MY_INSTANCE --zone ZONE \
  --format="yaml(serviceAccounts)"
它将显示vm使用的服务帐户及其作用域集:

serviceAccounts:
- email: xxx@bla.gserviceaccount.com
  scopes:
  - https://www.googleapis.com/auth/devstorage.read_only
  - https://www.googleapis.com/auth/logging.write
  - https://www.googleapis.com/auth/monitoring.write
  - https://www.googleapis.com/auth/servicecontrol
  - https://www.googleapis.com/auth/service.management.readonly
  - https://www.googleapis.com/auth/trace.append

您可以使用
--format
标志执行
jq
工具提供给您的许多操作,或者设置
--format=json
并将其传输到
jq
以提取相关信息。

您不需要在实例上就可以获得这些信息。如果你跑

gcloud compute instances describe MY_INSTANCE --zone ZONE \
  --format="yaml(serviceAccounts)"
它将显示vm使用的服务帐户及其作用域集:

serviceAccounts:
- email: xxx@bla.gserviceaccount.com
  scopes:
  - https://www.googleapis.com/auth/devstorage.read_only
  - https://www.googleapis.com/auth/logging.write
  - https://www.googleapis.com/auth/monitoring.write
  - https://www.googleapis.com/auth/servicecontrol
  - https://www.googleapis.com/auth/service.management.readonly
  - https://www.googleapis.com/auth/trace.append
您可以使用
--format
标志执行
jq
工具提供给您的许多操作,或者设置
--format=json
并将其传送到
jq
以提取相关信息