microsoft / app-store-vsts-extension

Visual Studio Team Services (VSTS) extension for performing continuous delivery to the App Store store from your automated CI builds
Other
95 stars 53 forks source link

API Connect Key: Pilot fails with "string contains null byte (ArgumentError)" #219

Closed willardf closed 3 years ago

willardf commented 3 years ago

Using Hosted MacOS Azure Pipeline agents, the release task fails with the error at the bottom. Both a service connection and the in-task fields produce the same result. Recreating the commands with a bash script task, but using echo to create the jsonKeyFile seems to work fine.

2021-02-24T03:34:57.0101050Z /Users/runner/.gem-cache/gems/fastlane-2.175.0/spaceship/lib/spaceship/connect_api/token.rb:62:in initialize': [!] string contains null byte (ArgumentError) 2021-02-24T03:34:57.0102550Z from /Users/runner/.gem-cache/gems/fastlane-2.175.0/spaceship/lib/spaceship/connect_api/token.rb:62:innew' 2021-02-24T03:34:57.0104050Z from /Users/runner/.gem-cache/gems/fastlane-2.175.0/spaceship/lib/spaceship/connect_api/token.rb:62:in create' 2021-02-24T03:34:57.0106320Z from /Users/runner/.gem-cache/gems/fastlane-2.175.0/spaceship/lib/spaceship/connect_api/token.rb:40:infrom_json_file' 2021-02-24T03:34:57.0107720Z from /Users/runner/.gem-cache/gems/fastlane-2.175.0/pilot/lib/pilot/manager.rb:34:in api_token' 2021-02-24T03:34:57.0109150Z from /Users/runner/.gem-cache/gems/fastlane-2.175.0/pilot/lib/pilot/build_manager.rb:358:intransporter_for_selected_team' 2021-02-24T03:34:57.0110580Z from /Users/runner/.gem-cache/gems/fastlane-2.175.0/pilot/lib/pilot/build_manager.rb:33:in upload' 2021-02-24T03:34:57.0112000Z from /Users/runner/.gem-cache/gems/fastlane-2.175.0/pilot/lib/pilot/commands_generator.rb:66:inblock (2 levels) in run' 2021-02-24T03:34:57.0113430Z from /usr/local/lib/ruby/gems/2.7.0/gems/commander-fastlane-4.4.6/lib/commander/command.rb:178:in call' 2021-02-24T03:34:57.0114790Z from /usr/local/lib/ruby/gems/2.7.0/gems/commander-fastlane-4.4.6/lib/commander/command.rb:153:inrun' 2021-02-24T03:34:57.0116210Z from /usr/local/lib/ruby/gems/2.7.0/gems/commander-fastlane-4.4.6/lib/commander/runner.rb:476:in run_active_command' 2021-02-24T03:34:57.0117700Z from /Users/runner/.gem-cache/gems/fastlane-2.175.0/fastlane_core/lib/fastlane_core/ui/fastlane_runner.rb:76:inrun!' 2021-02-24T03:34:57.0119120Z from /usr/local/lib/ruby/gems/2.7.0/gems/commander-fastlane-4.4.6/lib/commander/delegates.rb:15:in run!' 2021-02-24T03:34:57.0121000Z from /Users/runner/.gem-cache/gems/fastlane-2.175.0/pilot/lib/pilot/commands_generator.rb:166:inrun' 2021-02-24T03:34:57.0122400Z from /Users/runner/.gem-cache/gems/fastlane-2.175.0/pilot/lib/pilot/commands_generator.rb:18:in start' 2021-02-24T03:34:57.0123810Z from /Users/runner/.gem-cache/gems/fastlane-2.175.0/fastlane/lib/fastlane/cli_tools_distributor.rb:114:intake_off' 2021-02-24T03:34:57.0125180Z from /Users/runner/.gem-cache/gems/fastlane-2.175.0/bin/fastlane:23:in <top (required)>' 2021-02-24T03:34:57.0126440Z from /usr/local/lib/ruby/gems/2.7.0/bin/fastlane:23:inload' 2021-02-24T03:34:57.0127650Z from /usr/local/lib/ruby/gems/2.7.0/bin/fastlane:23:in `

'

max-zaytsev commented 3 years ago

Hi @willardf How did you encode the content of the api key?

jopache commented 3 years ago

I'm experiencing the same issue using a service connection and in task fields as well. the command being run in the release task is:

021-02-24T18:24:11.1424680Z [command]/usr/local/lib/ruby/gems/2.7.0/bin/fastlane pilot upload --api_key_path /Users/runner/work/_temp/api_key***.json -i /Users/runner/work/r1/a/_PIPELINENAME/drop/output/iphoneos/Release QA/ourapp.ipa -a com.company.ourapp.qa -p 123456789

I didn't create an api_key****.json file; was I supposed to create this?

In the stack trace, I see a reference to where that key is trying to be read from "a file" here if it's value is null then on 63 the argumenterror occurs.

https://github.com/fastlane/fastlane/blob/master/spaceship/lib/spaceship/connect_api/token.rb#L53

I have provided the contents of my API Key through the in task field as well as through service connection. I copy/pasted the contents of the .p8 file I downloaded from apple in the following format:

-----BEGIN PRIVATE KEY----- NotMyRealPrivateKeyButYouGetThePointMIGAMBMGByqKxW3ZWKlSZEQ9EeLajuO6VE7MO26rwDoHUcD +ax7gdR -----END PRIVATE KEY-----

jopache commented 3 years ago

Also, seeing this on the fastlane issues gh repo. It's culminating in a different area, but the error here "feels" the same. I need to try an earlier version of fastlane to see if it fixes the issue. Edit: https://github.com/fastlane/fastlane/issues/18271

jopache commented 3 years ago

Downgrading fastlane did nothing. I feel like the issue is in the key file being passed in... the "***" smells off to me; perusing through the codebase here it seems like that should "-keyid.json"

I tried outputting all files in that directory and it's actually empty. Something feels off in the creation of that file..

fastlane pilot upload --api_key_path /Users/runner/work/_temp/api_key***.json -i /Users/runner/work/r1/a/_PIPELINENAME/drop/output/iphoneos/Release QA/ourapp.ipa -a com.company.ourapp.qa -p 123456789

jopache commented 3 years ago

Ok, the ***.json; looks like is only happening when I use a service connection. When I use in task fields to specify an API Key connection, it sees the api_key{keyid}.json instead as passed in to the fastlane command.

I still get a similar error...

using the older version (2.158.0) just caused an error reading json as well. Seems like the file can't be found? but I'm not entirely sure if "the file" is actually there/being created. Added a bash task echoing some output and doing ls/cat of files in that dir, but I'm not seeing the console output of it in the logs...

max-zaytsev commented 3 years ago

Hi @jopache, You have to encode the content of .p8 file to base64 to use it in the task. You can try this tool or the following powershell snippet:

$api_key_content = '-----BEGIN PRIVATE KEY-----
YourPrivateKeyMIGAMBMGByqKxW3ZWKlSZEQ9EeLajuO6VE7MO26rwDoHUcD
Be6zkyp2SAUU99QS/3TPiKlOQ6agCgYIKoZIzj0DAQehRANCAAQTymeZ9NqX8rO
+ax7gdRMBMGByqKxW3ZWKlSZEMBMGByqKxW3ZWKlSZEMBMGByqKxW3ZW
-----END PRIVATE KEY-----'

[System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($api_key_content))
jopache commented 3 years ago

My apologies; that was the issue and it is now running. Thank you for the quick response!

max-zaytsev commented 3 years ago

@willardf Are you still experiencing this issue?

akeblom commented 3 years ago

I also ran into a similar problem but solved it using the following in bash to get a valid base64-string

more your_key_file.p8 | base64 and then use the output.

max-zaytsev commented 3 years ago

@willardf feel free to reopen it if you still have issues

realityworks commented 1 year ago

@max-zaytsev thanks, this helped us with Azure Dev Ops on the same problem. It was not clear in the documentation for Azure that you need to independently encode a text string into the base64 representation.