@@ -22,11 +22,14 @@ package config
2222
2323import (
2424 "context"
25- "github.com/elastic/elastic-agent-libs/logp"
25+ "errors"
26+ "fmt"
2627 "os"
2728 "path/filepath"
2829 "time"
2930
31+ "github.com/elastic/elastic-agent-libs/logp"
32+
3033 "github.com/elastic/beats/v7/libbeat/processors"
3134 "github.com/elastic/beats/v7/x-pack/libbeat/common/aws"
3235 "github.com/elastic/elastic-agent-libs/config"
@@ -38,11 +41,7 @@ const DefaultNamespace = "default"
3841
3942const ResultsDatastreamIndexPrefix = "logs-cloud_security_posture.findings"
4043
41- const (
42- InputTypeVanillaK8s = "cloudbeat/cis_k8s"
43- InputTypeEks = "cloudbeat/cis_eks"
44- InputTypeAws = "cloudbeat/cis_aws"
45- )
44+ var ErrBenchmarkNotSupported = errors .New ("benchmark is not supported" )
4645
4746type Fetcher struct {
4847 Name string `config:"name"` // Name of the fetcher
@@ -57,6 +56,7 @@ type Config struct {
5756 Period time.Duration `config:"period"`
5857 Processors processors.PluginConfig `config:"processors"`
5958 BundlePath string `config:"bundle_path"`
59+ Benchmark * string `config:"config.v1.benchmark"`
6060}
6161
6262type RuntimeConfig struct {
@@ -79,16 +79,23 @@ func New(cfg *config.C) (*Config, error) {
7979 return nil , err
8080 }
8181
82- if c .RuntimeCfg != nil && c .RuntimeCfg .ActivatedRules != nil && len (c .RuntimeCfg .ActivatedRules .CisEks ) > 0 {
83- c .Type = InputTypeEks
82+ if c .Benchmark != nil {
83+ if ! isSupportedBenchmark (* c .Benchmark ) {
84+ return c , ErrBenchmarkNotSupported
85+ }
86+ c .Type = buildConfigType (* c .Benchmark )
87+ } else {
88+ if c .RuntimeCfg != nil && c .RuntimeCfg .ActivatedRules != nil && len (c .RuntimeCfg .ActivatedRules .CisEks ) > 0 {
89+ c .Type = buildConfigType (CIS_EKS )
90+ }
8491 }
8592 return c , nil
8693}
8794
8895func defaultConfig () (* Config , error ) {
8996 ret := & Config {
9097 Period : 4 * time .Hour ,
91- Type : InputTypeVanillaK8s ,
98+ Type : buildConfigType ( CIS_K8S ) ,
9299 }
93100
94101 bundle , err := getBundlePath ()
@@ -120,3 +127,16 @@ func Datastream(namespace string, indexPrefix string) string {
120127type AwsConfigProvider interface {
121128 InitializeAWSConfig (ctx context.Context , cfg aws.ConfigAWS , log * logp.Logger ) (awssdk.Config , error )
122129}
130+
131+ func isSupportedBenchmark (benchmark string ) bool {
132+ for _ , s := range SupportedCIS {
133+ if benchmark == s {
134+ return true
135+ }
136+ }
137+ return false
138+ }
139+
140+ func buildConfigType (benchmark string ) string {
141+ return fmt .Sprintf ("cloudbeat/%s" , benchmark )
142+ }
0 commit comments