Skip to content

Commit

Permalink
fix: support base64password field in secret
Browse files Browse the repository at this point in the history
  • Loading branch information
andyzhangx committed Jan 18, 2025
1 parent 613018d commit a5f8270
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ endif
.PHONY: install-smb-provisioner
install-smb-provisioner:
kubectl delete secret smbcreds --ignore-not-found -n default
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
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
ifdef TEST_WINDOWS
kubectl apply -f deploy/example/smb-provisioner/smb-server-lb.yaml
else
Expand Down
13 changes: 12 additions & 1 deletion pkg/smb/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
}
defer d.volumeLocks.Release(lockKey)

var username, password, domain string
var username, password, base64Password, domain string
for k, v := range secrets {
switch strings.ToLower(k) {
case usernameField:
Expand All @@ -192,9 +192,20 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
password = strings.TrimSpace(v)
case domainField:
domain = strings.TrimSpace(v)
case base64PasswordField:
base64Password = strings.TrimSpace(v)
}
}

if base64Password != "" {
klog.V(2).Infof("NodeStageVolume: decoding password from base64 string")
decodePassword, err := base64.StdEncoding.DecodeString(password)
if err != nil {
return nil, status.Error(codes.InvalidArgument, "error base64 decoding password")
}
password = string(decodePassword)
}

if ephemeralVol {
mountFlags = strings.Split(ephemeralVolMountOptions, ",")
}
Expand Down
11 changes: 11 additions & 0 deletions pkg/smb/smb.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package smb

import (
"context"
"encoding/base64"
"errors"
"fmt"
"net"
Expand Down Expand Up @@ -49,6 +50,7 @@ const (
sourceField = "source"
subDirField = "subdir"
domainField = "domain"
base64PasswordField = "base64password"
mountOptionsField = "mountoptions"
secretNameField = "secretname"
secretNamespaceField = "secretnamespace"
Expand Down Expand Up @@ -232,6 +234,15 @@ func (d *Driver) GetUserNamePasswordFromSecret(ctx context.Context, secretName,
username := strings.TrimSpace(string(secret.Data[usernameField][:]))
password := strings.TrimSpace(string(secret.Data[passwordField][:]))
domain := strings.TrimSpace(string(secret.Data[domainField][:]))
base64Password := strings.TrimSpace(string(secret.Data[base64PasswordField][:]))
if base64Password != "" {
klog.V(2).Infof("decoding password from base64 string")
decodePassword, err := base64.StdEncoding.DecodeString(password)
if err != nil {
return "", "", "", fmt.Errorf("could not decode password from base64 string: %v", err)
}
password = string(decodePassword)
}
return username, password, domain, nil
}

Expand Down

0 comments on commit a5f8270

Please sign in to comment.