Skip to content

CertificateProvider auto-imports PKI module many times #11241

Closed

Description

@doctordns

Attempting to use the PKI Module in Win10 using Preview 6.

I kind of expect a warning when the module is first loaded, with either import-module or via module autoload. But not on every operation:

See this graphic:
2019-12-03_14-25-53

In this session, I Set-Location (getting a warning), then did a get-ChildItem (and got a second warning message) then I did another Get-ChildItem (and got a THIRD warning. All the commands sent to the provider seem to generate a warning and I'd argue this is not a good user experience.

Steps to reproduce

# 1. Open a PowerShell console window then type:
CD Cert:\
LS
LS .\Currentuser

Expected behaviour

I would not expect the second two (and all subsequent) uses of cmdlets in a compatibility-imported module. I can live with the first warning, but the rest are a poor user experience.

Actual behaviour

See the graphic above

Environment data

PS Cert:\> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.0.0-preview.6
PSEdition                      Core
GitCommitId                    7.0.0-preview.6
OS                             Microsoft Windows 10.0.18363
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Activity

  1. added
    Issue-Question
    on Dec 3, 2019
  2. theJasonHelmick commented on Dec 3, 2019

    @theJasonHelmick
    Collaborator

    Thomas Lee (@doctordns) In reviewing this I also noticed that any use of tab completion for any cmdlet (not parameters) seems to produce the warning at the moment the tab key is pressed, then completion options are shown after the warning message.
    Get- produces the warning
    Get-Process - Does not produce warning

  3. SeeminglyScience commented on Dec 3, 2019

    @SeeminglyScience
    Contributor

    Also writes warnings in VSCode's integrated console when intellisense hits the same commands.

  4. doctordns commented on Dec 3, 2019

    @doctordns
    CollaboratorAuthor

    Jason Helmick (@theJasonHelmick) and Patrick Meinecke (@SeeminglyScience) Yes indeed. It does get worse! It messes IntelliSense as Patrick noticed. To amplify Jason's point...

    If I type:

    CD Cert:
    LS .\Curr<tab|>
    

    I see this:

    2019-12-03_18-04-49

    This can not be acceptable. :-(

  5. added
    Issue-Bug
    and removed
    Issue-Question
    on Dec 3, 2019
  6. vexx32 commented on Dec 3, 2019

    @vexx32
    Collaborator
  7. anmenaga commented on Dec 3, 2019

    @anmenaga

    Short version: This looks like a manifestation of a bug in CertificateProvider - loading pki module on every operation with a certificate path. Wincompat's warning just made this visible.

    Long version: When creating new items or getting existing certificate items CertificateProvider auto-imports pki module based on it's internal flag _hasAttemptedToLoadPkiModule.
    This _hasAttemptedToLoadPkiModule flag is set to false only once - in CertificateProvider's constructor.
    However, SessionStateInternal.GetProviderInstance simply creates a new instance of the provider every time, therefore resetting _hasAttemptedToLoadPkiModule flag which subsequently causes pki module to be re-imported again.

    Here is the call stack that resets the _hasAttemptedToLoadPkiModule flag during PS Cert:\> ls call:

    Microsoft.PowerShell.Commands.CertificateProvider.CertificateProvider() Line 517
    System.RuntimeType.CreateInstanceDefaultCtor(bool publicOnly, bool skipCheckThis, bool fillCache, bool wrapExceptions)
    System.Activator.CreateInstance(System.Type type, bool nonPublic, bool wrapExceptions)
    System.Management.Automation.ProviderInfo.CreateInstance() Line 571
    System.Management.Automation.SessionStateInternal.GetProviderInstance(System.Management.Automation.ProviderInfo provider) Line 284
    System.Management.Automation.SessionStateInternal.GetContainerProviderInstance(System.Management.Automation.ProviderInfo provider) Line 604
    System.Management.Automation.SessionStateInternal.GetChildItems(string path, bool recurse, uint depth, System.Management.Automation.CmdletProviderContext context) Line 1491
    System.Management.Automation.ChildItemCmdletProviderIntrinsics.Get(string path, bool recurse, uint depth, System.Management.Automation.CmdletProviderContext context) Line 278
    Microsoft.PowerShell.Commands.GetChildItemCommand.ProcessRecord() Line 318
    
  8. anmenaga commented on Dec 3, 2019

    @anmenaga

    On a side note, a single PS Cert:\> Get-ChildItem call ends up invoking CertificateProvider constructor 19 (!) times at various stages.

  9. doctordns commented on Dec 4, 2019

    @doctordns
    CollaboratorAuthor

    Andrew (@anmenaga) - thanks for this.

    What does this mean for the PKI module? With this P/'R, will these commands work??

    And will the CERT: provider work properly (as in act the same as in Windows PowerShell).

  10. jhoneill commented on Dec 4, 2019

    @jhoneill

    Thomas Lee (@doctordns) In reviewing this I also noticed that any use of tab completion for any cmdlet (not parameters) seems to produce the warning at the moment the tab key is pressed, then completion options are shown after the warning message.

    I've been seeing this with particular module I have been working with (or I might say has been working against me) dynamic parameters seem to be expanded as part of get-command and the tab completion seems to cause the dynamicParam code to run. I found if I set $verbosePrefernce to Continue, tab expanding a command generated hundreds of lines of verbose output because the module in question had 60+ dynamic params, each of which did significant work.
    I suspect something similar is going on here.

  11. iSazonov commented on Dec 5, 2019

    @iSazonov
    Collaborator

    On a side note, a single PS Cert:> Get-ChildItem call ends up invoking CertificateProvider constructor 19 (!) times at various stages.

    I guess it is in LocationGlobber. It unify entry points to providers but this causes performance problems. It calls helper methods repeatedly many times. We have a tracking issue for FileSystem provider v2 and looking this I think we needs to change design and make entry points in base provider class to preserve unification and get high performance.

  12. added
    WG-Engine
    on Dec 5, 2019
  13. anmenaga commented on Dec 5, 2019

    @anmenaga

    Thomas Lee (@doctordns) #11259 will remove excessive warnings that you're observing. Functionality-wise commands of PKI module will continue to behave like they currently are. If they support serialization - they should work fine - this is basically a general rule for any module that is loaded through WinCompat.

    This issue is good for tracking a multi-import of PKI module bug in CertificateProvider/LocationGlobber boundary. This should be fixed.

  14. changed the title [-]PowerShell 7 P6 - PKI Modules Over issues warning due to compatibility[/-] [+]CertificateProvider auto-imports PKI module many times[/+] on Dec 20, 2019
  15. doctordns commented on Jan 11, 2020

    @doctordns
    CollaboratorAuthor

    This issue appears to have gone away by RC1. IT now works as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugResolution-FixedWG-Engine

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions