Skip to content

Commit b62d746

Browse files
authored
Merge pull request #5942 from totegamma/master
fix fnplugin storagemounts validation
2 parents ab48be3 + 4bdc3f3 commit b62d746

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

api/internal/plugins/loader/loader.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ func (l *Loader) loadPlugin(res *resource.Resource) (resmap.Configurable, error)
251251
return nil, errors.Errorf("plugin %s with mount path '%s' is not permitted; "+
252252
"mount paths must be relative to the current kustomization directory", res.OrgId(), mount.Src)
253253
}
254-
if strings.HasPrefix(filepath.Clean(mount.Src), "../") {
254+
if strings.HasPrefix(filepath.Clean(mount.Src), "..") {
255255
return nil, errors.Errorf("plugin %s with mount path '%s' is not permitted; "+
256256
"mount paths must be under the current kustomization directory", res.OrgId(), mount.Src)
257257
}

api/internal/plugins/loader/loader_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,43 @@ func TestLoaderWithWorkingDir(t *testing.T) {
9595
npLdr.Config().FnpLoadingOptions.WorkingDir,
9696
"the plugin working dir is not updated")
9797
}
98+
99+
func TestLoaderWithStorageMounts(t *testing.T) {
100+
const storageMountTransformer = `
101+
apiVersion: com.example.kustomize/v1
102+
kind: Test
103+
metadata:
104+
name: test-transformer
105+
annotations:
106+
config.kubernetes.io/function: |
107+
container:
108+
image: test
109+
mounts:
110+
- type: bind
111+
src: ../
112+
dst: /mount
113+
`
114+
p := provider.NewDefaultDepProvider()
115+
rmF := resmap.NewFactory(p.GetResourceFactory())
116+
fsys := filesys.MakeFsInMemory()
117+
fLdr, err := loader.NewLoader(
118+
loader.RestrictionRootOnly,
119+
filesys.Separator, fsys)
120+
if err != nil {
121+
t.Fatal(err)
122+
}
123+
configs, err := rmF.NewResMapFromBytes([]byte(storageMountTransformer))
124+
if err != nil {
125+
t.Fatal(err)
126+
}
127+
c := types.EnabledPluginConfig(types.BploLoadFromFileSys)
128+
pLdr := NewLoader(c, rmF, fsys)
129+
if pLdr == nil {
130+
t.Fatal("expect non-nil loader")
131+
}
132+
_, err = pLdr.LoadTransformers(
133+
fLdr, valtest_test.MakeFakeValidator(), configs)
134+
if err == nil { // should fail because src specified is outside root
135+
t.Fatal("the loader allowed a mount outside root")
136+
}
137+
}

0 commit comments

Comments
 (0)