Skip to content

Commit a5f8270

Browse files
committed
fix: support base64password field in secret
1 parent 613018d commit a5f8270

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ endif
246246
.PHONY: install-smb-provisioner
247247
install-smb-provisioner:
248248
kubectl delete secret smbcreds --ignore-not-found -n default
249-
kubectl create secret generic smbcreds --from-literal username=USERNAME --from-literal password="PASSWORD" --from-literal mountOptions="dir_mode=0777,file_mode=0777,uid=0,gid=0,mfsymlinks" -n default
249+
kubectl create secret generic smbcreds --from-literal username=USERNAME --from-literal base64password="UEFTU1dPUkQK" --from-literal mountOptions="dir_mode=0777,file_mode=0777,uid=0,gid=0,mfsymlinks" -n default
250250
ifdef TEST_WINDOWS
251251
kubectl apply -f deploy/example/smb-provisioner/smb-server-lb.yaml
252252
else

pkg/smb/nodeserver.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
183183
}
184184
defer d.volumeLocks.Release(lockKey)
185185

186-
var username, password, domain string
186+
var username, password, base64Password, domain string
187187
for k, v := range secrets {
188188
switch strings.ToLower(k) {
189189
case usernameField:
@@ -192,9 +192,20 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
192192
password = strings.TrimSpace(v)
193193
case domainField:
194194
domain = strings.TrimSpace(v)
195+
case base64PasswordField:
196+
base64Password = strings.TrimSpace(v)
195197
}
196198
}
197199

200+
if base64Password != "" {
201+
klog.V(2).Infof("NodeStageVolume: decoding password from base64 string")
202+
decodePassword, err := base64.StdEncoding.DecodeString(password)
203+
if err != nil {
204+
return nil, status.Error(codes.InvalidArgument, "error base64 decoding password")
205+
}
206+
password = string(decodePassword)
207+
}
208+
198209
if ephemeralVol {
199210
mountFlags = strings.Split(ephemeralVolMountOptions, ",")
200211
}

pkg/smb/smb.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package smb
1818

1919
import (
2020
"context"
21+
"encoding/base64"
2122
"errors"
2223
"fmt"
2324
"net"
@@ -49,6 +50,7 @@ const (
4950
sourceField = "source"
5051
subDirField = "subdir"
5152
domainField = "domain"
53+
base64PasswordField = "base64password"
5254
mountOptionsField = "mountoptions"
5355
secretNameField = "secretname"
5456
secretNamespaceField = "secretnamespace"
@@ -232,6 +234,15 @@ func (d *Driver) GetUserNamePasswordFromSecret(ctx context.Context, secretName,
232234
username := strings.TrimSpace(string(secret.Data[usernameField][:]))
233235
password := strings.TrimSpace(string(secret.Data[passwordField][:]))
234236
domain := strings.TrimSpace(string(secret.Data[domainField][:]))
237+
base64Password := strings.TrimSpace(string(secret.Data[base64PasswordField][:]))
238+
if base64Password != "" {
239+
klog.V(2).Infof("decoding password from base64 string")
240+
decodePassword, err := base64.StdEncoding.DecodeString(password)
241+
if err != nil {
242+
return "", "", "", fmt.Errorf("could not decode password from base64 string: %v", err)
243+
}
244+
password = string(decodePassword)
245+
}
235246
return username, password, domain, nil
236247
}
237248

0 commit comments

Comments
 (0)