Skip to content

Commit 7dcb9ea

Browse files
authored
Merge pull request #908 from kubernetes-csi/revert-906-fix-password
Revert "feat: support base64password field in secret"
2 parents 7f78b7a + c1138d0 commit 7dcb9ea

File tree

5 files changed

+2
-69
lines changed

5 files changed

+2
-69
lines changed

Makefile

+1-1
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 base64password="UEFTU1dPUkQ=" --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 password="PASSWORD" --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

+1-12
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, base64Password, domain string
186+
var username, password, domain string
187187
for k, v := range secrets {
188188
switch strings.ToLower(k) {
189189
case usernameField:
@@ -192,20 +192,9 @@ 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)
197195
}
198196
}
199197

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

pkg/smb/nodeserver_test.go

-17
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,6 @@ func TestNodeStageVolume(t *testing.T) {
9292
passwordField: "test_password",
9393
domainField: "test_doamin",
9494
}
95-
secretsWithBase64Password := map[string]string{
96-
usernameField: "test_username",
97-
passwordField: base64.StdEncoding.EncodeToString([]byte("test_password")),
98-
domainField: "test_doamin",
99-
}
10095

10196
tests := []struct {
10297
desc string
@@ -235,18 +230,6 @@ func TestNodeStageVolume(t *testing.T) {
235230
strings.Replace(testSource, "\\", "\\\\", -1), sourceTest, testSource, sourceTest),
236231
expectedErr: testutil.TestError{},
237232
},
238-
{
239-
desc: "[Success] Valid request with base64 encoded password",
240-
req: &csi.NodeStageVolumeRequest{VolumeId: "vol_1##", StagingTargetPath: sourceTest,
241-
VolumeCapability: &stdVolCap,
242-
VolumeContext: volContext,
243-
Secrets: secretsWithBase64Password},
244-
skipOnWindows: true,
245-
flakyWindowsErrorMessage: fmt.Sprintf("rpc error: code = Internal desc = volume(vol_1##) mount \"%s\" on %#v failed with "+
246-
"NewSmbGlobalMapping(%s, %s) failed with error: rpc error: code = Unknown desc = NewSmbGlobalMapping failed.",
247-
strings.Replace(testSource, "\\", "\\\\", -1), sourceTest, testSource, sourceTest),
248-
expectedErr: testutil.TestError{},
249-
},
250233
}
251234

252235
// Setup

pkg/smb/smb.go

-11
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package smb
1818

1919
import (
2020
"context"
21-
"encoding/base64"
2221
"errors"
2322
"fmt"
2423
"net"
@@ -50,7 +49,6 @@ const (
5049
sourceField = "source"
5150
subDirField = "subdir"
5251
domainField = "domain"
53-
base64PasswordField = "base64password"
5452
mountOptionsField = "mountoptions"
5553
secretNameField = "secretname"
5654
secretNamespaceField = "secretnamespace"
@@ -234,15 +232,6 @@ func (d *Driver) GetUserNamePasswordFromSecret(ctx context.Context, secretName,
234232
username := strings.TrimSpace(string(secret.Data[usernameField][:]))
235233
password := strings.TrimSpace(string(secret.Data[passwordField][:]))
236234
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(base64Password)
241-
if err != nil {
242-
return "", "", "", fmt.Errorf("could not decode password from base64 string: %v", err)
243-
}
244-
password = string(decodePassword)
245-
}
246235
return username, password, domain, nil
247236
}
248237

pkg/smb/smb_test.go

-28
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ limitations under the License.
1717
package smb
1818

1919
import (
20-
"context"
2120
"fmt"
2221
"os"
2322
"path/filepath"
@@ -521,33 +520,6 @@ users:
521520
}
522521
}
523522

524-
func TestGetUserNamePasswordFromSecret(t *testing.T) {
525-
tests := []struct {
526-
desc string
527-
secretName string
528-
secretNamespace string
529-
expectedUsername string
530-
expectedPassword string
531-
expectedDomain string
532-
expectedError error
533-
}{
534-
{
535-
desc: "kubeclient is nil",
536-
secretName: "secretName",
537-
expectedError: fmt.Errorf("could not username and password from secret(secretName): KubeClient is nil"),
538-
},
539-
}
540-
541-
d := NewFakeDriver()
542-
for _, test := range tests {
543-
username, password, domain, err := d.GetUserNamePasswordFromSecret(context.Background(), test.secretName, test.secretNamespace)
544-
assert.Equal(t, test.expectedUsername, username, "test[%s]: unexpected username", test.desc)
545-
assert.Equal(t, test.expectedPassword, password, "test[%s]: unexpected password", test.desc)
546-
assert.Equal(t, test.expectedDomain, domain, "test[%s]: unexpected domain", test.desc)
547-
assert.Equal(t, test.expectedError, err, "test[%s]: unexpected error", test.desc)
548-
}
549-
}
550-
551523
func createTestFile(path string) error {
552524
f, err := os.Create(path)
553525
if err != nil {

0 commit comments

Comments
 (0)