laravel-google-cloud-storage icon indicating copy to clipboard operation
laravel-google-cloud-storage copied to clipboard

(ServiceException) json key is missing the type field

Open ralfiannor opened this issue 5 years ago • 39 comments

I updated to latest version 2.2.1 and get that if i upload image to bucket.

ralfiannor avatar Apr 25 '19 07:04 ralfiannor

Could you please provide a full stack trace, and the contents of your config file?

nicja avatar Apr 25 '19 08:04 nicja

Could you please provide a full stack trace, and the contents of your config file?

I use Google App Engine Use config in filesystem laravel : 'gcs' => [ 'driver' => 'gcs', 'project_id' => env('GOOGLE_CLOUD_PROJECT_ID'), 'key_file' => env('GOOGLE_CLOUD_KEY_FILE', null), // optional: /path/to/service-account.json 'bucket' => env('GOOGLE_CLOUD_STORAGE_BUCKET'), 'path_prefix' => env('GOOGLE_CLOUD_STORAGE_PATH_PREFIX', null), // optional: /default/path/to/apply/in/bucket 'storage_api_uri' => env('GOOGLE_CLOUD_STORAGE_API_URI', null), // see: Public URLs below ],

Before update my code work successfull.

ralfiannor avatar Apr 25 '19 08:04 ralfiannor

The PR in question doesn't actually make any logical changes, it just changes the order of operations, so I cant see how this fixes your issue..

Please can you provide: 1: The full stack trace for the ServiceException 2: The value of env('GOOGLE_CLOUD_KEY_FILE', null)

The only way I can see this working is if env('GOOGLE_CLOUD_KEY_FILE', null) === null

nicja avatar Apr 25 '19 09:04 nicja

The PR in question doesn't actually make any logical changes, it just changes the order of operations, so I cant see how this fixes your issue..

Please can you provide: 1: The full stack trace for the ServiceException 2: The value of env('GOOGLE_CLOUD_KEY_FILE', null)

The only way I can see this working is if env('GOOGLE_CLOUD_KEY_FILE', null) === null

Its same with my logic bro. If you learn clean code dont use === null in if argument

ralfiannor avatar Apr 25 '19 09:04 ralfiannor

i get same issue, basically my laravel project running on google app yesterday still working fine without use GOOGLE_CLOUD_KEY_FILE but now i get this error.

Screen Shot 2019-04-26 at 13 26 26

alfin87aa avatar Apr 26 '19 06:04 alfin87aa

Can you please update your config and replace

'project_id' => env('GOOGLE_CLOUD_PROJECT_ID')

with

'project_id' => env('GOOGLE_CLOUD_PROJECT')

and let me know if it works for you then

MaggotMouth avatar Apr 26 '19 07:04 MaggotMouth

i still get same error bro, and how if i use the json key for my google app engine, because i try put my directory of json key in my locahost project and it's work but if i deploy to app engine still get this issue, thanks for your help.

Screen Shot 2019-04-26 at 15 19 40

alfin87aa avatar Apr 26 '19 08:04 alfin87aa

Can you tell me if env('GOOGLE_CLOUD_KEY_FILE', null) is null or whether it has an actual (string etc.) value in your situation? I want to merge your PR but I need to know it will not break for others, and since I can't replicate your situation it is very difficult to do so. Thanks

nicja avatar Apr 26 '19 09:04 nicja

i have solve it with this step :

  • make json api key from here https://console.cloud.google.com/apis/credentials/serviceaccountkey
  • download and put file to storage folder of your project
  • edit your key_file variable to storage_path('file_name.json') like picture bellow
Screen Shot 2019-04-26 at 16 46 59

alfin87aa avatar Apr 26 '19 09:04 alfin87aa

@alfin87aa @ralfiannor Are you satisfied with this solution or do you need it to be able to work with a null key_file?

nicja avatar Apr 26 '19 09:04 nicja

@nicja @MaggotMouth for me it's enough, thanks for your help 👍

alfin87aa avatar Apr 26 '19 11:04 alfin87aa

Can you tell me if env('GOOGLE_CLOUD_KEY_FILE', null) is null or whether it has an actual (string etc.) value in your situation? I want to merge your PR but I need to know it will not break for others, and since I can't replicate your situation it is very difficult to do so. Thanks

Work perfect if i edit your code to handle null. Please, merge my pull request https://github.com/Superbalist/laravel-google-cloud-storage/pull/61 and this issue will solve. image

ralfiannor avatar Apr 27 '19 07:04 ralfiannor

i have solve it with this step :

  • make json api key from here https://console.cloud.google.com/apis/credentials/serviceaccountkey
  • download and put file to storage folder of your project
  • edit your key_file variable to storage_path('file_name.json') like picture bellow
Screen Shot 2019-04-26 at 16 46 59

Add google credential file in your source project is bad. Dont try it in production.

ralfiannor avatar Apr 28 '19 14:04 ralfiannor

i have solve it with this step :

  • make json api key from here https://console.cloud.google.com/apis/credentials/serviceaccountkey
  • download and put file to storage folder of your project
  • edit your key_file variable to storage_path('file_name.json') like picture bellow
Screen Shot 2019-04-26 at 16 46 59

Add google credential file in your source project is bad. Dont try it in production.

You don't need to put it in your storage folder. You can just deploy the key with your app to App Engine, then set the key_file to that file (outside of storage); or alternatively, don't set a key_file at all and just set the GOOGLE_APPLICATION_CREDENTIALS env var.

matthewgoslett avatar Apr 28 '19 15:04 matthewgoslett

@nicja this issue has wreaked havoc on us today. We need the ability to set 'key_file' => null as per the proposed PR.

I don't actually see why we need to do any array_merge at all though, since the project ID is already in the service key? Commented on that in the PR.

phroggyy avatar May 09 '19 14:05 phroggyy

@nicja @ralfiannor I rewrote the entire function so it makes more sense logically, it's also commented so you can easily tell what's going on. In my PR I wrote up the issue.

cjcox17 avatar May 13 '19 22:05 cjcox17

I've got a same issue on standard app engine. It doesn't work with GOOGLE_CLOUD_KEY_FILE set to null. As I can recall, it used to work on v2.1.0, but it has "json key is missing the type field" error now.

hos-shams avatar May 31 '19 19:05 hos-shams

I encountered the same issue today, i see a pull request is awaiting. Can anyone check / approve this?

EntonoX avatar Jun 05 '19 09:06 EntonoX

Hi all, apologies for how long this has been outstanding. Unfortunately I can't test the specific scenarios that are broken. We now have 2 open PRs to fix this issue. I am in favour of #61 as it includes updates to the README. @cjcox17 @EntonoX @ralfiannor @ShaMSofT can you let me know if this PR solves the issue for you? Thanks!

EDIT: #63 is preferred, not #61

nicja avatar Jun 05 '19 09:06 nicja

@nicja I'm testing #63 right now, I can test #61 as well if this is a preferred PR. i'll report back today.

EntonoX avatar Jun 05 '19 09:06 EntonoX

@EntonoX thank you! Apologies, I meant #63 which has the changes to the README

nicja avatar Jun 05 '19 09:06 nicja

@nicja I tested #63 locally and within GCS docker container. I was not able to get it working without using the service account key as a secret. (So i needed to provide the 'key_file_path' environment variable). Without this environment variable i got a 'insufficient permission' error.

I can not judge if this is a service account rights setting or some other problem. Maybe you or @cjcox17 can provide some details for this?

EntonoX avatar Jun 05 '19 13:06 EntonoX

🙏

I'm able to replicate this in GKE. I'm not using a key file. I just want the lib to use the default service account of the instance, which the CredentialsLoader does as fallback.

I was able to hack around it by setting key_file in the config to an empty string. This passes the if (is_string($keyFile)) { check in createClient and tries to load the client with just a project id and empty keyFilePath. In Google's ClientTrait, it fails their loose if ($config['keyFile']) { check and lands up using return CredentialsLoader::fromEnv() ?: CredentialsLoader::fromWellKnownFile(); which is what I want.

matthewgoslett avatar Jun 18 '19 18:06 matthewgoslett

I'm using #63 in production without a key_file, I'll setup another instance this weekend to test.

@EntonoX @matthewgoslett Can you provide your filesystem.php config for the GCS disk? I'll use this when I'm testing.

cjcox17 avatar Jun 21 '19 20:06 cjcox17

Set up the newest version of this today on a new App Engine instance and ran into the same issue.

I was able to hack around it by setting key_file in the config to an empty string. This passes the if (is_string($keyFile)) { check in createClient and tries to load the client with just a project id and empty keyFilePath. In Google's ClientTrait, it fails their loose if ($config['keyFile']) { check and lands up using return CredentialsLoader::fromEnv() ?: CredentialsLoader::fromWellKnownFile(); which is what I want.

This solution worked for me, thank you @matthewgoslett

bredmor avatar Jun 22 '19 21:06 bredmor

@matthewgoslett @bredmor You are experiencing the ongoing issue that the pending pull request fixes. Pull request #63 Works in these cases.

@ EntonoX @nicja I setup another Google Cloud Compute Engine Instance yesterday and verified the the pull request works as intended.

@EntonoX Verify that you're using the newest config file included in the pull request and verify that your instance has the proper permissions on the service account. For testing I simply select "Allow full access to all API's". The README has been updated as well.

Can you post your Laravel config, docker config, and a stack trace?

@nicja If there is a separate issue for Docker, Kubernetes, or Google Cloud App Engine, I think it would make sense to approve the current pull request to fix the current issue and address the other issue separately so people like @matthewgoslett and @bredmor and myself don't continue to run into this issue.

cjcox17 avatar Jun 25 '19 08:06 cjcox17

@nicja @ralfiannor I rewrote the entire function so it makes more sense logically, it's also commented so you can easily tell what's going on. In my PR I wrote up the issue.

it's ok bro.

ralfiannor avatar Jul 06 '19 15:07 ralfiannor

I was deploying on GAE flexible environment and i got that error too, my config is like this: 'key_file' => env('GOOGLE_CLOUD_KEY_FILE', null), // optional: /path/to/service-account.json

Has been found a solution?

alexcaselli avatar Aug 02 '19 10:08 alexcaselli

I was deploying on GAE flexible environment and i got that error too, my config is like this: 'key_file' => env('GOOGLE_CLOUD_KEY_FILE', null), // optional: /path/to/service-account.json

Has been found a solution?

Downgrade version until fix version release.

ralfiannor avatar Aug 06 '19 07:08 ralfiannor

Hi found the solution... set : 'key_file' => env('GOOGLE_CLOUD_KEY_FILE', '') // empty string instead null solve for me the problem

hussonkevin avatar Oct 17 '19 10:10 hussonkevin