I am having security issues with lab management and standard environments.
I have TFS2012 update 2 installed in my domain "DevDomain". I have a separate build/lab machine also in "DevDomain" on which both a build controller, build agents and a test controller for the same collection "CollectionA" are installed.
Automated builds work just perfectly.
I have deployment target PCs in "DevDomain" and in "TestDomain" (more on that later).
To take this to the next level, I want to now automatically deploy the TFS build agent constructed software to test rig machines; specifically I want to have a deployment script uninstall the existing product, copy the updated installer onto the target PC and then install it.
My first foray was to define a standard environment in my "DevDomain" and get the deployment part of a lab build working within the same domain.
This worked. Here is what I did;
The automated build (using the DefaultTemplate.xaml process) creates a MSI file I want to use for the deployment, and a PowerShell script which I want to run to orchestrate the deployment. (the script simply attempts to run the MSI via msiexec to uninstall, copy the new version locally then run it via msiexec to install the new copy). The automated build happily makes both these artefacts and puts them in the defined TFS drop share.
In order to go about this I have:
- Created a new standard lab environment with a single machine (desktop client role)
- The lab manager successfully deployed the agent to this PC
- the agent is running interactive and showing its online.
- Created a new build definition using the LabDefaultTemplate.11.xaml workflow.
- referenced the above lab in the configuration
- referenced the latest output of the automated build in config
- specified the build output PowerShell script (via the $(BuildLocation) macro.
This deploy tab of the build specifies the following script to be run on the machine sin the lab with "Desktop Client" role:
cmd /c powershell.exe "$(BuildLocation)\DeployGuiToLabWorkstation.ps1" "$(BuildLocation)"
This works.
Note that I am configuring test agents to run as interactive processes as my ultimate aim after the deployment works is to drive coded UI tests on these labs.
The problems start when trying to deploy to a machine in a different domain Now to make this more realistic I now need to define a standard lab environment for my QA machines, which are in a different domain; "TestDomain".
The domain "TestDomain" has a trust relationship with the domain "DevDomain". There is no reciprocal trust between "DevDomain" and "TestDomain"
Again the test manager lab centre defined this OK and deployed the agent, and the agent reported itself online to my test controller.
Now when I change the lab build to reference the new standard environment (on "TestDomain") the deployment fails with this error;
Exception Message: Team Foundation Server could not complete the deployment task for
machine '10.7.70.71', script 'cmd' and arguments '/c copy \\*buildmachine*
\TFS_Drop\...\DeployGuiToWorkstation.ps1 C:\GuiDeploy'. (type LabDeploymentProcessException)
In order to diagnose this I have modified the lab deploy script to be:
"cmd /c powershell whoami"
And according to the logs the process is being run as "nt authority\system" and not the account the lab environment specified for the test agent.
This explains the script error; PowerShell on the target PC cannot access the TFS drop share, but since this account is a local machine account I cant possibly grant permissions to the machine account of a PC in "TestDomain" to a share and NTFS folder on a machine in "DevDomain"
So how can I grant permissions on the "devDomain" share/filesystem to a "System" service account from a machine in "TestDomain"?
or
How do I get the test agent (running as a local machine administrator) to execute the deployment script in its own account context rather then this machine system context?
I am stumped!
EDIT: It seems that the test agent UI runs in the account you specify, but when you configure it that way it leaves the service "Visual Studio Lab Agent Service" running as local system, you can manually change this in services, to a more appropriate domain account and that account is then reflected in the PS "whoami" results.
I am now investigating using a TestDomain account for the service that mirrors a "DevDomain" account so I can set share permissions appropriately.
This is a similar scenario to TFS Lab management Deployment Scripts but since that was side-stepped by using tests and test settings, and I specifically want a resolution of the deploy part I thought it worth asking the question.