Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "feat: support base64password field in secret" #908

Merged
merged 1 commit into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 base64password="UEFTU1dPUkQ=" --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 password="PASSWORD" --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: 1 addition & 12 deletions 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, base64Password, domain string
var username, password, domain string
for k, v := range secrets {
switch strings.ToLower(k) {
case usernameField:
Expand All @@ -192,20 +192,9 @@ 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(base64Password)
if err != nil {
return nil, status.Error(codes.InvalidArgument, "error base64 decoding password")
}
password = string(decodePassword)
}

if ephemeralVol {
mountFlags = strings.Split(ephemeralVolMountOptions, ",")
}
Expand Down
17 changes: 0 additions & 17 deletions pkg/smb/nodeserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,6 @@ func TestNodeStageVolume(t *testing.T) {
passwordField: "test_password",
domainField: "test_doamin",
}
secretsWithBase64Password := map[string]string{
usernameField: "test_username",
passwordField: base64.StdEncoding.EncodeToString([]byte("test_password")),
domainField: "test_doamin",
}

tests := []struct {
desc string
Expand Down Expand Up @@ -235,18 +230,6 @@ func TestNodeStageVolume(t *testing.T) {
strings.Replace(testSource, "\\", "\\\\", -1), sourceTest, testSource, sourceTest),
expectedErr: testutil.TestError{},
},
{
desc: "[Success] Valid request with base64 encoded password",
req: &csi.NodeStageVolumeRequest{VolumeId: "vol_1##", StagingTargetPath: sourceTest,
VolumeCapability: &stdVolCap,
VolumeContext: volContext,
Secrets: secretsWithBase64Password},
skipOnWindows: true,
flakyWindowsErrorMessage: fmt.Sprintf("rpc error: code = Internal desc = volume(vol_1##) mount \"%s\" on %#v failed with "+
"NewSmbGlobalMapping(%s, %s) failed with error: rpc error: code = Unknown desc = NewSmbGlobalMapping failed.",
strings.Replace(testSource, "\\", "\\\\", -1), sourceTest, testSource, sourceTest),
expectedErr: testutil.TestError{},
},
}

// Setup
Expand Down
11 changes: 0 additions & 11 deletions pkg/smb/smb.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package smb

import (
"context"
"encoding/base64"
"errors"
"fmt"
"net"
Expand Down Expand Up @@ -50,7 +49,6 @@ const (
sourceField = "source"
subDirField = "subdir"
domainField = "domain"
base64PasswordField = "base64password"
mountOptionsField = "mountoptions"
secretNameField = "secretname"
secretNamespaceField = "secretnamespace"
Expand Down Expand Up @@ -234,15 +232,6 @@ 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(base64Password)
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
28 changes: 0 additions & 28 deletions pkg/smb/smb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package smb

import (
"context"
"fmt"
"os"
"path/filepath"
Expand Down Expand Up @@ -521,33 +520,6 @@ users:
}
}

func TestGetUserNamePasswordFromSecret(t *testing.T) {
tests := []struct {
desc string
secretName string
secretNamespace string
expectedUsername string
expectedPassword string
expectedDomain string
expectedError error
}{
{
desc: "kubeclient is nil",
secretName: "secretName",
expectedError: fmt.Errorf("could not username and password from secret(secretName): KubeClient is nil"),
},
}

d := NewFakeDriver()
for _, test := range tests {
username, password, domain, err := d.GetUserNamePasswordFromSecret(context.Background(), test.secretName, test.secretNamespace)
assert.Equal(t, test.expectedUsername, username, "test[%s]: unexpected username", test.desc)
assert.Equal(t, test.expectedPassword, password, "test[%s]: unexpected password", test.desc)
assert.Equal(t, test.expectedDomain, domain, "test[%s]: unexpected domain", test.desc)
assert.Equal(t, test.expectedError, err, "test[%s]: unexpected error", test.desc)
}
}

func createTestFile(path string) error {
f, err := os.Create(path)
if err != nil {
Expand Down
Loading