我有一个访问令牌ya29...0God,并且我知道该令牌具有以下权限compute.instances.setMetadata。
我知道我可以使用它编辑元数据,如下所示:
curl --request POST \
'https://www.googleapis.com/compute/v1/projects/[PROJECT]/zones/[ZONE]/instances/[INSTANCE-NAME]/setMetadata' \
-H 'Authorization: Bearer [ACCESS-TOKEN]' \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
--data '{
"fingerprint": "[INSTANCE-METADATA-FINGERPRINT]",
"items": [
{
"key": "ssh-keys",
"value": "ubuntu:ssh-rsa [SSH-PUBLIC-KEY] ubuntu"
}
]
}'但是我想用gcloud代替:
gcloud compute instances add-metadata [INSTANCE] --metadata-from-file ssh-keys=meta.txt是否可以使用访问令牌配置gcloud?
发布于 2022-08-22 15:53:47
这可以使用--access-token-file标志来完成。
使用此标志使用访问令牌对gcloud进行身份验证。活动帐户的凭据(如果存在)将被忽略。该文件只应包含没有其他信息的访问令牌。
gcloud compute instances add-metadata [INSTANCE] \
--metadata-from-file ssh-keys=meta.txt \
--access-token-file token.txt请注意,如果令牌过期,这将无法工作。
来源:https://cloud.google.com/sdk/gcloud/reference#--access-token-file
https://stackoverflow.com/questions/73447087
复制相似问题