2017-06-01 47 views

回答

0

有可能是一個更好,更直接的方式,但這裏有一個方法做到這一點,可以在任何地方工作,GCE與否。 gcloud可以使用像這樣的實例的憑據打印您的訪問令牌:

$> 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": "[email protected]", 
    "verified_email": true, 
    "access_type": "offline" 
} 

所以,一個完整的命令來獲得:

$> gcloud auth print-access-token 
ya29.GlxcBCtxyP3xW1JwKL62vh4h_8W0vqH9awoCXgcYkOguBP2DKc4JxgHpX6HHuaaaaaaaaaaaaa 

然後,您可以標記直接與谷歌的OAuth API查詢的是准入範圍作用域列表可能是這樣的(假設你有HTTPie和JQ安裝):

$> http 'https://www.googleapis.com/oauth2/v1/tokeninfo' \ 
    access_token==`gcloud auth print-access-token` | 
    jq '.["scope"]' 
0

你不需要是在實例來獲取這些信息。如果您運行

gcloud compute instances describe MY_INSTANCE --zone ZONE \ 
    --format="yaml(serviceAccounts)" 

它會顯示由VM和設定範圍的使用服務帳戶有:

serviceAccounts: 
- email: [email protected] 
    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以提取相關信息。