Skip to content

Instantly share code, notes, and snippets.

@liamg
Created April 4, 2022 10:00
Show Gist options
  • Save liamg/34669a0c3f8e5d3a4a6f5e46c88836a9 to your computer and use it in GitHub Desktop.
Save liamg/34669a0c3f8e5d3a4a6f5e46c88836a9 to your computer and use it in GitHub Desktop.
Example: Kubernetes scanning with defsec
package main
import (
"context"
"fmt"
"os"
"strings"
"github.com/aquasecurity/defsec/pkg/scanners/kubernetes"
)
func main() {
results, err := kubernetes.NewScanner().ScanReader(context.TODO(), "k8s.yml", strings.NewReader(`
apiVersion: v1
kind: Pod
metadata:
name: hello-cpu-limit
spec:
containers:
- command: ["sh", "-c", "echo 'Hello' && sleep 1h"]
image: busybox
name: hello
`))
if err != nil {
panic(err)
}
if len(results.GetFailed()) == 0 {
fmt.Println("AOK")
os.Exit(0)
}
for _, result := range results.GetFailed() {
fmt.Printf("%#v\n\n", result)
}
os.Exit(1)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment