diff --git a/pkg/smb/controllerserver.go b/pkg/smb/controllerserver.go index c51691ab2ea..55c7b5581d0 100644 --- a/pkg/smb/controllerserver.go +++ b/pkg/smb/controllerserver.go @@ -83,26 +83,26 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest) } // check if create SubDir is enable in storage class parameters - parameters := req.GetParameters() - var createSubDir string - for k, v := range parameters { - switch strings.ToLower(k) { - case createSubDirField: - createSubDir = v - } + // parameters := req.GetParameters() + // var createSubDir string + // for k, v := range parameters { + // switch strings.ToLower(k) { + // case createSubDirField: + // createSubDir = v + // } + // } + + // if strings.EqualFold(createSubDir, "true") { + // Mount smb base share so we can create a subdirectory + if err := d.internalMount(ctx, smbVol, volCap); err != nil { + return nil, status.Errorf(codes.Internal, "failed to mount smb server: %v", err.Error()) } - - if strings.EqualFold(createSubDir, "true") { - // Mount smb base share so we can create a subdirectory - if err := d.internalMount(ctx, smbVol, volCap); err != nil { - return nil, status.Errorf(codes.Internal, "failed to mount smb server: %v", err.Error()) + defer func() { + if err = d.internalUnmount(ctx, smbVol); err != nil { + klog.Warningf("failed to unmount smb server: %v", err.Error()) } - defer func() { - if err = d.internalUnmount(ctx, smbVol); err != nil { - klog.Warningf("failed to unmount smb server: %v", err.Error()) - } - }() - } + }() + // } // Create subdirectory under base-dir // TODO: revisit permissions @@ -181,7 +181,7 @@ func (d *Driver) ListSnapshots(ctx context.Context, req *csi.ListSnapshotsReques } // Given a smbVolume, return a CSI volume id -func (d *Driver) getVolumeIDFromNfsVol(vol *smbVolume) string { +func (d *Driver) getVolumeIDFromSmbVol(vol *smbVolume) string { idElements := make([]string, totalIDElements) idElements[idsourceField] = strings.Trim(vol.sourceField, "/") idElements[idBaseDir] = strings.Trim(vol.baseDir, "/") @@ -214,6 +214,10 @@ func (d *Driver) internalMount(ctx context.Context, vol *smbVolume, volCap *csi. }, VolumeCapability: volCap, VolumeId: vol.id, + Secrets: map[string]string{ + "username": "username", + "password": "password", + }, }) return err } @@ -264,7 +268,7 @@ func (d *Driver) newSMBVolume(name string, size int64, params map[string]string) subDir: name, size: size, } - vol.id = d.getVolumeIDFromNfsVol(vol) + vol.id = d.getVolumeIDFromSmbVol(vol) return vol, nil } diff --git a/pkg/smb/nodeserver.go b/pkg/smb/nodeserver.go index c8a8fbb1eb6..916cf8d4db9 100644 --- a/pkg/smb/nodeserver.go +++ b/pkg/smb/nodeserver.go @@ -176,6 +176,8 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe defer d.volumeLocks.Release(volumeID) var username, password, domain string + // username = "a" + // password = "b" for k, v := range secrets { switch strings.ToLower(k) { case usernameField: @@ -202,6 +204,7 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe return nil, status.Error(codes.Internal, fmt.Sprintf("MkdirAll %s failed with error: %v", targetPath, err)) } sensitiveMountOptions = []string{fmt.Sprintf("%s=%s,%s=%s", usernameField, username, passwordField, password)} + klog.V(2).Infof("sensitive mount options %v", sensitiveMountOptions) mountOptions = mountFlags if domain != "" { mountOptions = append(mountOptions, fmt.Sprintf("%s=%s", domainField, domain)) diff --git a/test/integration/run-test.sh b/test/integration/run-test.sh index 3f8627ec34e..ec98a46fc8f 100755 --- a/test/integration/run-test.sh +++ b/test/integration/run-test.sh @@ -51,13 +51,13 @@ if [[ "${ARCH}" == "x86_64" || ${ARCH} == "unknown" ]]; then fi # Run CSI driver as a background service -_output/${ARCH}/smbplugin --endpoint "$endpoint" --nodeid CSINode -v=5 & +# _output/${ARCH}/smbplugin --endpoint "$endpoint" --nodeid CSINode -v=5 & trap cleanup EXIT sleep 5 # set secret for csc node stage -export X_CSI_SECRETS=username=username,"password=test" -params='source="//0.0.0.0",createSubDir="true",share=share' +export X_CSI_SECRETS="username=username","password=test" +params='source="//127.0.0.1/share",createSubDir="true",share=share' # Begin to run CSI functions one by one echo 'Create volume test:' readonly value=$("$CSC_BIN" controller new --endpoint "$endpoint" --cap 1,block "$volname" --req-bytes 2147483648 --params "$params")