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

x-pack/packetbeat: install Npcap at start-up when required #29112

Merged
merged 32 commits into from
Jan 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
1a9dc95
packetbeat: add npcap installer hooks
efd6 Nov 22, 2021
5c4a632
packetbeat: use a remote registry
efd6 Nov 24, 2021
b1cbe24
packetbeat: allow specification of Npcap install location
efd6 Nov 24, 2021
55731c0
packetbeat: fix error handling and make failure an option
efd6 Nov 25, 2021
c6017af
add changelog line
efd6 Nov 25, 2021
b8aac75
improve error reporting
efd6 Nov 29, 2021
a335ebc
restrict oem npcap installation to elastic licensed use
efd6 Nov 29, 2021
4a9daa2
add logic for installing from embedded byte artifact
efd6 Dec 1, 2021
4195197
make npcap installer code visible from x-pack
efd6 Dec 1, 2021
d7dffe0
allow installation of npcap from embedded npcap installer
efd6 Dec 2, 2021
b0620ae
reload npcap dll on install
efd6 Dec 2, 2021
639664a
make compilation succeed and handle un-bundled case
efd6 Dec 2, 2021
0a8979b
update docs for new approach and note limiting use to x-pack
efd6 Dec 2, 2021
b168922
remove option to retain downloaded installer file
efd6 Dec 3, 2021
becaf5e
only include Npcap config options on Windows when Elastic Licensed
efd6 Dec 9, 2021
70635df
back out remote provisioning of installer
efd6 Dec 9, 2021
f3d8867
be explicit about included files in installer
efd6 Dec 9, 2021
3be42f6
allow the tree to remain clean during packaging
efd6 Dec 9, 2021
fe57072
use config struct and allow user to block install
efd6 Dec 9, 2021
7ff30e5
test config file contents
efd6 Dec 10, 2021
f3d26e6
log pcap version for windows platforms
efd6 Jan 12, 2022
7d5778a
add logic to select crossbuilder image for npcap installer artifact
efd6 Jan 13, 2022
ec83ab2
hard code npcap version to build with and provide non-CI build option
efd6 Jan 14, 2022
4f89991
copy installer asset into source tree before starting crossbuild
efd6 Jan 17, 2022
8e370b0
use hostname to determine whether we are on a beats-ci builder
efd6 Jan 18, 2022
64decc8
x-pack/packetbeat: add license notices
efd6 Dec 3, 2021
ba59bf9
experiment DO NOT MERGE
efd6 Jan 25, 2022
1e7c68e
test: print the CI env variable
v1v Jan 25, 2022
c0df4fc
include CI in mage var dump
efd6 Jan 25, 2022
e47956b
use correct call
efd6 Jan 26, 2022
8846b90
move image selection logic into x-pack
efd6 Jan 26, 2022
460a80a
Revert "test: print the CI env variable"
efd6 Jan 26, 2022
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
2 changes: 2 additions & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d

*Packetbeat*

- Add automated OEM Npcap installation handling. {pull}29112[29112]

*Functionbeat*


Expand Down
75 changes: 37 additions & 38 deletions NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16728,6 +16728,43 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


--------------------------------------------------------------------------------
Dependency : golang.org/x/mod
Version: v0.5.1
Licence type (autodetected): BSD-3-Clause
--------------------------------------------------------------------------------

Contents of probable licence file $GOMODCACHE/golang.org/x/[email protected]/LICENSE:

Copyright (c) 2009 The Go Authors. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


--------------------------------------------------------------------------------
Dependency : golang.org/x/net
Version: v0.0.0-20211020060615-d418f374d309
Expand Down Expand Up @@ -34519,43 +34556,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.


--------------------------------------------------------------------------------
Dependency : golang.org/x/mod
Version: v0.5.1
Licence type (autodetected): BSD-3-Clause
--------------------------------------------------------------------------------

Contents of probable licence file $GOMODCACHE/golang.org/x/[email protected]/LICENSE:

Copyright (c) 2009 The Go Authors. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


--------------------------------------------------------------------------------
Dependency : golang.org/x/term
Version: v0.0.0-20210615171337-6886f2dfbf5b
Expand Down Expand Up @@ -37624,4 +37624,3 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.



