Skip to content

Commit a118c24

Browse files
committed
fix: enable to use secrets with special characters
If the password to SMB-server contained special characters (e.g. "foo,bar"), the mount failed. Now, when the password is passed to mount via "credentials=filename" option, then mount succeeds.
1 parent 17485a5 commit a118c24

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

pkg/smb/nodeserver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
231231
return nil, status.Error(codes.Internal, fmt.Sprintf("MkdirAll %s failed with error: %v", targetPath, err))
232232
}
233233
if requireUsernamePwdOption && !useKerberosCache {
234-
sensitiveMountOptions = []string{fmt.Sprintf("%s=%s,%s=%s", usernameField, username, passwordField, password)}
234+
sensitiveMountOptions = []string{fmt.Sprintf("%s=%s", usernameField, username), fmt.Sprintf("%s=%s", passwordField, password)}
235235
}
236236
mountOptions = mountFlags
237237
if !gidPresent && volumeMountGroup != "" {

pkg/smb/smb_common_linux.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,30 @@ limitations under the License.
2020
package smb
2121

2222
import (
23+
"fmt"
2324
"os"
2425

2526
mount "k8s.io/mount-utils"
2627
)
2728

2829
func Mount(m *mount.SafeFormatAndMount, source, target, fsType string, options, sensitiveMountOptions []string, _ string) error {
30+
if len(sensitiveMountOptions) != 0 {
31+
file, err := os.CreateTemp("/tmp/", "*.smb.credentials")
32+
if err != nil {
33+
return err
34+
}
35+
36+
for _, option := range sensitiveMountOptions {
37+
_, err = file.Write([]byte(fmt.Sprintf("%s\n", option)))
38+
if err != nil {
39+
return err
40+
}
41+
}
42+
file.Close()
43+
defer os.Remove(file.Name())
44+
45+
sensitiveMountOptions = []string{fmt.Sprintf("credentials=%s", file.Name())}
46+
}
2947
return m.MountSensitive(source, target, fsType, options, sensitiveMountOptions)
3048
}
3149

0 commit comments

Comments
 (0)