Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(install): wait for KubeArmor to create probe file before probing #338

Merged
merged 1 commit into from
Jun 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 35 additions & 17 deletions install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func printAnimation(msg string, flag bool) int {
if flag {
progress++
}
printBar(" KubeArmor Installing ", 16)
printBar(" KubeArmor Installing ", 17)
return 0
}

Expand Down Expand Up @@ -141,23 +141,41 @@ func checkPods(c *k8s.Client, o Options) {
break
}
}
probeData, err := probe.ProbeRunningKubeArmorNodes(c, probe.Options{
Namespace: o.Namespace,
})
if err != nil || len(probeData) == 0 {
return
}
enforcing := true
for _, k := range probeData {
if k.ActiveLSM == "" || !k.ContainerSecurity {
enforcing = false
break
fmt.Print("\n🔧 Verifying KubeArmor functionality (this may take upto a minute) ...")
ctx, cancel := context.WithTimeout(context.Background(), 40*time.Second)
defer cancel()

for {
select {
case <-time.After(1 * time.Second):
nyrahul marked this conversation as resolved.
Show resolved Hide resolved
case <-ctx.Done():
fmt.Print("⚠️ Failed verifying KubeArmor functionality ...")
return
}
}
if enforcing {
fmt.Print(color.New(color.FgWhite, color.Bold).Sprint("\n\t🛡️ Your Cluster is Armored Up Now! \n"))
} else {
color.Yellow("\n\t⚠️ KubeArmor is running in Audit mode, only Observability will be available and Policy Enforcement won't work. \n")
probeData, err := probe.ProbeRunningKubeArmorNodes(c, probe.Options{
Namespace: o.Namespace,
})
if err != nil || len(probeData) == 0 {
fmt.Printf("\r🔧 Verifying KubeArmor functionality (this may take upto a minute) ... %s", cursor[cursorcount])
cursorcount++
if cursorcount == 4 {
cursorcount = 0
}
continue
}
enforcing := true
for _, k := range probeData {
if k.ActiveLSM == "" || !k.ContainerSecurity {
enforcing = false
break
}
}
if enforcing {
fmt.Print(color.New(color.FgWhite, color.Bold).Sprint("\n\n\t🛡️ Your Cluster is Armored Up! \n"))
} else {
color.Yellow("\n\n\t⚠️ KubeArmor is running in Audit mode, only Observability will be available and Policy Enforcement won't work. \n")
}
break
}

}
Expand Down
6 changes: 2 additions & 4 deletions probe/probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,9 +489,9 @@ func readDataFromKubeArmor(c *k8s.Client, o Options, nodeName string) (KubeArmor
VersionedParams(&corev1.PodExecOptions{
Container: pods.Items[0].Spec.Containers[0].Name,
Command: cmdArr,
Stdin: true,
Stdin: false,
Stdout: true,
Stderr: true,
Stderr: false,
TTY: false,
}, scheme.ParameterCodec)
exec, err := remotecommand.NewSPDYExecutor(c.Config, "POST", req.URL())
Expand All @@ -501,9 +501,7 @@ func readDataFromKubeArmor(c *k8s.Client, o Options, nodeName string) (KubeArmor
go func() {
defer outStream.Close()
err = exec.StreamWithContext(context.TODO(), remotecommand.StreamOptions{
Stdin: os.Stdin,
Stdout: outStream,
Stderr: os.Stderr,
Tty: false,
})
}()
Expand Down