salt icon indicating copy to clipboard operation
salt copied to clipboard

cmd.run priviliges on windows minion

Open shantanub opened this issue 13 years ago • 3 comments

I'd like to control the insertion and removal of DNS records and DHCP leases/reservations in Active Directory for all of our Linux hosts/VMs. These hosts/VMs can easily have at least 4 IPs each depending which VLANs they have access to and it's really hard to maintain this manually and I'd prefer not to have to write powershell to do all of this if possible (I've written some of it with WMI and powershell and I can't say I enjoy it).

So before we get too far, I'd just like to be able to get basic command execution returning results.

I'm finding cmd.run isn't executing my calls to dnscmd with sufficient privileges (not surprising):

when run in a command prompt with my A/D Domain admin user:


C:\>dnscmd dc-name-goes-here /enumzones

Enumerated zone list:
        Zone count = 17

 Zone name                      Type       Storage         Properties

 .                              Cache      AD-Domain
 _msdcs.domain.org            Primary    AD-Forest       Secure Aging
 a.b.in-addr.arpa              Primary    AD-Forest       Update Rev Aging
 c.d.e.in-addr.arpa          Primary    AD-Domain       Secure Rev Aging
 <snip>
 domain2.org                  Forwarder  AD-Forest
 domain.org                   Primary    AD-Domain       Update Aging
 TrustAnchors                   Primary    AD-Forest       Aging

Here is when I try running the same command from the same host via salt's cmd.run module on the salt master:


[root@salt-master ~]# salt -v "win-dev*" cmd.run "dnscmd dc-name-goes-here /enumzones"
Executing job with jid 20131026090518282166
-------------------------------------------

win-dev:

    Zone enumeration failed
        status = 5 (0x00000005)
    Command failed:  ERROR_ACCESS_DENIED     5    0x5

The salt-minion is set to run as a "Local System" service. Do I just need to replace the "Local System" start as privileges with an A/D privileged service account that has a tailored permission set for the service access we need?

I tried to in fact do this but I can't get the salt-minion service to start when I change the "Log On As" user to a privileged A/D account.

The error is as follows:


Windows could not start the salt-minion service on Local Computer.

Error 5: Access is Denied.

I try the same thing with shelled out calls to netsh dhcp server and here it errors out but with a cryptic error that suggests something else may be in play (although permissions could be playing a role).

add a dhcp reservation from the command prompt:

netsh dhcp server <dhcp-server-ip-goes-here> scope <scope-ip-goes-here> add reservedip a.b.c.d abc123abc123 test123.domain.org added-by-script

Changed the current scope context to <scope-ip-goes-here> scope.

Command completed successfully.

when I try this from the salt-master via cmd-run:


[root@salt-master ~]# salt -v 'win-dev*' cmd.run "netsh dhcp server <dhcp-server-ip-goes-here> scope <scope-ip-goes-here> add reservedip a.b.c.d abc123abc123 test123.domain.org added-by-script"

Executing job with jid 20131026155559514704
-------------------------------------------

win-dev.trailmix.net:

    The command needs a valid Scope IP Address.

Normally I would think I've entered something in wrong, but I'm literally copying and pasting commands from the command prompt and what I'm trying to execute via cmd.run via salt. Is this just a poorly worded error message associated with salt not having access to the referenced scope in DHCP? I can't tell.

shantanub avatar Oct 26 '13 20:10 shantanub

Managing DNS and DHCP has been on my list of things I've wanted to add for quite a while! I'll do some testing to see what rights the salt minion must have. I'd like to build out a nice set of execution modules and states for dns and dhcp.

Let us know if you make any more progress and I'll keep my progress noted here, too

UtahDave avatar Oct 26 '13 21:10 UtahDave

Alright. I have to fess up that this in fact does work and I'm an idiot.

I certainly created an A/D user for salt but then promptly forgot to add it to "Domain Admins". The salt-minion now starts as this user and has sufficient privileges to perform netsh and dnscmd requests.

That said, I could still use a cleaner salt API way of interacting with A/D. cmd.run will work for my needs now and I'm now working on a way to perform updates to existing reservations and dns entries (polling clients, diffing with what's in the directory and then updating entries with calls to delete and add).

shantanub avatar Nov 06 '13 00:11 shantanub

@shantanub Could you create a new issue for the Active Directory improvements? Repurposing issues sometimes causes confusion and is not as clean. I'm going to close this one since it sounds like it's not an issue.

basepi avatar Nov 06 '13 19:11 basepi