Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Firebase CLOUD\u SDK\u凭据\u警告我们建议大多数服务器应用程序改用服务帐户_Firebase_Google Cloud Platform_Google Cloud Firestore_Gcloud_Google Cloud Monitoring - Fatal编程技术网

Firebase CLOUD\u SDK\u凭据\u警告我们建议大多数服务器应用程序改用服务帐户

Firebase CLOUD\u SDK\u凭据\u警告我们建议大多数服务器应用程序改用服务帐户,firebase,google-cloud-platform,google-cloud-firestore,gcloud,google-cloud-monitoring,Firebase,Google Cloud Platform,Google Cloud Firestore,Gcloud,Google Cloud Monitoring,上下文:我刚刚学习了从FireStore仪表板获取(下载)数据的技巧。很明显,在浏览器上打开Google Dashboard,用我的眼睛看到自己的Google Dasboard,会容易得多。然而,出于个人原因,在我的公司,操作员不能查看第三个仪表板。他们只能看到内部仪表盘。我正在尝试一些解决方法,在那里我可以获取/下载用于填充仪表板的相同数据,并将其导入到基于Dynatrace/ELK的内部解决方案中 出于学习目的,为了下载Google Dashboard数据,我遵循以下步骤: 1-使用gclo

上下文:我刚刚学习了从FireStore仪表板获取(下载)数据的技巧。很明显,在浏览器上打开Google Dashboard,用我的眼睛看到自己的Google Dasboard,会容易得多。然而,出于个人原因,在我的公司,操作员不能查看第三个仪表板。他们只能看到内部仪表盘。我正在尝试一些解决方法,在那里我可以获取/下载用于填充仪表板的相同数据,并将其导入到基于Dynatrace/ELK的内部解决方案中

出于学习目的,为了下载Google Dashboard数据,我遵循以下步骤:

1-使用gcloud获取访问令牌

C:\Program Files (x86)\Google\Cloud SDK>gcloud auth application-default print-access-token
C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\bin\..\lib\third_party\google\auth\_default.py:69: UserWarning: Your application has authenticated using end user credentials from Google Cloud SDK. We recommend that most server applications use service accounts instead. If your application continues to use end user credentials from Cloud SDK, you might receive a "quota exceeded" or "API not enabled" error. For more information about service accounts, see https://cloud.google.com/docs/authentication/
  warnings.warn(_CLOUD_SDK_CREDENTIALS_WARNING)
ya29. ... ACCESS-TOKEN ...7hu
2-使用上述访问令牌获取仪表板数据,如:

curl --location --request GET 'https://monitoring.googleapis.com/v3/projects/firetestjimis/timeSeries?filter=metric.type%20%3D%20%22firestore.googleapis.com%2Fdocument%2Fread_count%22&interval.endTime=2020-05-07T15:01:23.045123456Z&interval.startTime=2020-05-05T15:01:23.045123456Z' --header 'Authorization: Bearer ya29...ACCESS-TOKEN 7hu'
显然,这只是一个如何获得满足筛选条件的连接数的示例。我可以根据和不断搜索调整API和过滤器

这次从API版本1获取仪表板metada的另一个示例是

curl --location --request GET 'https://monitoring.googleapis.com/v1/projects/firetestjimis/dashboards' --header 'Authorization: Bearer ya29... ACCESS-TOKEN ...7hu'
从gcloud获取ACCESS-TOKEN时出现的警告鼓励我查看,我做到了。好的,它没有解释如何修复这个警告,也没有解释为什么“如果您的应用程序继续使用来自CloudSDK的最终用户凭据,您可能会收到一个“超出配额”或“API未启用”错误。我可以看到我从仪表板获取数据的技巧正在发挥作用,但我似乎依赖于一种奇怪的方式来获取访问令牌

所以我的直接问题是:手动获取访问令牌并在curl/postman中使用它以避免此类警告的适当步骤是什么

在我看来,基于此,根本原因是“…此错误消息表示您使用的是用户帐户,而不是服务帐户…”,因此我如何修复它?我必须创建一个服务帐户吗?如果是,怎么做?在这个被接受的答案的末尾,我读到“…要使用真正的应用程序默认值,您可以使用gcloud auth application default login…”,这正是我使用gcloud登录的方式:运行gcloud auth application default login,当打开Google SingleSignOn时,我选择我在Firebase帐户中注册的同一用户的电子邮件。答案还提到“…关联特定服务帐户的方法是gcloud auth activate service account--key file…”我想尝试一下,但他/她说的是哪个key file

如果它是相关的,在我的情况下,我只使用Firebase项目下的FireStore(我不使用FireStore以外的任何东西)

***根据约翰的回答编辑

我们很快将这个项目投入生产

1-我们的移动应用程序将通过将其发布到我们的内部微服务来创建转账。这样的post请求将返回从内部NodeJs服务器生成的CustomToken

2-我们的内部微服务将复制此类传输到Firestore,并相应地更新Firestore上的状态

