Skip to content
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
25 changes: 18 additions & 7 deletions src/bpm/runc/adapter/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"os"
"path/filepath"
"slices"
"strings"

"code.cloudfoundry.org/bytefmt"
Expand Down Expand Up @@ -232,11 +233,11 @@ func (a *RuncAdapter) BuildSpec(
ms.addMounts(boshMounts)
ms.addMounts(userProvidedIdentityMounts(bpmCfg, procCfg.AdditionalVolumes))
if procCfg.Unsafe != nil && len(procCfg.Unsafe.UnrestrictedVolumes) > 0 {
expanded, err := a.globExpandVolumes(procCfg.Unsafe.UnrestrictedVolumes)
expandUnrestrictedVolumes, err := a.globExpandVolumes(procCfg.Unsafe.UnrestrictedVolumes)
if err != nil {
return specs.Spec{}, err
}
filteredVolumes := filterVolumesUnderBoshMounts(boshMounts, expanded)
filteredVolumes := filterVolumesUnderBoshMounts(boshMounts, expandUnrestrictedVolumes)
ms.addMounts(userProvidedIdentityMounts(bpmCfg, filteredVolumes))
}

Expand Down Expand Up @@ -288,13 +289,23 @@ func (a *RuncAdapter) BuildSpec(
return *spec, nil
}

func filterVolumesUnderBoshMounts(mounts []specs.Mount, volumes []config.Volume) []config.Volume {
func filterVolumesUnderBoshMounts(boshMounts []specs.Mount, unrestrictedVolumes []config.Volume) []config.Volume {
var filteredVolumes []config.Volume
for _, v := range volumes {
for _, v := range unrestrictedVolumes {
keep := true
for _, m := range mounts {
if strings.HasPrefix(v.Path, m.Destination) {
keep = false
for _, m := range boshMounts {
// 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.
boshMountDirParts := strings.Split(m.Destination, fmt.Sprintf("%c", filepath.Separator))
volumeDirParts := strings.Split(v.Path, fmt.Sprintf("%c", filepath.Separator))

if len(boshMountDirParts) <= len(volumeDirParts) {
volumeDirPartsPrefix := volumeDirParts[:len(boshMountDirParts)]
if slices.Compare(boshMountDirParts, volumeDirPartsPrefix) == 0 {
keep = false
}
}
}

Expand Down
11 changes: 9 additions & 2 deletions src/bpm/runc/adapter/adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,8 @@ var _ = Describe("RuncAdapter", func() {
{Path: "/this/is/an/unrestricted/path"},
{Path: "/writable/executable/path", Writable: true, AllowExecutions: true},
{Path: "/var/vcap/jobs/example/config/config.yml", MountOnly: true},
{Path: "/var/vcap/jobs/other/config/config.yml", MountOnly: true},
{Path: "/var/vcap/jobs/other/config/config.yml", MountOnly: true, AllowExecutions: true},
{Path: "/var/vcap/jobs/example-two/config/config.yml", MountOnly: true, AllowExecutions: true},
},
}
})
Expand All @@ -894,7 +895,13 @@ var _ = Describe("RuncAdapter", func() {
Destination: "/var/vcap/jobs/other/config/config.yml",
Type: "bind",
Source: "/var/vcap/jobs/other/config/config.yml",
Options: []string{"nodev", "nosuid", "noexec", "rbind", "ro"},
Options: []string{"nodev", "nosuid", "rbind", "exec", "ro"},
}))
Expect(spec.Mounts).To(HaveMount(specs.Mount{
Destination: "/var/vcap/jobs/example-two/config/config.yml",
Type: "bind",
Source: "/var/vcap/jobs/example-two/config/config.yml",
Options: []string{"nodev", "nosuid", "rbind", "exec", "ro"},
}))
})

Expand Down