web-dev-qa-db-ja.com

Google Cloud gsutilでのJSONキーの使用


key.jsonファイルにssh秘密鍵があり、この認証情報を使用して、gsutilを使用してストレージバケットにアクセスします。

認証方法としてjsonキーを含める方法について何も見つからないようです。「プライベート」フィールドと「シークレット」フィールドのみです。

ファイル構造は次のとおりです。

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

そのファイルでgsutilを使用するにはどうすればよいですか?

13
GuySoft

短いバージョンでは、次のコマンドを実行し、指示に従います。

gsutil config -e

Gsutilツールには組み込みのヘルプがあり、あらゆる種類のオプションや操作モードについて調べることができます。実行中gsutil help credsは、gsutilを単独で実行するときに推奨されるヘルプオプションの1つです。「OAuth2 Service Account "を使用して、サービスアカウントの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
Nick

今日現在、 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」を実行します。

9
Alex F