Created
April 4, 2022 10:00
-
-
Save liamg/34669a0c3f8e5d3a4a6f5e46c88836a9 to your computer and use it in GitHub Desktop.
Example: Kubernetes scanning with defsec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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