From 147b1d0c161afd38d279cb563aacf65d026e69f0 Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Thu, 27 May 2021 08:54:35 +0200 Subject: [PATCH] NodePublishVolume: require parents of target directory to exist According to the spec, "the CO SHALL ensure that the parent directory of this path exists". The driver didn't rely on that and created those parent directories itself if necessary, without removing them in NodeUnpublishVolume. This hides potential bugs in the CO or incorrect configuration of csi-sanity (like creating directories in the wrong pod). Therefore it is better to be strict and only create the actual target directory itself. --- pkg/hostpath/nodeserver.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/hostpath/nodeserver.go b/pkg/hostpath/nodeserver.go index a1465deb1..22a42d703 100644 --- a/pkg/hostpath/nodeserver.go +++ b/pkg/hostpath/nodeserver.go @@ -141,7 +141,7 @@ func (hp *hostPath) NodePublishVolume(ctx context.Context, req *csi.NodePublishV notMnt, err := mount.IsNotMountPoint(mount.New(""), targetPath) if err != nil { if os.IsNotExist(err) { - if err = os.MkdirAll(targetPath, 0750); err != nil { + if err = os.Mkdir(targetPath, 0750); err != nil { return nil, fmt.Errorf("create target path: %w", err) } notMnt = true