Skip to content

Commit 1e53ee5

Browse files
nader-ziadaaramprice
authored andcommitted
Compare path-parts instead of path-strings when filtering mounts
Check to see whether the "directory parts" of the volume are a sub-set of and existing BPM-default directory (that will already be mounted) so that we do not accidentally filter out mounts which have a name that is a sub-string of the existing job. For example the job `service-metrics` should be able to have an unrestricted volume mount of the `service-metrics-adapter` job directory. Specifically a job located at `/var/vcap/jobs/service-metrics` was unable to access an "unrestricted volume" located at `/var/vcap/jobs/service-metrics-adapter` because the job being instantiated alreay had default mount which was a (string) prefix of the job directory it was attempting to mount. Signed-off-by: Rajath Agasthya <rajath.agasthya@broadcom.com> Signed-off-by: aram price <aram.price@broadcom.com>
1 parent 5b3a58c commit 1e53ee5

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

src/bpm/runc/adapter/adapter.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"fmt"
2121
"os"
2222
"path/filepath"
23+
"slices"
2324
"strings"
2425

2526
"code.cloudfoundry.org/bytefmt"
@@ -293,8 +294,18 @@ func filterVolumesUnderBoshMounts(boshMounts []specs.Mount, unrestrictedVolumes
293294
for _, v := range unrestrictedVolumes {
294295
keep := true
295296
for _, m := range boshMounts {
296-
if strings.HasPrefix(v.Path, m.Destination) {
297-
keep = false
297+
// Check to see whether the "directory parts" of the volume are a sub-set of and existing BPM-default
298+
// directory (that will already be mounted) so that we do not accidentally filter out mounts which
299+
// have a name that is a sub-string of the existing job. For example the job `service-metrics` should be
300+
// able to have an unrestricted volume mount of the `service-metrics-adapter` job directory.
301+
boshMountDirParts := strings.Split(m.Destination, fmt.Sprintf("%c", filepath.Separator))
302+
volumeDirParts := strings.Split(v.Path, fmt.Sprintf("%c", filepath.Separator))
303+
304+
if len(boshMountDirParts) <= len(volumeDirParts) {
305+
volumeDirPartsPrefix := volumeDirParts[:len(boshMountDirParts)]
306+
if slices.Compare(boshMountDirParts, volumeDirPartsPrefix) == 0 {
307+
keep = false
308+
}
298309
}
299310
}
300311

src/bpm/runc/adapter/adapter_test.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,8 @@ var _ = Describe("RuncAdapter", func() {
869869
{Path: "/this/is/an/unrestricted/path"},
870870
{Path: "/writable/executable/path", Writable: true, AllowExecutions: true},
871871
{Path: "/var/vcap/jobs/example/config/config.yml", MountOnly: true},
872-
{Path: "/var/vcap/jobs/other/config/config.yml", MountOnly: true},
872+
{Path: "/var/vcap/jobs/other/config/config.yml", MountOnly: true, AllowExecutions: true},
873+
{Path: "/var/vcap/jobs/example-two/config/config.yml", MountOnly: true, AllowExecutions: true},
873874
},
874875
}
875876
})
@@ -894,7 +895,13 @@ var _ = Describe("RuncAdapter", func() {
894895
Destination: "/var/vcap/jobs/other/config/config.yml",
895896
Type: "bind",
896897
Source: "/var/vcap/jobs/other/config/config.yml",
897-
Options: []string{"nodev", "nosuid", "noexec", "rbind", "ro"},
898+
Options: []string{"nodev", "nosuid", "rbind", "exec", "ro"},
899+
}))
900+
Expect(spec.Mounts).To(HaveMount(specs.Mount{
901+
Destination: "/var/vcap/jobs/example-two/config/config.yml",
902+
Type: "bind",
903+
Source: "/var/vcap/jobs/example-two/config/config.yml",
904+
Options: []string{"nodev", "nosuid", "rbind", "exec", "ro"},
898905
}))
899906
})
900907

0 commit comments

Comments
 (0)