Skip to content

Commit 69289c8

Browse files
committed
Add additional check for dockershim.sock
1 parent 0103043 commit 69289c8

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ jobs:
2020
args: release --rm-dist
2121
env:
2222
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
23-
# - name: Update new version in krew-index
24-
#uses: rajatjindal/krew-release-bot@v0.0.40
23+
# - name: Update new version in krew-index
24+
# uses: rajatjindal/krew-release-bot@v0.0.40

.krew.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ metadata:
55
spec:
66
version: {{ .TagName }}
77
homepage: https://github.com/aws-containers/kubectl-detector-for-docker-socket
8-
shortDescription: Detect if workloads are mounting docker.sock
8+
shortDescription: Detect if workloads are mounting the docker socket
99
description: |
1010
This plugin checks workloads in a Kubernetes cluster or manifest files
1111
and reports if any of the mounted volumes contain the string "docker.sock".
@@ -20,7 +20,7 @@ spec:
2020
{{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 }}
2121
bin: "./kubectl-dds"
2222
files:
23-
- from: kubectl-example
23+
- from: kubectl-dds
2424
to: .
2525
- from: LICENSE
2626
to: .
@@ -31,7 +31,7 @@ spec:
3131
{{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 }}
3232
bin: "./kubectl-dds"
3333
files:
34-
- from: kubectl-example
34+
- from: kubectl-dds
3535
to: .
3636
- from: LICENSE
3737
to: .
@@ -42,7 +42,7 @@ spec:
4242
{{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 }}
4343
bin: "./kubectl-dds"
4444
files:
45-
- from: kubectl-example
45+
- from: kubectl-dds
4646
to: .
4747
- from: LICENSE
4848
to: .

main.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ func printResources(namespace corev1.Namespace, clientset *kubernetes.Clientset,
275275
for _, v := range daemonset.Spec.Template.Spec.Volumes {
276276
if v.VolumeSource.HostPath != nil {
277277
// fmt.Printf("testing %s\n", v.VolumeSource.HostPath.Path)
278-
if strings.Contains(v.VolumeSource.HostPath.Path, "docker.sock") {
278+
if containsDockerSock(v.VolumeSource.HostPath.Path) {
279279
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t\n", namespaceName, "daemonset", daemonset.Name, "mounted")
280280
break
281281
}
@@ -312,13 +312,21 @@ func printResources(namespace corev1.Namespace, clientset *kubernetes.Clientset,
312312
}
313313
}
314314

315+
func containsDockerSock(s string) bool {
316+
if strings.Contains(s, "docker.sock") || strings.Contains(s, "dockershim.sock") {
317+
return true
318+
} else {
319+
return false
320+
}
321+
}
322+
315323
func printVolumes(w *tabwriter.Writer, volumes []corev1.Volume, namespace, resType, resName string, verbose bool) bool {
316324
// initialize sockFound to use for exit code
317325
sockFound := false
318326
for _, v := range volumes {
319327
if v.VolumeSource.HostPath != nil {
320328
mounted := "not-mounted"
321-
if strings.Contains(v.VolumeSource.HostPath.Path, "docker.sock") {
329+
if containsDockerSock(v.VolumeSource.HostPath.Path) {
322330
mounted = "mounted"
323331
sockFound = true
324332
}
@@ -365,7 +373,7 @@ func searchFile(path string) (int, error) {
365373

366374
line := 1
367375
for scanner.Scan() {
368-
if strings.Contains(scanner.Text(), "docker.sock") {
376+
if containsDockerSock(scanner.Text()) {
369377
return line, nil
370378
}
371379

0 commit comments

Comments
 (0)