1 change: 1 addition & 0 deletions dev-tools/mage/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ func makeConfigTemplate(destination string, mode os.FileMode, confParams ConfigF
params := map[string]interface{}{
"GOOS": EnvOr("DEV_OS", "linux"),
"GOARCH": EnvOr("DEV_ARCH", "amd64"),
"BeatLicense": BeatLicense,
"Reference": false,
"Docker": false,
"ExcludeConsole": false,
Expand Down
7 changes: 5 additions & 2 deletions dev-tools/mage/crossbuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func CrossBuild(options ...CrossBuildOption) error {
builder := GolangCrossBuilder{buildPlatform.Name, params.Target, params.InDir, params.ImageSelector}
if params.Serial {
if err := builder.Build(); err != nil {
return errors.Wrapf(err, "failed cross-building target=%v for platform=%v %v", params.ImageSelector,
return errors.Wrapf(err, "failed cross-building target=%s for platform=%s",
params.Target, buildPlatform.Name)
}
} else {
Expand Down Expand Up @@ -321,8 +321,11 @@ func (b GolangCrossBuilder) Build() error {
"-v", repoInfo.RootDir+":"+mountPoint,
"-w", workDir,
image,

// Arguments for docker crossbuild entrypoint. For details see
// https://github.com/elastic/golang-crossbuild/blob/main/go1.17/base/rootfs/entrypoint.go.
"--build-cmd", buildCmd+" "+b.Target,
"-p", b.Platform,
"--platforms", b.Platform,
)

return dockerRun(args...)
Expand Down
1 change: 1 addition & 0 deletions dev-tools/mage/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ BeatUser = {{.BeatUser}}
VersionQualifier = {{.Qualifier}}
PLATFORMS = {{.PLATFORMS}}
PACKAGES = {{.PACKAGES}}
CI = {{.CI}}
## Functions
Expand Down
4 changes: 2 additions & 2 deletions dev-tools/notice/NOTICE.txt.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ Third party libraries used by the Elastic Beats project:
{{ "=" | line }}
Indirect dependencies

{{ template "depInfo" .Indirect }}
{{ end }}
{{ template "depInfo" .Indirect -}}
{{- end}}
78 changes: 75 additions & 3 deletions dev-tools/packaging/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ package dev_tools
import (
"archive/tar"
"archive/zip"
"bufio"
"bytes"
"compress/gzip"
"encoding/json"
Expand Down Expand Up @@ -169,7 +170,7 @@ func checkTar(t *testing.T, file string) {
}

func checkZip(t *testing.T, file string) {
p, err := readZip(file)
p, err := readZip(t, file, checkNpcapNotices)
if err != nil {
t.Error(err)
return
Expand All @@ -183,6 +184,62 @@ func checkZip(t *testing.T, file string) {
checkLicensesPresent(t, "", p)
}

const (
npcapSettings = "Windows Npcap installation settings"
npcapGrant = `Insecure.Com LLC \(“The Nmap Project”\) has granted Elasticsearch`
npcapLicense = `Dependency : Npcap \(https://nmap.org/npcap/\)`
libpcapLicense = `Dependency : Libpcap \(http://www.tcpdump.org/\)`
winpcapLicense = `Dependency : Winpcap \(https://www.winpcap.org/\)`
radiotapLicense = `Dependency : ieee80211_radiotap.h Header File`
)

var (
// These reflect the order that the licenses and notices appear in the relevant files.
npcapConfigPattern = regexp.MustCompile(
"(?s)" + npcapSettings +
".*" + npcapGrant,
)
npcapLicensePattern = regexp.MustCompile(
"(?s)" + npcapLicense +
".*" + libpcapLicense +
".*" + winpcapLicense +
".*" + radiotapLicense,
)
)

func checkNpcapNotices(pkg, file string, contents io.Reader) error {
if !strings.Contains(pkg, "packetbeat") {
return nil
}

wantNotices := strings.Contains(pkg, "windows") && !strings.Contains(pkg, "oss")

// If the packetbeat README.md is made to be generated
// conditionally then it should also be checked here.
pkg = filepath.Base(pkg)
file, err := filepath.Rel(pkg[:len(pkg)-len(filepath.Ext(pkg))], file)
if err != nil {
return err
}
switch file {
case "packetbeat.yml", "packetbeat.reference.yml":
if npcapConfigPattern.MatchReader(bufio.NewReader(contents)) != wantNotices {
if wantNotices {
return fmt.Errorf("Npcap config section not found in config file %s in %s", file, pkg)
}
return fmt.Errorf("unexpected Npcap config section found in config file %s in %s", file, pkg)
}
case "NOTICE.txt":
if npcapLicensePattern.MatchReader(bufio.NewReader(contents)) != wantNotices {
if wantNotices {
return fmt.Errorf("Npcap license section not found in %s file in %s", file, pkg)
}
return fmt.Errorf("unexpected Npcap license section found in %s file in %s", file, pkg)
}
}
return nil
}

func checkDocker(t *testing.T, file string) {
p, info, err := readDocker(file)
if err != nil {
Expand Down Expand Up @@ -623,7 +680,11 @@ func readTarContents(tarName string, data io.Reader) (*packageFile, error) {
return p, nil
}

func readZip(zipFile string) (*packageFile, error) {
// inspector is a file contents inspector. It vets the contents of the file
// within a package for a requirement and returns an error if it is not met.
type inspector func(pkg, file string, contents io.Reader) error

func readZip(t *testing.T, zipFile string, inspectors ...inspector) (*packageFile, error) {
r, err := zip.OpenReader(zipFile)
if err != nil {
return nil, err
Expand All @@ -636,6 +697,18 @@ func readZip(zipFile string) (*packageFile, error) {
File: f.Name,
Mode: f.Mode(),
}
for _, inspect := range inspectors {
r, err := f.Open()
if err != nil {
t.Errorf("failed to open %s in %s: %v", f.Name, zipFile, err)
break
}
err = inspect(zipFile, f.Name, r)
if err != nil {
t.Error(err)
}
r.Close()
}
}

return p, nil
Expand Down Expand Up @@ -740,7 +813,6 @@ func readDockerManifest(r io.Reader) (*dockerManifest, error) {
err = json.Unmarshal(data, &manifests)
if err != nil {
return nil, err

}

if len(manifests) != 1 {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ require (
go.uber.org/zap v1.14.1
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616
golang.org/x/mod v0.5.1
golang.org/x/net v0.0.0-20211020060615-d418f374d309
golang.org/x/oauth2 v0.0.0-20211005180243-6b3c2da341f1
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
Expand Down Expand Up @@ -268,7 +269,6 @@ require (
github.com/xdg/stringprep v1.0.3 // indirect
go.elastic.co/fastjson v1.1.0 // indirect
go.opencensus.io v0.23.0 // indirect
golang.org/x/mod v0.5.1 // indirect
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
google.golang.org/appengine v1.6.7 // indirect
Expand Down
14 changes: 14 additions & 0 deletions packetbeat/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,17 @@ If you are sure you found a bug or have a feature request, open an issue on

We love contributions from our community! Please read the
[CONTRIBUTING.md](../CONTRIBUTING.md) file.

## LICENSE NOTICE for Windows users of Packetbeat

The default distribution of Packetbeat for Windows comes bundled with the Npcap
library. This is not available in the OSS-only distribution of Packetbeat.

**Restrictions on Distribution**

Insecure.Com LLC (“The Nmap Project”) has granted Elasticsearch BV and its
affiliates the right to include Npcap with this distribution of Packetbeat.
You may not distribute this version of Packetbeat or any other package from
Elastic that includes Npcap. If you wish to distribute Npcap, or any package
that includes Npcap, you should reach out to The Nmap Project to obtain a
distribution license. See https://nmap.org/npcap/ for more details.
2 changes: 2 additions & 0 deletions packetbeat/_meta/config/beat.reference.yml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ packetbeat.interfaces.internal_networks:
# can stay enabled even after beat is shut down.
#packetbeat.interfaces.auto_promisc_mode: true

{{- template "windows_npcap.yml.tmpl" .}}

{{header "Flows"}}

packetbeat.flows:
Expand Down
2 changes: 2 additions & 0 deletions packetbeat/_meta/config/beat.yml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ packetbeat.interfaces.device: {{ call .device .GOOS }}
packetbeat.interfaces.internal_networks:
- private

{{- template "windows_npcap.yml.tmpl" .}}

{{header "Flows"}}

# Set `enabled: false` or comment out all options to disable flows reporting.
Expand Down
36 changes: 36 additions & 0 deletions packetbeat/_meta/config/windows_npcap.yml.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{{if and (eq .BeatLicense "Elastic License") (eq .GOOS "windows")}}

{{header "Windows Npcap installation settings"}}

# Windows Npcap installation options. These options specify how the Npcap packet
# capture library for Windows should be obtained and installed.
# Npcap installation is only available in the default distribution of Packetbeat
# for Windows and is not available in the OSS-only distribution of Packetbeat.
#
# LICENSE NOTICE
#
# Restrictions on Distribution
#
# Insecure.Com LLC (“The Nmap Project”) has granted Elasticsearch BV and its
# affiliates the right to include Npcap with this distribution of Packetbeat.
# You may not distribute this version of Packetbeat or any other package from
# Elastic that includes Npcap. If you wish to distribute Npcap, or any package
# that includes Npcap, you should reach out to The Nmap Project to obtain a
# distribution license. See https://nmap.org/npcap/ for more details.
#
#npcap:
# # install_destination allows configuration of the location that the Npcap will
# # place the Npcap library and associated files. See https://nmap.org/npcap/guide/npcap-users-guide.html#npcap-installation-uninstall-options.
# install_destination: ""
# install_timeout: 120s
# # ignore_missing_registry specifies that failure to query the registry server
# # will be ignored with a logged warning.
# ignore_missing_registry: false
# # By default Npcap will be installed only when a newer version of Npcap is available.
# # force_reinstall forces a new installation of Npcap in all cases.
# force_reinstall: false
# # If a specific local version of Npcap is required installation by packetbeat
# # can be blocked by setting never_install to true. No action is taken if this
# # option is set to true.
# never_install: false
{{- end -}}
Loading