Skip to content
This repository was archived by the owner on Jan 29, 2021. It is now read-only.

Commit c126074

Browse files
author
Logan L
committed
Merge branch 'master' into 54-1-7-19-Fixes
Merged master back in to feature branch in order to bring in fixes needed to test the new installer.
2 parents c12e04a + 316afa5 commit c126074

34 files changed

+798
-304
lines changed

README.md

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ often practical to install everything in one place.
1919
**You must ensure the RITA database can be contacted on an IP address other
2020
than localhost**. This can be done by editing the `bindIP` setting in
2121
`/etc/mongod.conf`. The installer will prompt you to ensure this change is made
22-
before continuing on. If you intend to install IPFIX-RITA on the same machine
22+
before continuing on. If you intend to install IPFIX-RITA on the same machine
2323
as RITA and MongoDB, please add the IP address suggested by the installer.
2424
\
2525
NOTE: if you want multiple bind IP addresses in your MongoDB config file you
@@ -31,7 +31,7 @@ for IPFIX-RITA to access) your bind IP line should look like the following.
3131
Also if your RITA config file (`/etc/rita/config.yaml`) connects to MongoDB on
3232
localhost you will need to change that to the same value as MongoDB is listening
3333
on. For example if you change the bindIP in your MongoDB config file to 10.0.0.5
34-
and you check your RITA config file and the connection string is
34+
and you check your RITA config file and the connection string is
3535
`mongodb://localhost:27017` you'll need to change it to ` mongodb://10.0.0.5:27017`.
3636

