update
This commit is contained in:
parent
1831a27600
commit
4f80e889d4
|
@ -39,6 +39,10 @@ func NewConsoleCmd() *cobra.Command {
|
||||||
}
|
}
|
||||||
log.Fatal("Local API is disabled, please run this command on the local API machine")
|
log.Fatal("Local API is disabled, please run this command on the local API machine")
|
||||||
}
|
}
|
||||||
|
if err := csConfig.LoadCrowdsec(); err != nil {
|
||||||
|
log.Fatalf("Unable to load CrowdSec Agent: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
if csConfig.DisableAPI {
|
if csConfig.DisableAPI {
|
||||||
log.Fatal("Local API is disabled, please run this command on the local API machine")
|
log.Fatal("Local API is disabled, please run this command on the local API machine")
|
||||||
}
|
}
|
||||||
|
@ -280,7 +284,7 @@ Disable given information push to the central API.`,
|
||||||
}
|
}
|
||||||
csConfig.API.Server.ConsoleConfig.LabelsToSend[key] = data
|
csConfig.API.Server.ConsoleConfig.LabelsToSend[key] = data
|
||||||
}
|
}
|
||||||
if err := csConfig.API.Server.DumpLabelConfigFile(); err != nil {
|
if err := csConfig.Crowdsec.DumpLabelConfigFile(); err != nil {
|
||||||
log.Fatalf(err.Error())
|
log.Fatalf(err.Error())
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -21,7 +21,6 @@ const (
|
||||||
var CONSOLE_CONFIGS = []string{SEND_CUSTOM_SCENARIOS, SEND_MANUAL_SCENARIOS, SEND_TAINTED_SCENARIOS, SEND_LABEL}
|
var CONSOLE_CONFIGS = []string{SEND_CUSTOM_SCENARIOS, SEND_MANUAL_SCENARIOS, SEND_TAINTED_SCENARIOS, SEND_LABEL}
|
||||||
|
|
||||||
var DefaultConsoleConfigFilePath = DefaultConfigPath("console.yaml")
|
var DefaultConsoleConfigFilePath = DefaultConfigPath("console.yaml")
|
||||||
var DefaultLabelsConfigFilePath = DefaultConfigPath("console", "labels.yaml")
|
|
||||||
|
|
||||||
type ConsoleConfig struct {
|
type ConsoleConfig struct {
|
||||||
ShareManualDecisions *bool `yaml:"share_manual_decisions"`
|
ShareManualDecisions *bool `yaml:"share_manual_decisions"`
|
||||||
|
@ -52,15 +51,6 @@ func (c *LocalApiServerCfg) LoadConsoleConfig() error {
|
||||||
return fmt.Errorf("unmarshaling console config file '%s': %s", c.ConsoleConfigPath, err)
|
return fmt.Errorf("unmarshaling console config file '%s': %s", c.ConsoleConfigPath, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
yamlFile, err = ioutil.ReadFile(DefaultLabelsConfigFilePath)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("reading console config file '%s': %s", DefaultLabelsConfigFilePath, err)
|
|
||||||
}
|
|
||||||
err = yaml.Unmarshal(yamlFile, c.ConsoleConfig.LabelsToSend)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("unmarshaling labels console config file '%s': %s", DefaultLabelsConfigFilePath, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if c.ConsoleConfig.ShareCustomScenarios == nil {
|
if c.ConsoleConfig.ShareCustomScenarios == nil {
|
||||||
log.Debugf("no share_custom scenarios found, setting to true")
|
log.Debugf("no share_custom scenarios found, setting to true")
|
||||||
c.ConsoleConfig.ShareCustomScenarios = types.BoolPtr(true)
|
c.ConsoleConfig.ShareCustomScenarios = types.BoolPtr(true)
|
||||||
|
@ -103,18 +93,3 @@ func (c *LocalApiServerCfg) DumpConsoleConfig() error {
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *LocalApiServerCfg) DumpLabelConfigFile() error {
|
|
||||||
var out []byte
|
|
||||||
var err error
|
|
||||||
|
|
||||||
if out, err = yaml.Marshal(c.ConsoleConfig.LabelsToSend); err != nil {
|
|
||||||
return errors.Wrapf(err, "while marshaling ConsoleConfig (for %s)", DefaultLabelsConfigFilePath)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := os.WriteFile(DefaultLabelsConfigFilePath, out, 0600); err != nil {
|
|
||||||
return errors.Wrapf(err, "while dumping console config to %s", DefaultLabelsConfigFilePath)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
|
@ -2,18 +2,20 @@ package csconfig
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
"gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
/*Configurations needed for crowdsec to load parser/scenarios/... + acquisition*/
|
/*Configurations needed for crowdsec to load parser/scenarios/... + acquisition*/
|
||||||
type CrowdsecServiceCfg struct {
|
type CrowdsecServiceCfg struct {
|
||||||
AcquisitionFilePath string `yaml:"acquisition_path,omitempty"`
|
AcquisitionFilePath string `yaml:"acquisition_path,omitempty"`
|
||||||
AcquisitionDirPath string `yaml:"acquisition_dir,omitempty"`
|
AcquisitionDirPath string `yaml:"acquisition_dir,omitempty"`
|
||||||
|
ConsoleLabelsPath string `yaml:"console_labels_path"`
|
||||||
AcquisitionFiles []string `yaml:"-"`
|
AcquisitionFiles []string `yaml:"-"`
|
||||||
ParserRoutinesCount int `yaml:"parser_routines"`
|
ParserRoutinesCount int `yaml:"parser_routines"`
|
||||||
BucketsRoutinesCount int `yaml:"buckets_routines"`
|
BucketsRoutinesCount int `yaml:"buckets_routines"`
|
||||||
|
@ -24,13 +26,16 @@ type CrowdsecServiceCfg struct {
|
||||||
BucketStateDumpDir string `yaml:"state_output_dir,omitempty"` //if we need to unserialize buckets on shutdown
|
BucketStateDumpDir string `yaml:"state_output_dir,omitempty"` //if we need to unserialize buckets on shutdown
|
||||||
BucketsGCEnabled bool `yaml:"-"` //we need to garbage collect buckets when in forensic mode
|
BucketsGCEnabled bool `yaml:"-"` //we need to garbage collect buckets when in forensic mode
|
||||||
|
|
||||||
HubDir string `yaml:"-"`
|
HubDir string `yaml:"-"`
|
||||||
DataDir string `yaml:"-"`
|
DataDir string `yaml:"-"`
|
||||||
ConfigDir string `yaml:"-"`
|
ConfigDir string `yaml:"-"`
|
||||||
HubIndexFile string `yaml:"-"`
|
HubIndexFile string `yaml:"-"`
|
||||||
SimulationFilePath string `yaml:"-"`
|
SimulationFilePath string `yaml:"-"`
|
||||||
|
LabelsToSend map[string][]string `yaml:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var DefaultLabelsConfigFilePath = DefaultConfigPath("console", "labels.yaml")
|
||||||
|
|
||||||
func (c *Config) LoadCrowdsec() error {
|
func (c *Config) LoadCrowdsec() error {
|
||||||
var err error
|
var err error
|
||||||
// Configuration paths are dependency to load crowdsec configuration
|
// Configuration paths are dependency to load crowdsec configuration
|
||||||
|
@ -89,6 +94,18 @@ func (c *Config) LoadCrowdsec() error {
|
||||||
if c.Crowdsec.OutputRoutinesCount <= 0 {
|
if c.Crowdsec.OutputRoutinesCount <= 0 {
|
||||||
c.Crowdsec.OutputRoutinesCount = 1
|
c.Crowdsec.OutputRoutinesCount = 1
|
||||||
}
|
}
|
||||||
|
if c.Crowdsec.ConsoleLabelsPath == "" {
|
||||||
|
c.Crowdsec.ConsoleLabelsPath = DefaultLabelsConfigFilePath
|
||||||
|
}
|
||||||
|
yamlFile, err := ioutil.ReadFile(c.Crowdsec.ConsoleLabelsPath)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("reading console label file '%s': %s", c.Crowdsec.ConsoleLabelsPath, err)
|
||||||
|
}
|
||||||
|
c.Crowdsec.LabelsToSend = make(map[string][]string, 0)
|
||||||
|
err = yaml.Unmarshal(yamlFile, c.Crowdsec.LabelsToSend)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unmarshaling labels console config file '%s': %s", DefaultLabelsConfigFilePath, err)
|
||||||
|
}
|
||||||
|
|
||||||
var crowdsecCleanup = []*string{
|
var crowdsecCleanup = []*string{
|
||||||
&c.Crowdsec.AcquisitionFilePath,
|
&c.Crowdsec.AcquisitionFilePath,
|
||||||
|
@ -118,3 +135,18 @@ func (c *Config) LoadCrowdsec() error {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *CrowdsecServiceCfg) DumpLabelConfigFile() error {
|
||||||
|
var out []byte
|
||||||
|
var err error
|
||||||
|
|
||||||
|
if out, err = yaml.Marshal(c.LabelsToSend); err != nil {
|
||||||
|
return errors.Wrapf(err, "while marshaling ConsoleConfig (for %s)", DefaultLabelsConfigFilePath)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := os.WriteFile(DefaultLabelsConfigFilePath, out, 0600); err != nil {
|
||||||
|
return errors.Wrapf(err, "while dumping console config to %s", DefaultLabelsConfigFilePath)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue