StackExchange / dnscontrol

Infrastructure as code for DNS!
https://dnscontrol.org/
MIT License
3.07k stars 389 forks source link

MSDNS: Enable MSDNS to work from Linux host #1731

Open tuananh opened 2 years ago

tuananh commented 2 years ago

Running on Non-Windows systems Currently this driver disables itself when run on Non-Windows systems. It should be possible for non-Windows hosts with PowerShell Core installed to execute commands remotely via > SSH. The module used to talk to PowerShell supports this. It should be easy to implement. Volunteers requested.

I just want to ask is this feature already implemented? Has anyone try this?

tlimoncelli commented 2 years ago

Hi there!

As far as I know, nobody is working on this.

If someone volunteers, I'd be glad to support them and answer questions.

Here's my suggestions:

  1. If PowerShell Core supports pssession, then support is already complete. Simply enable the provider for non-Windows systems, verify pssession works, and update the docs to explain how to use it.
  2. If you want real SSH support, in powershell.go replace newPowerShell() is what needs to change.
tuananh commented 2 years ago

@tlimoncelli thank you. lemme try it to see if it works.

if not, maybe i can dive into it.

tlimoncelli commented 2 years ago

If you do dive in, here's a start. I split out the Windows vs. non-Windows code: https://github.com/StackExchange/dnscontrol/pull/1733

tlimoncelli commented 1 year ago

Friendly ping? Would love to see if this is possible.

tuananh commented 1 year ago

@tlimoncelli sorry I don't have the capacity to do this at the moment. Maybe someone else can jump it?

tlimoncelli commented 1 year ago

No worries! I'm just pinging old tickets.

I'm going to close this issue. There doesn't seem to be demand for this feature. If new demand appears, we can re-open this issue.

n-rodriguez commented 11 months ago

@tlimoncelli

No worries! I'm just pinging old tickets.

I'm going to close this issue. There doesn't seem to be demand for this feature. If new demand appears, we can re-open this issue.

Hi there!

I've hacked around to try to make it works "as is" and took another approach influenced by https://github.com/profesorfalken/jPowerShell (I don't know if what follows matches with what you had in mind at that time but here it is 😄 )

By looking at their code I saw in https://github.com/profesorfalken/jPowerShell/blob/master/src/main/java/com/profesorfalken/jpowershell/PowerShell.java#L55 (and https://github.com/profesorfalken/jPowerShell/blob/master/src/main/java/com/profesorfalken/jpowershell/PowerShell.java#L130) that they can shellout PowerShell commands to any PowerShell CLI installed and discovered that a Linux version of PowerShell exists (https://learn.microsoft.com/en-us/powershell/scripting/install/install-debian?view=powershell-7.3) (I didn't know that 🙄 )

So I installed PowerShell on my Debian 11, made a symlink between /usr/bin/pwsh and /usr/local/bin/powershell.exe (because it's hardcorded https://github.com/bhendo/go-powershell/blob/master/shell.go#L31) and disabled OS check in dnscontrol https://github.com/StackExchange/dnscontrol/blob/fa890063a18fb97470b1b4b47318e016bc2b5b85/providers/msdns/msdnsProvider.go#L49-L52

But still, it doesn't work... The command hangs forever (and never timeout).

I suspect it's due to how things are escaped as it runs on Linux and might be linked to https://github.com/StackExchange/dnscontrol/pull/1733

But before going any further I wanted to see with you if it was the way to go.

Thank you! 👍

Edit:

It should also works on MacOS : https://stackoverflow.com/a/70421665

To check that WinRM works (MacOS or Linux) :

powershell.exe -Command "New-PSSession -ComputerName server.ad.corp -Credential dnscontrol"
tlimoncelli commented 11 months ago

Yes! I think this is a good direction.

By the way... go-powershell is abandoned. We should either adopt something different, write our own, or fork go-powershell and make our own changes.