From f46b4add938e3dfac828d3ca3061c55cfb159fd8 Mon Sep 17 00:00:00 2001 From: Dan Kortschak Date: Thu, 27 Jan 2022 14:57:44 +1030 Subject: [PATCH] x-pack/packetbeat: remove installation configurability --- dev-tools/packaging/package_test.go | 25 ++++--------- .../_meta/config/beat.reference.yml.tmpl | 2 -- packetbeat/_meta/config/beat.yml.tmpl | 2 -- .../_meta/config/windows_npcap.yml.tmpl | 36 ------------------- packetbeat/beater/install_npcap.go | 29 ++------------- 5 files changed, 9 insertions(+), 85 deletions(-) delete mode 100644 packetbeat/_meta/config/windows_npcap.yml.tmpl diff --git a/dev-tools/packaging/package_test.go b/dev-tools/packaging/package_test.go index 9759568de6a6..e4ac35f46cf0 100644 --- a/dev-tools/packaging/package_test.go +++ b/dev-tools/packaging/package_test.go @@ -193,18 +193,12 @@ const ( 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, - ) +// This reflects the order that the licenses and notices appear in the relevant files. +var npcapLicensePattern = regexp.MustCompile( + "(?s)" + npcapLicense + + ".*" + libpcapLicense + + ".*" + winpcapLicense + + ".*" + radiotapLicense, ) func checkNpcapNotices(pkg, file string, contents io.Reader) error { @@ -222,13 +216,6 @@ func checkNpcapNotices(pkg, file string, contents io.Reader) error { 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 { diff --git a/packetbeat/_meta/config/beat.reference.yml.tmpl b/packetbeat/_meta/config/beat.reference.yml.tmpl index 856a9475fe91..5d8d8fa9c7a7 100644 --- a/packetbeat/_meta/config/beat.reference.yml.tmpl +++ b/packetbeat/_meta/config/beat.reference.yml.tmpl @@ -57,8 +57,6 @@ 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: diff --git a/packetbeat/_meta/config/beat.yml.tmpl b/packetbeat/_meta/config/beat.yml.tmpl index 954100455933..2a69df425175 100644 --- a/packetbeat/_meta/config/beat.yml.tmpl +++ b/packetbeat/_meta/config/beat.yml.tmpl @@ -23,8 +23,6 @@ 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. diff --git a/packetbeat/_meta/config/windows_npcap.yml.tmpl b/packetbeat/_meta/config/windows_npcap.yml.tmpl deleted file mode 100644 index a6c13db4a539..000000000000 --- a/packetbeat/_meta/config/windows_npcap.yml.tmpl +++ /dev/null @@ -1,36 +0,0 @@ -{{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 -}} diff --git a/packetbeat/beater/install_npcap.go b/packetbeat/beater/install_npcap.go index ef9edd5617b7..e947bca5b012 100644 --- a/packetbeat/beater/install_npcap.go +++ b/packetbeat/beater/install_npcap.go @@ -32,17 +32,7 @@ import ( "github.com/elastic/beats/v7/packetbeat/npcap" ) -type npcapConfig struct { - NeverInstall bool `config:"npcap.never_install"` - ForceReinstall bool `config:"npcap.force_reinstall"` - InstallTimeout time.Duration `config:"npcap.install_timeout"` - InstallDestination string `config:"npcal.install_destination"` -} - -func (c *npcapConfig) Init() { - // Set defaults. - c.InstallTimeout = 120 * time.Second -} +const installTimeout = 120 * time.Second func installNpcap(b *beat.Beat) error { if !b.Info.ElasticLicensed { @@ -62,16 +52,7 @@ func installNpcap(b *beat.Beat) error { } }() - var cfg npcapConfig - err := b.BeatConfig.Unpack(&cfg) - if err != nil { - return fmt.Errorf("failed to unpack npcap config: %w", err) - } - if cfg.NeverInstall { - return nil - } - - ctx, cancel := context.WithTimeout(context.Background(), cfg.InstallTimeout) + ctx, cancel := context.WithTimeout(context.Background(), installTimeout) defer cancel() log := logp.NewLogger("npcap_install") @@ -79,10 +60,6 @@ func installNpcap(b *beat.Beat) error { if npcap.Installer == nil { return nil } - if !cfg.ForceReinstall && !npcap.Upgradeable() { - npcap.Installer = nil - return nil - } tmp, err := os.MkdirTemp("", "") if err != nil { return fmt.Errorf("could not create installation temporary directory: %w", err) @@ -100,5 +77,5 @@ func installNpcap(b *beat.Beat) error { if err != nil { return fmt.Errorf("could not create installation temporary file: %w", err) } - return npcap.Install(ctx, log, installerPath, cfg.InstallDestination, false) + return npcap.Install(ctx, log, installerPath, "", false) }