-
Notifications
You must be signed in to change notification settings - Fork 41
/
eks_preset.go
83 lines (69 loc) · 3.64 KB
/
eks_preset.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package preset
import (
"fmt"
"regexp"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/elastic/elastic-agent-libs/logp"
k8s "k8s.io/client-go/kubernetes"
"github.com/elastic/cloudbeat/internal/dataprovider/providers/cloud"
"github.com/elastic/cloudbeat/internal/resources/fetching"
"github.com/elastic/cloudbeat/internal/resources/fetching/condition"
awsfetchers "github.com/elastic/cloudbeat/internal/resources/fetching/fetchers/aws"
k8sfetchers "github.com/elastic/cloudbeat/internal/resources/fetching/fetchers/k8s"
"github.com/elastic/cloudbeat/internal/resources/fetching/registry"
"github.com/elastic/cloudbeat/internal/resources/providers/awslib"
"github.com/elastic/cloudbeat/internal/resources/providers/awslib/ecr"
"github.com/elastic/cloudbeat/internal/resources/providers/awslib/elb"
"github.com/elastic/cloudbeat/internal/uniqueness"
)
const (
elbRegexTemplate = "([\\w-]+)-\\d+\\.%s.elb.amazonaws.com"
)
var (
eksRequiredProcesses = k8sfetchers.ProcessesConfigMap{"kubelet": {ConfigFileArguments: []string{"config"}}}
eksFsPatterns = []string{
"/hostfs/etc/kubernetes/kubelet/kubelet-config.json",
"/hostfs/var/lib/kubelet/kubeconfig"}
)
func NewCisEksFetchers(log *logp.Logger, awsConfig aws.Config, ch chan fetching.ResourceInfo, le uniqueness.Manager, k8sClient k8s.Interface, identity *cloud.Identity) registry.FetchersMap {
log.Infof("Initializing EKS fetchers")
m := make(registry.FetchersMap)
if identity != nil {
log.Info("Initialize aws-related fetchers")
ecrPrivateProvider := ecr.NewEcrProvider(log, awsConfig, &awslib.MultiRegionClientFactory[ecr.Client]{})
privateRepoRegex := fmt.Sprintf(awsfetchers.PrivateRepoRegexTemplate, identity.Account)
ecrPodDescriber := awsfetchers.PodDescriber{
FilterRegex: regexp.MustCompile(privateRepoRegex),
Provider: ecrPrivateProvider,
}
ecrFetcher := awsfetchers.NewEcrFetcher(log, ch, k8sClient, ecrPodDescriber)
m[fetching.EcrType] = registry.RegisteredFetcher{Fetcher: ecrFetcher, Condition: []fetching.Condition{condition.NewIsLeader(le)}}
elbProvider := elb.NewElbProvider(awsConfig)
loadBalancerRegex := fmt.Sprintf(elbRegexTemplate, awsConfig.Region)
elbFetcher := awsfetchers.NewElbFetcher(log, ch, k8sClient, elbProvider, identity, loadBalancerRegex)
m[fetching.ElbType] = registry.RegisteredFetcher{Fetcher: elbFetcher, Condition: []fetching.Condition{condition.NewIsLeader(le)}}
}
fsFetcher := k8sfetchers.NewFsFetcher(log, ch, eksFsPatterns)
m[fetching.FileSystemType] = registry.RegisteredFetcher{Fetcher: fsFetcher}
procFetcher := k8sfetchers.NewProcessFetcher(log, ch, eksRequiredProcesses)
m[fetching.ProcessType] = registry.RegisteredFetcher{Fetcher: procFetcher}
kubeFetcher := k8sfetchers.NewKubeFetcher(log, ch, k8sClient)
m[fetching.KubeAPIType] = registry.RegisteredFetcher{Fetcher: kubeFetcher, Condition: []fetching.Condition{condition.NewIsLeader(le)}}
return m
}