Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve subpath to mount matching #3269

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions syft/internal/fileresolver/path_skipper.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,13 @@ func (ps pathSkipper) pathIndexVisitor(_ string, givenPath string, _ os.FileInfo
for _, mi := range ps.mounts {
conditionalPaths, ignorable := ps.ignorableMountTypes[mi.FSType]

if len(conditionalPaths) == 0 {
// Rule 1: ignore any path within a mount point that is of the given filesystem type unconditionally
if !containsPath(givenPath, mi.Mountpoint) {
continue
}
// Rule 0: Make sure the given path is within the mount point; if not let the scan continue
if !containsPath(givenPath, mi.Mountpoint) {
kzantow marked this conversation as resolved.
Show resolved Hide resolved
continue
}

// Rule 1: ignore any path within a mount point that is of the given filesystem type unconditionally
if len(conditionalPaths) == 0 {
if !ignorable {
// we've matched on the most specific path at this point, which means we should stop searching
// mount points for this path
Expand Down Expand Up @@ -151,7 +152,7 @@ func simpleClean(p string) string {
return "."
}
if p == "/" {
return "/"
return ""
}
return strings.TrimSuffix(p, "/")
}
37 changes: 37 additions & 0 deletions syft/internal/fileresolver/path_skipper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,43 @@ func Test_newPathSkipper(t *testing.T) {
},
},
},
{
name: "buildkit github ubuntu 22.04",
root: "/run/src/core/sbom",
mounts: []*mountinfo.Info{
{Mountpoint: "/", FSType: "overlay"},
{Mountpoint: "/proc", FSType: "proc"},
{Mountpoint: "/dev", FSType: "tmpfs"},
{Mountpoint: "/dev/pts", FSType: "devpts"},
{Mountpoint: "/dev/shm", FSType: "tmpfs"},
{Mountpoint: "/dev/mqueue", FSType: "mqueue"},
{Mountpoint: "/sys", FSType: "sysfs"},
{Mountpoint: "/etc/resolv.conf", FSType: "ext4"},
{Mountpoint: "/etc/hosts", FSType: "ext4"},
{Mountpoint: "/sys/fs/cgroup", FSType: "cgroup2"},
{Mountpoint: "/run/out", FSType: "ext4"},
{Mountpoint: "/run/src/core/sbom", FSType: "overlay"},
{Mountpoint: "/tmp", FSType: "tmpfs"},
{Mountpoint: "/dev/otel-grpc.sock", FSType: "overlay"},
{Mountpoint: "/proc/bus", FSType: "proc"},
{Mountpoint: "/proc/fs", FSType: "proc"},
{Mountpoint: "/proc/irq", FSType: "proc"},
{Mountpoint: "/proc/sys", FSType: "proc"},
{Mountpoint: "/proc/sysrq-trigger", FSType: "proc"},
{Mountpoint: "/proc/acpi", FSType: "tmpfs"},
{Mountpoint: "/proc/kcore", FSType: "tmpfs"},
{Mountpoint: "/proc/keys", FSType: "tmpfs"},
{Mountpoint: "/proc/latency_stats", FSType: "tmpfs"},
{Mountpoint: "/proc/timer_list", FSType: "tmpfs"},
{Mountpoint: "/sys/firmware", FSType: "tmpfs"},
{Mountpoint: "/proc/scsi", FSType: "tmpfs"},
},
want: []expect{
{
path: "/run/src/core/sbom",
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
Loading