From e464386b06b60b835f432133f7e31565e6a3fcd6 Mon Sep 17 00:00:00 2001 From: AlteredCoder Date: Mon, 12 Apr 2021 17:38:11 +0200 Subject: [PATCH 1/2] update piddir to pid_dir in configuration --- README.md | 2 +- config.go | 11 ++++++++--- config/cs-firewall-bouncer.yaml | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 11e21f91..6d910e70 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ $ vim /etc/crowdsec/cs-firewall-bouncer/cs-firewall-bouncer.yaml ```yaml mode: iptables -piddir: /var/run/ +pid_dir: /var/run/ update_frequency: 10s daemonize: true log_mode: file diff --git a/config.go b/config.go index d26d340b..e084242f 100644 --- a/config.go +++ b/config.go @@ -13,7 +13,7 @@ import ( type bouncerConfig struct { Mode string `yaml:"mode"` //ipset,iptables,tc - PidDir string `yaml:"piddir"` + PidDir string `yaml:"pid_dir"` UpdateFrequency string `yaml:"update_frequency"` Daemon bool `yaml:"daemonize"` LogMode string `yaml:"log_mode"` @@ -39,12 +39,17 @@ func NewConfig(configPath string) (*bouncerConfig, error) { return &bouncerConfig{}, fmt.Errorf("failed to read %s : %v", configPath, err) } - err = yaml.UnmarshalStrict(configBuff, &config) + err = yaml.Unmarshal(configBuff, &config) if err != nil { return &bouncerConfig{}, fmt.Errorf("failed to unmarshal %s : %v", configPath, err) } - if config.Mode == "" || config.PidDir == "" || config.LogMode == "" { + if config.PidDir == "" { + log.Warningf("missing 'pid_dir' directive in '%s', using default: '/run/'", configPath) + config.PidDir = "/run/" + } + + if config.Mode == "" || config.LogMode == "" { return &bouncerConfig{}, fmt.Errorf("invalid configuration in %s", configPath) } if config.DenyLog && config.DenyLogPrefix == "" { diff --git a/config/cs-firewall-bouncer.yaml b/config/cs-firewall-bouncer.yaml index 824605b5..ab29fdb0 100644 --- a/config/cs-firewall-bouncer.yaml +++ b/config/cs-firewall-bouncer.yaml @@ -1,5 +1,5 @@ mode: ${BACKEND} -piddir: /var/run/ +pid_dir: /var/run/ update_frequency: 10s daemonize: true log_mode: file From 269c6282de366e086452ce941fc00ec45bbfd2f3 Mon Sep 17 00:00:00 2001 From: AlteredCoder Date: Mon, 12 Apr 2021 17:39:19 +0200 Subject: [PATCH 2/2] fix default --- config.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config.go b/config.go index e084242f..5c44e17f 100644 --- a/config.go +++ b/config.go @@ -45,8 +45,8 @@ func NewConfig(configPath string) (*bouncerConfig, error) { } if config.PidDir == "" { - log.Warningf("missing 'pid_dir' directive in '%s', using default: '/run/'", configPath) - config.PidDir = "/run/" + log.Warningf("missing 'pid_dir' directive in '%s', using default: '/var/run/'", configPath) + config.PidDir = "/var/run/" } if config.Mode == "" || config.LogMode == "" {