Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Ingest Management] Fixed parsing of npipe URI #22978

Merged
merged 2 commits into from
Dec 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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