PowerShell / PSResourceGet

PSResourceGet is the package manager for PowerShell
https://www.powershellgallery.com/packages/Microsoft.PowerShell.PSResourceGet
MIT License
483 stars 92 forks source link

V2ServerAPICalls: JFrog quirk flag should enable for Artifactory domains without "jfrog" in the domain #1530

Closed sean-r-williams closed 7 months ago

sean-r-williams commented 7 months ago

Prerequisites

Steps to reproduce

(Related to #1485 and #1526 - spinning off a separate issue at the request of @alerickson in https://github.com/PowerShell/PSResourceGet/issues/1485#issuecomment-1897197544)

Our Artifactory/JFrog instances all have local DNS name artifactory (plus some environment-specific DNS suffixes that are NDAed). In any case, we'd expect the Artifactory NuGet URLs to look something like https://artifactory.f.q.d.n/artifactory/api/nuget/v2/<feed-name>/ (replacing f.q.d.n) with the DNS suffix

Expected behavior

Microsoft.PowerShell.PSResourceGet.Cmdlets.V2ServerAPICalls._isJFrogRepo is true when PSResourceGet makes calls to Artifactory endpoints

Actual behavior

Microsoft.PowerShell.PSResourceGet.Cmdlets.V2ServerAPICalls._isJFrogRepo is false

Error details

N/A

Environment data

ModuleType Version    Name                                ExportedCommands                                             
---------- -------    ----                                ----------------                                             
Binary     1.0.1      Microsoft.PowerShell.PSResourceGet  {Find-PSResource, Get-InstalledPSResource, Get-PSResourceR...

Key   : PSVersion
Value : 5.1.19041.3803
Name  : PSVersion

Key   : PSEdition
Value : Desktop
Name  : PSEdition

Key   : PSCompatibleVersions
Value : {1.0, 2.0, 3.0, 4.0...}
Name  : PSCompatibleVersions

Key   : BuildVersion
Value : 10.0.19041.3803
Name  : BuildVersion

Key   : CLRVersion
Value : 4.0.30319.42000
Name  : CLRVersion

Key   : WSManStackVersion
Value : 3.0
Name  : WSManStackVersion

Key   : PSRemotingProtocolVersion
Value : 2.3
Name  : PSRemotingProtocolVersion

Key   : SerializationVersion
Value : 1.1.0.1
Name  : SerializationVersion

Visuals

N/A

sean-r-williams commented 7 months ago

Depending on the requirements of this specific class, it may be worth replacing hostname-/URL-based detection with an HTTP request to the root feed URL. (This call does not need to be authenticated.)

Artifactory's response (be it 2xx, 401, 403, or 5xx) will include one of the following HTTP headers in the response:

alerickson commented 7 months ago

I didn't couldn't find X-Artifactory-Id, X-Artifactory-Node-Id, or X-Jfrog-Version in the HTTP Headers (using my test account), but did find <title>JFrog</title> in the response content.

@sean-r-williams do you happen to see <title>JFrog</title> in the content of your response as well?

sean-r-williams commented 7 months ago

@sean-r-williams do you happen to see <title>JFrog</title> in the content of your response as well?

@alerickson I don't, no. To clarify, I'm talking about a request to the root URL of the feed (i.e. the one users provide when registering the repository) - that is, something like https://artifactory.f.q.d.n/artifactory/api/nuget/v2/psgallery-nuget-local. I don't see the aforementioned X-* headers when hitting the domain root (https://artifactory.f.q.d.n), even though it is a selfhosted JFrog Platform/Artifactory instance.

I do see <title>JFrog</title> when GETting the domain root, but I would caution against using that for any heuristics. If Artifactory were hosted behind a reverse-proxy (or similar) under a specific VPath, the domain-root might "point to" a service other than JFrog and that detection would break.

For the sake of completeness, the response content when GETing https://artifactory.f.q.d.n/artifactory/api/nuget/v2/psgallery-nuget-local (the root URL of the feed) looks like this:

In both cases, headers look something like this (plus WWW-Authenticate: Basic realm="Artifactory Realm" for the 401):

X-JFrog-Version: Artifactory/7.59.12 75912900
X-Artifactory-Id: 0123456789abcdef0123456789abcdef01234567
X-Artifactory-Node-Id: artifactory02
Transfer-Encoding: chunked
Date: Tue, 23 Jan 2024 06:35:13 GMT
Content-Type: application/json