Proposal Details
Allow adding Security Capabilities to SysProcAttr on Windows. Note this is separate from the existing SecurityAttributes struct which can be set as the ProcessAttributes or ThreadAttributes field.
Motivation
Recently as part of work to sandbox a subprocess, the Nomad team at HashiCorp needed to add a SECURITY_CAPABILITIES struct to the StartupInfoEx for a process. Because this is not exposed in SysProcAttr this involved writing an unfortunate amount of code, much of which had to be simply lifted from the os/exec stdlib. See helper/winexec/create.go
Implementation Notes
Previously a proposal was implemented to add a ParentProcess field to SysProcAttr for Windows #44011. This was discussed around the same time as a rejected proposal to add the full StartupInfoEx struct #44005.
One of the reasons why the StartupInfoEx proposal was rejected was because it resulted in ambiguity around how one would merge any default attributes with ones provided by the user. There are two options to work around this:
Option 1: Extensible
Our implementation referenced above adds a ProcThreadAttributes field to the forked os/exec.Cmd which is a slice of ProcThreadAttribute. This instead could be added to SysProcAttr as an extensible way of adding more attributes:
type SysProcAttr struct {
// ...
ProcThreadAttributes []ProcThreadAttribute
}
type ProcThreadAttribute struct {
Attribute uintptr
Value unsafe.Pointer
Size uintptr
}
When the StartupInfoEx struct is built, we call newProcThreadAttributeList with a count of len(ProcThreadAttributes) + 2 (taking the default attributes from syscall/exec_windows.go). Any ProcThreadAttributes that come from the user override those defaults if using the same Attribute field, which makes for unambiguous behavior.
Option 2: SecurityAttributes only
An alternative would be to add a SecurityCapabilities field to SysProcAttr and
type SysProcAttr struct {
// ...
SecurityCapabilities SecurityCapabilities
}
type SecurityCapabilities struct {
AppContainerSid uintptr // PSID *windows.SID
Capabilities uintptr // SID_AND_ATTRIBUTES *windows.SIDAndAttributes
CapabilityCount uint32
Reserved uint32
}
It would then be up to syscall/exec_windows.go to create the appropriate attributes for StartupInfoEx, as we do already for the parent handle, etc.
Proposal Details
Allow adding Security Capabilities to
SysProcAttron Windows. Note this is separate from the existingSecurityAttributesstruct which can be set as theProcessAttributesorThreadAttributesfield.Motivation
Recently as part of work to sandbox a subprocess, the Nomad team at HashiCorp needed to add a
SECURITY_CAPABILITIESstruct to theStartupInfoExfor a process. Because this is not exposed inSysProcAttrthis involved writing an unfortunate amount of code, much of which had to be simply lifted from theos/execstdlib. Seehelper/winexec/create.goImplementation Notes
Previously a proposal was implemented to add a
ParentProcessfield toSysProcAttrfor Windows #44011. This was discussed around the same time as a rejected proposal to add the fullStartupInfoExstruct #44005.One of the reasons why the
StartupInfoExproposal was rejected was because it resulted in ambiguity around how one would merge any default attributes with ones provided by the user. There are two options to work around this:Option 1: Extensible
Our implementation referenced above adds a
ProcThreadAttributesfield to the forkedos/exec.Cmdwhich is a slice ofProcThreadAttribute. This instead could be added toSysProcAttras an extensible way of adding more attributes:When the
StartupInfoExstruct is built, we callnewProcThreadAttributeListwith a count oflen(ProcThreadAttributes) + 2(taking the default attributes fromsyscall/exec_windows.go). AnyProcThreadAttributesthat come from the user override those defaults if using the sameAttributefield, which makes for unambiguous behavior.Option 2: SecurityAttributes only
An alternative would be to add a
SecurityCapabilitiesfield toSysProcAttrandIt would then be up to
syscall/exec_windows.goto create the appropriate attributes forStartupInfoEx, as we do already for the parent handle, etc.