abdolence / firestore-rs

Google Firestore for Rust based on gRPC API with Serde serializer
Apache License 2.0
111 stars 18 forks source link

Error reading the Service Account json #188

Closed chokosabe closed 3 months ago

chokosabe commented 3 months ago

Hi all,

a bit of a weird issue. Have some code I've repeatedly used along with a service account json file I've also used a few times. Porting the code to a new micorservice and getting this error:

Failed to initialize FCM client: Oauth(ServiceAccountKeyReadingFailed(Custom { kind: InvalidData, error: "Bad service account key: expected value at line 1 column 1" }))

Error seems to suggest its an issue reading the json rather than a handshake issue or anything else like that. This is running from inside a docker container. Have tried changing the json file but always getting the same error.

code looks like this:

use firestore::{FirestoreDb, FirestoreDbOptions};

    let project_id = env::var("PROJECT_ID").unwrap();
    let db = FirestoreDb::with_options_service_account_key_file(
        FirestoreDbOptions::new(project_id),
        "/etc/project/project.json".into(),
    ).await?;

Flummoxed at this point and reaching out to see if anyone had come across this before.

debug info:

[2024-08-11T00:33:16Z INFO  firestore::db] Creating a new database client. database_path="projects/test1-j1vzp4/databases/(default)" api_url="https://firestore.googleapis.com" token_scopes="https://www.googleapis.com/auth/cloud-platform"
[2024-08-11T00:33:16Z DEBUG gcloud_sdk::api_client] Creating a new Google API client for https://firestore.googleapis.com. Scopes: ["https://www.googleapis.com/auth/cloud-platform"]
[2024-08-11T00:33:16Z DEBUG rustls::webpki::anchors] add_parsable_certificates processed 140 valid and 0 invalid certs
[2024-08-11T00:33:16Z DEBUG hyper::client::connect::dns] resolving host="firestore.googleapis.com"
[2024-08-11T00:33:16Z DEBUG hyper::client::connect::http] connecting to 172.217.16.234:443
[2024-08-11T00:33:16Z DEBUG hyper::client::connect::http] connected to 172.217.16.234:443
[2024-08-11T00:33:16Z DEBUG rustls::client::hs] No cached session for DnsName("firestore.googleapis.com")
[2024-08-11T00:33:16Z DEBUG rustls::client::hs] Not resuming any session
[2024-08-11T00:33:16Z DEBUG rustls::client::hs] Using ciphersuite TLS13_AES_256_GCM_SHA384
[2024-08-11T00:33:16Z DEBUG rustls::client::tls13] Not resuming
[2024-08-11T00:33:16Z DEBUG rustls::client::tls13] TLS1.3 encrypted extensions: [Protocols([ProtocolName(6832)])]
[2024-08-11T00:33:16Z DEBUG rustls::client::hs] ALPN protocol is Some(b"h2")
[2024-08-11T00:33:16Z DEBUG h2::client] binding client connection
[2024-08-11T00:33:16Z DEBUG h2::client] client connection bound
[2024-08-11T00:33:16Z DEBUG h2::codec::framed_write] send frame=Settings { flags: (0x0), enable_push: 0, initial_window_size: 2097152, max_frame_size: 16384 }
[2024-08-11T00:33:16Z DEBUG h2::proto::connection] Connection; peer=Client
[2024-08-11T00:33:16Z DEBUG h2::codec::framed_write] send frame=WindowUpdate { stream_id: StreamId(0), size_increment: 5177345 }
thread 'main' panicked at src/main.rs:252:10:
Failed to initialize FCM client: Oauth(ServiceAccountKeyReadingFailed(Custom { kind: InvalidData, error: "Bad service account key: expected value at line 1 column 1" }))
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
chokosabe commented 3 months ago

Wondering if anything changed, like maybe a downstream app or library used to read and validate the json file. This behaviour literally started overnight.

abdolence commented 3 months ago

Hey,

AFAIK, nothing related to key JSON files was changed recently. It works in my environment as well. Looking at error it complains about JSON structure just at the first line.

Please verify if you have appropriate JSON file there that looks similar to this: image

The error looks like it may be not even JSON file.

abdolence commented 3 months ago

Failed to initialize FCM client: Oauth(ServiceAccountKeyReadingFailed(Custom { kind: InvalidData, error: "Bad service account key: expected value at line 1 column 1" }))

By the way, I don't recognize this error. FCM/Oauth/ServiceAccountKeyReadingFailed aren't coming neither from firestore or gcloud sdk.

Is it Firebase Cloud Messaging? This crate is not related to anything else except Firestore (database).

chokosabe commented 3 months ago

Thanks! combing through the code found the issue. It was another library with a very similar connection scheme. The connection method was named the same but works differently. Apologies p firestore-rs was working fine the whole time.