Skip to content

fix: improve mount parsing to handle Docker socket path variations - #89

Merged
nozaq merged 2 commits into
mainfrom
claude/docker-mount-parsing-da7hsb
Aug 1, 2026
Merged

fix: improve mount parsing to handle Docker socket path variations#89
nozaq merged 2 commits into
mainfrom
claude/docker-mount-parsing-da7hsb

Conversation

@nozaq

@nozaq nozaq commented Aug 1, 2026

Copy link
Copy Markdown
Member

Summary

This PR improves the robustness of mount parsing in the no-docker-socket-mount and no-bind-mount rules by properly handling path normalization and supporting the full syntax of Docker mount specifications.

Key Changes

  • Added isDockerSocketSource() function: Centralizes Docker socket detection by normalizing paths using path.Clean(), ensuring that variations like //var/run/docker.sock and /var/run/docker.sock/ are correctly identified as the Docker socket.

  • Refactored runArgsFlagValues() as an iterator: Changed from a single-match function to an iterator that yields all values for a given flag, enabling detection of multiple Docker socket mounts in a single runArgs array.

  • Enhanced parseMountString() for CSV compliance: Updated to properly parse --mount values as CSV records (supporting quoted fields with embedded commas) and added support for the src alias for source. Also normalized type values to lowercase to match Docker's behavior.

  • Added volumeSpecSource() function: Extracts the host path from -v/--volume values, properly handling the colon-separated syntax and distinguishing between anonymous volumes (single field) and host mounts.

  • Improved parseMountObject() normalization: Now normalizes the type field to lowercase for consistent comparison.

  • Refactored checkDockerSocketRunArgs(): Now inspects the entire runArgs array and checks all mount-related flags (--mount, --volume, -v), reporting each problematic mount individually.

Notable Implementation Details

  • The isDockerSocketSource() function is the single source of truth for Docker socket detection, preventing disagreement between rules about the same mount.
  • Mount type comparisons are now case-insensitive, matching Docker's actual behavior.
  • The src alias for source in --mount values is now recognized.
  • CSV parsing for --mount values allows proper handling of quoted fields containing commas.
  • Path normalization handles edge cases like doubled slashes and trailing slashes that Docker's daemon normalizes before use.
  • Test coverage expanded to verify these improvements work correctly.

https://claude.ai/code/session_0127yGsFgejQ2hSfrYmW48GT

no-docker-socket-mount and no-bind-mount read "mounts" entries and the
"runArgs" mount flags with hand-rolled parsers that neither matched
docker's syntax nor kept the two flag syntaxes apart, so they missed real
Docker socket mounts and reported ones that never happen.

A "--mount" value is now read the way docker/cli's opts.MountOpt.Set does:
the whole value is trimmed and read as one CSV record, keys are matched
case-insensitively with "src" as an alias for "source", and the type is
lower-cased. Object entries get the same type folding, since
devcontainers/cli hands them to docker as a "--mount" value.

A "-v"/"--volume" value has no syntax in common with that, so it gets its
own reader: colon-separated fields where a comma is an ordinary character,
and a single-field value is an anonymous volume that binds nothing from
the host. Which syntax applies depends on the flag introducing the value,
which an entry does not carry on its own, so the rule now inspects the
whole "runArgs" array.

Whether a source is the socket is now one predicate, so the rule that
reports it and the rule that excuses it cannot disagree. It cleans the
path first, as the daemon does before mounting, so "//var/run/docker.sock"
and "/var/run/docker.sock/" are recognized too.
@nozaq nozaq changed the title Improve mount parsing to handle Docker socket path variations fix: improve mount parsing to handle Docker socket path variations Aug 1, 2026
The conflict was the rules/util.go import block: main added "iter" for
arrayMembers while this branch added "encoding/csv", "iter", and "path".

Both sides made a runArgs-reading rule see more of the document, so cover
the interaction: this branch moved no-docker-socket-mount from "/runArgs/*"
to "/runArgs", and main made rules read every copy of a duplicated array
property.
@nozaq
nozaq merged commit f28301e into main Aug 1, 2026
11 checks passed
@nozaq
nozaq deleted the claude/docker-mount-parsing-da7hsb branch August 1, 2026 08:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants