PowerShell / PowerShell

PowerShell for every system!
https://microsoft.com/PowerShell
MIT License
43.66k stars 7.08k forks source link

macOS can't use New-PSSession to Connect to O365 from PowerShell Host - WSMAN client library not found #10600

Closed jnevins-gcm closed 4 years ago

jnevins-gcm commented 4 years ago

Steps to reproduce

Same issue as described here: https://github.com/PowerShell/PowerShell/issues/5561

except when using Microsoft.PowerShell.SDK (6.2.3) instead of PowerShell CLI


Error:

Unhandled Exception: System.AggregateException: One or more errors occurred. (This parameter set requires WSMan, and no supported WSMan client library was found. WSMan is either not installed or unavailable for this system.) ---> System.Management.Automation.CmdletInvocationException: This parameter set requires WSMan, and no supported WSMan client library was found. WSMan is either not installed or unavailable for this system. ---> System.Management.Automation.Remoting.PSRemotingTransportException: This parameter set requires WSMan, and no supported WSMan client library was found. WSMan is either not installed or unavailable for this system. ---> System.DllNotFoundException: Unable to load shared library 'libpsrpclient' or one of its dependencies. In order to help diagnose loading problems, consider setting the DYLD_PRINT_LIBRARIES environment variable: dlopen(liblibpsrpclient, 1): image not found at System.Management.Automation.Remoting.Client.WSManNativeApi.WSManInitialize(Int32 flags, IntPtr& wsManAPIHandle) at System.Management.Automation.Remoting.Client.WSManClientSessionTransportManager.WSManAPIDataCommon..ctor()


If I set DYLD_PRINT_LIBRARIES to 1, I see the following when running from C# right before the error:

dyld: loaded: /Users/jeff/.nuget/packages/microsoft.powershell.native/6.2.0/runtimes/osx/native/libpsrpclient.dylib dyld: unloaded: /Users/jeff/.nuget/packages/microsoft.powershell.native/6.2.0/runtimes/osx/native/libpsrpclient.dylib


Works:

