Firebase-tools: خطأ مصادقة ADC: النطاقات مطلوبة لهذا الطلب

تم إنشاؤها على ٢٩ مايو ٢٠١٨  ·  46تعليقات  ·  مصدر: firebase/firebase-tools

مرحبًا ، أحاول أتمتة نشر وظائف Firebase. عندما أشغل شيئًا مثل "GOOGLE_APPLICATION_CREDENTIALS =استخدام Firebase- non-Interactive --debug "لدي الخطأ التالي أدناه

معلومات الإصدار

3.18.5

معلومات المنصة

عقدة الحاوية

خطوات التكاثر

/ usr / bin / docker run --rm -v / workspace: / workspace -e GOOGLE_APPLICATION_CREDENTIALS =العقدة: 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 تستخدم مصادقة google التلقائية للحصول على ذلك.

او انا مخطئ؟

لن أستخدم رمز CI المميز لأنني أرغب في المصادقة باستخدام حساب خدمة وليس مستخدم Google (GSuite أو Cloud Identity أو أي شيء آخر)

شكرا لك

أهلا،
يبدو أن المكتبة تجري مكالمة إلى firebase-public.firebaseio. com: 443 ويحتوي على كود إرجاع HTTP يبلغ 200 ولكن استجابة من 0 بايت

مرحبًا ، أنت على حق. آسف ، لقد نسيت ذلك العلاقات العامة. أنا لست على دراية بهذا الأمر. مايكل ، هل يمكنك إلقاء نظرة عندما تعود إلى المكتب؟

