OneGet / oneget

PackageManagement (aka OneGet) is a package manager for Windows
MIT License
2.38k stars 189 forks source link

PackageManagement Auth for PowerShellGet sources not working #196

Closed jhochwald closed 7 years ago

jhochwald commented 8 years ago

I can register the source as "NuGet", but never as "PowerShellGet" source! The Access shows, that PackageManagement commands never try to authenticate.

I tried that on PowerShell 4 (Windows 7 and 8).

My goal is, a PowerShellGet based feed that needs to authenticate! NuGet is great, but not to distribute PowerShell Modules :-(

When register via nuget.exe source add

PS C:\> Find-Package -Source NETX.SCA -Credential (Get-Credential)
Name                           Version          Source                         Summary
----                           -------          ------                         -------
NETX.scadist                   1.2.3.132        NETX.SCA                       NET-Experts PowerShell Toolbox Distri...

NGINX Proxy Logs for that request:

10.10.16.10 - deploy [24/Jul/2016:22:59:15 +0200] "GET /repository/test/Search()?$filter=IsLatestVersion&searchTerm=''&targetFramework=''&includePrerelease=false&$skip=0&$top=40 HTTP/1.1" 200 3049 "-" "Mozilla/5.0 NuGet"

Here is what I get when I register the same Repository as PowerShellGet Source:

PS C:\> Register-PackageSource -Name "enatec.TEST" -Location "http://nuget.netx.lan/repository/test/" -ProviderName "PowerShellGet" -Credential (Get-Credential) -Force

NGINX Proxy Logs for that request:

10.10.16.10 - - [24/Jul/2016:23:02:39 +0200] "GET /repository/test/ HTTP/1.1" 401 3084 "-" "-"
10.10.16.10 - - [24/Jul/2016:23:02:39 +0200] "GET /repository/test/api/v2/ HTTP/1.1" 401 3084 "-" "-"
10.10.16.10 - - [24/Jul/2016:23:02:39 +0200] "GET /repository/test/api/v2/ HTTP/1.1" 401 3084 "-" "Mozilla/5.0 NuGet"
10.10.16.10 - - [24/Jul/2016:23:02:39 +0200] "GET /repository/test/api/v2/ HTTP/1.1" 401 3084 "-" "Mozilla/5.0 NuGet"
10.10.16.10 - - [24/Jul/2016:23:02:39 +0200] "GET /repository/test/api/v2/ HTTP/1.1" 401 3084 "-" "Mozilla/5.0 NuGet"
10.10.16.10 - - [24/Jul/2016:23:02:39 +0200] "GET /repository/test/api/v2/items/psscript/ HTTP/1.1" 401 3084 "-" "-"
PS C:\> Find-Package -Source enatec.TEST -Credential (Get-Credential)
cmdlet Get-Credential at command pipeline position 1
Supply values for the following parameters:
Credential
WARNING: Unable to resolve package source 'http://nuget.netx.lan/repository/test/api/v2/'.

NGINX Proxy Logs for that request:

10.10.16.10 - - [24/Jul/2016:23:03:26 +0200] "GET /repository/test/api/v2/ HTTP/1.1" 401 3084 "-" "Mozilla/5.0 NuGet"
10.10.16.10 - - [24/Jul/2016:23:03:26 +0200] "GET /repository/test/api/v2/ HTTP/1.1" 401 3084 "-" "Mozilla/5.0 NuGet"
10.10.16.10 - - [24/Jul/2016:23:03:26 +0200] "GET /repository/test/api/v2/ HTTP/1.1" 401 3084 "-" "Mozilla/5.0 NuGet"```
PS C:\> Get-PackageProvider

Name                     Version
----                     -------
msi                      3.0.0.0
msu                      3.0.0.0
NuGet                    2.8.5.205
PowerShellGet            1.0.0.1
Programs                 3.0.0.0
PS C:\> Get-Module -Name 'PackageManagement'

ModuleType Version    Name
---------- -------    ----
Binary     1.0.0.1    PackageManagement
PS C:\> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      4.0
WSManStackVersion              3.0
SerializationVersion           1.1.0.1
CLRVersion                     4.0.30319.42000
BuildVersion                   6.3.9600.16406
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0}
PSRemotingProtocolVersion      2.2

When I try to access the Feed from plain NuGet it works, even from Octopus Deploy it works like a charm. Only the PackageManagement seems to have this issue.

P.S.: The NGINX is just a reverse Proxy and all other tests use this to.

jianyunt commented 8 years ago

@jhochwald are you using WMF 5.0 RTM? Auth won't work on WMF 5.0 RTM. Please try WMF 5.1.

jhochwald commented 8 years ago

@jianyunt at the moment the system it want to use that is PowerShell 4 box (Windows 7). Because this is what all the clients run right now. But I will test it with a VM and install WMF 5.1.

jhochwald commented 8 years ago

@jianyunt Did the test: Works with WMF 5.1! But not with the system above (PowerShell 4 with PackageManagement installed from the Download center).

Here is what I have now:

PS C:> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.14394.1000
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.14394.1000
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

And here what I did to test it:

PS C:\> $UpdateCredentials = (Get-Credential)

cmdlet Get-Credential at command pipeline position 1
Supply values for the following parameters:
Credential

PS C:\> Find-Package -Source 'enatec.TEST' -Credential $UpdateCredentials

Name                           Version          Source           Summary
----                           -------          ------           -------
NETX.scadist                   1.2.3.158        enatec.TEST      NET-Experts PowerShell Toolbox Distribution

PS C:\> Save-Package -Name 'NETX.scadist' -Source 'enatec.TEST' -Credential $UpdateCredentials -Path C:\temp

Name                           Version          Source           Summary
----                           -------          ------           -------
NETX.scadist                   1.2.3.158        enatec.TEST      NET-Experts PowerShell Toolbox Distribution

I registered the source like in the Issue description (The only difference is the safed Credential instead of typing it in on every command).

So is this something that will work/not come to the PackageManagement Module running on PowerShell 4?

CC: @bmanikm @quoctruong

jianyunt commented 8 years ago

@jhochwald Regarding register-packagesource with cred, it was our design choice to not save user's credential any where on the machine. This is mostly for software security consideration.

The PackageManagement from the download center does not contain these cred, proxy, etc features recently added. I will discuss with the team. Sorry for the inconvenience.

jhochwald commented 8 years ago

@jianyunt no problem. Credentials (-credential) works well with NuGet as source. Even if the source was not registered before.

But if the feature is not available, there should be at least a hint about that somewhere.

CC: @bmanikm @quoctruong

DarwinJS commented 6 years ago

This does not seem to work on Server 2016, PSH 5.1.14393.2097, PowerShellGet version 1.6.0.

Seems like this should be rudimentary functionality for secure DevOps.

Is there a new issue tracking this?