Skip to content

Commit

Permalink
Merge pull request #815 from Ankurk99/main
Browse files Browse the repository at this point in the history
address review comments in #709
  • Loading branch information
nyrahul authored Aug 13, 2022
2 parents ace1cc3 + aeb6fec commit fbbeb23
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
3 changes: 1 addition & 2 deletions KubeArmor/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,7 @@ func GetCRISocket(ContainerRuntime string) string {
if ContainerRuntime != "" && k != ContainerRuntime {
continue
}
criruntime := k
for _, candidate := range ContainerRuntimeSocketMap[criruntime] {
for _, candidate := range ContainerRuntimeSocketMap[k] {
if _, err := os.Stat(candidate); err == nil {
return candidate
}
Expand Down
21 changes: 7 additions & 14 deletions KubeArmor/core/kubeArmor.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,12 +311,6 @@ func GetOSSigChannel() chan os.Signal {
return c
}

// Trim sock file location from the env variable
func trimmedSocketPath() string {
trimmedPath := strings.TrimPrefix(cfg.GlobalCfg.CRISocket, "unix://")
return trimmedPath
}

// ========== //
// == Main == //
// ========== //
Expand Down Expand Up @@ -451,7 +445,7 @@ func KubeArmor() {
}
}

trimmedSocket := trimmedSocketPath()
enableContainerPolicy := true

// Un-orchestrated workloads
if !dm.K8sEnabled && cfg.GlobalCfg.Policy {
Expand All @@ -460,10 +454,9 @@ func KubeArmor() {
if cfg.GlobalCfg.CRISocket == "" {
if kl.GetCRISocket("") == "" {
dm.Logger.Warnf("Error while looking for CRI socket file")
enableContainerPolicy = false
} else {
cfg.GlobalCfg.CRISocket = "unix://" + kl.GetCRISocket("")
// update the value of trimmed socket path when the cfg.GlobalCfg.CRISocket is not set
trimmedSocket = trimmedSocketPath()
}
}

Expand All @@ -481,6 +474,7 @@ func KubeArmor() {
go dm.MonitorCrioEvents()
} else {
dm.Logger.Warnf("Failed to monitor containers: %s is not a supported CRI socket.", cfg.GlobalCfg.CRISocket)
enableContainerPolicy = false
}

dm.Logger.Printf("Using %s for monitoring containers", cfg.GlobalCfg.CRISocket)
Expand All @@ -489,6 +483,7 @@ func KubeArmor() {
if dm.K8sEnabled && cfg.GlobalCfg.Policy {
// check if the CRI socket set while executing kubearmor exists
if cfg.GlobalCfg.CRISocket != "" {
trimmedSocket := strings.TrimPrefix(cfg.GlobalCfg.CRISocket, "unix://")
if _, err := os.Stat(trimmedSocket); err != nil {
dm.Logger.Warnf("Error while looking for CRI socket file: %s", err.Error())

Expand Down Expand Up @@ -616,11 +611,9 @@ func KubeArmor() {

policyService := &policy.ServiceServer{}

if !dm.K8sEnabled && cfg.GlobalCfg.Policy {
if _, err := os.Stat(trimmedSocket); err == nil {
policyService.UpdateContainerPolicy = dm.ParseAndUpdateContainerSecurityPolicy
dm.Logger.Print("Started to monitor container security policies on gRPC")
}
if enableContainerPolicy {
policyService.UpdateContainerPolicy = dm.ParseAndUpdateContainerSecurityPolicy
dm.Logger.Print("Started to monitor container security policies on gRPC")
}

if !cfg.GlobalCfg.K8sEnv && cfg.GlobalCfg.HostPolicy {
Expand Down

0 comments on commit fbbeb23

Please sign in to comment.