3737
#### How to [Install RITA](https://github.com/activecm/rita#automatic-installation)
@@ -53,7 +53,7 @@ $ wget $(curl --silent "https://api.github.com/repos/activecm/ipfix-rita/release
5353
| grep '"browser_download_url":' | cut -d \" -f 4 ) -O ipfix-rita.tgz
5454
```
5555

56-
#### Upack the installer
56+
#### Unpack the installer
5757
```
5858
$ tar -zxf ipfix-rita.tgz
5959
```
@@ -67,7 +67,7 @@ You will be prompted for configuration details regarding the RITA database
6767
connection and the names of the resulting datasets. Further configuration
6868
options can be set in `/etc/ipfix-rita/converter/converter.yaml`.
6969

70-
By default, **IPFIX-RITA will run at start up unless it is stopped**. For more
70+
By default, **IPFIX-RITA will run at start up unless it is stopped**. For more
7171
information see [Additional Info](docs/Additional%20Info.md). Full
7272
documentation for IPFIX-RITA can be found in the [docs](docs/) folder.
7373

@@ -85,7 +85,7 @@ setting up your router for use with IPFIX-RITA.
8585
| Cisco ASA | || | |
8686
| Cisco ASR 9k | || | |
8787
| SonicWall | || | |
88-
| MikroTik | ||| |
88+
| MikroTik | ||| |
8989
| YAF || | | Use `--uniflow` |
9090

9191
## What Do I Do If My Router Isn't On the List?
@@ -164,7 +164,7 @@ Output:
164164
CAFile: null
165165
...
166166
```
167-
try connecting to mongo using
167+
try connecting to mongo using
168168
```
169169
mongo [ipaddress]:[port]
170170
mongo 10.0.0.5:27017
@@ -199,15 +199,20 @@ IPFix).
199199
The following bugs have been documented by Active Countermeasures and solutions
200200
are in development
201201

202-
### IPFix Time Error
203-
A common error that might occur is something like
202+
### IPFix-RITA Fails on Reboot
203+
If IPFix-RITA is configured to write to a MongoDB database running on the
204+
Docker host (as in the default configuration), IPFix-RITA may encounter
205+
an error after a system reboot.
206+
The following error may arise:
204207
```
205-
converter_1_a86985062afe | ERRO[1082] input map must contain key 'netflow.flowStartMilliseconds' ...
208+
converter_1_eeb48d380f26 | ERRO[0038] could not connect to RITA MongoDB: could not connect to MongoDB (no TLS): could not connect to MongoDB: no reachable servers stacktrace="[rita_dates.go:60 convert.go:194 convert.go:40 app.go:490 command.go:210 app.go:255 boot.go:18 proc.go:198 asm_amd64.s:2361]"
209+
```
210+
This is due to an error in which the MongoDB server starts before the Docker engine.
211+
Until a fix is implemented, Active Countermeasures recommends running the following command
212+
to resolve the issue
213+
```
214+
sudo systemctl restart mongod.service
206215
```
207-
If you are using IPFix this is likely caused by the router using an IPFix version
208-
that uses timestamps relative to the system initilization time and not Unix timestamps.
209-
This is a known issue and we are working on a solution to support more IPFix versions.
210-
If this error persists, Active Countermeasures recommends switching to Netflow v9 or v5.
211216

212217
### Log Rotation Error
213218
It has been discovered that some flow logs will report flow start and end

converter/commands/check_config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55

66
"github.com/activecm/ipfix-rita/converter/config"
77
"github.com/activecm/ipfix-rita/converter/config/yaml"
8-
"github.com/activecm/ipfix-rita/converter/input/mgologstash"
8+
"github.com/activecm/ipfix-rita/converter/input/logstash/mongodb"
99
"github.com/activecm/ipfix-rita/converter/output/rita"
1010
"github.com/urfave/cli"
1111
)
@@ -35,7 +35,7 @@ func init() {
3535
}
3636
fmt.Printf("Loaded Configuration:\n%s\n", confStr)
3737

38-
db, err := mgologstash.NewLogstashMongoInputDB(conf.GetInputConfig().GetLogstashMongoDBConfig())
38+
db, err := mongodb.NewLogstashMongoInputDB(conf.GetInputConfig().GetLogstashMongoDBConfig())
3939
if err != nil {
4040
return cli.NewExitError(fmt.Sprintf("%+v\n", err), 1)
4141
}

converter/commands/convert.go

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ package commands
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
67
"os"
78
"os/signal"
89
"syscall"
910
"time"
1011

1112
"github.com/activecm/ipfix-rita/converter/environment"
12-
input "github.com/activecm/ipfix-rita/converter/input/mgologstash"
13+
"github.com/activecm/ipfix-rita/converter/filter"
14+
input "github.com/activecm/ipfix-rita/converter/input/logstash/mongodb"
1315
"github.com/activecm/ipfix-rita/converter/logging"
1416
"github.com/activecm/ipfix-rita/converter/output"
1517
batchRITAOutput "github.com/activecm/ipfix-rita/converter/output/rita/batch/dates"
@@ -54,6 +56,8 @@ func convert(env environment.Environment, noRotate bool) error {
5456
//TODO: Decide on how to scale these options depending on the specs
5557
//of the computer
5658

59+
//-------------------------------Input setup-------------------------------
60+
5761
//pollWait is how long to wait before checking if the input buffer has
5862
//more data
5963
pollWait := 30 * time.Second
@@ -81,6 +85,40 @@ func convert(env environment.Environment, noRotate bool) error {
8185
env.Logger,
8286
)
8387

88+
//-------------------------------Filter setup-------------------------------
89+
90+
//Create the filter which will filter out flows as specified by the
91+
//Filter config section
92+
internalNets, errs := env.GetFilteringConfig().GetInternalSubnets()
93+
if len(errs) != 0 {
94+
for _, err := range errs {
95+
env.Logger.Error(err, nil)
96+
}
97+
return errors.New("unable to parse filtering config")
98+
}
99+
neverIncludeNets, errs := env.GetFilteringConfig().GetNeverIncludeSubnets()
100+
if len(errs) != 0 {
101+
for _, err := range errs {
102+
env.Logger.Error(err, nil)
103+
}
104+
return errors.New("unable to parse filtering config")
105+
}
106+
alwaysIncludeNets, errs := env.GetFilteringConfig().GetAlwaysIncludeSubnets()
107+
if len(errs) != 0 {
108+
for _, err := range errs {
109+
env.Logger.Error(err, nil)
110+
}
111+
return errors.New("unable to parse filtering config")
112+
}
113+
114+
flowFilter := filter.NewFlowBlacklist(
115+
internalNets,
116+
neverIncludeNets,
117+
alwaysIncludeNets,
118+
)
119+
120+
//------------------------------Stitching setup------------------------------
121+
84122
//sameSessionThreshold determines is used in the process of determining
85123
//whether two flows should be stitched together or not.
86124
//If the time between one flow ending and the other flow starting
@@ -132,9 +170,12 @@ func convert(env environment.Environment, noRotate bool) error {
132170
outputBufferSize,
133171
matcherSize,
134172
matcherFlushToPercent,
173+
flowFilter,
135174
env.Logger,
136175
)
137176

177+
//-------------------------------Output setup-------------------------------
178+
138179
//flushDeadline determines how long data may sit in a buffer
139180
//before it is exported to MongoDB
140181
flushDeadline := 1 * time.Minute
@@ -152,7 +193,7 @@ func convert(env environment.Environment, noRotate bool) error {
152193
//which splits output records up based on the time the connection finished
153194
writer, err = streamingRITAOutput.NewStreamingRITATimeIntervalWriter(
154195
env.GetOutputConfig().GetRITAConfig(),
155-
env.GetIPFIXConfig(),
196+
internalNets,
156197
bulkBatchSize, flushDeadline,
157198
dayRotationPeriodMillis, gracePeriodMillis,
158199
clock.New(), time.Local, dateFormatString,
@@ -164,7 +205,7 @@ func convert(env environment.Environment, noRotate bool) error {
164205
} else {
165206
writer, err = batchRITAOutput.NewBatchRITAConnDateWriter(
166207
env.GetOutputConfig().GetRITAConfig(),
167-
env.GetIPFIXConfig(),
208+
internalNets,
168209
bulkBatchSize, flushDeadline,
169210
env.Logger,
170211
)
@@ -174,6 +215,8 @@ func convert(env environment.Environment, noRotate bool) error {
174215
env.Info("Database rotation has been disabled", nil)
175216
}
176217

218+
//-------------------------------Execution-------------------------------
219+
177220
//input channels
178221
inputData, inputErrors := reader.Drain(ctx)
179222
//run the stitching manager and get the output channels

converter/config/config.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ import (
2626
//Config holds IPFIX-RITA (converter) configuration details
2727
type Config interface {
2828
GetInputConfig() Input
29+
GetFilteringConfig() Filtering
2930
GetOutputConfig() Output
30-
GetIPFIXConfig() IPFIX
3131
}
3232

3333
//Serializable represents application configuration data
@@ -71,16 +71,18 @@ type Output interface {
7171
GetRITAConfig() RITA
7272
}
7373

74-
//RITA2 contains configuration for writing out the
74+
//RITA contains configuration for writing out the
7575
//stitched IPFIX/ Netflow records RITA compatible MongoDB databases
7676
type RITA interface {
7777
GetConnectionConfig() MongoDBConnection
7878
GetDBRoot() string
7979
GetMetaDB() string
8080
}
8181

82-
//IPFIX provides information for accessing IPFIX data
83-
//and information regarding the individual records
84-
type IPFIX interface {
85-
GetLocalNetworks() ([]net.IPNet, []error)
82+
//Filtering contains information on local subnets and other networks/hosts
83+
//that should be filtered out of the result set
84+
type Filtering interface {
85+
GetAlwaysIncludeSubnets() ([]net.IPNet, []error)
86+
GetNeverIncludeSubnets() ([]net.IPNet, []error)
87+
GetInternalSubnets() ([]net.IPNet, []error)
8688
}

converter/config/yaml/filtering.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package yaml
2+
3+
import "net"
4+
import "github.com/pkg/errors"
5+
6+
//filtering implements config.Filtering
7+
type filtering struct {
8+
AlwaysInclude []string `yaml:"AlwaysInclude"`
9+
NeverInclude []string `yaml:"NeverInclude"`
10+
InternalSubnets []string `yaml:"InternalSubnets"`
11+
}
12+
13+
func (f *filtering) GetAlwaysIncludeSubnets() ([]net.IPNet, []error) {
14+
return f.parseSubnetList(f.AlwaysInclude)
15+
}
16+
17+
func (f *filtering) GetNeverIncludeSubnets() ([]net.IPNet, []error) {
18+
return f.parseSubnetList(f.NeverInclude)
19+
}
20+
21+
func (f *filtering) GetInternalSubnets() ([]net.IPNet, []error) {
22+
return f.parseSubnetList(f.InternalSubnets)
23+
}
24+
25+
func (f *filtering) parseSubnetList(netList []string) ([]net.IPNet, []error) {
26+
var errorList []error
27+
var nets []net.IPNet
28+
for j := range netList {
29+
//parse as network
30+
_, network, err := net.ParseCIDR(netList[j])
31+
if err != nil {
32+
//parse as IP
33+
ipAddr := net.ParseIP(netList[j])
34+
35+
if ipAddr == nil {
36+
errorList = append(errorList, errors.WithStack(err))
37+
continue
38+
}
39+
40+
network = f.ipToIPNet(ipAddr)
41+
}
42+
43+
nets = append(nets, *network)
44+
}
45+
return nets, errorList
46+
}
47+
48+
func (f *filtering) ipToIPNet(ipAddr net.IP) *net.IPNet {
49+
var netmask net.IPMask
50+
if ipAddr.To4() == nil {
51+
netmask = net.CIDRMask(32, 32)
52+
} else {
53+
netmask = net.CIDRMask(128, 128)
54+
}
55+
return &net.IPNet{
56+
IP: ipAddr,
57+
Mask: netmask,
58+
}
59+
}

converter/config/yaml/ipfix.go

Lines changed: 0 additions & 23 deletions
This file was deleted.

converter/config/yaml/yaml.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ func ReadConfigFile() ([]byte, error) {
3232
//yamlConfig contains the applications settings
3333
//as represented by a YAML string. Implements config.Config
3434
type yamlConfig struct {
35-
Input input `yaml:"Input"`
36-
Output output `yaml:"Output"`
37-
IPFIX ipfix `yaml:"IPFIX"`
35+
Input input `yaml:"Input"`
36+
Output output `yaml:"Output"`
37+
Filtering filtering `yaml:"Filtering"`
3838
}
3939

4040
func (y *yamlConfig) GetInputConfig() config.Input {
@@ -45,8 +45,8 @@ func (y *yamlConfig) GetOutputConfig() config.Output {
4545
return &y.Output
4646
}
4747

48-
func (y *yamlConfig) GetIPFIXConfig() config.IPFIX {
49-
return &y.IPFIX
48+
func (y *yamlConfig) GetFilteringConfig() config.Filtering {
49+
return &y.Filtering
5050
}
5151

5252
//NewYAMLConfig creates a new yamlConfig from

0 commit comments

Comments
 (0)