Skip to content

Commit

Permalink
Add suricata support (#6)
Browse files Browse the repository at this point in the history
* Initial suricata templates

* install suricata-update service

* added suricata configuration

Co-authored-by: Stefan Majer <[email protected]>
  • Loading branch information
mwindower and majst01 authored Apr 22, 2020
1 parent 989055e commit 4751eba
Show file tree
Hide file tree
Showing 14 changed files with 2,041 additions and 9 deletions.
21 changes: 12 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,23 @@ release: bin/$(BINARY) validate
tar -czvf metal-networker.tgz \
-C ./bin metal-networker \
-C ../internal/netconf/ \
droptailer.service.tpl \
firewall_policy_controller.service.tpl \
frr.firewall.tpl \
frr.machine.tpl \
hostname.tpl \
hosts.tpl \
interfaces.firewall.tpl \
interfaces.machine.tpl \
frr.machine.tpl \
frr.firewall.tpl \
nftables_exporter.service.tpl \
node_exporter.service.tpl \
rules.v4.tpl \
rules.v6.tpl \
suricata_config.yaml.tpl \
suricata_defaults.tpl \
suricata_update.service.tpl \
systemd.link.tpl \
systemd.network.tpl \
hosts.tpl \
hostname.tpl \
droptailer.service.tpl \
firewall_policy_controller.service.tpl \
nftables_exporter.service.tpl \
node_exporter.service.tpl
systemd.network.tpl

.PHONY: validate
validate:
Expand Down
26 changes: 26 additions & 0 deletions internal/netconf/configurator.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,24 @@ func (configurator FirewallConfigurator) Configure() {
mustEnableUnit(u.unit)
}
}

src = mustTmpFile("suricata_")
applier, err = NewSuricataDefaultsApplier(kb, src)

if err != nil {
log.Warnf("failed to configure suricata defaults: %v", err)
}

applyAndCleanUp(applier, TplSuricataDefaults, src, "/etc/default/suricata", FileModeSixFourFour)

src = mustTmpFile("suricata.yaml_")
applier, err = NewSuricataConfigApplier(kb, src)

if err != nil {
log.Warnf("failed to configure suricata: %v", err)
}

applyAndCleanUp(applier, TplSuricataConfig, src, "/etc/suricata/suricata.yaml", FileModeSixFourFour)
}

func (configurator FirewallConfigurator) getUnits() []unitConfiguration {
Expand Down Expand Up @@ -158,6 +176,14 @@ func (configurator FirewallConfigurator) getUnits() []unitConfiguration {
},
enabled: true,
},
{
unit: SystemdUnitSuricataUpdate,
templateFile: TplSuricataUpdate,
constructApplier: func(kb KnowledgeBase, v ServiceValidator) (net.Applier, error) {
return NewSuricataUpdateServiceApplier(kb, v)
},
enabled: true,
},
}
}

Expand Down
1 change: 1 addition & 0 deletions internal/netconf/nftables_exporter.service.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Description=Nftables exporter - provides prometheus metrics for nftables
After=network.target

[Service]
LimitMEMLOCK=infinity
ExecStart=/bin/ip vrf exec {{ .TenantVrf }} /usr/local/bin/nftables_exporter --config=/etc/nftables_exporter.yaml
Restart=always
RestartSec=30
Expand Down
1 change: 1 addition & 0 deletions internal/netconf/node_exporter.service.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Description=Node exporter - provides prometheus metrics about the node
After=network.target

[Service]
LimitMEMLOCK=infinity
ExecStart=/bin/ip vrf exec {{ .TenantVrf }} /usr/local/bin/node_exporter --collector.tcpstat
Restart=always
RestartSec=30
Expand Down
7 changes: 7 additions & 0 deletions internal/netconf/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ func TestServices(t *testing.T) {
assert.NoError(err)
nftablesExporterApplier, err := NewNftablesExporterServiceApplier(kb, v)
assert.NoError(err)
suApplier, err := NewSuricataUpdateServiceApplier(kb, v)
assert.NoError(err)

tests := []struct {
applier net.Applier
Expand All @@ -49,6 +51,11 @@ func TestServices(t *testing.T) {
expected: "testdata/nftables-exporter.service",
template: TplNftablesExporter,
},
{
applier: suApplier,
expected: "testdata/suricata-update.service",
template: TplSuricataUpdate,
},
}

for _, test := range tests {
Expand Down
37 changes: 37 additions & 0 deletions internal/netconf/suricata_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package netconf

import (
"github.com/metal-stack/metal-networker/pkg/net"
)

// TplSuricataConfig is the name of the template for the suricata configuration.
const TplSuricataConfig = "suricata_config.yaml.tpl"

// SuricataConfigData represents the information required to render suricata configuration.
type SuricataConfigData struct {
Comment string
DefaultRouteVrf string
}

// SuricataConfigValidator can validate configuration for suricata.
type SuricataConfigValidator struct {
path string
}

// NewSuricataConfigApplier constructs a new instance of this type.
func NewSuricataConfigApplier(kb KnowledgeBase, tmpFile string) (net.Applier, error) {
defaultRouteVrf, err := getDefaultRouteVRFName(kb)
if err != nil {
return nil, err
}

data := SuricataUpdateData{Comment: versionHeader(kb.Machineuuid), DefaultRouteVrf: defaultRouteVrf}
validator := SuricataConfigValidator{tmpFile}

return net.NewNetworkApplier(data, validator, nil), nil
}

// Validate validates suricata configuration.
func (v SuricataConfigValidator) Validate() error {
return nil
}
Loading

0 comments on commit 4751eba

Please sign in to comment.