尝试使用Golang / Cloud Function将数据存储在Google Firestore中时如何解决“身份验证握手失败”

I'm using Google Cloud Function for Go/Golang (Http-trigger) and tyring to store data within the Firestore Database. But the client always fails with

"rpc error: code = Unavailable desc = all SubConns are in TransientFailure, latest connection error: connection error: desc = transport: authentication handshake failed: context deadline exceeded".

The database was created via the Firebase Admin console (https://console.firebase.google.com) with the following rules

service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if false;
    }
  }
}

I'm working in the 'Pay-as-you-Go' plan.

the "important" imports

import (
    "context"
    ...
    firebase "firebase.google.com/go"

)

the code for saving

func saveValues(registration shared.Registration) error {

    ctx := context.Background()

    conf := &firebase.Config{ProjectID: projectID}
    app, err := firebase.NewApp(ctx, conf)
    if err != nil {
        return fmt.Errorf("error creating client %v", err)
    }

    client, err := app.Firestore(ctx)
    if err != nil {
        return fmt.Errorf("Failed to create client %v", err)
    }
    defer client.Close()

    t := time.Now()
    documentName := "registration"
    _, err = client.Collection("registration").Doc(documentName).Set(ctx, registration)
    if err != nil {
        return fmt.Errorf("Failed adding registration: %v", err)
    }

    return nil
}

go.mod file:

module githib.com/kkoehler/<my-project>

require (
    cloud.google.com/go v0.37.4
    firebase.google.com/go v3.7.0+incompatible
    github.com/KyleBanks/depth v1.2.1 // indirect
    github.com/sirupsen/logrus v1.4.1
    golang.org/x/oauth2 v0.0.0-20190402181905-9f3314589c9a // indirect
    google.golang.org/api v0.3.2 // indirect
)

The last call (client.Collection("registration").Doc(documentName).Set(ctx, registration)) fails with the given error message.

Is there any option to get more info about that problem? Any suggestion?

Thanks, Kristian

Solution

That's a firestore permission problem. If I change the permissions for the firestore database it works. Changed temporarily to write for everybody ;-)