Skip to content

Commit

Permalink
[Ingest Management] Fixed parsing of npipe URI (#22978) (#23014)
Browse files Browse the repository at this point in the history
[Ingest Management] Fixed parsing of npipe URI (#22978)
  • Loading branch information
michalpristas authored Dec 9, 2020
1 parent 36d51cb commit e063ded
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
9 changes: 9 additions & 0 deletions libbeat/api/npipe/listener_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,14 @@ func DefaultSD(forUser string) (string, error) {
// String definition: https://docs.microsoft.com/en-us/windows/win32/secauthz/ace-strings
// Give generic read/write access to the specified user.
descriptor := "D:P(A;;GA;;;" + u.Uid + ")"
if u.Username == "NT AUTHORITY\\SYSTEM" {
// running as SYSTEM, include Administrators group so Administrators can talk over
// the named pipe to the running Elastic Agent system process
admin, err := user.LookupGroup("Administrators")
if err != nil {
return "", errors.Wrap(err, "failed to lookup Administrators group")
}
descriptor += "(A;;GA;;;" + admin.Gid + ")"
}
return descriptor, nil
}
23 changes: 20 additions & 3 deletions metricbeat/mb/parse/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,29 @@ func getURL(
u.Scheme = "http"
u.Host = "unix"
case "http+npipe":
p := strings.Replace(u.Path, "/pipe", `\\.\pipe`, 1)
p = strings.Replace(p, "/", "\\", -1)
t = dialer.NewNpipeDialerBuilder(p)
p := u.Path
u.Path = ""
u.Scheme = "http"
u.Host = "npipe"

if p == "" && u.Host != "" {
p = u.Host
}

// cleanup of all possible prefixes
p = strings.TrimPrefix(p, "/pipe")
p = strings.TrimPrefix(p, `\\.\pipe`)
p = strings.TrimPrefix(p, "\\")
p = strings.TrimPrefix(p, "/")

segs := strings.SplitAfterN(p, "/", 2)
if len(segs) == 2 {
p = strings.TrimSuffix(segs[0], "/")
u.Path = "/" + segs[1]
}

p = `\\.\pipe\` + strings.Replace(p, "/", "\\", -1)
t = dialer.NewNpipeDialerBuilder(p)
default:
t = dialer.NewDefaultDialerBuilder()
}
Expand Down
15 changes: 15 additions & 0 deletions metricbeat/mb/parse/url_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,21 @@ func TestParseURL(t *testing.T) {
}
})

t.Run("http+npipe short with", func(t *testing.T) {
rawURL := "http+npipe:///custom"
hostData, err := ParseURL(rawURL, "http", "", "", "apath", "")
if assert.NoError(t, err) {
transport, ok := hostData.Transport.(*dialer.NpipeDialerBuilder)
assert.True(t, ok)
assert.Equal(t, `\\.\pipe\custom`, transport.Path)
assert.Equal(t, "http://npipe/apath", hostData.URI)
assert.Equal(t, "http://npipe/apath", hostData.SanitizedURI)
assert.Equal(t, "npipe", hostData.Host)
assert.Equal(t, "", hostData.User)
assert.Equal(t, "", hostData.Password)
}
})

t.Run("npipe", func(t *testing.T) {
rawURL := "npipe://./pipe/docker_engine"
hostData, err := ParseURL(rawURL, "tcp", "", "", "", "")
Expand Down
1 change: 1 addition & 0 deletions x-pack/elastic-agent/CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
- Fix deb/rpm packaging for Elastic Agent {pull}22153[22153]
- Fix composable input processor promotion to fix duplicates {pull}22344[22344]
- Fix sysv init files for deb/rpm installation {pull}22543[22543]
- Fixed parsing of npipe URI {pull}22978[22978]

==== New features

Expand Down

0 comments on commit e063ded

Please sign in to comment.