مرحباlaurenzlongmbleigh،
لقد وجدت أن تكوين "المجال واسع النطاق" للسماح لحساب الخدمة للمصادقة.
لكن الآن لدي المشكلة التالية:

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 (وليس حساب 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

نفس السلوك حتى مع حساب الخدمة الذي يحتوي على الدور Owner المعين لمحاولة القيام بأي شيء باستخدام أداة CLI firebase :

$ 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-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

الوسط x هو حمولة البيانات ويبلغ حجمه حرفًا واحدًا ، لذا من الواضح أنه ليس ممتلئًا جدًا.

تستخدم أدوات Firebase-auto-auth للحصول على رمز مميز لذا أعتقد أن المشكلة قد تكون موجودة.

عفوًا ، لا يبدو أن الإصدار الجديد ( 3.18.6 ) يتجاوز authScopes إلى autoAuth() . إذا أضفت بيان سجل قبل هذا السطر: https://github.com/firebase/firebase-tools/blob/b2594467d8980c5a1e2b8c4aff3de9877a98b42b/lib/requireAuth.js#L21
أحصل على 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",

شكرا! موافق لذلك عندما أحصل على المشروع لم يتم العثور على خطأ. عندما أقوم بفك تشفير الرمز المميز ، يكون لدي نطاق واحد فقط " https://www.googleapis.com/auth/cloud-platform ".

هناك فرق بين "العادي" رمزي (أي واحد المكتسبة من خلال 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"
}

لذلك يبدو أن الرمز المميز لم يتم إصداره إلى اليمين audience و user_id ، والذي يجب أن يكون من https://github.com/firebase/firebase-tools/blob/376678fef91f71de5859f14d8374b2d8d2731980/ lib / api.js # L84

tomlarkworthy لا يزال غريبًا ، authScope هو undefined إلا إذا أضفت النطاقات الصحيحة صراحةً. هل كنت firebase logout قبل تشغيل هذا؟

حسنًا ، معرّف العميل هذا هو عميل oath2 ، الذي يحتوي على نطاقات محددة جدًا يمكنه العمل على تهيئتها بعيدًا عن متناولنا. و / أو يتطلب تفاعل المستخدم على المضيف المحلي. لذلك من الصعب جدًا الحصول على إذن في CI.

أنا أقوم بتشغيل خاصتي على وظيفة. لم يكن لدي نفس الخطأ مثلك. لم يتم العثور على مشروع مثل الملصق الأصلي.

إذا قمت بإنشاء رمز مميز خاص بي من حساب الخدمة وقمت بتمريره باستخدام --token ، فسأحصل على: -

تختلف استجابة HTTP 401 = 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 ؛ الوضع = كتلة ، الخادم = GSE ، alt-svc = quic = ": 443" ؛ أماه = 2592000 ؛ v = "43،42،41،39،35" ، نطاقات القبول = لا شيء ، الاتصال = إغلاق
[2018-06-07T00: 16: 43.786Z] <<< خطأ جسم استجابة HTTP = unauthorized_client، error_description = غير مصرح به
[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 https://www.googleapis.com/oauth2/v3/token
{Refresh_token: 'ya29.c.XXXXXXXXXXXX' ،
client_id: "563584335869-fgrhgmd47bqnekij5i8b5pr03ho849e6.apps.googleusercontent.com" ،
client_secret: "j9iVZfS8kkCEFUPaAeJV0sAi" ،
نوع_منحة: "Refresh_token"،
النطاق: "بريد إلكتروني مفتوح https://www.googleapis.com/auth/cloudplatformprojects.readonly https://www.googleapis.com/auth/firebase "}

أعتقد أن معرف عميل القسم هذا يعيق الطريق؟

tomlarkworthy ليس بالضرورة صعبًا - أنا أختبر التكوين باستخدام clientId الآن.

حاولت إنشاء مشروع مخصص مع عميل oauth الخاص به وتجاوز client_id و secret_id لأدوات firebase. ثم قمت بتكوين تطبيق الويب oath تلقائيًا ، ونسخ الرمز المميز واستخدمته لاستدعاء أدوات Firebase. يسير في مسار مختلف قليلاً ويقوم بتحديث الرمز المميز بنجاح ولكنه يفشل بعد ذلك في الحصول على قائمة المشاريع. لقد أكدت في وحدة فك الرموز المميزة أن لديها نطاق مشاريع cloudplatforms للقراءة فقط لذا كان يجب أن تكون قادرة على قراءتها.

info: stderr: [2018-06-07T01: 02: 21.126Z] تجاوزات Env: 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 https://www.googleapis.com/oauth2/v3/token
{Refresh_token: 'ya29.XXX'،
client_id: "278696186940-fbqtl733l62g4qj8aekr4i66cpo0k5c1.apps.googleusercontent.com" ،
client_secret: "XXXX" ،
نوع_منحة: "Refresh_token"،
النطاق: "بريد إلكتروني مفتوح https://www.googleapis.com/auth/cloudplatformprojects.readonly https://www.googleapis.com/auth/firebase https://www.googleapis.com/auth/cloud-platform "}
الأربعاء 06 حزيران (يونيو) 2018 ، الساعة 18:02:21 بتوقيت غرينتش -0700 (توقيت المحيط الهادي الصيفي)

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، 01 Jan 1990 00:00:00 GMT، date = Thu، 07 Jun 2018 01:02:21 GMT، تختلف = 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 ؛ الوضع = 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 : هوية-o-auth-2-service -igration ،

info: stderr: [2018-06-07T01: 02: 21.319Z] >>> طلب HTTP احصل على https://admin.firebase.com/v1/projects/docsite-go

الأربعاء 06 حزيران (يونيو) 2018 ، الساعة 18:02:21 بتوقيت غرينتش -0700 (توقيت المحيط الهادي الصيفي)

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 = PROJECT_NOT_FOUND ، message = لم يتم العثور على المشروع المحدد.

tomlarkworthy لن ينجح تجاوز client_id و secret بقيم مخصصة ، لأن Firebase يستخدم حاليًا عميلًا محددًا مسبقًا منفصل عن أي من مشاريع العملاء (على الأقل هذا ما أفهمه).

بالإضافة إلى ذلك ، فإن خيار --token يدعم فقط رمز التحديث ، والذي لا تحصل عليه إذا كان لديك حساب خدمة (مرة أخرى ، على حد علمي).

نحتاج إلى إيجاد طريقة بسيطة لإنشاء رمز وصول SA باستخدام معرّف العميل هذا ، إن أمكن.

قد يكون من الممكن الانتقال إلى مسار بديل والاتصال بواجهات Firebase API مع عميل JWT بدلاً من رمز OAuth المميز ، كما هو موضح هنا: https://developers.google.com/identity/protocols/OAuth2ServiceAccount#jwt -auth

يوفر google / google-auth-library-nodejs ، والذي يتم استخدامه داخليًا بواسطة stephenplusplus / google-auto-auth ، طريقة أكثر ملاءمة / أمانًا للقيام بذلك.

لا أعتقد أنه يمكننا إحراز تقدم.

يبدو أن https://github.com/firebase/firebase-tools/issues/647#issuecomment -361926336 قد أبلغ عن النجاح سابقًا ، وإن لم تكن متأكدًا مما إذا كان ذلك مؤكدًا. يبدو أن واجهة Firebase API المعنية (https://admin.firebase.com/v1/projects) خاصة ، ولا تقبل سوى الرموز المميزة التي تم إنشاؤها لمعرف العميل هذا.

ربما يجب تقديم هذا كطلب ميزة - فامتلاك القدرة على استخدام حساب خدمة للنشر سيمكن استخدام بيانات اعتماد واحدة (وغير مقترنة من أي مستخدم) لنشر كل من موارد Firebase و GCP.

يُقصد من الخيار --token في CLI تمرير رمز تحديث ، وليس رمز وصول. إنه الشخص الذي يتم إنشاؤه من firebase login:ci .

لم أختبر تفويض حساب الخدمة على نطاق واسع ، لكنني أشك في أنه قد يكون هناك فحص IAM يتطلب إذنًا واسعًا يحدث في الواجهة الخلفية admin.firebase.com . يمكننا إجراء مزيد من التحقيق ، لكنني لا أتوقع بالضرورة دقة فائقة هنا.

يُقصد من الخيار --token في CLI تمرير رمز تحديث مميز

نعم ، كما هو مذكور أعلاه.

سيكون من الرائع استخدام مفتاح SA للنشر من بيئات CI. يرتبط رمز التحديث بمستخدم معين ، وليس من الواضح كيفية استخدامه لمصادقة أوامر gcloud لإدارة خدمات GCP الأخرى. حاليًا ، يتعين علينا توفير كلا النوعين من بيانات الاعتماد (رمز تحديث المستخدم الإداري لـ Firebase CLI ، ومفتاح SA لـ gcloud ).

أنا قادر على FIREBASE_TOKEN='<token_here>' firebase deploy --only firestore,storage (لم أجرب أهدافًا أخرى ، من الممكن أن تعمل) باستخدام رمز مميز تم إنشاؤه لحساب خدمة.

تم إنشاء الرمز المميز الفعلي لحساب خدمة بواسطة محرك GCP Secrets الخاص بـ Vault بنطاق " https://www.googleapis.com/auth/cloud-platform ".

أؤكد أنه من المستحيل استخدام مفتاح SA + GOOGLE_APPLICATION_CREDENTIALS ، مع أحدث cli لـ firebase ، تخرج أي أوامر مع:

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 لأنه يعتمد على تنفيذ قائمة مشروع قديم. ومع ذلك ، يجب القيام بكل شيء آخر (على الرغم من أنك قد تحتاج إلى تمكين بعض واجهات برمجة التطبيقات أولاً). أوصي بتجربة أمر آخر وانظر.

نحن نعمل على الحصول على دعم كامل لـ GOOGLE_APPLICATION_CREDENTIALS دون القفز عبر مجموعة من الحلقات لأننا نعتقد أنه يفتح بعض حالات الاستخدام الرائعة.

paolomainardi أعتقد أن تنفيذ vault موجود هنا (هذا مجرد تخمين بعد بحث سريع من خلال الكود الخاص به).

أعتقد أيضًا gcloud alpha iam service-accounts sign-jwt (مرة أخرى ، تخمين متعلم إلى حد ما).

شكرًا جزيلاً cpick ،

ألقيت نظرة سريعة على هذا ، وكاختبار حاولت فرض بيانات اعتماد حساب الخدمة و access_token في requiredAuth.js
في محاولة لرؤية شيء ما يعمل على الأقل.

يبدو أن cli يحاول دائمًا الاتصال بـ https://admin.firebase.com/v1/projects/ مهما كان الأمر (يمكنك ما أعنيه بعلامة --debug . إذا قرأت في التعليق السابق في هذه المشكلة ، فربما يكون "الإرث" نقطة نهاية API التي لا تعمل مع حسابات svc.

لقد اختبرت بعض نقاط النهاية الأخرى باستخدام مكالمات بسيطة GET ويبدو أنها لا بأس بها:

للمرجع


  • التعديل المرمز الذي أجريته على requireAuth.js فقط للاختبار الذي سيعيد رمز وصول svc_accounts مع نطاقات واسعة
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);
    }); 

