Skip to content

Commit 20e9829

Browse files
committed
Add agent gRPC plugin
Add plugin to send pcap data over Unix socket using gRPC
1 parent 191e826 commit 20e9829

File tree

12 files changed

+273
-9
lines changed

12 files changed

+273
-9
lines changed

.gitmodules

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[submodule "deps/agent-plugins-grpc"]
2+
path = deps/agent-plugins-grpc
3+
url = [email protected]:deepfence/agent-plugins-grpc.git
4+
branch = add-pcap

Makefile

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ ifeq ($(RELEASE),1)
1313
LDFLAGS += -s -w
1414
endif
1515

16-
.PHONY: all build docker-bin docker-image test
16+
.PHONY: all build docker-bin docker-image test localinit
1717

18-
all: build
18+
all: proto build
19+
20+
localinit:
21+
$(PWD)/bootstrap.sh
1922

2023
build:
2124
go build -tags '$(TAGS)' --ldflags '$(LDFLAGS)' -o packetstreamer ./main.go
@@ -35,3 +38,13 @@ docker-test:
3538

3639
test:
3740
go test -tags '$(TAGS)' ./...
41+
42+
clean:
43+
-rm ./packetstreamer
44+
-rm ./deps/agent-plugins-grpc/proto/*.go
45+
-rm -r $(PWD)/proto
46+
47+
proto: ./deps/agent-plugins-grpc/proto/*.proto
48+
(cd ./deps/agent-plugins-grpc && make go)
49+
-mkdir $(PWD)/proto
50+
cp ./deps/agent-plugins-grpc/proto/*.go $(PWD)/proto

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ little performance impact on the remote hosts. PacketStreamer sensors can be
3333
run on bare-metal servers, on Docker hosts, and on Kubernetes nodes.
3434

3535
The PacketStreamer receiver accepts network traffic from multiple sensors,
36-
collecting it into a single, central `pcap` file. You can then process the
36+
collecting it into a single, central `pcap` file. You can then process the
3737
pcap file or live feed the traffic to the tooling of your choice, such as
3838
`Zeek`, `Wireshark` `Suricata`, or as a live stream for Machine Learning models.
3939

@@ -54,16 +54,17 @@ network data from multiple machines for central logging and analysis.
5454
For full instructions, refer to the [PacketStreamer Documentation](https://deepfence.github.io/PacketStreamer/).
5555

5656
You will need to install the golang toolchain and `libpcap-dev` before building PacketStreamer.
57-
57+
5858
```shell script
5959
# Pre-requisites (Ubuntu): sudo apt install golang-go libpcap-dev
6060
git clone https://github.com/deepfence/PacketStreamer.git
6161
cd PacketStreamer/
62+
make localinit
6263
make
6364
```
6465

6566
Run a PacketStreamer receiver, listening on port **8081** and writing pcap output to **/tmp/dump_file** (see [receiver.yaml](contrib/config/receiver.yaml)):
66-
67+
6768
```shell script
6869
./packetstreamer receiver --config ./contrib/config/receiver.yaml
6970
```
@@ -79,7 +80,7 @@ cp ./contrib/config/sensor-local.yaml ./contrib/config/sensor.yaml
7980
./packetstreamer sensor --config ./contrib/config/sensor.yaml
8081
```
8182

82-
83+
8384
## Who uses PacketStreamer?
8485

8586
* Deepfence [ThreatStryker](https://deepfence.io/threatstryker/) uses

bootstrap.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
git submodule update --init --remote --recursive ./deps/agent-plugins-grpc/

contrib/config/sensor-agent.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
output:
2+
plugins:
3+
agent:
4+
socketPath: /tmp/agent.sock
5+
pcapMode: all

deps/agent-plugins-grpc

Submodule agent-plugins-grpc added at a94c8f6

go.mod

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ require (
1616
gopkg.in/yaml.v3 v3.0.1
1717
)
1818

19+
require (
20+
github.com/golang/protobuf v1.5.2 // indirect
21+
golang.org/x/text v0.3.6 // indirect
22+
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 // indirect
23+
google.golang.org/protobuf v1.27.1 // indirect
24+
)
25+
1926
require (
2027
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.1 // indirect
2128
github.com/aws/aws-sdk-go-v2/credentials v1.11.2 // indirect
@@ -35,8 +42,9 @@ require (
3542
github.com/miekg/dns v1.1.25 // indirect
3643
github.com/pierrec/lz4/v4 v4.1.14 // indirect
3744
github.com/spf13/pflag v1.0.5 // indirect
38-
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 // indirect
45+
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 // indirect
3946
golang.org/x/net v0.0.0-20211209124913-491a49abca63 // indirect
4047
golang.org/x/sys v0.0.0-20211210111614-af8b64212486 // indirect
48+
google.golang.org/grpc v1.48.0
4149
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
4250
)

go.sum

Lines changed: 109 additions & 0 deletions
Large diffs are not rendered by default.

pkg/config/config.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,14 @@ type KafkaPluginConfig struct {
6464
Timeout time.Duration `yaml:"timeout,omitempty"`
6565
}
6666

67+
type AgentPluginConfig struct {
68+
SocketPath string `yaml:"socketPath"`
69+
}
70+
6771
type PluginsConfig struct {
6872
S3 *S3PluginConfig
6973
Kafka *KafkaPluginConfig
74+
Agent *AgentPluginConfig
7075
}
7176

7277
type OutputConfig struct {
@@ -75,6 +80,10 @@ type OutputConfig struct {
7580
Plugins *PluginsConfig
7681
}
7782

83+
type AgentOutputRawConfig struct {
84+
SocketPath string `yaml:"socketPath"`
85+
}
86+
7887
type S3OutputRawConfig struct {
7988
Bucket string
8089
Region string
@@ -97,6 +106,7 @@ type KafkaOutputRawConfig struct {
97106
type PluginsRawConfig struct {
98107
S3 *S3OutputRawConfig
99108
Kafka *KafkaOutputRawConfig
109+
Agent *AgentOutputRawConfig
100110
}
101111

102112
type OutputRawConfig struct {
@@ -166,6 +176,7 @@ func NewConfig(configFileName string) (*Config, error) {
166176

167177
var s3Config *S3PluginConfig
168178
var kafkaConfig *KafkaPluginConfig
179+
var agentConfig *AgentPluginConfig
169180
if rawConfig.Output != nil && rawConfig.Output.Plugins != nil {
170181

171182
s3Config, err = populateS3Config(rawConfig)
@@ -179,6 +190,12 @@ func NewConfig(configFileName string) (*Config, error) {
179190
if err != nil {
180191
return nil, err
181192
}
193+
194+
agentConfig, err = populateAgentConfig(rawConfig)
195+
196+
if err != nil {
197+
return nil, err
198+
}
182199
}
183200

184201
compressBlockSize := 65
@@ -213,6 +230,7 @@ func NewConfig(configFileName string) (*Config, error) {
213230
Plugins: &PluginsConfig{
214231
S3: s3Config,
215232
Kafka: kafkaConfig,
233+
Agent: agentConfig,
216234
},
217235
},
218236
TLS: rawConfig.TLS,
@@ -303,6 +321,16 @@ func populateKafkaConfig(rawConfig RawConfig) (*KafkaPluginConfig, error) {
303321
}, nil
304322
}
305323

324+
func populateAgentConfig(rawConfig RawConfig) (*AgentPluginConfig, error) {
325+
if rawConfig.Output.Plugins.Agent == nil {
326+
return nil, nil
327+
}
328+
329+
return &AgentPluginConfig{
330+
SocketPath: rawConfig.Output.Plugins.Agent.SocketPath,
331+
}, nil
332+
}
333+
306334
func populateS3Config(rawConfig RawConfig) (*S3PluginConfig, error) {
307335
if rawConfig.Output.Plugins.S3 == nil {
308336
return nil, nil

pkg/config/sensor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ var (
1212
func ValidateSensorConfig(config *Config) error {
1313
if config.Output.File == nil && config.Output.Server == nil &&
1414
(config.Output.Plugins == nil ||
15-
(config.Output.Plugins.S3 == nil && config.Output.Plugins.Kafka == nil)) {
15+
(config.Output.Plugins.S3 == nil && config.Output.Plugins.Kafka == nil && config.Output.Plugins.Agent == nil)) {
1616
return ErrNoOutputConfigured
1717
}
1818
if config.Output.Server != nil && config.Output.Server.Port == nil {

0 commit comments

Comments
 (0)