-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
packetbeat: Enable setting promiscuous mode automatically #11366
Merged
Merged
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
ffd96e6
Enable setting of promiscuous mode
michalpristas 46db28a
seccomp disabled
michalpristas 1c2146a
Merge branch 'master' of https://github.com/elastic/beats into fix-700
michalpristas 637eaab
update faq
michalpristas 1ff4818
changelog
michalpristas 7fc011e
fix
michalpristas 4e140f3
mage update
michalpristas 9ef3f56
Merge branch 'master' into fix-700
michalpristas 70dc0cd
syscall
michalpristas fbe7398
syscall
michalpristas 8c87687
whitespaces
michalpristas c00eb6f
typo
michalpristas 24db049
review round
michalpristas 1d2f681
not breaking
michalpristas 185fbff
Merge branch 'master' into fix-700
michalpristas 8e83262
first attemp for system test
michalpristas 22048ec
it's autopep8 style :notes:
michalpristas 49cd7a6
more strict for devices count
michalpristas fa877f5
import unit test
michalpristas 2065731
fixed tests :party:
michalpristas cdd6069
Merge branch 'master' into fix-700
michalpristas 24109ff
use test environment
michalpristas 4bafbee
Merge branch 'master' into fix-700
michalpristas ae6bf1c
Merge branch 'master' into fix-700
michalpristas 498c230
Merge branch 'master' into fix-700
michalpristas 8a99e60
Merge branch 'master' into fix-700
michalpristas 93e48ac
Merge branch 'master' into fix-700
michalpristas 23d5948
configurable promisc mode
michalpristas 9111121
meta reference
michalpristas 52ce33e
invalid condition, shame on me
michalpristas 70d02b0
Merge branch 'master' into fix-700
michalpristas ef0ae7d
Merge branch 'master' into fix-700
michalpristas 7bb2402
changelog merge fix
michalpristas a00e370
updated dockerfile for packetbeat
michalpristas 941f534
added comment
michalpristas bbcc013
updated config file
michalpristas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
FROM golang:1.13.7 | ||
|
||
RUN \ | ||
apt-get update \ | ||
&& apt-get install -y --no-install-recommends \ | ||
python-pip \ | ||
virtualenv \ | ||
librpm-dev \ | ||
netcat \ | ||
libpcap-dev \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
RUN pip install --upgrade pip | ||
RUN pip install --upgrade setuptools | ||
RUN pip install --upgrade docker-compose==1.23.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
version: '2.3' | ||
services: | ||
beat: | ||
build: ${PWD}/. | ||
depends_on: | ||
- proxy_dep | ||
working_dir: /go/src/github.com/elastic/beats/packetbeat | ||
environment: | ||
- ES_HOST=elasticsearch | ||
- ES_PORT=9200 | ||
- ES_USER=beats | ||
- ES_PASS=testing | ||
- KIBANA_HOST=kibana | ||
- KIBANA_PORT=5601 | ||
volumes: | ||
- ${PWD}/..:/go/src/github.com/elastic/beats/ | ||
command: make | ||
privileged: true | ||
pid: host | ||
|
||
# This is a proxy used to block beats until all services are healthy. | ||
# See: https://github.com/docker/compose/issues/4369 | ||
proxy_dep: | ||
image: busybox | ||
depends_on: | ||
elasticsearch: { condition: service_healthy } | ||
kibana: { condition: service_healthy } | ||
|
||
elasticsearch: | ||
extends: | ||
file: ../testing/environments/${TESTING_ENVIRONMENT}.yml | ||
service: elasticsearch | ||
|
||
kibana: | ||
extends: | ||
file: ../testing/environments/${TESTING_ENVIRONMENT}.yml | ||
service: kibana |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import os | ||
import subprocess | ||
import sys | ||
import time | ||
import unittest | ||
from packetbeat import BaseTest | ||
|
||
""" | ||
Tests for afpacket. | ||
""" | ||
|
||
|
||
def is_root(): | ||
if 'geteuid' not in dir(os): | ||
return False | ||
euid = os.geteuid() | ||
print("euid is", euid) | ||
return euid == 0 | ||
|
||
|
||
class Test(BaseTest): | ||
|
||
@unittest.skipUnless( | ||
sys.platform.startswith("linux"), | ||
"af_packet only on Linux") | ||
@unittest.skipUnless(is_root(), "Requires root") | ||
def test_afpacket_promisc(self): | ||
""" | ||
Should switch to promisc mode and back. | ||
""" | ||
|
||
# get device name, leave out loopback device | ||
devices = [f for f in os.listdir( | ||
"/sys/class/net") if f.startswith("lo")] | ||
assert len(devices) > 0 | ||
|
||
device = devices[0] | ||
|
||
ip_proc = subprocess.Popen( | ||
["ip", "link", "show", device], stdout=subprocess.PIPE) | ||
o, e = ip_proc.communicate() | ||
assert e is None | ||
|
||
prev_promisc = "PROMISC" in o.decode("utf-8") | ||
|
||
# turn off promics if was on | ||
if prev_promisc: | ||
subprocess.call(["ip", "link", "set", device, | ||
"promisc", "off"], stdout=subprocess.PIPE) | ||
|
||
self.render_config_template( | ||
af_packet=True, | ||
iface_device=device | ||
) | ||
packetbeat = self.start_packetbeat() | ||
|
||
# wait for promisc to be turned on, cap(90s) | ||
for x in range(10): | ||
time.sleep(5) | ||
|
||
ip_proc = subprocess.Popen( | ||
["ip", "link", "show", device], stdout=subprocess.PIPE) | ||
o, e = ip_proc.communicate() | ||
|
||
is_promisc = "PROMISC" in o.decode("utf-8") | ||
if is_promisc: | ||
break | ||
|
||
assert is_promisc | ||
|
||
# stop packetbeat and check if promisc is set to previous state | ||
packetbeat.kill_and_wait() | ||
|
||
ip_proc = subprocess.Popen( | ||
["ip", "link", "show", device], stdout=subprocess.PIPE) | ||
o, e = ip_proc.communicate() | ||
assert e is None | ||
|
||
is_promisc = "PROMISC" in o.decode("utf-8") | ||
assert is_promisc == False | ||
|
||
# reset device | ||
if prev_promisc: | ||
subprocess.call(["ip", "link", "set", device, "promisc", "on"]) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function says its deprecated. Have you checked out what it recommends to use?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it says
x/net
where I did not find anything useful. so, for now, I went with this with a possible rewrite to direct syscallsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's at least add a code comment here explaining the issue + follow up issue in repo.