Использование ключей JSON с Google Cloud gsutil


У меня есть закрытый ключ ssh в файле key.json , и я хочу использовать эти учетные данные для доступа ведро хранилища с использованием gsutil.

Кажется, я не могу найти ничего о том, как включить ключи json в качестве метода аутентификации, только поля "private" и "secret".

Структура файла:

{
  "private_key_id":
  "private_key": "-----BEGIN PRIVATE KEY-- ...
   "client_email":
   "client_id":
  "type": "service_account"
}

Как мне использовать gsutil с этим файлом?

10
задан 8 September 2019 в 00:52
2 ответа

Краткая версия - запустить следующую команду и следовать инструкциям:

gsutil config -e

Инструмент gsutil имеет встроенный помощь, к которой можно обратиться по всем видам опций и режимов работы. При запуске gsutil help creds , одного из параметров справки, рекомендованных при запуске только gsutil , мы можем прочитать раздел « Учетная запись службы OAuth2 », чтобы увидеть инструкции для использования файла ключей json для служебной учетной записи:

OAuth2 Service Account:

This is the preferred type of credential to use when authenticating on
behalf of a service or application (as opposed to a user). For example, if
you will run gsutil out of a nightly cron job to upload/download data,
using a service account allows the cron job not to depend on credentials of
an individual employee at your company. This is the type of credential that
will be configured when you run "gsutil config -e".

It is important to note that a service account is considered an Editor by
default for the purposes of API access, rather than an Owner. In particular,
the fact that Editors have OWNER access in the default object and
bucket ACLs, but the canned ACL options remove OWNER access from
Editors, can lead to unexpected results. The solution to this problem is to
ensure the service account is an Owner in the Permissions tab for your
project. To find the email address of your service account, visit the
`Google Developers Console <https://cloud.google.com/console#/project>`_,
click on the project you're using, click "APIs & auth", and click
"Credentials".

To create a service account, visit the Google Developers Console and then:

   - Click "APIs & auth" in the left sidebar.

   - Click "Credentials".

   - Click "Create New Client ID".

   - Select "Service Account" as your application type.

   - Save the JSON private key or the .p12 private key and password
     provided.

For further information about account roles, see:
  https://developers.google.com/console/help/#DifferentRoles

For more details about OAuth2 service accounts, see:
  https://developers.google.com/accounts/docs/OAuth2ServiceAccount
2
ответ дан 2 December 2019 в 22:12

На сегодняшний день gsutil config -e все еще находится в документе, когда вы выполняете gsutil help config , но не работает. gsutil help creds сообщает сначала сделать gcloud auth activate-service-account

Я сделал:

gcloud auth activate-service-account --key-file=mycredentialsialreadyhad.json

Заполнил ~ / .config / gcloud / и gsutil теперь работает.

Из документов:

Учетная запись службы OAuth2: Это предпочтительный тип учетных данных для использования при аутентификации от имени службы или приложения (в отличие от пользователя). (...). Это тип учетных данных, которые будут настроены при запуске «gsutil config -e». Чтобы настроить учетные данные учетной записи службы при установке через Cloud SDK, запустите «gcloud auth activate-service-account».

6
ответ дан 2 December 2019 в 22:12

Теги

Похожие вопросы