Firebase-tools: ADC認証エラー:このリクエストにはスコープが必要です

作成日 2018年05月29日  ·  46コメント  ·  ソース: firebase/firebase-tools

こんにちは、Firebase関数のデプロイを自動化しようとしています。 「GOOGLE_APPLICATION_CREDENTIALS =」のようなものを実行するとFirebaseの使用--non-interactive--debug」次のエラーが発生しました

バージョン情報

3.18.5

プラットフォーム情報

コンテナノード:6.14-アルパイン

再現する手順

/ usr / bin / docker run --rm -v /ワークスペース:/ワークスペース-e GOOGLE_APPLICATION_CREDENTIALS =node:6.14-alpine node_modules / firebase-tools / bin / firebase use- デバッグ

予想される行動

認証される

実際の動作

[2018-05-29T15:57:32.507Z]>コマンドにはスコープが必要です:[“ email”、“ openid”、“ https://www.googleapis.com/auth/cloudplatformprojects.readonly“、” https:// www .googleapis.com / auth / firebase”]
[2018-05-29T15:57:32.507Z]>アプリのデフォルトのクレデンシャルを介して認証を試みています
[2018-05-29T15:57:32.547Z]! 自動認証エラー:このリクエストにはスコープが必要です。
[2018-05-29T15:57:32.547Z]>資格情報が見つからないか、自動的に取得できませんでした

何か提案はありますか?

最も参考になるコメント

@mbleigh更新はありますか? 現在、firebase CLIはサービスアカウントを使用してデプロイできないことを確認していますか? CIツールに必要です。 だからGOOGLE_APPLICATION_CREDENTIALSサポートは機能しませんか?

全てのコメント46件

こんにちは。必要なクレデンシャルはGOOGLE_APPLICATION_CREDENTIALSではないため、この行は実際には役に立ちません。

CIトークンを生成してから、-tokenフラグを指定してコマンドを実行する必要があります。詳細については、 https://github.com/firebase/firebase-tools#using-with-ci-systemsをご覧ください。

やあ、
https://github.com/firebase/firebase-tools/pull/417はどうですか?
GOOGLE_APPLICATION_CREDENTIALSが実装されており、firebase-toolsがgoogle-auto-authを使用してそれを取得しているようです。

または私は間違っていますか?

Googleユーザー(GSuiteやCloud Identityなど)ではなくサービスアカウントで認証したいので、CIトークンは使用しません。

ありがとうございました

やあ、
ライブラリがfirebase-public.firebaseioを呼び出しているようです。 com:443であり、HTTP戻りコードは200ですが、応答は0バイトです。

こんにちは、その通りです。 すみません、そのPRを忘れてしまいました。 私はこれにあまり精通していません。 マイケル、あなたがオフィスに戻ったときに見てもらえますか?

こんにちは@ laurenzlong @ mbleigh
サービスアカウントに「ドメイン全体の権限」を設定すると、認証が許可されることがわかりました。
しかし今、私は次の問題を抱えています:

GOOGLE_APPLICATION_CREDENTIALS=<path_to_json> firebase deploy --only functions --non-interactive --project=<project_id> --debug

[2018-06-04T09:25:46.202Z] ----------------------------------------------------------------------
[2018-06-04T09:25:46.211Z] CLI Version:   3.18.5
[2018-06-04T09:25:46.212Z] Platform:      linux
[2018-06-04T09:25:46.212Z] Node Version:  v6.14.2
[2018-06-04T09:25:46.212Z] Time:          Mon Jun 04 2018 09:25:46 GMT+0000 (UTC)
[2018-06-04T09:25:46.213Z] ----------------------------------------------------------------------

[2018-06-04T09:25:46.238Z] > command requires scopes: ["email","openid","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","https://www.googleapis.com/auth/cloud-platform"]
[2018-06-04T09:25:46.238Z] > attempting to authenticate via app default credentials
[2018-06-04T09:25:46.445Z] xxxx.x.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-xx
[2018-06-04T09:25:46.446Z] > retrieved access token via default credentials
[2018-06-04T09:25:46.449Z] >>> HTTP REQUEST GET https://admin.firebase.com/v1/projects/<project_id>  

 Mon Jun 04 2018 09:25:46 GMT+0000 (UTC)
[2018-06-04T09:25:47.067Z] <<< HTTP RESPONSE 404 server=nginx, date=Mon, 04 Jun 2018 09:25:47 GMT, content-type=application/json; charset=utf-8, content-length=87, connection=close, x-content-type-options=nosniff
[2018-06-04T09:25:47.069Z] <<< HTTP RESPONSE BODY code=PROJECT_NOT_FOUND, message=The specified project was not found.

サービスアカウントにはプロジェクトに対する編集者権限があり、Google ID(svcアカウントではない)を使用する場合、問題は存在しません

私はこれと同様の問題を見つけました(ただし、トークンを使用しています) https://github.com/firebase/firebase-tools/issues/744

ありがとう

いいえ、私は間違っています。
Firebaseの使用を実行

[2018-06-04T14:39:38.660Z] > command requires scopes: ["email","openid","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase"]
[2018-06-04T14:39:38.660Z] > attempting to authenticate via app default credentials
[2018-06-04T14:39:38.693Z] ! auto-auth error: Scopes are required for this request.
[2018-06-04T14:39:38.694Z] > no credentials could be found or automatically retrieved

firebase CLIツールを使用して何かをしようとして、 Ownerロールが割り当てられているサービスアカウントでも同じ動作をします。

$ export GOOGLE_APPLICATION_CREDENTIALS=account.json
$ firebase list --debug
[2018-06-05T12:15:17.340Z] ----------------------------------------------------------------------
[2018-06-05T12:15:17.343Z] Command:       /usr/local/bin/node /usr/local/bin/firebase list --debug
[2018-06-05T12:15:17.343Z] CLI Version:   3.18.5
[2018-06-05T12:15:17.343Z] Platform:      linux
[2018-06-05T12:15:17.343Z] Node Version:  v10.3.0
[2018-06-05T12:15:17.343Z] Time:          Tue Jun 05 2018 12:15:17 GMT+0000 (UTC)
[2018-06-05T12:15:17.343Z] ----------------------------------------------------------------------

[2018-06-05T12:15:17.347Z] > command requires scopes: ["email","openid","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase"]
[2018-06-05T12:15:17.348Z] > attempting to authenticate via app default credentials
[2018-06-05T12:15:17.352Z] ! auto-auth error: Scopes are required for this request.
[2018-06-05T12:15:17.352Z] > no credentials could be found or automatically retrieved

Error: Command requires authentication, please run firebase login

マイナーな手がかりは、アクセストークンが空であるということです(私は同じ問題を抱えています、私はJWTをデコードしました)

その形から暗示される
xxxx.x.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

中央のxはデータペイロードであり、サイズは1文字であるため、明らかに完全ではありません。

firebase-toolsはgoogle-auto-authを使用してトークンを取得するため、問題がある可能性があると思います。

おっと、新しいバージョン( 3.18.6 )はまだauthScopesautoAuth()に渡していないようです。 この行の前にログステートメントを追加した場合: https
authScopes: undefinedを取得します。

追加した場合

authScopes = [
  scopes.EMAIL,
  scopes.OPENID,
  scopes.CLOUD_PROJECTS_READONLY,
  scopes.FIREBASE_PLATFORM,
];

その行の前に、アクセストークンの取得に進みますが、 PROJECT_NOT_FOUND失敗します

また、 @ tomlarkworthy 、そのOAuthトークンはJWTではないため、中間部分を含めるべきではありません。 https://developers.google.com/apis-explorer/#search/oauth2/oauth2/v2/oauth2.tokeninfoで実行すると、 "scope": "https://www.googleapis.com/auth/cloudplatformprojects.readonly https://www.googleapis.com/auth/plus.me https://www.googleapis.com/auth/firebase https://www.googleapis.com/auth/userinfo.email",有効なトークンとして報告されます

ありがとう! OKだから、プロジェクトが見つからないというエラーが表示されます。 トークンをデコードすると、スコープは「 https://www.googleapis.com/auth/cloud-platform 」の1つだけになります。

「通常の」トークン(つまり、 firebase login介して取得したトークン)には違いがあります。

{
 "issued_to": "563584335869-fgrhgmd47bqnekij5i8b5pr03ho849e6.apps.googleusercontent.com",
 "audience": "563584335869-fgrhgmd47bqnekij5i8b5pr03ho849e6.apps.googleusercontent.com",
 "user_id": "xxxyyy",
 "scope": "https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/cloudplatformprojects.readonly https://www.googleapis.com/auth/firebase https://www.googleapis.com/auth/plus.me",
 "expires_in": 3484,
 "email": "[email protected]",
 "verified_email": true,
 "access_type": "offline"
}

およびサービスアカウント(SA)から生成されたもの:

{
 "issued_to": "1160xxxx",
 "audience": "1160xxxx",
 "user_id": "1160xxxx",
 "scope": "https://www.googleapis.com/auth/cloudplatformprojects.readonly https://www.googleapis.com/auth/plus.me https://www.googleapis.com/auth/firebase https://www.googleapis.com/auth/userinfo.email",
 "expires_in": 3563,
 "email": "[email protected]",
 "verified_email": true,
 "access_type": "offline"
}

したがって、トークンは右側のaudienceuser_idに発行されていないようです。これは、 https://github.com/firebase/firebase-tools/blob/376678fef91f71de5859f14d8374b2d8d2731980/からのものである必要があり

@tomlarkworthyはまだ奇妙ですが、適切なスコープを明示的に追加しない限り、私のauthScopeundefinedです。 これを実行する前にfirebase logoutか?

クライアントIDはoath2クライアントであり、私たちの手の届かないところに構成された非常に特定のドメインがあります。 および/またはローカルホストでのユーザー操作が必要です。 そのため、CIで承認を得るのは非常に困難です。

関数で実行しています。 私はあなたと同じエラーを持っていませんでした。 元のポスターのようにプロジェクトが見つかりませんでした。

サービスアカウントから独自のトークンを作成し、それを--tokenで渡すと、次のよう

HTTP RESPONSE 401varie = X-Origin、Origin、Accept-Encoding、www-authenticate = Bearer realm = " https://accounts.google.com/"、content-type = application / json; charset = UTF-8、date = Thu、07 Jun 2018 00:16:43 GMT、expires = Thu、07 Jun 2018 00:16:43 GMT、cache-control = private、max-age = 0、x-content- type-options = nosniff、x-frame-options = SAMEORIGIN、x-xss-protection = 1; mode = block、server = GSE、alt-svc = quic = ":443"; ma = 2592000; v = "43,42,41,39,35"、accept-ranges = none、connection = close
[2018-06-07T00:16:43.786Z] <<< HTTP RESPONSE BODY error = unauthorized_client、error_description = Unauthorized
[2018-06-07T00:16:43.791Z]>コマンドにはスコープが必要です:["email"、 "openid"、 "https://www.googleapis.com/auth/cloudplatformprojects.readonly"、 "https:// www .googleapis.com / auth / firebase "]
[2018-06-07T00:16:43.792Z]>-tokenオプションによる認証
[2018-06-07T00:16:43.792Z]>スコープを使用してアクセストークンを更新:["email"、 "openid"、 "https://www.googleapis.com/auth/cloudplatformprojects.readonly","https:/ /www.googleapis.com/auth/firebase "]
[2018-06-07T00:16:43.793Z] >>> HTTPリクエストPOSThttps: //www.googleapis.com/oauth2/v3/token
{refresh_token: 'ya29.c.XXXXXXXXXXXX'、
client_id: '563584335869-fgrhgmd47bqnekij5i8b5pr03ho849e6.apps.googleusercontent.com'、
client_secret: 'j9iVZfS8kkCEFUPaAeJV0sAi'、
grant_type: 'refresh_token'、
スコープ: 'email openid https://www.googleapis.com/auth/cloudplatformprojects.readonly https://www.googleapis.com/auth/firebase '}

この誓いのクライアントIDが邪魔になっていると思いますか?

@tomlarkworthyは必ずしも難しいとはclientId使用して構成をテストしています。

ああ、あなたはこれらの値を上書きすることができます:

https://github.com/firebase/firebase-tools/blob/376678fef91f71de5859f14d8374b2d8d2731980/lib/api.js

独自のoauthクライアントを使用してカスタムプロジェクトを作成し、firebase-toolsclient_idとsecret_idをオーバーライドしてみました。 次に、宣誓Webアプリケーション認証し、トークンをコピーして、firebase-toolsを呼び出すために使用しました。 わずかに異なるパスをたどり、トークンを正常に更新しますが、プロジェクトのリストを取得できません。 トークンデコーダーで、cloudplatformprojectsの読み取り専用スコープがあることを確認したので、それらを読み取ることができるはずでした。

情報:stderr:[2018-06-07T01:02:21.126Z]環境オーバーライド:FIREBASE_CLIENT_ID、FIREBASE_CLIENT_SECRET
[2018-06-07T01:02:21.126Z] -------------------------------------- --------------------------------

info:stderr:[2018-06-07T01:02:21.138Z]>コマンドにはスコープが必要です:["email"、 "openid"、 " https://www.googleapis.com/auth/cloudplatformprojects.readonly "、 " https ://www.googleapis.com/auth/firebase "、" https://www.googleapis.com/auth/cloud-platform "]

info:stderr:[2018-06-07T01:02:21.138Z]>-tokenオプションによる認証
[2018-06-07T01:02:21.140Z]>スコープを使用してアクセストークンを更新:["email"、 "openid"、 "https://www.googleapis.com/auth/cloudplatformprojects.readonly","https:/ /www.googleapis.com/auth/firebase "、" https://www.googleapis.com/auth/cloud-platform "]
[2018-06-07T01:02:21.140Z] >>> HTTPリクエストPOSThttps: //www.googleapis.com/oauth2/v3/token
{refresh_token: 'ya29.XXX'、
client_id: '278696186940-fbqtl733l62g4qj8aekr4i66cpo0k5c1.apps.googleusercontent.com'、
client_secret: 'XXXX'、
grant_type: 'refresh_token'、
スコープ: 'email openid https://www.googleapis.com/auth/cloudplatformprojects.readonly https://www.googleapis.com/auth/firebase https://www.googleapis.com/auth/cloud-platform '}
2018年6月6日水曜日18:02:21GMT-0700(PDT)

info:stderr:[2018-06-07T01:02:21.318Z] <<< HTTP RESPONSE 200 x-google-netmon-label = / bns / ph / borg / ph / bns / apiserving / prod_hightraffic_api_frontend.server / 998、x -google-gfe-backend-request-info = eid = HYQYW5jODYyytgbB3JfoAg、cache-control = no-cache、no-store、max-age = 0、must-revalidate、pragma = no-cache、expires = Mon、1990年1月1日00:00:00 GMT、日付= 2018年6月7日木曜日01:02:21GMT、vary = X-Origin、Origin、Accept-Encoding、x-google-session-info = GgIYBiAB、content-type = application / json ; charset = UTF-8、x-content-type-options = nosniff、x-frame-options = SAMEORIGIN、x-xss-protection = 1; mode = block、server = GSE、x-google-servertype = apiserving、x-google-gfe-request-trace = acsfoh11:443、phnm21-v6:9897、/ bns / ph / borg / ph / bns / apiserving / prod_hightraffic_api_frontend .server / 998、phnm21-v6:9897、acsfoh11:443、x-google-gslb-service = apiserving-hightraffic、x-google-backends = plbn61:9882、/ bns / ph / borg / ph / bns / apiserving / prod_hightraffic_api_frontend.server / 998、phnm21-v6:9897、/ bns / ph / borg / ph / bns / traffic-prod / shared-layer2-gfe / 495、acsfoh11:443、x-google-dos-service-trace = main :identity-o-auth-2-service-migrationmain:shared-layer2-gfe 、x-google-service = identity-o-auth-2-service-migration、restricted-shared-layer2-grpc-aggregate、x -google-gfe-response-code-details-trace = response_code_set_by_backend、response_code_set_by_backend、x-google-gfe-response-body-transformations = gunzipped、x-google-shellfish-status = CA0gBEBG、alt-svc = quic = ":443 "; ma = 2592000; v = "43,42,41,39,35"、x-google-gfe-service-trace = identity-o-auth-2-service-migration、restricted-shared-layer2-grpc-aggregate、accept-ranges =なし、connection = close

info:stderr:[2018-06-07T01:02:21.319Z] >>> HTTP REQUEST GET https://admin.firebase.com/v1/projects/docsite-go

2018年6月6日水曜日18:02:21GMT-0700(PDT)

info:stderr:[2018-06-07T01:02:21.652Z] <<< HTTP RESPONSE 404 server = nginx、date = Thu、07 Jun 2018 01:02:21 GMT、content-type = application / json; charset = utf-8、content-length = 87、connection = close、x-content-type-options = nosniff

info:stderr:[2018-06-07T01:02:21.652Z] <<< HTTP RESPONSE BODY code = PROJECT_NOT_FOUND、message =指定されたプロジェクトが見つかりませんでした。

@tomlarkworthyがclient_idとsecretをカスタム値でオーバーライドしても機能しません。これは、Firebaseが現在、顧客プロジェクトとは別の事前定義されたクライアントを使用しているためです(少なくとも私の理解では)。

さらに、 --tokenオプションは更新トークンのみをサポートします。これは、サービスアカウントを持っている場合は取得できません(私が理解している限り)。

可能であれば、このクライアントIDを使用してSAアクセストークンを生成する簡単な方法を見つける必要があります。

https://developers.google.com/identity/protocols/OAuth2ServiceAccount#jwt -authで説明されているように、代替ルートに移動して、OAuthトークンの代わりにクライアントJWTを使用してFirebaseAPIを呼び出すことができる場合があり

stephenplusplus / google-auto-authによって内部的に使用されるgoogle / google-auth-library-nodejsは、これを行うためのより便利で安全な方法を提供します。

進歩できるとは思いません。

https://github.com/firebase/firebase-tools/issues/647#issuecomment -361926336は以前に成功を報告したようですが、確認されているかどうかはわかりません。 問題のFirebaseAPI(https://admin.firebase.com/v1/projects)はプライベートであり、そのクライアントID用に生成されたトークンのみを受け入れるようです。

おそらく、これは機能リクエストとして提出する必要があります-デプロイにサービスアカウントを使用する機能があると、単一のクレデンシャルを使用して(そして任意のユーザーから切り離して)FirebaseとGCPリソースの両方をデプロイできるようになります。

CLIの--tokenオプションは、アクセストークンではなく、更新トークンを渡すことを目的としています。 これは、 firebase login:ciから生成されるものです。

サービスアカウントの承認を広範囲にテストしていませんが、 admin.firebase.comバックエンドで広範な許可を必要とするIAMチェックが行われている可能性があると思われます。 さらに調査することはできますが、ここで超高速の解決を期待する必要はありません。

CLIの--tokenオプションは、更新トークンを渡すことを目的としています

うん、上記のように理解されています。

SAキーを使用してCI環境からデプロイするのは素晴らしいことです。 更新トークンは特定のユーザーに関連付けられており、他のGCPサービスを管理するためのgcloudコマンドを認証するためにそれを使用する方法が明確ではありません。 現在、両方のタイプの認証情報を提供する必要があります(Firebase CLIの管理者ユーザーの更新トークンとgcloud SAキー)。

サービスアカウント用に生成されたトークンを使用して、 FIREBASE_TOKEN='<token_here>' firebase deploy --only firestore,storage (他のターゲットを試したことがないので、機能する可能性があります)できます。

実際のトークンは、「 https://www.googleapis.com/auth/cloud-platform 」スコープを持つVaultのGCPシークレットエンジンによってサービスアカウント用に生成されました。

最新のfirebasecliでSAキー+ GOOGLE_APPLICATION_CREDENTIALSを使用することは不可能であることを確認しました。コマンドは、次のように終了します。

root<strong i="6">@frontend</strong>:/usr/src/app$ firebase list

Error: HTTP Error: 404, The specified project was not found.

Having trouble? Try firebase list --help

興味深い@ cpick 、vaultがサービスアカウントのoauthトークンを生成する方法を知っていますか?

@paolomainardi firebase listは、レガシープロジェクトリストの実装に依存しているため、SAキーでは機能しません。 ただし、他のほとんどすべてのことを行う必要があります(ただし、最初にいくつかのAPIを有効にする必要がある場合があります)。 別のコマンドを試してみることをお勧めします。

私たちは、いくつかの優れたユースケースのロックを解除すると考えているため、たくさんのフープを飛び越えることなく、 GOOGLE_APPLICATION_CREDENTIALS完全なサポートを取得するよう取り組んでいます。

@paolomainardiと思うvault実装をされ、ここで(そのコードを迅速に検索した後だけで推測だという)。

また、それはgcloud alpha iam service-accounts sign-jwtと同じことだと思います(繰り返しになりますが、ある程度知識に基づいた推測です)。

どうもありがとう

私はこれを簡単に見て、テストとしてサービスアカウントのクレデンシャルとaccess_tokenrequireAuth.jsに強制的に入れようとしました
少なくとも何かが機能するのを見ようとして。

cliは常にhttps://admin.firebase.com/v1/projects/に接続しようとしているようです( --debugフラグを使用して意味することができます。この号の前のコメントを読んだ場合、それはおそらく 'レガシーです'svcアカウントで機能しないAPIエンドポイント'。

単純なGET呼び出しを使用して他のいくつかのエンドポイントをテストしましたが、問題ないようです。

参考のために


  • ワイドスコープのsvc_accountsアクセストークンを返すテストのためだけにrequireAuth.jsハードコードされた変更を加えました
function getServiceAccountClient() {
  const credFile = '/path/to/cert.json';
  const keys = require(credFile);
  let client = new JWT(
    keys.client_email,
    null,
    keys.private_key,
    ["email","openid","https://www.googleapis.com/auth/cloud-platform", "https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase"],
  );
  return client;
};

function _autoAuth(options, authScopes) {
  return new Promise(function(resolve, reject) {
    var client = getServiceAccountClient();
    client.getAccessToken().then(res => {
      console.log(res);
     api.setAccessToken(res.token);
     resolve();

    }).catch(function (error) {
      console.error('Unable to recall targetClient access_token ' + error);
    });    

    /*
        logger.debug("> attempting to authenticate via app default credentials");
 ......

  • ジェネリッククライアント
const {JWT} = require('google-auth-library');

function getServiceAccountClient() {
    const credFile = '/path/to/cert.json';
    const keys = require(credFile);

    let client = new JWT(
      keys.client_email,
      null,
      keys.private_key,
      ["email","openid","https://www.googleapis.com/auth/cloud-platform", "https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase"],
    );
    return client;
  };

  var client = getServiceAccountClient();
    let project_id = 'your_project';
    let url = 'https://admin.firebase.com/v1/projects/' + project_id
    //let url = "https://firestore.googleapis.com/v1beta1/projects/" + project_id + "/databases/(default)/indexes"
    //let url = "https://firebaserules.googleapis.com/v1/projects/" + project_id  + "/rulesets" 

    client.requestAsync({url}).then(resp => {
      console.log(resp.data);
    }).catch(function (error) {
      console.error('Unable to list buckets: ' + error);
    }); 

この要点示されているようにfirestorestorage 、およびhostingデプロイできます。
すでにそこにあったADC ..>

以下は基本的にハックであり、 functionsデプロイメントでは機能しないため不完全です。 上記のmbleighが「ファーストクラスのサポート」について言及した完全なソリューションは、待つ価値があります。


とにかく、私はそれを次のように確認しました:

gcloudコンテキストでもあるFirebaseアカウントから始めます

  1. サービスアカウントの秘密鍵を取得する
$ gcloud iam service-accounts list
NAME                                EMAIL
App Engine default service account  [email protected]
firebase-adminsdk                   firebase-adminsdk-h2v8k@firebase-auth-sal.iam.gserviceaccount.com

gcloud iam service-accounts keys  create `pwd`/svc.json --iam-account=firebase-adminsdk-h2v8k@firebase-auth-sal.iam.gserviceaccount.com
  1. そのプロジェクトにOWNERとしてサービスアカウントを追加します

  2. クラウドコンソールに移動し、いくつかのAPIを有効にします。

https://console.developers.google.com/apis/api/cloudresourcemanager.googleapis.com/overview?project=<your_project>

https://console.developers.google.com/apis/api/firebasehosting.googleapis.com/overview?project=<your_project>
  1. ローカルクレデンシャルを削除する

gcloudfirebase両方

$ firebase logout
✔  Logged out from [email protected]

$ mv ~/.config/gcloud ~/.config/gcloud_backup
  1. ADC env-varを設定してデプロイします
export GOOGLE_APPLICATION_CREDENTIALS=`pwd`/svc.json

$ firebase deploy -P firebase-auth-sal --only firestore,hosting,storage 
{ token: 'ya29.c.EmJ8B....',  res: null }

=== Deploying to 'firebase-auth-sal'...

i  deploying storage, firestore, hosting
i  storage: checking storage.rules for compilation errors...
✔  storage: rules file storage.rules compiled successfully
i  firestore: checking firestore.rules for compilation errors...
i  firestore: reading indexes from firestore.indexes.json...
✔  firestore: rules file firestore.rules compiled successfully
i  storage: uploading rules storage.rules...
i  firestore: uploading rules firestore.rules...
✔  firestore: deployed indexes in firestore.indexes.json successfully
i  hosting[fir-auth-sal]: beginning deploy...
i  hosting[fir-auth-sal]: found 1 files in public
✔  hosting[fir-auth-sal]: file upload complete
✔  storage: released rules storage.rules to firebase.storage/firebase-auth-sal.appspot.com
✔  firestore: released rules firestore.rules to cloud.firestore
i  hosting[fir-auth-sal]: finalizing version...
✔  hosting[fir-auth-sal]: version finalized
i  hosting[fir-auth-sal]: releasing new version...
✔  hosting[fir-auth-sal]: release complete

✔  Deploy complete!

Project Console: https://console.firebase.google.com/project/firebase-auth-sal/overview
Hosting URL: https://fir-auth-sal.firebaseapp.com
  1. 展開の確認

deployment_hosting

  1. functions展開を試みます

functionsデプロイメントタイプは、以下の有効化チェックをオーバーライドしようとしても機能しません(他のmobilesdk.googleapis.comエンドポイントへのアクセスで停止します。Firebase関数のデプロイメントがclient_id関連付けられている可能性がありますFirebase関数の

$ firebase deploy -P firebase-auth-sal --only functions --debug

[2018-12-24T01:36:44.034Z] >>> HTTP REQUEST GET https://servicemanagement.googleapis.com/v1/services/cloudfunctions.googleapis.com/projectSettings/firebase-auth-sal?view=CONSUMER_VIEW  

[2018-12-24T01:36:44.034Z] >>> HTTP REQUEST GET https://servicemanagement.googleapis.com/v1/services/runtimeconfig.googleapis.com/projectSettings/firebase-auth-sal?view=CONSUMER_VIEW  

[2018-12-24T01:36:44.486Z] <<< HTTP RESPONSE 404 vary=X-Origin, Referer, Origin,Accept-Encoding, content-type=application/json; charset=UTF-8, date=Mon, 24 Dec 2018 01:36:44 GMT, server=ESF, cache-control=private, x-xss-protection=1; mode=block, x-frame-options=SAMEORIGIN, x-content-type-options=nosniff, alt-svc=quic=":443"; ma=2592000; v="44,43,39,35", accept-ranges=none, connection=close
[2018-12-24T01:36:44.486Z] <<< HTTP RESPONSE BODY code=404, message=Method not found., status=NOT_FOUND

Error: HTTP Error: 404, Method not found.
[2018-12-24T01:36:44.495Z] Error Context: {
  "body": {
    "error": {
      "code": 404,
      "message": "Method not found.",
      "status": "NOT_FOUND"

内部バグリファレンス:122552119

この問題に関する更新はありますか@tinaliang ? 認証のためのサービスアカウントのサポートは優先度が高いはずだと思います。

現時点では更新はありません...

昨日からの私の発見は、特にFirebase Cloud関数は必要ないので、期待どおりに機能するGCP Cloud関数https://cloud.google.com/functions/を使用できることです(デプロイはgcloud CLIを介して行われます)。これは実際の回避策ではありません...しかし、誰かにとって役立つかもしれません:)

#1175で複製

更新はまだありますか? CloudBuildを介してFirebaseアプリをデプロイしようとしました。 hostingなどは正しく機能し、展開されているようです。 functionsが正しくデプロイされず、上記のように、IAM内で適切に構成された404を取得します。 (サービスアカウントcloudbuildは、「FirebaseAdmin」と「APIKeysAdmin」の権限があります。)このチケットの優先度は高い必要があります🔥

まだ更新はありませんが、すぐに確認したいと思っています。

@mbleigh更新はありますか? 現在、firebase CLIはサービスアカウントを使用してデプロイできないことを確認していますか? CIツールに必要です。 だからGOOGLE_APPLICATION_CREDENTIALSサポートは機能しませんか?

前述のように、すべてのfirebase CLIコマンドがGOOGLE_APPLICATION_CREDENTIALSで機能するわけではありませんが、適切な数で機能するはずです。 サービスアカウントのクレデンシャルのパスに設定するだけで十分です(実際、 test-hosting.shスクリプトはこれを実行します)。

firebase login:ci使用すると、CIシステムでトークンなります。

GOOGLE_APPLICATION_CREDENTIALSの使用法と機能を形式化することは私たちの頭の中にありますが、そのタイムラインを確約することはできません。 お待ち頂きまして、ありがとうございます。

明確にできますか?この場合、インスタンスメタデータADCは機能しますか、それともGOOGLE_APPLICATION_CREDENTIALSますか?

このスレッドの誰でも:冒険心があれば、#1463のブランチを試してみて、サービスアカウント認証で探していることができるかどうかを確認してください。 私たちは問題の大部分を支えたかもしれないと思いますが、私はそのようなもののいくつかの外部テストをしたいと思います。

@mbleigh firebase apps:list webは、 CloudBuildの半分の時間で断続的に失敗します。 デバッグを使用して実行しても、失敗の理由に関する情報は得られません。 何が起こっているのかについて何か考えはありますか?

[2020-02-13T21:25:55.987Z] ----------------------------------------------------------------------
[2020-02-13T21:25:55.991Z] Command:       /usr/local/bin/node /workspace/node_modules/.bin/firebase apps:list web -j --project=projectName --debug
[2020-02-13T21:25:55.991Z] CLI Version:   7.12.1
[2020-02-13T21:25:55.991Z] Platform:      linux
[2020-02-13T21:25:55.991Z] Node Version:  v10.18.0
[2020-02-13T21:25:55.992Z] Time:          Thu Feb 13 2020 21:25:55 GMT+0000 (Coordinated Universal Time)
[2020-02-13T21:25:55.992Z] ----------------------------------------------------------------------

また、 @ mbleigh firebase use projectNameコマンドも、メタデータサーバーから適切な資格情報を取得できないため、断続的に失敗します。

[2020-02-13T21:49:41.050Z] ----------------------------------------------------------------------
[2020-02-13T21:49:41.055Z] Command:       /usr/bin/node /directory/node_modules/.bin/firebase --debug use projectName
[2020-02-13T21:49:41.056Z] CLI Version:   7.12.1
[2020-02-13T21:49:41.056Z] Platform:      linux
[2020-02-13T21:49:41.056Z] Node Version:  v10.16.3
[2020-02-13T21:49:41.056Z] Time:          Thu Feb 13 2020 21:49:41 GMT+0000 (Coordinated Universal Time)
[2020-02-13T21:49:41.056Z] ----------------------------------------------------------------------
[2020-02-13T21:49:41.057Z] 
[2020-02-13T21:49:41.073Z] > command requires scopes: ["email","openid","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","https://www.googleapis.com/auth/cloud-platform"]
[2020-02-13T21:49:41.073Z] > attempting to authenticate via app default credentials
[2020-02-13T21:49:41.669Z] TypeError: Cannot create property 'refresh_token' on string 'Not Found
'
    at /directory/node_modules/google-auto-auth/node_modules/google-auth-library/lib/auth/oauth2client.js:208:28
    at /directory/node_modules/google-auto-auth/node_modules/google-auth-library/lib/auth/computeclient.js:85:7
    at Request._callback (/directory/node_modules/google-auto-auth/node_modules/google-auth-library/lib/transporters.js:106:7)
    at Request.self.callback (/directory/node_modules/request/request.js:185:22)
    at Request.emit (events.js:198:13)
    at Request.EventEmitter.emit (domain.js:448:20)
    at Request.<anonymous> (/directory/node_modules/request/request.js:1161:10)
    at Request.emit (events.js:198:13)
    at Request.EventEmitter.emit (domain.js:448:20)
    at IncomingMessage.<anonymous> (/directory/node_modules/request/request.js:1083:12)
    at Object.onceWrapper (events.js:286:20)
    at IncomingMessage.emit (events.js:203:15)
    at IncomingMessage.EventEmitter.emit (domain.js:448:20)
    at endReadableNT (_stream_readable.js:1145:12)
    at process._tickCallback (internal/process/next_tick.js:63:19)

10/02/20の時点で、サービスアカウントを使用しているときに、cloudbuildを使用してFirebaseホスティングにデプロイすると、断続的な障害が発生し始めました。 それ以前は一貫して問題はありませんでしたが、今では失敗することが多いようです。 これを正常に実行するために、サービスアカウントに委任する必要のある新しいアクセス許可のセットがあるかどうか疑問に思い始めています。 私の展開のほとんどが単に失敗するので、それは少し問題になりました😞

以下は、ビルドの例と、ビルドが突然失敗し始めたときのスクリーンショットです。

image

デバッグエラーは、上記のコメントと非常によく似ています。

[2020-02-16T07:30:46.905Z] ----------------------------------------------------------------------
[2020-02-16T07:30:46.908Z] Command:       /usr/local/bin/node /home/node/.npm-global/bin/firebase deploy --only hosting -P project-production --debug
[2020-02-16T07:30:46.908Z] CLI Version:   7.8.1
[2020-02-16T07:30:46.908Z] Platform:      linux
[2020-02-16T07:30:46.909Z] Node Version:  v12.13.1
[2020-02-16T07:30:46.909Z] Time:          Sun Feb 16 2020 07:30:46 GMT+0000 (Coordinated Universal Time)
[2020-02-16T07:30:46.910Z] ----------------------------------------------------------------------
[2020-02-16T07:30:46.910Z] 
[2020-02-16T07:30:46.920Z] > command requires scopes: ["email","openid","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","https://www.googleapis.com/auth/cloud-platform"]
[2020-02-16T07:30:46.920Z] > attempting to authenticate via app default credentials
[2020-02-16T07:30:47.023Z] TypeError: Cannot create property 'refresh_token' on string 'Not Found
'
    at /home/node/.npm-global/lib/node_modules/firebase-tools/node_modules/google-auto-auth/node_modules/google-auth-library/lib/auth/oauth2client.js:208:28
    at /home/node/.npm-global/lib/node_modules/firebase-tools/node_modules/google-auto-auth/node_modules/google-auth-library/lib/auth/computeclient.js:85:7
    at Request._callback (/home/node/.npm-global/lib/node_modules/firebase-tools/node_modules/google-auto-auth/node_modules/google-auth-library/lib/transporters.js:106:7)
    at Request.self.callback (/home/node/.npm-global/lib/node_modules/firebase-tools/node_modules/request/request.js:185:22)
    at Request.emit (events.js:210:5)
    at Request.EventEmitter.emit (domain.js:475:20)
    at Request.<anonymous> (/home/node/.npm-global/lib/node_modules/firebase-tools/node_modules/request/request.js:1161:10)
    at Request.emit (events.js:210:5)
    at Request.EventEmitter.emit (domain.js:475:20)
    at IncomingMessage.<anonymous> (/home/node/.npm-global/lib/node_modules/firebase-tools/node_modules/request/request.js:1083:12)
    at Object.onceWrapper (events.js:299:28)
    at IncomingMessage.emit (events.js:215:7)
    at IncomingMessage.EventEmitter.emit (domain.js:475:20)
    at endReadableNT (_stream_readable.js:1184:12)
    at processTicksAndRejections (internal/process/task_queues.js:80:21)

Error: An unexpected error has occurred.

これはhttps://github.com/firebase/firebase-tools/issues/1970に関連しているようです(つまり、古いgcloud Authで引き続き使用されている古いv1beta1インスタンスメタデータエンドポイントの非推奨Firebase CLIで使用されるライブラリ..)

このページは役に立ちましたか?
0 / 5 - 0 評価