أنا قادرة على نشر أخيرا باستخدام حساب خدمة ل firestore ، storage و hosting بعد إجراء تعديل على requireAuth.js كما showin في هذا جوهر
ADC التي كانت موجودة بالفعل ..>

ما يلي هو في الأساس اختراق وغير مكتمل لأنه لا يعمل مع نشر functions . الحل الكامل الذي ذكره mbleigh أعلاه لـ "دعم من الدرجة الأولى" يستحق الانتظار.


على أي حال ، لقد تحققت من ذلك على النحو التالي:

ابدأ بحساب firebase الموجود أيضًا في السياق مع gcloud

  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. انتقل إلى وحدة التحكم السحابية وقم بتمكين بعض واجهات برمجة التطبيقات:

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. قم بإزالة بيانات الاعتماد المحلية

لكل من gcloud و firebase

$ firebase logout
✔  Logged out from [email protected]

$ mv ~/.config/gcloud ~/.config/gcloud_backup
  1. قم بتعيين env-var ADC ونشر
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 أو بطريقة ما يتطلب 3LO .... لكن هذا كل شيء

$ 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

هل هناك أي تحديثات حتى الآن؟ حاولت نشر تطبيق Firebase عبر Cloud Build. hosting وما إلى ذلك يعمل وينتشر بشكل صحيح. لن يتم نشر functions بشكل صحيح وأحصل على 404 ، كما هو موضح أعلاه ، مع التكوين المناسب داخل IAM. (حساب الخدمة cloudbuild له حقوق لـ "Firebase Admin" و "API Keys Admin".) يجب أن يكون لهذه البطاقة أولوية عالية 🔥

