Skip to content

Commit

Permalink
[Ingest Manager] Use ML_SYSTEM to detect if agent is running as a ser…
Browse files Browse the repository at this point in the history
…vice (elastic#21884)

[Ingest Manager] Use ML_SYSTEM to detect if agent is running as a service (elastic#21884)
  • Loading branch information
michalpristas committed Oct 21, 2020
1 parent 8532820 commit 3d4b6f5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 3 additions & 0 deletions x-pack/elastic-agent/CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
- Include inputs in action store actions {pull}21298[21298]
- Fix issue where inputs without processors defined would panic {pull}21628[21628]
- Partial extracted beat result in failure to spawn beat {issue}21718[21718]
- Use ML_SYSTEM to detect if agent is running as a service {pull}21884[21884]
- Use local temp instead of system one {pull}21883[21883]
- Rename monitoring index from `elastic.agent` to `elastic_agent` {pull}21932[21932]
- Fix issue with named pipes on Windows 7 {pull}21931[21931]
- Rename monitoring index from `elastic.agent` to `elastic_agent` {pull}21932[21932]

Expand Down
8 changes: 6 additions & 2 deletions x-pack/elastic-agent/pkg/agent/install/svc_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ import (
"golang.org/x/sys/windows"
)

const (
ML_SYSTEM_RID = 0x4000
)

// RunningUnderSupervisor returns true when executing Agent is running under
// the supervisor processes of the OS.
func RunningUnderSupervisor() bool {
serviceSid, err := allocSid(windows.SECURITY_SERVICE_RID)
serviceSid, err := allocSid(ML_SYSTEM_RID)
if err != nil {
return false
}
Expand All @@ -40,7 +44,7 @@ func RunningUnderSupervisor() bool {

func allocSid(subAuth0 uint32) (*windows.SID, error) {
var sid *windows.SID
err := windows.AllocateAndInitializeSid(&windows.SECURITY_NT_AUTHORITY,
err := windows.AllocateAndInitializeSid(&windows.SECURITY_MANDATORY_LABEL_AUTHORITY,
1, subAuth0, 0, 0, 0, 0, 0, 0, 0, &sid)
if err != nil {
return nil, err
Expand Down

0 comments on commit 3d4b6f5

Please sign in to comment.