Active Directory
Sooner or later a workflow has to touch Active Directory: create an account for a new starter, add a service account to a group, put a new server’s computer object in the right OU, or check who’s in a group before granting access. The Active Directory plug-in does this over LDAP, with users, groups, computers, and organizational units as inventory objects, and around forty ready-made workflows.
In this recipe you register a domain controller over LDAPS, create an OU and a group with the built-in workflows, and write a workflow that creates a user with a password, makes it change the password at the next logon, and adds it to the group.
Getting ready
- A domain controller that Orchestrator can reach on TCP 636 (LDAPS), with a certificate. This recipe uses
dc01.vmw.labin the domainvmw.lab. - A service account,
svc-vcfguide-ad@vmw.lab, that may create and change users and groups in the OU this recipe creates. Delegate that right on the OU rather than making the account a domain administrator. - A login with administrator rights, the action module
com.vcfguide.chapter5, and the workflow folder VCF Orchestrator Guide/Chapter 5.
How to do it
Register the domain controller
- Go to Library > Workflows, search with the tags
active_directoryandconfiguration, and run Add an Active Directory server. - Enter the host
dc01.vmw.lab, the port636, and the rootDC=vmw,DC=lab. Set Use SSL to Yes, and enter the default domain@vmw.lab. - Choose a shared session, and enter the user
svc-vcfguide-ad@vmw.laband its password. - On the Alternative hosts tab, leave the load-balancing choice at Single Server. Click Run.
- Go to Administration > Inventory > Active Directory. Expand
dc01.vmw.lab: the containers and OUs of the domain are listed.
Run dialog of Add an Active Directory server: host dc01.vmw.lab, port 636, root DC=vmw,DC=lab, Use SSL = Yes, default domain @vmw.lab; the shared-session and Alternative hosts tabs visible.
dc01.vmw.lab:636.Create an OU and a group
- Search with the tags
active_directoryand run Create an organizational unit. Select the domain’s root in the inventory picker as the parent, and enter the nameVCF Guide. - Run Create a user group in an organizational unit. Enter the group name
vcfguide-usersand select the OUVCF Guide. - In the inventory, refresh
dc01.vmw.lab. The OUVCF Guideholds the groupvcfguide-users.
Create users from a workflow
- In Library > Actions, create the action
findAdUserincom.vcfguide.chapter5, with the inputaccountNameof typestringand the Return typeAD:User:
// Returns the user with exactly this account name, or null.// searchExactMatch can also return users whose names are only similar,// so check the account name of each result.var candidates = ActiveDirectory.searchExactMatch("User", accountName, 10);for (var i = 0; i < candidates.length; i++) { var name = candidates[i].getAttribute("sAMAccountName"); if (name && String(name).toLowerCase() === accountName.toLowerCase()) { return candidates[i]; }}return null;- Create the workflow Create lab user in VCF Orchestrator Guide/Chapter 5, with these inputs and one output:
| Name | Type | Use |
|---|---|---|
ou |
AD:OrganizationalUnit |
Where the user is created: VCF Guide |
accountName |
string |
The logon name, such as jdoe |
displayName |
string |
The full name, such as Jane Doe |
password |
SecureString |
The first password |
group |
AD:UserGroup |
A group to add the user to: vcfguide-users |
user (output) |
AD:User |
The new user |
- Add one scriptable task, Create user, with this script:
var chapter5 = System.getModule("com.vcfguide.chapter5");
if (!/^[A-Za-z0-9._-]{1,20}$/.test(accountName)) { throw "Create lab user: account names are 1-20 letters, digits, dots, dashes or underscores";}if (chapter5.findAdUser(accountName)) { throw "Create lab user: " + accountName + " already exists";}
ou.createUserWithPassword(accountName, password, "vmw.lab", displayName);user = chapter5.findAdUser(accountName);if (!user) { throw "Create lab user: " + accountName + " was created but can't be found";}
user.setChangePasswordAtNextLogon(true);group.addElements([user]);System.log("Created " + accountName + " (" + displayName + ") in " + ou.name + " and added it to " + group.name);- On the Inputs tab of the workflow’s input form, set
ouandgroupto default toVCF Guideandvcfguide-users, and save. - Run the workflow with
jdoe,Jane Doe, and a password that meets the domain’s password policy. The log names the OU and the group. - In Active Directory Users and Computers, open
jdoein VCF Guide: User must change password at next logon is set, and Member Of listsvcfguide-users.
Run of Create lab user for jdoe, Logs tab with Created jdoe (Jane Doe) in VCF Guide and added it to vcfguide-users; the Variables tab with user set; password hidden.
The API reference for 9.x gives createUserWithPassword(accountName, password, domainName, displayName), returning nothing.
vmw.lab or @vmw.lab, whether a SecureString input can be passed as the password, whether the new account is enabled or must be enabled with Enable a user, and that searchExactMatch, getAttribute(“sAMAccountName”), setChangePasswordAtNextLogon, and addElements work as shown.How it works
One connection, many objects. Add an Active Directory server stores the host, the root, and the account, and opens LDAP connections when a workflow needs them. Everything below the root shows up in the inventory, and each LDAP entry becomes the type that matches its object class: AD:User, AD:UserGroup, AD:Computer, AD:OrganizationalUnit, or AD:Group for a plain container. That’s why the workflow’s inputs can be typed as an OU and a group: the input form shows a picker of real objects, and the script gets objects with methods, not strings.
Why LDAPS? Active Directory accepts a password only over an encrypted connection. Without SSL, the plug-in can create a user but not give it a password: Broadcom’s documentation for Change a user password and Create a user with a password in an organizational unit says so. Port 636 with Use SSL also keeps the service account’s password off the wire.
Why check the account name? ActiveDirectory.searchExactMatch finds objects by name, and Broadcom documents that it can return a user whose name is only similar to the one you asked for, because the first match wins (KB 453685). Asking for up to ten results and comparing sAMAccountName yourself makes findAdUser return the right user or none. The same check makes step 11 refuse to create a duplicate.
Validate before you call. The script checks the account name against a short pattern before it reaches AD, so a name with spaces or @ fails with a clear message rather than an LDAP error. Do the same on the input form (recipe 3.6), so users see the rule before they click Run.
There's more
Several domains. With more than one server registered, searches go to the default one unless you name another. Get the server and pass it as the last argument:
var hosts = AD_HostManager.findAllHosts();var lab2 = null;for (var i = 0; i < hosts.length; i++) { if (hosts[i].name === "dc01.lab2.vmw.lab") { lab2 = hosts[i]; }}var users = ActiveDirectory.searchExactMatch("User", "jdoe", 10, lab2);On 9.1.1, Server.findAllForType("AD:AdHost", null) lists the registered servers, and each one’s name is the configuration name shown in the inventory. Url holds the address the plug-in actually connects to.
More than one domain controller. On the Alternative hosts tab of Add an Active Directory server or Update an Active Directory server, list the other domain controllers and choose Round-Robin, Failover, or Round-Robin DNS Server. If runs fail with LDAPException(resultCode=91 (connect error)) and a timeout on port 636, raise the connection timeout on the Advanced tab of Update an Active Directory server, or add alternative hosts (KB 395023).
LDAP filters. The search functions match names. To find, say, every disabled user in an OU, or users by their mail attribute, get an LDAP client from the server with getLdapClient(), search with an LDAP filter, and close it when done.
The workflow library. Search with the tags active_directory and user, user_group, computer, or organizational_unit. There are workflows to create, enable, disable, and destroy users and computers, change passwords, and manage group members. Use them as they are, or read their scripts for the calls you need.
Machines from VCF Automation. VCF Automation 9.0 no longer adds new machines to Active Directory by itself. Broadcom’s replacement is an extensibility subscription that runs an Orchestrator workflow with the computer workflows from this plug-in (KB 393273). Chapter 8 covers subscriptions.
See also
- 3.6 Building input forms, for defaults and validation on the form.
- 4.7 Configuration elements in code, to keep the default OU and group in one place.
- 5.1 How plug-ins work, for configuration workflows and the inventory.
- Broadcom TechDocs (VCF 9.0): Using the Active Directory plug-in, Using the Active Directory plug-in workflow library, and Client-side load balancing for the Active Directory plug-in.
- Broadcom TechDocs (Aria Automation 8.17): Active Directory plug-in workflow library and Client-side load balancing.
- Broadcom KB 453685:
searchExactMatchreturns a similar user. KB 395023: connection timeouts on port 636. KB 393273: adding VCF Automation machines to AD. - VMware’s TypeScript definitions for the Active Directory plug-in, in build-tools-for-vmware-aria.
- CloudBlogger, the author’s blog: How to Unlock an AD User Account Using vRO.
