Skip to content

Commit

Permalink
Add additional check for dockershim.sock
Browse files Browse the repository at this point in the history
  • Loading branch information
rothgar committed Apr 21, 2022
1 parent 0103043 commit 69289c8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ jobs:
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# - name: Update new version in krew-index
#uses: rajatjindal/[email protected]
# - name: Update new version in krew-index
# uses: rajatjindal/[email protected]
8 changes: 4 additions & 4 deletions .krew.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
spec:
version: {{ .TagName }}
homepage: https://github.com/aws-containers/kubectl-detector-for-docker-socket
shortDescription: Detect if workloads are mounting docker.sock
shortDescription: Detect if workloads are mounting the docker socket
description: |
This plugin checks workloads in a Kubernetes cluster or manifest files
and reports if any of the mounted volumes contain the string "docker.sock".
Expand All @@ -20,7 +20,7 @@ spec:
{{addURIAndSha "https://github.com/aws-containers/kubectl-detector-for-docker-socket/releases/download/{{ .TagName }}/kubectl-detector-for-docker-socket_{{ .TagName }}_darwin_amd64.tar.gz" .TagName }}
bin: "./kubectl-dds"
files:
- from: kubectl-example
- from: kubectl-dds
to: .
- from: LICENSE
to: .
Expand All @@ -31,7 +31,7 @@ spec:
{{addURIAndSha "https://github.com/aws-containers/kubectl-detector-for-docker-socket/releases/download/{{ .TagName }}/kubectl-detector-for-docker-socket_{{ .TagName }}_darwin_arm64.tar.gz" .TagName }}
bin: "./kubectl-dds"
files:
- from: kubectl-example
- from: kubectl-dds
to: .
- from: LICENSE
to: .
Expand All @@ -42,7 +42,7 @@ spec:
{{addURIAndSha "https://github.com/aws-containers/kubectl-detector-for-docker-socket/releases/download/{{ .TagName }}/kubectl-detector-for-docker-socket_{{ .TagName }}_linux_amd64.tar.gz" .TagName }}
bin: "./kubectl-dds"
files:
- from: kubectl-example
- from: kubectl-dds
to: .
- from: LICENSE
to: .
Expand Down
14 changes: 11 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ func printResources(namespace corev1.Namespace, clientset *kubernetes.Clientset,
for _, v := range daemonset.Spec.Template.Spec.Volumes {
if v.VolumeSource.HostPath != nil {
// fmt.Printf("testing %s\n", v.VolumeSource.HostPath.Path)
if strings.Contains(v.VolumeSource.HostPath.Path, "docker.sock") {
if containsDockerSock(v.VolumeSource.HostPath.Path) {
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t\n", namespaceName, "daemonset", daemonset.Name, "mounted")
break
}
Expand Down Expand Up @@ -312,13 +312,21 @@ func printResources(namespace corev1.Namespace, clientset *kubernetes.Clientset,
}
}

func containsDockerSock(s string) bool {
if strings.Contains(s, "docker.sock") || strings.Contains(s, "dockershim.sock") {
return true
} else {
return false
}
}

func printVolumes(w *tabwriter.Writer, volumes []corev1.Volume, namespace, resType, resName string, verbose bool) bool {
// initialize sockFound to use for exit code
sockFound := false
for _, v := range volumes {
if v.VolumeSource.HostPath != nil {
mounted := "not-mounted"
if strings.Contains(v.VolumeSource.HostPath.Path, "docker.sock") {
if containsDockerSock(v.VolumeSource.HostPath.Path) {
mounted = "mounted"
sockFound = true
}
Expand Down Expand Up @@ -365,7 +373,7 @@ func searchFile(path string) (int, error) {

line := 1
for scanner.Scan() {
if strings.Contains(scanner.Text(), "docker.sock") {
if containsDockerSock(scanner.Text()) {
return line, nil
}

Expand Down

0 comments on commit 69289c8

Please sign in to comment.