gaelcolas / Sampler

Module template with build pipeline and examples, including DSC elements.
MIT License
172 stars 42 forks source link

PSRepository and SourceLocation #298

Closed fMichaleczek closed 3 years ago

fMichaleczek commented 3 years ago

Details of the scenario you tried and the problem that is occurring

Install this module, create a sample, the script build.ps1 stop and Windows PowerShell user's configuration of PSRepository is broken. (maybe SourceLocation is come back to V2 ? I dont remember because the insane switch between nuget for C# and nuget for PowerShell) I can't provide previous configuration, it's gone!

Verbose logs showing the problem


PS C:\Users\ XXX> Install-Module -Name Sampler

Untrusted repository
You are installing the modules from an untrusted repository. If you trust this repository, change its InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to install the modules from 'PSGallery'?        
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): cd documents\sam        y                                                               [Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): y

PS C:\Users\ XXX> import-module sampler

PS C:\Users\ XXX>
>> $sampleModuleArgs = @{
>>     DestinationPath   = "$env:USERPROFILE\Documents\Sampler\Modules"
>>     ModuleName        = 'Microsoft.NPS'
>>     ModuleType        = 'CompleteSample' # ModuleType and Features are incompatible
>>   # Features          = 'All'
>>     ModuleAuthor      = 'Flavien
>>     ModuleDescription = 'Module for NPS administration and Management'
>>     LicenseType       = 'None'
>>     Verbose           = $true
>> }
>>
>> New-SampleModule @sampleModuleArgs
Name of your default branch (main):
Destination path: C:\Users\XXX\Documents\Sampler\Modules
   Create Microsoft.NPS/source\
   Create Microsoft.NPS/source/Classes\
   Create Microsoft.NPS/source/Enum\
   Create Microsoft.NPS/source/Private\
   Create Microsoft.NPS/source/Public\
   Create Microsoft.NPS/tests\
   Create Microsoft.NPS/tests/Unit/Private\
   Create Microsoft.NPS/tests/Unit/Public\
   Create Microsoft.NPS\tests\Unit\Classes\class1.tests.ps1
   Create Microsoft.NPS\tests\Unit\Classes\class2.tests.ps1
   Create Microsoft.NPS\tests\Unit\Classes\class11.tests.ps1
   Create Microsoft.NPS\tests\Unit\Classes\class12.tests.ps1
   Create Microsoft.NPS\tests\Unit\Private\Get-PrivateFunction.tests.ps1
   Create Microsoft.NPS\tests\Unit\Public\Get-Something.tests.ps1
   Create Microsoft.NPS/tests/Unit/Modules\
   Create Microsoft.NPS\tests\Unit\Modules\Folder.Common.tests.ps1
   Create Microsoft.NPS/tests/Unit/DSCResources\
   Create Microsoft.NPS\tests\Unit\DSCResources\DSC_Folder.tests.ps1
   Create Microsoft.NPS\tests\QA\module.tests.ps1
   Create Microsoft.NPS\source\Public\Get-Something.ps1
   Create Microsoft.NPS\source\Private\Get-PrivateFunction.ps1
   Create Microsoft.NPS\source\Classes\1.class1.ps1
   Create Microsoft.NPS\source\Classes\2.class2.ps1
   Create Microsoft.NPS\source\Classes\3.class11.ps1
   Create Microsoft.NPS\source\Classes\4.class12.ps1
   Create Microsoft.NPS/output\
   Create Microsoft.NPS/output/RequiredModules\
   Create Microsoft.NPS/source/WikiSource\
   Create Microsoft.NPS\.gitignore
   Create Microsoft.NPS\.gitattributes
   Create Microsoft.NPS\build.ps1
   Create Microsoft.NPS\RequiredModules.psd1
   Create Microsoft.NPS\Resolve-Dependency.ps1
   Create Microsoft.NPS\Resolve-Dependency.psd1
   Create Microsoft.NPS\build.yaml                                                                                                                                              Create Microsoft.NPS\azure-pipelines.yml                                                                            
Create Microsoft.NPS/source/DSCResources\                 
Create Microsoft.NPS/source/Examples\                     
Create Microsoft.NPS/source/Modules\                      
Create Microsoft.NPS/source/Modules/Folder.Common\        
Create Microsoft.NPS\source\Modules\Folder.Common\Folder.Common.psm1   
Create Microsoft.NPS/source/DSCResources/DSC_Folder\     
Create Microsoft.NPS\source\DSCResources\DSC_Folder\DSC_Folder.schema.mof  
Create Microsoft.NPS\source\DSCResources\DSC_Folder\DSC_Folder.psm1
Create Microsoft.NPS/source/DSCResources/DSC_Folder/en-US\           
Create Microsoft.NPS\source\DSCResources\DSC_Folder\en-US\DSC_Folder.strings.psd1                                                                                               Create Microsoft.NPS/source/Examples/Resources\                                                                                                                                    Create Microsoft.NPS\source\Examples\README.md                                                                                                                                  Create Microsoft.NPS/source/Examples/Resources/Folder\
   Create Microsoft.NPS\source\Examples\Resources\Folder\1-DscResourceTemplate_CreateFolderAsSystemConfig.ps1
   Create Microsoft.NPS\source\Examples\Resources\Folder\2-DscResourceTemplate_CreateFolderAsUserConfig.ps1
   Create Microsoft.NPS\source\Examples\Resources\Folder\3-DscResourceTemplate_RemoveFolderConfig.ps1
   Create Microsoft.NPS\source\Microsoft.NPS.psd1
   Modify Microsoft.NPS\source\Microsoft.NPS.psd1 into temp file before copying to destination
   Update Microsoft.NPS\source\Microsoft.NPS.psd1
   Modify Microsoft.NPS\source\Microsoft.NPS.psd1 into temp file before copying to destination
   Update Microsoft.NPS\source\Microsoft.NPS.psd1
   Create Microsoft.NPS\source\Microsoft.NPS.psm1
   Create Microsoft.NPS\README.md
   Create Microsoft.NPS\source\en-US\about_Microsoft.NPS.help.txt
   Create Microsoft.NPS\CONTRIBUTING.md
   Create Microsoft.NPS\CODE_OF_CONDUCT.md
   Create Microsoft.NPS\SECURITY.md
   Create Microsoft.NPS\CHANGELOG.md
   Create Microsoft.NPS\GitVersion.yml
   Create Microsoft.NPS\.markdownlint.json
   Create Microsoft.NPS\.vscode\settings.json
   Create Microsoft.NPS\.vscode\analyzersettings.psd1
   Create Microsoft.NPS\.vscode\tasks.json
   Create Microsoft.NPS/.github\
   Create Microsoft.NPS/.github/ISSUE_TEMPLATE\
   Create Microsoft.NPS\.github\PULL_REQUEST_TEMPLATE.md
   Create Microsoft.NPS\.github\ISSUE_TEMPLATE\General.md
   Create Microsoft.NPS\.github\ISSUE_TEMPLATE\Problem_with_resource.md
   Create Microsoft.NPS\.github\ISSUE_TEMPLATE\Resource_proposal.md
   Create Microsoft.NPS\codecov.yml