لا توجد تحديثات بعد ، لكننا نأمل أن نلقي نظرة عليها قريبًا.

mbleigh أي تحديث؟ التأكيد اعتبارًا من الآن لا يمكن لـ firebase CLI استخدام حساب خدمة للنشر؟ نريدها لأداة CI. إذن ، هل دعم GOOGLE_APPLICATION_CREDENTIALS لا يعمل؟

كما ذكرنا سابقًا ، لن تعمل جميع أوامر CLI firebase مع GOOGLE_APPLICATION_CREDENTIALS ، لكن يجب أن يعمل العدد الجيد. يجب أن يكون تعيينه على مسار بيانات اعتماد حساب الخدمة هو كل ما عليك القيام به (في الواقع ، هذا ما يفعله البرنامج النصي test-hosting.sh ، من بين أشياء أخرى).

باستخدام firebase login:ci يجب أن تكون قادرًا على استخدام رمز مميز في نظام CI الخاص بك

إن إضفاء الطابع الرسمي على استخدام وإمكانيات GOOGLE_APPLICATION_CREDENTIALS في أذهاننا ، لكن لا يمكننا الالتزام بجدول زمني عليه. شكرا لصبرك.

هل يمكن أن توضح - هل تعمل البيانات الوصفية للمثيل ADC في هذه الحالة ، أم فقط GOOGLE_APPLICATION_CREDENTIALS ؟

أي شخص في هذا الموضوع: إذا كنت تشعر بالمغامرة ، فأنا أحب أن تجرب الفرع على # 1463 ومعرفة ما إذا كان يتيح لك القيام بالأشياء التي تتطلع إلى القيام بها باستخدام مصادقة حساب الخدمة. أعتقد أننا ربما نكون قد دعمنا غالبية القضايا ، لكني أرغب في إجراء بعض الاختبارات الخارجية لمثل هذه الأمور.

mbleigh firebase apps:list web سيفشل بشكل متقطع نصف الوقت في Cloud Build. لا يعطينا التشغيل مع التصحيح أي معلومات عن سبب الفشل. أي أفكار حول ما يمكن أن يكون عليه الحال؟

[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 (أي إهمال نقاط نهاية بيانات المثيل القديمة v1beta1 ، والتي لا تزال مستخدمة من قبل مصادقة gcloud القديمة مكتبة يستخدمها Firebase CLI ..)

هل كانت هذه الصفحة مفيدة؟
0 / 5 - 0 التقييمات