swiftlang / swift-package-manager

The Package Manager for the Swift Programming Language
Apache License 2.0
9.71k stars 1.33k forks source link

Xcode 15.1 - not able to add private package dependencies to app project #7237

Closed ncharniauski closed 8 months ago

ncharniauski commented 8 months ago

Description

We are hosting Swift package using https://jfrog.com/help/r/jfrog-artifactory-documentation/swift-registry. Registry is protected and requires authentication. Swift registry works fine using CLI.

When I add a dependency to an application project from Xcode UI (File -> Add package dependency)or via this UI:

Screenshot 2024-01-08 at 7 00 01 PM

Xcode displays error "Authentication failed because the credentials were rejected"

Screenshot 2024-01-09 at 10 55 14 AM

Xcode is able to resolve the same private package dependency just fine if I add dependency to a Swift package project via Package.swift" Screenshot 2024-01-09 at 11 28 10 AM

My registries.json:

{
  "authentication" : {
    "example.jfrog.io" : {
      "loginAPIPath" : "/artifactory/api/swift/swift-registry-local",
      "type" : "basic"
    }
  },
  "registries" : {
    "[default]" : {
      "supportsAvailability" : false,
      "url" : "https://example.jfrog.io/artifactory/api/swift/swift-registry-local"
    }
  },
  "version" : 1
}

I do have registry credentials stored on keychain. It is just one credentials set. Xcode asks to access registry creds on keychain and I grant the permission. I tested with both registry authentication types: basic and token. Both types of authentication fail when adding dependency package from Xcode UI.

Screenshot 2024-01-09 at 11 33 46 AM

Expected behavior

Xcode UI should allow adding protected package dependencies to application projects.

Actual behavior

Xcode displays authentication error when I attempt to add protected package dependency: Screenshot 2024-01-09 at 10 55 14 AM