3-代替我们的移动应用程序轮询或监听我们的内部微服务以获取状态,它将监听Firestore以从相应文档获取状态。为了监听,它将使用步骤1中post返回的CustomToken。我们公司希望在这个项目中充分利用谷歌Firestore的实时数据库功能(反应式方法)

当把我所做的与您的声明相比较时,您是否看到了任何考虑因素:“在大多数情况下,谷歌更喜欢您授权使用服务帐户”

CustomToken是使用此NodeJs服务器在内部创建的,具体取决于从经过身份验证的用户中提取的uid:

我们的手机(例如Angular,但IOS和Android的想法相同)有我下载的服务账户JSON文件,如下所示:

环境技术服务:

export const environment = {
  production: false,
  firebaseConfig: {
    apiKey: "AIzaSy ... 3DCGihK3xs",
    authDomain: "firetestjimis.firebaseapp.com",
    databaseURL: "https://firetestjimis.firebaseio.com",
    projectId: "firetestjimis",
    storageBucket: "firetestjimis.appspot.com",
    messagingSenderId: "795318872350",
    appId: "1:7953 ... 32b26fb53dc810f"
  }
};
app.component.ts

  public transfers: Observable<any[]>;

  transferCollectionRef: AngularFirestoreCollection<any>;

  constructor(public auth: AngularFireAuth, public db: AngularFirestore) {
    this.listenSingleTransferWithToken();
  }

  async listenSingleTransferWithToken() {
    await this.auth.signInWithCustomToken("eyJh ### CUSTOMTOKEN GENERATED FROM INTERNAL NODEJS SERVER ABOVE ### CVg");
    this.transferCollectionRef = this.db.collection<any>('transfer', ref => ref.where("id", "==", "1"));
    this.transfers = this.transferCollectionRef.snapshotChanges().map(actions => {
      return actions.map(action => {
        const data = action.payload.doc.data();
        const id = action.payload.doc.id;
        return { id, ...data };
      });
    });
  }
}
公共传输:可观察;
transferCollectionRef:AngularFirestoreCollection;
构造函数(公共身份验证:AngularFireAuth,公共数据库:AngularFirestore){
this.listenSingleTransferWithToken();
}
异步listenSingleTransferWithToken(){
等待此.auth.signInWithCustomToken(“eyJh######CUSTOMTOKEN是从上面的内部NODEJS服务器生成的”);
this.transferCollectionRef=this.db.collection('transfer',ref=>ref.where(“id”,“==”,“1”);
this.transfers=this.transferCollectionRef.snapshotChanges().map(操作=>{
返回actions.map(action=>{
const data=action.payload.doc.data();
const id=action.payload.doc.id;
返回{id,…data};
});
});
}
}

据我所知,CustomToken的创建和使用都完全依赖于服务帐户。我说得对吗?我是否错过了一些概念,我正在幕后使用用户凭证,而在开发环境中正常工作的某些东西在生产时会突然出现一些惊喜?显然,对于这个问题,所有这些都来自我的免费帐户,但在生产过程中它将是付费帐户,但这里的代码和步骤将完全相同。

因此,身份验证令牌是从您的
gcloud init
授权生成的,这是最终用户凭据。这就是为什么你会收到这样的警告。因为您已使用手动登录凭据生成令牌

身份验证的首选方法是使用服务帐户(此处的文档:)进行身份验证。该文档还将指导您创建服务帐户。如果您使用它与Firestore对话,您的服务帐户将需要适当的Firestore角色权限。我不想让您感到困惑,但IAM中的角色是用于
数据存储的
,尽管它们适用于Firestore

此页面:列出您的服务帐户需要哪些角色/权限才能使用Firestore执行各种操作

现在,尽管如此,它所说的关键文件是您可以在创建服务帐户时下载的服务帐户密钥。最简单的方法是通过GCP项目中的控制台执行,因为当您创建服务帐户时,会出现一个han
  public transfers: Observable<any[]>;

  transferCollectionRef: AngularFirestoreCollection<any>;

  constructor(public auth: AngularFireAuth, public db: AngularFirestore) {
    this.listenSingleTransferWithToken();
  }

  async listenSingleTransferWithToken() {
    await this.auth.signInWithCustomToken("eyJh ### CUSTOMTOKEN GENERATED FROM INTERNAL NODEJS SERVER ABOVE ### CVg");
    this.transferCollectionRef = this.db.collection<any>('transfer', ref => ref.where("id", "==", "1"));
    this.transfers = this.transferCollectionRef.snapshotChanges().map(actions => {
      return actions.map(action => {
        const data = action.payload.doc.data();
        const id = action.payload.doc.id;
        return { id, ...data };
      });
    });
  }
}
gcloud auth list
gcloud auth activate-service-account <SERVICE_ACCOUNT_EMAIL_ADDRESS> --key-file=<SERVICE_ACCOUNT_JSON_FILE>