我正在尝试使用 GCE 默认服务帐户签署 GCS URL。我为计算默认服务帐户提供了必要的“服务帐户令牌创建者”角色。当我尝试在以下 Python 代码中对 url 进行签名时,出现错误:
import google.auth
import google.auth.iam
from google.auth.transport.requests import Request as gRequest
creds, _ = google.auth.default(request=gRequest(), scopes=[
'https://www.googleapis.com/auth/cloud-platform',
'https://www.googleapis.com/auth/devstorage.read_write',
'https://www.googleapis.com/auth/logging.write',
'https://www.googleapis.com/auth/firebase',
'https://www.googleapis.com/auth/compute.readonly',
'https://www.googleapis.com/auth/userinfo.email',
])
## creds is a google.auth.compute_engine.credentials.Credentials
## creds.service_account_email is '<project-id>-compute@developer.gserviceaccount.com'
signer = google.auth.iam.Signer(
gRequest(), credentials=creds,
service_account_email=creds.service_account_email)
signer.sign('stuff')
错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
<TRUNCATED - my code>
File "/usr/local/lib/python3.6/dist-packages/google/auth/iam.py", line 101, in sign
response = self._make_signing_request(message)
File "/usr/local/lib/python3.6/dist-packages/google/auth/iam.py", line 85, in _make_signing_request
response.data))
google.auth.exceptions.TransportError: Error calling the IAM signBytes API: b'{\n "error": {\n "code": 400,\
n "message": "Invalid service account email (default).",\n "status": "INVALID_ARGUMENT"\n }\n}\n'
是否不允许使用 GCE 默认 SA?是否存在其他不允许的默认 SA(特别是 Google App Engine 灵活 SA)?