Steps to reproduce

  1. Install Xcode 15.1
  2. Set up SPM registry that requires authentication (such as https://jfrog.com/help/r/jfrog-artifactory-documentation/swift-registry)
  3. Setup registry URL by command line: package-registry set --global "url"
  4. Setup registries auth by command line: package-registry login "url" --username "uname" --password "pwd"
  5. Verify registries.json file is created with appropriate authentication type.
  6. Verify appropriate Keychain Internet Password is created for registry host URL
  7. Open application project in Xcode and go to File->Add Package Dependencies...
  8. In the "Add Package" window, in the top right corner input field "Search or Enter Package URL" enter registry URL
  9. Xcode displays "Authentication failed because the credentials were missing" window asking to re-enter user name and password
  10. Reentering username/password does also fails with authentication error

Swift Package Manager version/commit hash

No response

Swift & OS version (output of swift --version ; uname -a)

swift-driver version: 1.87.3 Apple Swift version 5.9.2 (swiftlang-5.9.2.2.56 clang-1500.1.0.2.5) Target: x86_64-apple-macosx13.0 Darwin 22.6.0 Darwin Kernel Version 22.6.0: Wed Oct 4 21:25:26 PDT 2023; root:xnu-8796.141.3.701.17~4/RELEASE_X86_64 x86_64

yim-lee commented 8 months ago

@ncharniauski Thanks for creating this. Have you tried entering the package registry identifier (e.g., mona.LinkedList) rather than the Artifactory URL in the search box?

ncharniauski commented 8 months ago

yes I did - package is not found.

yim-lee commented 8 months ago

Tracking with rdar://120735039

yim-lee commented 8 months ago

@ncharniauski A couple of things to check/try:

  1. If you are using user-level registries.json (under ~/.swiftpm/configuration/), please make sure you either don't have registries.json in local workspace or the info in it is correct.
  2. After you type the package registry identifier in the search box, you might need to hit enter to trigger a search. Copy-paste to the search box should also trigger a search.
ncharniauski commented 8 months ago

@ncharniauski A couple of things to check/try:

  1. If you are using user-level registries.json (under ~/.swiftpm/configuration/), please make sure you either don't have registries.json in local workspace or the info in it is correct.
  2. After you type the package registry identifier in the search box, you might need to hit enter to trigger a search. Copy-paste to the search box should also trigger a search.
  1. Confirmed - I only have user-level registries.json under ~/.swiftpm/configuration/
  2. Confirmed - typing package id and hitting enter, and copy-paste package id to the search box, both produce 0 packages found result
yim-lee commented 8 months ago

I am afraid I am out of idea at the moment. I don't think the issue is Xcode not reading registry credentials from Keychain, because you should have gotten an error rather than 0 packages found.

ncharniauski commented 8 months ago

0 packages found is the result of Xcode not being able to connect to my private registry. It couldn't connect, it doesn't know about the package ID i am looking for. This happens only if I am searching for my package by id.

If I enter registry URL into the search box, then I am getting authentication error. Xcode tries to grab credentials from Keychain and authenticate to my registry. This fails and I am getting prompted to enter my username/password as a fallback.

yim-lee commented 8 months ago

If I enter registry URL into the search box, then I am getting authentication error.

When you enter registry URL in the search box it is treated as the Git repo URL, so the authn error results from Xcode/SwiftPM trying to clone it and fails. In other words, that error and prompt don't have anything to do with registry.

sepsky commented 8 months ago

Could it be this? https://forums.developer.apple.com/forums/thread/729959 I fixed the issue by going to ~/.gitconfig and removing any reference to entries with [url "https://github.com/"] insteadOf = ... or [url "ssh://git@github.com/"]

EDIT: I also have the GitHub account in Xcode, as well as the entry in ~/.netrc.

MaxDesiatov commented 8 months ago

Would you be able to clarify if this issue is reproducible for you with swift build, swift test, or any other SwiftPM CLI commands?

ncharniauski commented 8 months ago

Could it be this? https://forums.developer.apple.com/forums/thread/729959 I fixed the issue by going to ~/.gitconfig and removing any reference to entries with [url "https://github.com/"] insteadOf = ... or [url "ssh://git@github.com/"]

EDIT: I also have the GitHub account in Xcode, as well as the entry in ~/.netrc.

Nope. We are not hosting private package on GitHub. It is hosted in Jfrog Swift Registry.

ncharniauski commented 8 months ago

Would you be able to clarify if this issue is reproducible for you with swift build, swift test, or any other SwiftPM CLI commands?

SwiftPM CLI works just fine. Furthermore, Xcode is resolving our private package just fine if package is imported into another package via Package.swift. My test Package lists our private SPM package as dependency on Package.swift. The moment I open the test Package in Xcode, private dependency gets resolved and Package.resolved gets generated.

When I try to add private SPM package dependency to TestApp.xcodeproj via >File>Add Package Dependency> entering Jfrog registry URL in the Search box , this is when Xcode is not able to resolve the package.

What is the difference in how Xcode resolves packages listed on the Package.swift vs via manually resolving through "Add Package Dependency" ?

MaxDesiatov commented 8 months ago

Unfortunately, this issue should be closed here then. This repository hosts the open-source SwiftPM project and its CLI, it does not track Xcode-specific issues. Please file anything Xcode-specific at https://feedbackassistant.apple.com.

tushar1998 commented 5 months ago

@ncharniauski @MaxDesiatov @yim-lee I am doing the same stuff but with AWS Code artifacts, there is docs to run a command called aws codeartifacts login which should create a .swiftpm directory in root with registry configurations. This works for with Package.swift create keychain and all everything is perfect but not with .xcodeproj

But when I try to Add package from File -> Add Pacakge Dependencies and url in search bar it says repository cannot be accessed, followed the docs same 0 pacakges found everytime

So I wanna know is this issue with Xcode?

tushar1998 commented 3 months ago

Okay, I dont know whether this is a bug or not. I tried putting this code snippet in user-level registries.json

// ~/.swiftpm/configurations/registries.json
{
  "authentication" : {
    "example.jfrog.io" : {
      "loginAPIPath" : "/artifactory/api/swift/swift-registry-local",
      "type" : "basic"
    }
  },
  "registries" : {
    "[default]" : {
      "supportsAvailability" : false,
      "url" : "https://example.jfrog.io/artifactory/api/swift/swift-registry-local"
    }
  },
  "version" : 1
}

and then quit xcode and reopen again and try to add package from Xcode UI it works perfectly 🎉

gurelkaynak commented 2 months ago

I solved the same problem, took me a while. @ncharniauski your keychain setup is probably wrong as far as I can see from you screenshot. "Where" should be the url to the swift repository like this:

Screenshot 2024-07-11 at 18 02 48

I had the same setup as you, then I updated the password entry in the keychain and it worked.

hbedekLU commented 2 months ago

Very interested in this topic. @ncharniauski where you able to solve this issue ?

@gurelkaynak I did try your solution but I am still not able to retrieve the packages.

The configuration I tried:

  1. Setup the swift registry swift package-registry set --global "https://example.jfrog.io/artifactory/api/swift/swift-registry-local"

  2. Use the login command to store credential in keychain

    swift package-registry login https://example.jfrog.io/artifactory/api/swift/swift-registry-local \
    --username myUser \
    --password myToken

    with myUser my artifactory user and myToken the token provided by artifactory with the set me up action

Here is the registries.json than I am getting:

{
  "authentication" : {
    "example.jfrog.io" : {
      "loginAPIPath" : "/artifactory/api/swift/swift-registry-local",
      "type" : "basic"
    }
  },
  "registries" : {
    "[default]" : {
      "supportsAvailability" : false,
      "url" : "https://example.jfrog.io/artifactory/api/swift/swift-registry-local"
    }
  },
  "version" : 1
}

At this point I tried to search for my package in the search bar but not able to get anything.

Screenshot 2024-07-19 at 13 36 08

I tried to put as URL:

None of these solutions is working.

kfa-onewelcome commented 3 weeks ago

@hbedekLU any success? got the same :)