/
main.go
80 lines (65 loc) · 1.77 KB
/
main.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
// SPDX-License-Identifier: Apache-2.0
// Copyright 2021 Authors of KubeArmor
// Package main is the entrypoint to initializing the armor
package main
import (
"os"
"path/filepath"
cfg "github.com/kubearmor/KubeArmor/KubeArmor/config"
"github.com/kubearmor/KubeArmor/KubeArmor/core"
kg "github.com/kubearmor/KubeArmor/KubeArmor/log"
)
// GitCommit represents build-time info for git commit
var GitCommit string
// GitBranch represents build-time info for git branch
var GitBranch string
// BuildDate represents build-time info for build date
var BuildDate string
func printBuildDetails() {
if GitCommit == "" {
return
}
kg.Printf("BUILD-INFO: commit: %v, branch: %v, date: %v",
GitCommit, GitBranch, BuildDate)
}
func init() {
printBuildDetails()
}
func main() {
if os.Geteuid() != 0 {
if os.Getenv("KUBEARMOR_UBI") == "" {
kg.Printf("Need to have root privileges to run %s\n", os.Args[0])
return
}
}
// initial clean up
bpfMapsDir := "/sys/fs/bpf/"
bpfMapsName := []string{"kubearmor_config", "kubearmor_events", "kubearmor_containers", "kubearmor_visibility"}
for _, mp := range bpfMapsName {
path := bpfMapsDir + mp
/* This should not be triggered in ideal cases,
if this is triggered that means there is incomplete cleanup process
from the last installation */
if _, err := os.Stat(path); !os.IsNotExist(err) {
err = os.Remove(path)
if err != nil {
kg.Err(err.Error())
}
kg.Warnf("Deleteing existing map %s. This means previous cleanup was failed", path)
}
}
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
kg.Err(err.Error())
return
}
if err := os.Chdir(dir); err != nil {
kg.Err(err.Error())
return
}
if err := cfg.LoadConfig(); err != nil {
kg.Err(err.Error())
return
}
core.KubeArmor()
}