Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save visortelle/93919b76f31896af7bb676b96669de6a to your computer and use it in GitHub Desktop.
Save visortelle/93919b76f31896af7bb676b96669de6a to your computer and use it in GitHub Desktop.
List all pods security context in current namespace
kubectl get pods --all-namespaces -o go-template --template='{{range .items}}{{"pod: "}}{{.metadata.name}}
{{if .spec.securityContext}}
PodSecurityContext:
{{"runAsGroup: "}}{{.spec.securityContext.runAsGroup}}
{{"runAsNonRoot: "}}{{.spec.securityContext.runAsNonRoot}}
{{"runAsUser: "}}{{.spec.securityContext.runAsUser}} {{if .spec.securityContext.seLinuxOptions}}
{{"seLinuxOptions: "}}{{.spec.securityContext.seLinuxOptions}} {{end}}
{{else}}PodSecurity Context is not set
{{end}}{{range .spec.containers}}
{{"container name: "}}{{.name}}
{{"image: "}}{{.image}}{{if .securityContext}}
{{"allowPrivilegeEscalation: "}}{{.securityContext.allowPrivilegeEscalation}} {{if .securityContext.capabilities}}
{{"capabilities: "}}{{.securityContext.capabilities}} {{end}}
{{"privileged: "}}{{.securityContext.privileged}} {{if .securityContext.procMount}}
{{"procMount: "}}{{.securityContext.procMount}} {{end}}
{{"readOnlyRootFilesystem: "}}{{.securityContext.readOnlyRootFilesystem}}
{{"runAsGroup: "}}{{.securityContext.runAsGroup}}
{{"runAsNonRoot: "}}{{.securityContext.runAsNonRoot}}
{{"runAsUser: "}}{{.securityContext.runAsUser}} {{if .securityContext.seLinuxOptions}}
{{"seLinuxOptions: "}}{{.securityContext.seLinuxOptions}} {{end}}{{if .securityContext.windowsOptions}}
{{"windowsOptions: "}}{{.securityContext.windowsOptions}} {{end}}
{{else}}
SecurityContext is not set
{{end}}
{{end}}{{end}}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment