Addition of Windows job objects in v1.9.1 of the client break cross-session spawning
In Nomad 1.9.1 (which was a patch release) a change was made to cause Nomad to kill child processes via the usage of Windows job objects as a result of this issue but had the side effect of changing the behaviour of the runtime environment of the job.
The session that Nomad runs in is unsuitable for certain use cases, and the user option does not help: it changes the identity a process runs as but leaves it in session 0. In particular, it's often necessary to use sessions which have a desktop either because the application we want to run uses the desktop, or in many cases because even when running the application in a non-graphical mode, it still breaks without the presence of a desktop.
In these cases it's necessary for us to perform cross-session spawning (e.g. by using WTSQueryUserToken to get the token of an RDP session we have ensured exists for this purpose). However, Windows documents that all processes within a job must run within the same session as the job, so a call to CreateProcessAsUserW fails with a permissions error whereas it would have succeeded without the presence of the Windows job object.
Currently we are having to work around this by doing a build of the Nomad client in which we add JOB_OBJECT_LIMIT_BREAKAWAY_OK to the job object flags. Combined with passing CREATE_BREAKAWAY_FROM_JOB to CreateProcessAsUserW this enables cross-session spawn to work.
This issue is present as of the latest release (2.0.4).
Suggestions for a fix include adding an option to allow opt-out of the Windows job object or adding the JOB_OBJECT_LIMIT_BREAKAWAY_OK flag which allows applications that are aware that they may be running inside a Windows job object to explicitly indicate intent that they wish to break away from it. The latter leaves the original behaviour intact: the job object still kills its members when the executor exits, and only a child that explicitly asks to break away does so.
Source: hashicorp/nomad