- Install PowerShell CLI (6.4.0) (on the exact same machine)
- Run ```sudo ln -s /opt/local/lib /usr/local/opt/openssl/lib``` (this doesn't seem to help the C# code any)
- Run the exact same script

If I set DYLD_PRINT_LIBARIES to 1 for the CLI, I see the following right before the connection succeeds:

dyld: loaded: /usr/local/microsoft/powershell/6/libpsrpclient.dylib dyld: loaded: /usr/local/microsoft/powershell/6/libmi.dylib dyld: loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib dyld: loaded: /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib



so the problem is specific to the SDK...and the ln command fix doesn't seem to work for the SDK.

# Expected behavior

Doesn't throw error

# Actual behavior

Throws error 

# Environment data

Mac OS Mojave
iSazonov commented 4 years ago

@adityapatwardhan Could you please comment the SDK issue?

jnevins-gcm commented 4 years ago

Anyone?

iSazonov commented 4 years ago

@jnevins-gcm MSFT team is busy in the days so waiting...

jnevins-gcm commented 4 years ago

It's been 15 days... @iSazonov @adityapatwardhan

iSazonov commented 4 years ago

@jnevins-gcm From previous discussions I can only say please check that libpsrpclient is installed and loaded. The same for OpenSSL.

/cc @SteveL-MSFT

jnevins-gcm commented 4 years ago

@isazonov - that isn’t a meaningful reply. It doesn’t seem like you’ve even read the issue

iSazonov commented 4 years ago

@jnevins-gcm Sorry for short answer.

and the ln command fix doesn't seem to work for the SDK.

libpsrpclient does not have a help logging so it would be great if you used diagnostic tools to identify broken dependencies (to ssl I guess). And do you want to get a workaround or fix?

jnevins-gcm commented 4 years ago

I’d be totally happy with a workaround.

I’m not super familiar with dependency analysis tools on OS X but I’m happy to try to gather some information if you could provide some guidance on what tools to use.

Thanks!

jnevins-gcm commented 4 years ago

any update...? been about a month

SteveL-MSFT commented 4 years ago

I believe you need to include https://www.nuget.org/packages/Microsoft.PowerShell.Native

Microsoft.PowerShell.Native 6.2.0
Native binaries for PowerShell Core
jnevins-gcm commented 4 years ago

@SteveL-MSFT already tried this

....did you try it?

SteveL-MSFT commented 4 years ago

@jnevins-gcm sorry, didn't see all the details of your report. I did try this and noticed that dotnet run fails, but if I explicitly run the built exe it works (in the sense it tired to connect)

Unhandled exception. System.Management.Automation.ActionPreferenceStopException: The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: [outlook.office365.com] Connecting to remote server outlook.office365.com failed with the following error message : Client did not get proper response from server. For more information, see the about_Remote_Troubleshooting Help topic.
   at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input)
   at System.Management.Automation.Runspaces.Pipeline.Invoke()
   at System.Management.Automation.PowerShell.Worker.ConstructPipelineAndDoWork(Runspace rs, Boolean performSyncInvoke)
   at System.Management.Automation.PowerShell.Worker.CreateRunspaceIfNeededAndDoWork(Runspace rsToUse, Boolean isSync)
   at System.Management.Automation.PowerShell.CoreInvokeHelper[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
   at System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
   at System.Management.Automation.PowerShell.CoreInvoke[TOutput](IEnumerable input, PSDataCollection`1 output, PSInvocationSettings settings)
   at System.Management.Automation.PowerShell.Invoke(IEnumerable input, PSInvocationSettings settings)
   at System.Management.Automation.PowerShell.Invoke()
   at wsman.Program.Main(String[] args) in /Users/steve/test/wsman/Program.cs:line 25
jnevins-gcm commented 4 years ago

thanks @SteveL-MSFT - what is the difference? how can I make a debugging experience function?

SteveL-MSFT commented 4 years ago

I don't know why dotnet run fails. You may have to bring that up in the dotnet CLI repo. Based on the traces it loads the necessary library, but unloads it for some reason. Running the exe directly doesn't unload that library.

jnevins-gcm commented 4 years ago

Got to trying this. Same error when calling "dotnet mydll"

You sure you actually got this to work via the command line?

jnevins-gcm commented 4 years ago

@SteveL-MSFT any updates? seems like a bug in PowerShell Core....

jnevins-gcm commented 4 years ago

@SteveL-MSFT @iSazonov

looking to get some/any support here please. PowerShell is supposedly actively supported by Microsoft and this is clearly a bug.

iSazonov commented 4 years ago

@jnevins-gcm Sorry, I haven't Mac to investigate. If you shared your project or sample project it would help MSFT experts.

jnevins-gcm commented 4 years ago

The sample code I posted, exactly as is, in an out of box csproj console app will reproduce the problem.

iSazonov commented 4 years ago

Having GitHub ready-to-run project would save reviewer's time.

jnevins-gcm commented 4 years ago

@iSazonov @SteveL-MSFT

ok....

https://github.com/JeffN825/PowerShellWSManBug

It's a simple csproj and Program.cs copied straight from my original post.

dotnet build
cd bin/Debug/netcoreapp2.2/
dotnet PowerShellWSManBug.dll 

would be great to get a resolution

GitHub
JeffN825/PowerShellWSManBug
Contribute to JeffN825/PowerShellWSManBug development by creating an account on GitHub.
iSazonov commented 4 years ago
netcoreapp2.2

We never targeted 2.2. Can you try 2.1?

jnevins-gcm commented 4 years ago

doesn't work

jnevins-gcm commented 4 years ago

@iSazonov @SteveL-MSFT

bump...any fix for this bug? I spent the time putting together that sample...would be great if you could reciprocate.

iSazonov commented 4 years ago

@jnevins-gcm I haven't MacOs to investigate the issue, sorry. Since you are using SDK I guess you can use debugger and I suggest to use a native dll handler (see #11032) and catch a path to openssl.dylib. This can help to get understanding where is a problem or even to fix it in OS or in your code.

jnevins-gcm commented 4 years ago

Very frustrating that there is one single person who supports/replies to bugs in PowerShell and they have no access to platforms that PowerShell claims to support.

@iSazonov how do I leverage what’s in the PR you linked to? Some basic direction would be helpful.

vexx32 commented 4 years ago

@jnevins-gcm keep in mind this is Thanksgiving weekend in the US, where the entire PS team is based. I'm sure they're all spending time with their families. :slightly_smiling_face:

jnevins-gcm commented 4 years ago

@vexx32 I'll be happily surprised if I get a helpful reply next week.

I opened this issue on September 23, more than 2 months ago and the team has been mostly unresponsive and I have not received any reply that has been useful.

iSazonov commented 4 years ago

Very frustrating that there is one single person ...

I am a community member like you and have limited resources and time. :-(

how do I leverage what’s in the PR you linked to?

I suggest to add the native dll handler in your project and set breakpoint. I guest you get more info that assembly is trying to load and that is path to native dll is. After that we could get understanding how fix this or make a workaround.

I opened this issue on September 23

We have some issues like this and I already pinged MSFT team. I hope they will look in depth because WSMan is sensitive. /cc @SteveL-MSFT

jnevins-gcm commented 4 years ago

@iSazonov - sorry, I didn't realize you were not with MS. I appreciate your time on this.

Knowing that makes Microsoft's lake of support even more frustrating.

davesil2 commented 4 years ago

do you see the openssl dependencies when you use otool?

ie: otool -L /usr/local/microsoft/powershell/6/libmi.dylib /usr/local/microsoft/powershell/6/libmi.dylib: @rpath/libmi.dylib (compatibility version 0.0.0, current version 0.0.0) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1238.60.2) /usr/lib/libpam.2.dylib (compatibility version 3.0.0, current version 3.0.0) /usr/local/opt/openssl/lib/libssl.1.0.0.dylib (compatibility version 1.0.0, current version 1.0.0) /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib (compatibility version 1.0.0, current version 1.0.0) /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.8)

did you install powershell with brew or downloaded through the packages on GitHub?

did you install openssl from brew, macports, other?

does the file dependency for libssl.1.0.0.dylib and libcrypto.1.0.0.dylib exist?

jnevins-gcm commented 4 years ago

@davesil2

 otool -L /usr/local/microsoft/powershell/6/libmi.dylib
/usr/local/microsoft/powershell/6/libmi.dylib:
    @rpath/libmi.dylib (compatibility version 0.0.0, current version 0.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1238.60.2)
    /usr/lib/libpam.2.dylib (compatibility version 3.0.0, current version 3.0.0)
    /usr/local/opt/openssl/lib/libssl.1.0.0.dylib (compatibility version 1.0.0, current version 1.0.0)
    /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib (compatibility version 1.0.0, current version 1.0.0)
    /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.8)

for PowerShell 6 CLI (which works).

and for PowerShell.SDK

otool -L /Users/jeff/dev/PowerShellWSManBug/bin/Debug/netcoreapp2.2/publish/runtimes/osx/native/libmi.dylib 
/Users/jeff/dev/PowerShellWSManBug/bin/Debug/netcoreapp2.2/publish/runtimes/osx/native/libmi.dylib:
        @rpath/libmi.dylib (compatibility version 0.0.0, current version 0.0.0)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1238.60.2)
        /usr/lib/libpam.2.dylib (compatibility version 3.0.0, current version 3.0.0)
        /usr/local/opt/openssl/lib/libssl.1.0.0.dylib (compatibility version 1.0.0, current version 1.0.0)
        /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib (compatibility version 1.0.0, current version 1.0.0)
        /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.8)

which doesn't work

I installed PowerShell.SDK through a regular PackageReference.

The command line PowerShell (which works), I installed via brew.

does the file dependency for libssl.1.0.0.dylib and libcrypto.1.0.0.dylib exist?

how do I check this?

davesil2 commented 4 years ago

otool shows the dependency:

/usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib

Do those files exists?

ls -la /usr/local/opt/openssl/lib/

I've also had issues with the file not existing in the standard library directory myself:

ls -la /usr/local/lib/libssl.1.0.0.dylib ls -la /usr/local/lib/libcrypto.1.0.0.dylib

you didn't mention what version of openssl you are running or how you installed it?

jnevins-gcm commented 4 years ago

I'm not really sure what to make of the latter missing libraries @davesil2

Jeffs-MacBook-Pro:~ jeff$ ls -la /usr/local/opt/openssl/lib/
total 11664
drwxr-xr-x  11 jeff  staff      352 Oct 20 19:19 .
drwxr-xr-x  13 jeff  staff      416 Oct 20 19:19 ..
drwxr-xr-x  14 jeff  staff      448 May 28  2019 engines
lrwxr-xr-x   1 root        staff       14 Sep 22 19:33 lib -> /opt/local/lib
-rw-r--r--   1 jeff  staff  1864096 Jun 24 17:11 libcrypto.1.0.0.dylib
-r--r--r--   1 jeff  staff  3208352 May 28  2019 libcrypto.a
lrwxr-xr-x   1 jeff  staff       21 May 28  2019 libcrypto.dylib -> libcrypto.1.0.0.dylib
-r--r--r--   1 jeff  staff   371128 Jun 24 17:11 libssl.1.0.0.dylib
-r--r--r--   1 jeff  staff   517904 May 28  2019 libssl.a
lrwxr-xr-x   1 jeff  staff       18 May 28  2019 libssl.dylib -> libssl.1.0.0.dylib
drwxr-xr-x   5 jeff  staff      160 Jun 24 17:11 pkgconfig

Jeffs-MacBook-Pro:~ jeff$ ls -la /usr/local/lib/libssl.1.0.0.dylib
ls: /usr/local/lib/libssl.1.0.0.dylib: No such file or directory

Jeffs-MacBook-Pro:~ jeff$ ls -la /usr/local/lib/libcrypto.1.0.0.dylib
ls: /usr/local/lib/libcrypto.1.0.0.dylib: No such file or directory

I have tried installing openssl both via MacPorts and Homebrew (both with negative results). Currently I'm running a copy installed via MacPorts (1.1.1d)

davesil2 commented 4 years ago

So for me, what i've had to do was to create the symlink for libssl.1.0.0.dylib and lib crypto.1.0.0.dylib.

ln -s /usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/lib/ ln -s /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib /usr/local/lib/

This should create a symlink in /usr/local/lib/ for that file. This has provided me success in using psremoting as it appears there may be some reference to that library (for me I can't get it to work on Catalina though it works find on Mojave).

One thing that doesn't make sense to me is that you have 1.1.1d from macports installed but you have the 1.0.0 library? did you install both 1.1.1d and 1.0 ?

The other option would be to reset your openssl installs. I've had the best results with brew (for the most part).

you'd need to remove the macports install:

ports uninstall installed

**Note: removes all macports installed, you can also just do openssl and openssl10

brew install openssl ln -s /usr/local/opt/openssl/lib/libcrypto.1.1.dylib /usr/local/lib/libcrypto.1.0.0.dylib ln -s /usr/local/opt/openssl/lib/libssl.1.1.dylib /usr/local/lib/libssl.1.0.0.dylib

As long as it's in Mojave, i've had pretty solid success, the symlinks being the key. Hoping @Microsoft can help with the Catalina side

jnevins-gcm commented 4 years ago

@davesil2 Tried:

ports uninstall installed
brew install openssl
brew install openssl
ln -s /usr/local/opt/openssl/lib/libcrypto.1.1.dylib /usr/local/lib/libcrypto.1.0.0.dylib
ln -s /usr/local/opt/openssl/lib/libssl.1.1.dylib /usr/local/lib/libssl.1.0.0.dylib

and didn't work (but I recently updated to Catalina so that is probably why)

jnevins-gcm commented 4 years ago

@davesil2 I’be given up hope that @microsoft cares (or is capable of) supporting this platform

daviscyd commented 4 years ago

@davesil2 & @jnevins-gcm

Here's the error I'm seeing after running the link commands mentioned and connecting to Exchange Online using New-PSSession: Symlink commands:

ln -s /usr/local/opt/openssl/lib/libcrypto.1.1.dylib /usr/local/lib/libcrypto.1.0.0.dylib
ln -s /usr/local/opt/openssl/lib/libssl.1.1.dylib /usr/local/lib/libssl.1.0.0.dylib

Error:

dyld: lazy symbol binding failed: Symbol not found: _SSL_library_init
  Referenced from: /usr/local/microsoft/powershell/6/libmi.dylib
  Expected in: /usr/local/lib/libssl.1.0.0.dylib

dyld: Symbol not found: _SSL_library_init
  Referenced from: /usr/local/microsoft/powershell/6/libmi.dylib
  Expected in: /usr/local/lib/libssl.1.0.0.dylib
russburden commented 4 years ago

I see the exact same error on my Catalina 15.1 Mac as well. I have spent many hours going through all of the iterations of this issue with no positive results. I'm basically backing down to using a Windows VM again just to accomplish 365 related tasks since PSSessions don't seem to work within PSCore and the newer libssl and libcrypto.

JeffN825 commented 4 years ago

@tthoma24 can you provide the exact command you used? and were you using powershell CLI or SDK (this post is about the SDK...I've had success using the CLI)

tthoma24 commented 4 years ago

Ah, never mind. My issue is with the CLI. Sorry for the confusion.

daviscyd commented 4 years ago

@JeffN825 Could you provide a link or info as to how you were able to get the CLI to work with o365?

jnevins-gcm commented 4 years ago

@daviscyd i just did the sudo ln commands mentioned in https://github.com/PowerShell/PowerShell/issues/5561

Glennzo commented 4 years ago

I had the same issue, managed to solve it by linking an older openssl version from brew with brew switch openssl 1.0.2s

jnevins-gcm commented 4 years ago

@Glennzo were you using the PowerShell CLI or the SDK nuget package. This issue is about the SDK nuget package.

daviscyd commented 4 years ago

@daviscyd i just did the sudo ln commands mentioned in #5561

@jnevins-gcm Are they the same as those mentioned in this thread here? Because if they are, I've already tried this and it doesn't work for me.

What OS are you running?

davesil2 commented 4 years ago

@Glennzo How did you install 1.0.2s? When running that, brew tells me there is no package for that version.

pyrohaz4good commented 4 years ago

I had the same issue, managed to solve it by linking an older openssl version from brew with brew switch openssl 1.0.2s

This is the solution. If you have brew, type brew switch openssl 1.0.2s

This only works if you had previously downloaded openssl because it's no longer available in the tap. If you can't get that to work, you probably need to manually find the files from 1.0.2s and symlink them in.

jnevins-gcm commented 4 years ago

@pyrohaz4good SDK or CLI?

pyrohaz4good commented 4 years ago

Name Value


PSVersion 6.2.0 PSEdition Core GitCommitId 6.2.0 OS Darwin 18.5.0 Darwin Kernel Version 18.5.0: Mon… Platform Unix PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…} PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1 WSManStackVersion 3.0