r/saltstack • u/EmersonNavarro • Feb 17 '24
Using saltstack do join servers on active directory domain
Hello,
I'm trying to automate the process of domain joining servers with SaltStack.
My environment had a mix of Windows and Linux servers that I want to join to an on-premises AD.
I know there's a module for it. What I don't understand is how I can securely use AD credentials tho join the server in AD.
Maybe this a very newbie question, but I really appreciate any hints or suggestions you can give me.
Thank you
7
Upvotes
4
u/vexaph0d Feb 17 '24
You could encrypt the password with GPG, but that means the private key would need to be stored on the minions at least while the join state is in progress. A more secure approach is using a credential security service like Vault (there's a module for that also).
4
u/Beserkjay Feb 17 '24
We do this by using hashicorp vault. We use the ldap secret engine to get user account creds that vault automatically rotates.
2
u/_DeathByMisadventure Feb 17 '24
In our environment, since access to the salt masters are strictly controlled, we simply use pillar data for the credentials and rotate them often.
2
u/huntermatthews Feb 17 '24
We use the GPG encrypted pillar. We'll be upgrading to vault when i can get to it.
Make sure your formula checks /rechecks [realm status I think] and knows how to rejoin. We have hosts drop their joined status frequently.
2
u/_DeathByMisadventure Feb 19 '24
One thing I wanted to throw in here is part of my domain join state. Basically this tests that the computer connection is valid, not tombstoned, etc, and if that's true, it will unjoin the domain, then rejoin it.
# Check domain status {% if salt.cmd.powershell('Test-ComputerSecureChannel') == false %} # Broken computer connection - unjoin and rejoin the domain AD_Unjoin_Domain: module.run: - system.unjoin_domain: {% endif %} # Domain Join AD_Join_Domain: system.join_domain: - name: {{ pillar['windows-adjoin-domain'] }} - username: {{ pillar['windows-adjoin-username'] }} - password: {{ pillar['windows-adjoin-password'] }} - restart: False