Skip to content

Commit f330f89

Browse files
committed
removed SMB file sharing
After the addition of 9p file sharing for Windows, we are removing SMB file sharing support (#4768).
1 parent f04c9fd commit f330f89

File tree

10 files changed

+9
-116
lines changed

10 files changed

+9
-116
lines changed

cmd/crc/cmd/start.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,6 @@ func runStart(ctx context.Context) (*types.StartResult, error) {
106106
}
107107
}
108108

109-
if runtime.GOOS == "windows" {
110-
username, err := crcos.GetCurrentUsername()
111-
if err != nil {
112-
return nil, err
113-
}
114-
115-
// config SharedDirPassword ('shared-dir-password') only exists in windows
116-
startConfig.SharedDirPassword = config.Get(crcConfig.SharedDirPassword).AsString()
117-
startConfig.SharedDirUsername = username
118-
}
119-
120109
return client.Start(ctx, startConfig)
121110
}
122111

pkg/crc/config/settings.go

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package config
22

33
import (
44
"fmt"
5-
"runtime"
65

76
"github.com/crc-org/crc/v2/pkg/crc/constants"
87
"github.com/crc-org/crc/v2/pkg/crc/logging"
@@ -62,17 +61,6 @@ func RegisterSettings(cfg *Config) {
6261
return validateBundlePath(value, GetPreset(cfg))
6362
}
6463

65-
validateSmbSharedDirs := func(value interface{}) (bool, string) {
66-
if !cfg.Get(HostNetworkAccess).AsBool() {
67-
return false, fmt.Sprintf("%s can only be used with %s set to 'true'",
68-
EnableSharedDirs, HostNetworkAccess)
69-
}
70-
if cfg.Get(SharedDirPassword).IsDefault {
71-
return false, fmt.Sprintf("Please set '%s' first to enable shared directories", SharedDirPassword)
72-
}
73-
return ValidateBool(value)
74-
}
75-
7664
// Preset setting should be on top because CPUs/Memory config depend on it.
7765
cfg.AddSetting(Preset, version.GetDefaultPreset().String(), validatePreset, RequiresDeleteAndSetupMsg,
7866
fmt.Sprintf("Virtual machine preset (valid values are: %s)", preset.AllPresets()))
@@ -96,18 +84,8 @@ func RegisterSettings(cfg *Config) {
9684
"Enable emergency login for 'core' user. Password is randomly generated. (true/false, default: false)")
9785
cfg.AddSetting(PersistentVolumeSize, constants.DefaultPersistentVolumeSize, validatePersistentVolumeSize, SuccessfullyApplied,
9886
fmt.Sprintf("Total size in GiB of the persistent volume used by the CSI driver for %s preset (must be greater than or equal to '%d')", preset.Microshift, constants.DefaultPersistentVolumeSize))
99-
100-
// Shared directories configs
101-
if runtime.GOOS == "windows" {
102-
cfg.AddSetting(SharedDirPassword, Secret(""), validateString, SuccessfullyApplied,
103-
"Password used while using CIFS/SMB file sharing (It is the password for the current logged in user)")
104-
105-
cfg.AddSetting(EnableSharedDirs, false, validateSmbSharedDirs, SuccessfullyApplied,
106-
"Mounts host's user profile folder at '/' in the CRC VM (true/false, default: false)")
107-
} else {
108-
cfg.AddSetting(EnableSharedDirs, true, ValidateBool, SuccessfullyApplied,
109-
"Mounts host's home directory at '/' in the CRC VM (true/false, default: true)")
110-
}
87+
cfg.AddSetting(EnableSharedDirs, true, ValidateBool, SuccessfullyApplied,
88+
"Mounts host's home directory at '/' in the CRC VM (true/false, default: true)")
11189

11290
if !version.IsInstaller() {
11391
cfg.AddSetting(NetworkMode, string(defaultNetworkMode()), network.ValidateMode, network.SuccessfullyAppliedMode,

pkg/crc/machine/driver.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,3 @@ func setDiskSize(host *host.Host, diskSize strongunits.GiB) error {
5757

5858
return updateDriverValue(host, diskSizeSetter)
5959
}
60-
61-
func setSharedDirPassword(host *host.Host, password string) error {
62-
driver, err := loadDriverConfig(host)
63-
if err != nil {
64-
return err
65-
}
66-
67-
if len(driver.SharedDirs) == 0 {
68-
return nil
69-
}
70-
71-
for i := range driver.SharedDirs {
72-
driver.SharedDirs[i].Password = password
73-
}
74-
return updateDriverStruct(host, driver)
75-
}

pkg/crc/machine/driver_darwin.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
machineVf "github.com/crc-org/crc/v2/pkg/drivers/vfkit"
1010
"github.com/crc-org/crc/v2/pkg/libmachine"
1111
"github.com/crc-org/crc/v2/pkg/libmachine/host"
12-
"github.com/crc-org/machine/libmachine/drivers"
1312
)
1413

1514
func newHost(api libmachine.API, machineConfig config.MachineConfig) (*host.Host, error) {
@@ -35,7 +34,3 @@ func updateDriverConfig(host *host.Host, driver *machineVf.Driver) error {
3534

3635
return host.UpdateConfig(driverData)
3736
}
38-
39-
func updateDriverStruct(_ *host.Host, _ *machineVf.Driver) error {
40-
return drivers.ErrNotImplemented
41-
}

pkg/crc/machine/driver_linux.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"github.com/crc-org/crc/v2/pkg/libmachine"
1111
"github.com/crc-org/crc/v2/pkg/libmachine/host"
1212
machineLibvirt "github.com/crc-org/machine/drivers/libvirt"
13-
"github.com/crc-org/machine/libmachine/drivers"
1413
)
1514

1615
func newHost(api libmachine.API, machineConfig config.MachineConfig) (*host.Host, error) {
@@ -44,7 +43,3 @@ func (r *RPCServerDriver) SetConfigRaw(data []byte, _ *struct{}) error {
4443
return json.Unmarshal(data, &r.ActualDriver)
4544
}
4645
*/
47-
48-
func updateDriverStruct(_ *host.Host, _ *machineLibvirt.Driver) error {
49-
return drivers.ErrNotImplemented
50-
}

pkg/crc/machine/driver_windows.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,3 @@ func updateDriverConfig(host *host.Host, driver *machineLibhvee.Driver) error {
3333
}
3434
return host.UpdateConfig(driverData)
3535
}
36-
37-
func updateDriverStruct(host *host.Host, driver *machineLibhvee.Driver) error {
38-
host.Driver = driver
39-
return nil
40-
}

pkg/crc/machine/libhvee/driver_windows.go

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package libhvee
22

33
import (
4+
"fmt"
45
"path/filepath"
56
"strings"
67

@@ -35,22 +36,14 @@ func convertToUnixPath(path string) string {
3536

3637
func configureShareDirs(machineConfig config.MachineConfig) []drivers.SharedDir {
3738
var sharedDirs []drivers.SharedDir
38-
for _, dir := range machineConfig.SharedDirs {
39+
for i, dir := range machineConfig.SharedDirs {
3940
sharedDir := drivers.SharedDir{
40-
Source: dir,
41-
Target: convertToUnixPath(dir),
42-
Tag: "crc-dir0", // smb share 'crc-dir0' is created in the msi
43-
Type: "cifs",
44-
Username: machineConfig.SharedDirUsername,
45-
}
46-
sharedDir9p := drivers.SharedDir{
4741
Source: dir,
48-
Target: convertToUnixPath(dir) + "9p", // temporary solution until smb sharing is removed
49-
Tag: "crc-dir0", // same as above
50-
//Tag: fmt.Sprintf("dir%d", i),
51-
Type: "9p",
42+
Target: convertToUnixPath(dir),
43+
Tag: fmt.Sprintf("dir%d", i),
44+
Type: "9p",
5245
}
53-
sharedDirs = append(sharedDirs, sharedDir, sharedDir9p)
46+
sharedDirs = append(sharedDirs, sharedDir)
5447
}
5548
return sharedDirs
5649
}

pkg/crc/machine/start.go

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,6 @@ func (client *client) updateVMConfig(startConfig types.StartConfig, vm *virtualM
100100
}
101101
}
102102

103-
// we want to set the shared dir password on-the-fly to be used
104-
// we do not want this value to be persisted to disk
105-
if startConfig.SharedDirPassword != "" {
106-
if err := setSharedDirPassword(vm.Host, startConfig.SharedDirPassword); err != nil {
107-
return fmt.Errorf("Failed to set shared dir password: %w", err)
108-
}
109-
}
110-
111103
return nil
112104
}
113105

@@ -214,7 +206,7 @@ func configureSharedDirs(vm *virtualMachine, sshRunner *crcssh.Runner) error {
214206
if err != nil {
215207
// the libvirt machine driver uses net/rpc, which wraps errors
216208
// in rpc.ServerError, but without using golang 1.13 error
217-
// wrapping feature. Moreover this package is marked as
209+
// wrapping feature. Moreover, this package is marked as
218210
// frozen/not accepting new features, so it's unlikely we'll
219211
// ever be able to use errors.Is()
220212
if err.Error() == drivers.ErrNotSupported.Error() || err.Error() == drivers.ErrNotImplemented.Error() {
@@ -249,16 +241,6 @@ func configureSharedDirs(vm *virtualMachine, sshRunner *crcssh.Runner) error {
249241
return err
250242
}
251243

252-
case "cifs":
253-
smbUncPath := fmt.Sprintf("//%s/%s", hostVirtualIP, mount.Tag)
254-
if _, _, err := sshRunner.RunPrivate("sudo", "mount", "-o", fmt.Sprintf("rw,uid=core,gid=core,username='%s',password='%s'", mount.Username, mount.Password), "-t", mount.Type, smbUncPath, mount.Target); err != nil {
255-
err = &crcerrors.MaskedSecretError{
256-
Err: err,
257-
Secret: mount.Password,
258-
}
259-
return fmt.Errorf("Failed to mount CIFS/SMB share '%s' please make sure configured password is correct: %w", mount.Tag, err)
260-
}
261-
262244
case "9p":
263245
// change owner to core user to allow mounting to it as a non-root user
264246
if _, _, err := sshRunner.RunPrivileged("Changing owner of mount directory", "chown core:core", mount.Target); err != nil {

pkg/drivers/libhvee/libhvee_windows.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,6 @@ func (d *Driver) GetIP() (string, error) {
271271
}
272272

273273
func (d *Driver) GetSharedDirs() ([]drivers.SharedDir, error) {
274-
for _, dir := range d.SharedDirs {
275-
if !smbShareExists(dir.Tag) {
276-
return []drivers.SharedDir{}, nil
277-
}
278-
}
279274
return d.SharedDirs, nil
280275
}
281276

pkg/drivers/libhvee/powershell_windows.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package libhvee
22

33
import (
44
"errors"
5-
"fmt"
65

76
log "github.com/crc-org/crc/v2/pkg/crc/logging"
87
"github.com/crc-org/crc/v2/pkg/os/windows/powershell"
@@ -20,11 +19,6 @@ func cmdOut(args ...string) (string, error) {
2019
return stdout, err
2120
}
2221

23-
func cmd(args ...string) error {
24-
_, err := cmdOut(args...)
25-
return err
26-
}
27-
2822
func hypervAvailable() error {
2923
stdout, err := cmdOut("@(Get-Module -ListAvailable hyper-v).Name | Get-Unique")
3024
if err != nil {
@@ -75,10 +69,3 @@ func isWindowsAdministrator() (bool, error) {
7569
resp := crcstrings.FirstLine(stdout)
7670
return resp == "True", nil
7771
}
78-
79-
func smbShareExists(name string) bool {
80-
if err := cmd(fmt.Sprintf("Get-SmbShare -Name %s", name)); err != nil {
81-
return false
82-
}
83-
return true
84-
}

0 commit comments

Comments
 (0)