periphery icon indicating copy to clipboard operation
periphery copied to clipboard

Periphery not making use of SSH key

Open jortberends opened this issue 2 years ago • 3 comments

Is Periphery running on some kind of clean shell? In Bitrise i'm activating a SSH key to read private Github repositories, but when starting the scan it is not able to load the content of the SPM packages hosted in a private github repo and it stops with the 74 exit status. When running the xcodebuild -resolvePackageDependencies command manually, it does use this SSH key and resolves them successfully.

Manual:

Command line invocation:
    /Applications/Xcode-13.4.1.app/Contents/Developer/usr/bin/xcodebuild -resolvePackageDependencies
User defaults from command line:
    IDEPackageSupportUseBuiltinSCM = YES
Resolve Package Graph
Fetching from [email protected]:CompanyName/productName-spm-internal.git
Fetching from [email protected]:CompanyName/core-spm-internal.git
Cloning local copy of package ‘core-spm-internal’
Checking out 34b60414da7b3ef57d1733b27defc9b075a98c0a of package ‘core-spm-internal’
Cloning local copy of package ‘productName-spm-internal’
Checking out 479310383c148757ff8de72cf17152e35e9a69c3 of package ‘productName-spm-internal’
Resolved source packages:
  Core: [email protected]:CompanyName/core-spm-internal.git @ 34b6041
  Product: [email protected]:CompanyName/productName-spm-internal.git @ 4793103
resolved source packages: Core, Product

When using periphery:

error: Shell command '/bin/sh -c xcodebuild -project '/Users/vagrant/git/ProductDemo/ProductDemo.xcodeproj' -scheme 'Product' -parallelizeTargets -derivedDataPath '/Users/vagrant/Library/Caches/com.github.peripheryapp/DerivedData-56e7146b-ce1f9cec' -quiet build CODE_SIGNING_ALLOWED="NO" ENABLE_BITCODE="NO" DEBUG_INFORMATION_FORMAT="dwarf" -sdk iphonesimulator' returned exit status '74':
xcodebuild: error: Could not resolve package dependencies:
  Failed to clone repository [email protected]:CompanyName/productName-spm-internal.git:
    Cloning into bare repository '/Users/vagrant/Library/Caches/com.github.peripheryapp/DerivedData-56e7146b-ce1f9cec/SourcePackages/repositories/productName-spm-internal-5da43b33'...
    Warning: Permanently added 'github.com' (ED25519) to the list of known hosts.
[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.
    Please make sure you have the correct access rights
    and the repository exists.
Skipping cache due to an error: Couldn’t fetch updates from remote repositories:
    Fetching origin
    Warning: Permanently added 'github.com' (ED25519) to the list of known hosts.
[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.
    Please make sure you have the correct access rights
    and the repository exists.
    error: Could not fetch origin

Do i need to do some extra work to make sure Periphery makes use of my private key to resolve packages at Github?

jortberends avatar Jul 20 '22 07:07 jortberends

I could resolve this issue by adding SSH private key to the Keychain and force ssh agent to use the Keychain.

Step 1 — Add your Private Key to Keychain ssh-add -K ~/.ssh/[name of your private key]

Step 2 — Allow SSH to use always your keychain Modify your SSH configuration file ~/.ssh/config and add the following lines:

Host *
  UseKeychain yes
  AddKeysToAgent yes
  IdentityFile ~/.ssh/[name of your private key]

mehdiimrz avatar Jul 26 '22 09:07 mehdiimrz

I'm having this exact issue too. I have multiple different private SSH keys, and I've got them configured in my .ssh/config file. The private keys are added to my Keychain correctly. But when I try to run periphery scan, it fails trying to load dependencies. I've managed to work around it by logging into GitHub using gh and choosing HTTPS as my preferred method of connecting, but it's a frustrating workaround all the same.

rhys-rant avatar Aug 30 '22 15:08 rhys-rant

ditto. strange given I've added the keys to the keygen. I can clone the private repo using git. but fails when building using periphery

markst avatar Sep 08 '22 10:09 markst

This is might be because Periphey launches external commands like xcodebuild in a (mostly) pristine shell environment. It only preserves the PATH and DEVELOPER_DIR values. Are you all using SSH forwarding or something? Perhaps we need to whitelist some SSH_* env values.

ileitch avatar Sep 29 '22 03:09 ileitch

Closing due to no response.

ileitch avatar Mar 04 '23 18:03 ileitch