Я создал сервисные аккаунты в GCP Console IAM & Admin> Сервисные аккаунты >> Создать
Назначенные администратор хранилища, администратор объекта хранилища, создатель объекта хранилища
Создан ключ и загружен файл json
Чтобы проверить эту учетную запись службы, я выполнил эту команду на виртуальной машине GCP.
$ gcloud auth activate-service-account --key-file service-account.json
Activated service account credentials for: [[email protected]]
Затем я смог скопировать файл в хранилище
$ gsutil cp image-src.txt gs://bucket-images
Copying file://image-src.txt [Content-Type=text/plain]...
/ [1 files][ 19.5 KiB/ 19.5 KiB]
Operation completed over 1 objects/19.5 KiB.
Но когда я пытаюсь использовать service-account.json
с приложением node.js, я получаю
(node:1) UnhandledPromiseRejectionWarning: Error: [email protected] does not have storage.objects.create access to the Google Cloud Storage object.
at new ApiError (/ingester/node_modules/@google-cloud/common/build/src/util.js:59:15)
at Util.parseHttpRespBody (/ingester/node_modules/@google-cloud/common/build/src/util.js:194:38)
at Util.handleResp (/ingester/node_modules/@google-cloud/common/build/src/util.js:135:117)
at retryRequest (/ingester/node_modules/@google-cloud/common/build/src/util.js:434:22)
at onResponse (/ingester/node_modules/retry-request/index.js:206:7)
at /ingester/node_modules/teeny-request/build/src/index.js:170:17
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:1) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 5)
Правильно ли я создаю учетную запись службы?
Обновление: после ответа v1gnus
Я пытался получить
cloudshell:~ $ gcloud iam service-accounts get-iam-policy [email protected]
etag: ACAB
Затем я попытался установить политику
cloudshell:~ $ gcloud projects add-iam-policy-binding xxx-123 --member serviceAccount:[email protected]
m.gserviceaccount.com --role roles/storage.admin
Updated IAM policy for project [xxx-123].
bindings:
...
- members:
- serviceAccount:[email protected]
role: roles/storage.admin
- members:
- serviceAccount:[email protected]
role: roles/storage.objectAdmin
- members:
- serviceAccount:[email protected]
role: roles/storage.objectCreator
etag: rfvtgyh-4Gw=
version: 1
После этого я все еще получаю это
cloudshell:~ $ gcloud iam service-accounts get-iam-policy [email protected]
etag: ACAB