PS C:\Users\ XXX> cd C:\Users\ XXX\Documents\Sampler\Modules\Microsoft.NPS

PS C:\Users\ XXX\Documents\Sampler\Modules\Microsoft.NPS> .\build.ps1
[pre-build] Starting Build Init
[pre-build] Pre-pending 'C:\Users\ XXX\Documents\Sampler\Modules\Microsoft.NPS\output\RequiredModules' folder to PSModulePath
[pre-build] Dependency missing, running './build.ps1 -ResolveDependency -Tasks noop' for you

[pre-build] Pre-pending 'C:\Users\ XXX\Documents\Sampler\Modules\Microsoft.NPS\output' folder to PSModulePath
[pre-build] Resolving dependencies.
[pre-build] Starting bootstrap process.
PackageManagement\Save-Package : No match was found for the specified search criteria and module name 'PowerShell-Yaml'. Try Get-PSRepository to see all available registered module repositories.
At C:\Users\ XXX\Documents\WindowsPowerShell\Modules\PowerShellGet\2.2.5\PSModule.psm1:11794 char:21
+             $null = PackageManagement\Save-Package @PSBoundParameters
+                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Microsoft.Power...ets.SavePackage:SavePackage) [Save-Package], Exception
    + FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.SavePackage

Import-Module : The specified module 'PowerShell-Yaml' was not loaded because no valid module file was found in any module directory.
At C:\Users\ XXX\Documents\Sampler\Modules\Microsoft.NPS\Resolve-Dependency.ps1:394 char:9
+         Import-Module -Name 'PowerShell-Yaml' -ErrorAction 'Stop'
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (PowerShell-Yaml:String) [Import-Module], FileNotFoundException
    + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand

PS C:\Users\ XXX\Documents\Sampler\Modules\Microsoft.NPS> get-module sampler

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     0.111.3    sampler                             {Add-Sample, Convert-SamplerHashtableToString, Get-BuildVersion, Get-BuiltModuleVersion...}

PS C:\Users\ XXX\Documents\Sampler\Modules\Microsoft.NPS> Install-module PowerShell-Yaml
PackageManagement\Install-Package : No match was found for the specified search criteria and module name 'PowerShell-Yaml'. Try Get-PSRepository to see all available registered module repositories.
At C:\Users\ XXX\Documents\WindowsPowerShell\Modules\PowerShellGet\2.2.5\PSModule.psm1:9711 char:34
+ ... talledPackages = PackageManagement\Install-Package @PSBoundParameters
+                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package], Exception
    + FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage

PS C:\Users\ XXX\Documents\Sampler\Modules\Microsoft.NPS> Get-PSRepository

Name                      InstallationPolicy   SourceLocation
----                      ------------------   --------------
PSGallery                 Untrusted            https://www.powershellgallery.com/api/v2

Suggested solution to the issue

Add a better layer to package source management. The module break my "enterprise" computer configuration. It's a barrier to ask people to test it after I test it. Not important at this point, because it's a code for "advanced users" but this kind of details should be resolved for the good of all.

The DSC configuration that is used to reproduce the issue (as detailed as possible)

N/A

The operating system the target node is running

OsName               : Microsoft Windows 10 Enterprise
OsOperatingSystemSKU : EnterpriseEdition
OsArchitecture       : 64-bit
WindowsVersion       : 1909
WindowsBuildLabEx    : 18362.1.amd64fre.19h1_release.190318-1202
OsLanguage           : en-US
OsMuiLanguages       : {en-US, fr-FR}

Version and build of PowerShell the target node is running

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

Version of the DSC module that was used ('dev' if using current dev branch)

N/A

fMichaleczek commented 3 years ago

Because there is also a proxy , a vpn and a general problem that need profile.ps1, I will check more.

fMichaleczek commented 3 years ago

That was a problem linked to VPN. Network state change between my sample generation,that affect PSRepository policy too (I love Authentificated Proxy).

Mostly because this kind of proxy use NTLMv2 or Kerberos (because ZeroLogon patch etc..), I need this :

[System.Net.WebRequest]::DefaultWebProxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials

(Maybe a security issue to add by default in the bootstrap, I'm not enough expert with this part of dotnet API)