Active Directory Service Integration / Improvements
As requested by @basepi in https://github.com/saltstack/salt/issues/8119, I'm re-opening this issue as a feature request.
I am currently adding/updating/deleting entries from DNS and DHCP using netsh and dnscmd using the remote command execution framework and run states. The salt-minion executing these commands requires the minion service to be started as a privileged A/D user.
Updates are complicated since netsh/dnscmd do not support "updates" directly, so I need to first determine if an update is required and then delete the current entry in DNS and DHCP before adding its replacement. This requires some set logic to compare the current state of all of my hosts/VMs with what's in DNS and DHCP. I will likely do this in memory from within python to start with (using dictionaries as hash tables perhaps) but will eventually move the set subtraction to redis probably.
It would be very helpful if we had functions in salt that provided add, delete and update/modify semantics for both DNS and DHCP in A/D.
Other A/D integration features like user management, user lookup (with member-of group lookups - including nested groups), etc.. would also be helpful but are secondary to anything I need at the moment.
@shantanub this sounds fantastic. I've assigned this to myself and added it to the Approved for future release milestone.
I won't be able to get started on this for probably a week at least. When I do get started I'm sure I'll need help working with netsh and dnscmd commands, since I've only worked lightly with the gui for dns and dhcp settings on Windows.
Could you add some comments to this thread with examples of various commands and their results that you expect will be needed?
Thanks!
Sorry about the delay in getting back to this, I've been tracking down some alien crosstalk issues in the data center - not fun...
Before we start the salt-minion on the windows host running the commands will need to be started by a domain user with sufficient privileges to make edits to DNS zones and DHCP leases.
DNS is probably easier to deal with than DHCP, so let's start there.
We'll need to specify the DC. It's likely easiest to do this by IP just in case hosts/servers are dual homed and DNS/DHCP aren't listening on all interfaces.
Arguments to pass into "add method":
dc_ip = "192.168.0.1"
dns_suffix = "test.org"
dns_name = "salt-minion-00.test.org"
ip_addr = "192.168.0.100"
reverse_dns_zone_1 = "0.168.192.in-addr.arpa."
reverse_dns_zone_2 = "168.192.in-addr.arpa." # example of wider reverse dns zone
So I want to just "add" a DNS entry with dnscmd (forward and reverse DNS need to be populated:
dnscmd 192.168.0.1 /recordadd test.org salt-minion-00.test.org. A 192.168.0.100
dnscmd 192.168.0.1 /recordadd 0.168.192.in-addr.arpa. 100 PTR salt-minion-00.test.org
If we were using a wider zone, the call to dnscmd would change slightly:
dnscmd 192.168.0.1 /recordadd test.org salt-minion-00.test.org. A 192.168.0.100
dnscmd 192.168.0.1 /recordadd 168.192.in-addr.arpa. 100.0 PTR salt-minion-00.test.org
Now say the address/name pair above was already in DNS and had to be updated. dnscmd doesn't have a modify/update method that I can find, so instead I need to perform a delete and add when a change occurs.
The semantics of what is an update need to be worked out, but in my case I want to ensure that if there is no change, that nothing is done (i.e. there is no delete or add in A/D), and if a hostname now points to a different ip address that it is updated to the new address (in forward and reverse DNS).
dnscmd 192.168.0.1 /recorddelete test.org salt-minion-00.test.org. A 192.168.0.100' /f
dnscmd 192.168.0.1 /recordadd test.org salt-minion-00.test.org. A 192.168.0.200
dnscmd 192.168.0.1 /recorddelete 168.192.in-addr.arpa. 100.0 PTR salt-minion-00.test.org /f
dnscmd 192.168.0.1 /recordadd 168.192.in-addr.arpa. 200.0 PTR salt-minion-00.test.org
The "/f" flags just indicate a force. This is because deletes are interactive if not forced.
I'm cheating a bit since I use dig with a zone transfer to pull all of the addresses currently in a given A/D zone and then do the diffs in memory to determine if updates are necessary. You can use nslookup or dig per address (reverse DNS) and hostname (forward DNS) to determine if that address needs to be updated instead.
"delete" methods would be just like the updates minus the adds. Nothing too complicated there. I have add/modify/delete methods and check to see with every highstate if any of my managed hosts need to be updated in A/D DNS.
DHCP netsh examples to follow in a bit.
re: DHCP / nesh
So DHCP is a bit easier if you expect the user to provide the scope. In that case you simply pass the following arguments in for an "add" method:
dc_ip = "192.168.0.1"
scope = "192.168.0.0" # this does not need to be passed in - and if it is not than calls to netsh must be made to determine the appropriate "container" for the reservation
reserved_ip = "192.168.0.100"
mac_addr = "001122334455"
hostname = "salt-minion-00.test.org"
comment = "managed-by-salt"
netsh doesn't allow separators in the supplied mac-address and I use the comment argument to indicate in A/D that the reservation is managed from within salt and shouldn't be manually mucked with.
The netsh call to "add" looks like this:
netsh dhcp server 192.168.0.1 scope 192.168.0.0 add reservedip 192.168.0.100 001122334455 salt-minion-00.test.org managed-by-salt
An update looks similar to the dns example above (with a delete first and then an add):
netsh dhcp server 192.168.0.1 scope 192.168.0.0 delete reservedip 192.168.0.100 001122334455
netsh dhcp server 192.168.0.1 scope 192.168.0.0 add reservedip 192.168.0.100 001122334455 salt-minion-00.test.org managed-by-salt
Now, IPs can change, mac addresses can change (our VMWare VMs have had mac addresses change in time because of changes to interfaces, some types of vmotions, etc...., we've had ports fail on physical hosts with bonding and need to account for changed mac addresses if any arp-based tracing is ever required), and hostnames can change. I even check to see if the comments field has changed since I use it to designate salt managed entries from normal reservations in DHCP. The callee may need to drive what is to be updated. I just assume everything I'm pulling from hosts is more accurate than what is in DHCP or DNS (this may not be appropriate in general).
If you don't want to be supplied the scope or would prefer to make it an optional argument, netsh gives you primitives to find what scopes are available:
netsh dhcp server 192.168.0.1 show scope
where "192.168.0.1" is your dc ip.
I don't create scopes dynamically with my script but if you'd like you can not only determine what scopes are present in A/D but add a scope if none of the current scopes are relevant/sufficient:
netsh dhcp server 192.168.0.1 add scope 192.168.0.0 255.255.255.0 test-org-scope managed-by-salt
from http://technet.microsoft.com/en-us/library/cc775619(v=ws.10).aspx.
Hope that was what you were looking for. Thanks.
ok found myself the solution was --> doubleqote not single quote single quotes would only be used if a argument would be separated by space
- args: "testserver24 192.168.1.100 mydomain.com 192.168.1.1"
- args: "testserver24 192.168.1.100 mydomain.com 192.168.1.1 'two commandargument''
Did this ever get done? definitely like to mange windows DNS from salt.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.
👍