Skip to content

Auto discovery not working similar to v4.x #210

@jedney0901

Description

@jedney0901

Describe the bug

Hi guys!

Firstly, thanks for supporting this, I really appreciate it.

I'm using Firebase in a personal project which I deploy via a docker container deployed on a GCE instance. I was previously relying on the auto discovery of the service account credentials on GCE when running v4.x of the package but since upgrading to v5.x, I've been unable to get it to work.

Installed packages

"barryvdh/laravel-dompdf": "^2.0",
        "eway/eway-rapid-php": "^1.4.1",
        "google/cloud-firestore": "^1.40",
        "google/cloud-secret-manager": "^1.13",
        "guzzlehttp/guzzle": "^7.4",
        "jackwh/laravel-new-relic": "^1.0",
        "kreait/laravel-firebase": "^5.1",
        "laravel/framework": "^10.40",
        "laravel/sanctum": "^3.2",
        "laravel/tinker": "^2.8",
        "maatwebsite/excel": "^3.1",
        "predis/predis": "^2.2",
        "sendgrid/sendgrid": "^7.9",
        "shivella/laravel-bitly": "^1.1",
        "spatie/laravel-google-cloud-storage": "^2.2",
        "twilio/sdk": "^6.35"

PHP version and extensions

8.2 and grpc

Steps to reproduce the issue.

How I used to authenticate when using 4.x
I have a service account attached to my GCE instance which I provide all of the roles that it needs to be able to run. I have a need for other containers to be running but this is the only one which requires GCP services so I wanted to use the default credentials.

I was able to authenticate by directly mounting the $HOME/.config/gcloud config directly to the path via my docker-compose file using /root/.config/gcloud:ro inside of my container which worked perfectly.

How I've tried to authenticate since upgrading to 5.x

  1. Authenticating via service account on GCE
> @php artisan package:discover --ansi

   InvalidArgumentException 

  json key is missing the client_email field

  at vendor/google/auth/src/Credentials/ServiceAccountCredentials.php:134
    130▕                 throw new \LogicException('invalid json for auth config');
    131▕             }
    132▕         }
    133▕         if (!array_key_exists('client_email', $jsonKey)) {
  ➜ 134▕             throw new \InvalidArgumentException(
    135▕                 'json key is missing the client_email field'
    136▕             );
    137▕         }
    138▕         if (!array_key_exists('private_key', $jsonKey)) {

      +12 vendor frames 
  13  app/Services/EmailTemplateService.php:18
      app("firebase.firestore")

  14  [internal]:0
      App\Services\EmailTemplateService::__construct(Object(App\Repositories\EmailTemplateRepository))
Script @php artisan package:discover --ansi handling the post-deploy event returned with error code 1

I checked that inside my container I was able to interact with the GCP metadata server and be able to generate all the correct tokens that I would need to be able to authenticate but I was unable to figure out why it was trying to search for a json value of client_email when I was expecting that to be a part of the service discovery.

  1. Auth via the application_default_credentials.json file

To test this, I decided to try and generate the default_application_credentials.json via gcloud auth application-default login file and still mount the ~/.config/gcloud folder directly to /root/.config/gcloud to my docker container. This didn't work out of the box even though it was considered a well known file path which I found really odd.

After reading through the source code, I noticed that google/auth was trying to read from $HOME/.config/gcloud/application_default_credentials.json and I checked my dockerfile to see that I have a USER configured called www so I also tested to see whether I could directly mount it to /home/www/.config/gcloud as this would resolve the $HOME variable correctly and it still didn't work. Something to note is that even before, I was only setting it to the /root directory and it was working fine.

  1. Setting up the GOOGLE_APPLICATION_CREDENTIALS environment variable

I generate a key via the GCP console and mount that directly to the container via /root/.config/gcloud/application_default_credentials.json and that ends up working perfectly yet GCP doesn't recommend doing this as long lasting keys are not secure.

Error message/Stack trace

> @php artisan package:discover --ansi

   InvalidArgumentException 

  json key is missing the client_email field

  at vendor/google/auth/src/Credentials/ServiceAccountCredentials.php:134
    130▕                 throw new \LogicException('invalid json for auth config');
    131▕             }
    132▕         }
    133▕         if (!array_key_exists('client_email', $jsonKey)) {
  ➜ 134▕             throw new \InvalidArgumentException(
    135▕                 'json key is missing the client_email field'
    136▕             );
    137▕         }
    138▕         if (!array_key_exists('private_key', $jsonKey)) {

      +12 vendor frames 
  13  app/Services/EmailTemplateService.php:18
      app("firebase.firestore")

  14  [internal]:0
      App\Services\EmailTemplateService::__construct(Object(App\Repositories\EmailTemplateRepository))
Script @php artisan package:discover --ansi handling the post-deploy event returned with error code 1


### Additional information

_No response_

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions