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

remove enabling of file sharing and creation of smbshare from MSI #4620

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
24 changes: 0 additions & 24 deletions packaging/windows/product.wxs.template
Original file line number Diff line number Diff line change
Expand Up @@ -92,24 +92,6 @@
Before="AddUserToHypervAdminGroup"
Sequence="execute"/>
<CustomAction Id="AddUserToHypervAdminGroup" BinaryKey="WixCA" DllEntry="WixQuietExec64" Execute="deferred" Impersonate="no" Return="ignore" />
<SetProperty Action="CACreateSMBShare"
Id="CreateSMBShare"
Value="&quot;[POWERSHELLEXE]&quot; -NonInteractive -ExecutionPolicy Bypass -NoProfile -Command &quot;New-SmbShare -Name '[SHAREDDIRNAME]' -Path '[USERFOLDER]' -FullAccess '[LogonUser]'&quot;"
Before="CreateSMBShare"
Sequence="execute"/>
<CustomAction Id="CreateSMBShare" BinaryKey="WixCA" DllEntry="WixQuietExec64" Execute="deferred" Impersonate="no" Return="ignore" />
<SetProperty Action="CAEnableFileAndPrinterSharing"
Id="EnableFileAndPrinterSharing"
Value="&quot;[POWERSHELLEXE]&quot; -NonInteractive -ExecutionPolicy Bypass -NoProfile -Command &quot;Set-NetFirewallRule -Group '@FirewallAPI.dll,-28502' -Enabled True -Profile 'Private,Public'&quot;"
Before="EnableFileAndPrinterSharing"
Sequence="execute"/>
<CustomAction Id="EnableFileAndPrinterSharing" BinaryKey="WixCA" DllEntry="WixQuietExec64" Execute="deferred" Impersonate="no" Return="ignore" />
<SetProperty Action="CARemoveSMBShare"
Id="RemoveSMBShare"
Value="&quot;[POWERSHELLEXE]&quot; -NonInteractive -ExecutionPolicy Bypass -NoProfile -Command &quot;Remove-SmbShare -Name '[SHAREDDIRNAME]' -Force&quot;"
Before="RemoveSMBShare"
Sequence="execute"/>
<CustomAction Id="RemoveSMBShare" BinaryKey="WixCA" DllEntry="WixQuietExec64" Execute="deferred" Impersonate="no" Return="ignore" />

<InstallExecuteSequence>
<Custom Action="CreateCrcGroup" Before="ConfigureUsers"> NOT Installed AND NOT REMOVE~="ALL" AND NOT WIX_UPGRADE_DETECTED</Custom>
Expand All @@ -118,9 +100,6 @@
<Custom Action="InstallHyperv" Before="CreateCrcGroup"> NOT Installed AND NOT REMOVE~="ALL" AND NOT WIX_UPGRADE_DETECTED</Custom>
<Custom Action="RemoveCrcGroupRollback" After="CreateCrcGroup"> NOT Installed AND NOT REMOVE~="ALL" AND NOT WIX_UPGRADE_DETECTED</Custom>
<Custom Action="RemoveCrcDaemonTask" Before='RemoveFiles'>Installed AND NOT UPGRADINGPRODUCTCODE</Custom>
<Custom Action="EnableFileAndPrinterSharing" After="AddUserToHypervAdminGroup"> NOT Installed AND NOT REMOVE~="ALL" AND NOT WIX_UPGRADE_DETECTED</Custom>
<Custom Action="CreateSMBShare" After="EnableFileAndPrinterSharing"> NOT Installed AND NOT REMOVE~="ALL"</Custom>
<Custom Action="RemoveSMBShare" After='RemoveCrcDaemonTask'>Installed AND NOT UPGRADINGPRODUCTCODE</Custom>
<ScheduleReboot After="InstallFinalize"> NOT Installed AND NOT REMOVE~="ALL" AND NOT WIX_UPGRADE_DETECTED</ScheduleReboot>
</InstallExecuteSequence>
<Feature Id="DefaultFeature" Title="Install core features" Absent="disallow" Level="1">
Expand All @@ -140,9 +119,6 @@
<ProgressText Action="InstallHyperv">Installing Hyper-V</ProgressText>
<ProgressText Action="AddUserToHypervAdminGroup">Adding user: [LogonUser] to Hyper-V Administrators group</ProgressText>
<ProgressText Action="RemoveCrcDaemonTask">Removing crcDaemon task</ProgressText>
<ProgressText Action="CreateSMBShare">Creating share named: [SHAREDDIRNAME] for folder: [USERFOLDER]</ProgressText>
<ProgressText Action="RemoveSMBShare">Removing share named: [SHAREDDIRNAME] for folder: [USERFOLDER]</ProgressText>
<ProgressText Action="EnableFileAndPrinterSharing">Enabling file and printer Sharing</ProgressText>
</UI>
<Property Id="WIXUI_INSTALLDIR" Value="INSTALLDIR" />
<!-- this should help to propagate env var changes -->
Expand Down
13 changes: 13 additions & 0 deletions pkg/crc/preflight/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type LabelName uint32
const (
Os LabelName = iota
NetworkMode
SharedDir

// Keep it last
// will be used in OS-specific go files to extend LabelName
Expand All @@ -29,6 +30,10 @@ const (
User
System

// shared dir enabled/disable
Enabled
Disabled

// Keep it last
// will be used in OS-specific go files to extend LabelValue
lastLabelValue // nolint
Expand Down Expand Up @@ -65,6 +70,14 @@ func (filter preflightFilter) SetNetworkMode(networkMode network.Mode) {
}
}

func (filter preflightFilter) SetSharedDirStatus(enabled bool) {
if enabled {
filter[SharedDir] = Enabled
return
}
filter[SharedDir] = Disabled
}

/* This will iterate over 'checks' and only keep the checks which match the filter:
* - if a key is present in the filter and not in the check labels, the check is kept
* - if a key is present in the check labels, but not in the filter, the check is kept
Expand Down
3 changes: 2 additions & 1 deletion pkg/crc/preflight/preflight.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,9 @@ func getPreflightChecksHelper(config crcConfig.Storage) []Check {
bundlePath := config.Get(crcConfig.Bundle).AsString()
preset := crcConfig.GetPreset(config)
enableBundleQuayFallback := config.Get(crcConfig.EnableBundleQuayFallback).AsBool()
sharedDirEnabled := config.Get(crcConfig.EnableSharedDirs).AsBool()
logging.Infof("Using bundle path %s", bundlePath)
return getPreflightChecks(experimentalFeatures, mode, bundlePath, preset, enableBundleQuayFallback)
return getPreflightChecks(experimentalFeatures, mode, bundlePath, preset, enableBundleQuayFallback, sharedDirEnabled)
}

// StartPreflightChecks performs the preflight checks before starting the cluster
Expand Down
63 changes: 63 additions & 0 deletions pkg/crc/preflight/preflight_checks_windows.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package preflight

import (
"errors"
"fmt"
"os/user"
"strconv"
"strings"

Expand Down Expand Up @@ -209,3 +211,64 @@ func checkAdminHelperNamedPipeAccessible() error {
}
return nil
}

func checkFileAndPrinterSharingIsEnabled() error {
cmd := `(Get-NetFirewallRule -Group '@FirewallAPI.dll,-28502' | Where-Object {$_.Profile -eq 'Private, Public'}).Enabled`
stdout, stderr, err := powershell.Execute(cmd)
if err != nil {
return fmt.Errorf("unable to check if Printer and File Sharing is enabled %v: %s", err, stderr)
}
if strings.Contains(stdout, "False") {
return errors.New("Printer and File Sharing is disabled")
}
return nil
}

func fixFileAndPrinterSharing() error {
cmd := `Set-NetFirewallRule -Group '@FirewallAPI.dll,-28502' -Enabled True -Profile 'Private,Public'`
stdout, stderr, err := powershell.ExecuteAsAdmin("to enable Printer and File Sharing", cmd)
if err != nil {
return fmt.Errorf("unable to check if Printer and File Sharing is enabled %v: %s: %s", err, stdout, stderr)
}
return nil
}

func checkCRCSmbShareCreated() error {
cmd := `Get-SmbShare -Name crc-dir0`
stdout, stderr, err := powershell.Execute(cmd)
if err != nil {
return fmt.Errorf("unable to check if Printer and File Sharing is enabled %v: %s: %s", err, stdout, stderr)
}
return nil
}

func fixCRCSmbShareCreated() error {
u, err := user.Current()
if err != nil {
return fmt.Errorf("unable to get user information for homedir and username: %v", err)
}
cmd := fmt.Sprintf(`New-SmbShare -Name 'crc-dir0' -Path '%s' -FullAccess '%s'`, u.HomeDir, username())
_, stderr, err := powershell.ExecuteAsAdmin("create new SMB share for home directory", cmd)
if err != nil {
return fmt.Errorf("unable to get create new SMB share %v: %s", err, stderr)
}
return nil
}

func removeSmbShare() error {
cmd := `Remove-SmbShare -Name 'crc-dir0' -Force`
_, stderr, err := powershell.ExecuteAsAdmin("remove SMB share for home directory", cmd)
if err != nil {
return fmt.Errorf("unable to get create new SMB share %v: %s", err, stderr)
}
return nil
}

func removeFirewallRuleAllowingPrinterAndFileSharing() error {
cmd := `Set-NetFirewallRule -Group '@FirewallAPI.dll,-28502' -Enabled False -Profile 'Private,Public'`
stdout, stderr, err := powershell.ExecuteAsAdmin("to disable Printer and File Sharing", cmd)
if err != nil {
logging.Warnf("unable to turn off Printer and File Sharing %v: %s: %s", err, stdout, stderr)
}
return nil
}
4 changes: 2 additions & 2 deletions pkg/crc/preflight/preflight_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ var daemonLaunchdChecks = []Check{
// Passing 'SystemNetworkingMode' to getPreflightChecks currently achieves this
// as there are no user networking specific checks
func getAllPreflightChecks() []Check {
return getPreflightChecks(true, network.SystemNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift, false)
return getPreflightChecks(true, network.SystemNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift, false, false)
}

func getChecks(_ network.Mode, bundlePath string, preset crcpreset.Preset, enableBundleQuayFallback bool) []Check {
Expand All @@ -132,7 +132,7 @@ func getChecks(_ network.Mode, bundlePath string, preset crcpreset.Preset, enabl
return checks
}

func getPreflightChecks(_ bool, mode network.Mode, bundlePath string, preset crcpreset.Preset, enableBundleQuayFallback bool) []Check {
func getPreflightChecks(_ bool, mode network.Mode, bundlePath string, preset crcpreset.Preset, enableBundleQuayFallback, _ bool) []Check {
filter := newFilter()
filter.SetNetworkMode(mode)

Expand Down
8 changes: 4 additions & 4 deletions pkg/crc/preflight/preflight_darwin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ func TestCountConfigurationOptions(t *testing.T) {
}

func TestCountPreflights(t *testing.T) {
assert.Len(t, getPreflightChecks(true, network.SystemNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift, false), 21)
assert.Len(t, getPreflightChecks(true, network.SystemNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift, false), 21)
assert.Len(t, getPreflightChecks(true, network.SystemNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift, false, false), 21)
assert.Len(t, getPreflightChecks(true, network.SystemNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift, false, false), 21)

assert.Len(t, getPreflightChecks(true, network.UserNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift, false), 20)
assert.Len(t, getPreflightChecks(true, network.UserNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift, false), 20)
assert.Len(t, getPreflightChecks(true, network.UserNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift, false, false), 20)
assert.Len(t, getPreflightChecks(true, network.UserNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift, false, false), 20)
}
2 changes: 1 addition & 1 deletion pkg/crc/preflight/preflight_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ func getAllPreflightChecks() []Check {
return filter.Apply(getChecks(distro(), constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift, false))
}

func getPreflightChecks(_ bool, networkMode network.Mode, bundlePath string, preset crcpreset.Preset, enableBundleQuayFallback bool) []Check {
func getPreflightChecks(_ bool, networkMode network.Mode, bundlePath string, preset crcpreset.Preset, enableBundleQuayFallback, _ bool) []Check {
usingSystemdResolved := checkSystemdResolvedIsRunning()

return getPreflightChecksForDistro(distro(), networkMode, usingSystemdResolved == nil, bundlePath, preset, enableBundleQuayFallback)
Expand Down
32 changes: 30 additions & 2 deletions pkg/crc/preflight/preflight_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,32 @@ var userPartOfCrcUsersAndHypervAdminsGroupCheck = Check{
labels: labels{Os: Windows},
}

// Checks to verify and setup SMB share is created and file sharing is enabled
var smbShareCreatedAndFileSharingEnabledChecks = []Check{
{
configKeySuffix: "check-file-sharing-enabled",
checkDescription: "Checking if Printer and File Sharing is enabled",
check: checkFileAndPrinterSharingIsEnabled,
fixDescription: "Enabling Printer and File Sharing",
fix: fixFileAndPrinterSharing,
cleanupDescription: "Disabling Printer and File Sharing",
cleanup: removeFirewallRuleAllowingPrinterAndFileSharing,

labels: labels{Os: Windows, SharedDir: Enabled},
},
{
configKeySuffix: "check-smb-share-exists",
checkDescription: "Checking if SMB share crc-dir0 exists",
check: checkCRCSmbShareCreated,
fixDescription: "Creating SMB share crc-dir0",
fix: fixCRCSmbShareCreated,
cleanupDescription: "Removing SMB share crc-dir0",
cleanup: removeSmbShare,

labels: labels{Os: Windows, SharedDir: Enabled},
},
}

var errReboot = errors.New("Please reboot your system and run 'crc setup' to complete the setup process")

func username() string {
Expand Down Expand Up @@ -202,7 +228,7 @@ func checkVsock() error {
// Passing 'UserNetworkingMode' to getPreflightChecks currently achieves this
// as there are no system networking specific checks
func getAllPreflightChecks() []Check {
return getPreflightChecks(true, network.UserNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift, false)
return getPreflightChecks(true, network.UserNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift, true, true)
}

func getChecks(bundlePath string, preset crcpreset.Preset, enableBundleQuayFallback bool) []Check {
Expand All @@ -219,12 +245,14 @@ func getChecks(bundlePath string, preset crcpreset.Preset, enableBundleQuayFallb
checks = append(checks, daemonTaskChecks...)
checks = append(checks, adminHelperServiceCheks...)
checks = append(checks, sshPortCheck())
checks = append(checks, smbShareCreatedAndFileSharingEnabledChecks...)
return checks
}

func getPreflightChecks(_ bool, networkMode network.Mode, bundlePath string, preset crcpreset.Preset, enableBundleQuayFallback bool) []Check {
func getPreflightChecks(_ bool, networkMode network.Mode, bundlePath string, preset crcpreset.Preset, enableBundleQuayFallback, sharedDirEnabled bool) []Check {
filter := newFilter()
filter.SetNetworkMode(networkMode)
filter.SetSharedDirStatus(sharedDirEnabled)

return filter.Apply(getChecks(bundlePath, preset, enableBundleQuayFallback))
}
16 changes: 11 additions & 5 deletions pkg/crc/preflight/preflight_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,19 @@ import (
func TestCountConfigurationOptions(t *testing.T) {
cfg := config.New(config.NewEmptyInMemoryStorage(), config.NewEmptyInMemorySecretStorage())
RegisterSettings(cfg)
assert.Len(t, cfg.AllConfigs(), 16)
assert.Len(t, cfg.AllConfigs(), 18)
}

func TestCountPreflights(t *testing.T) {
assert.Len(t, getPreflightChecks(false, network.SystemNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift, false), 23)
assert.Len(t, getPreflightChecks(true, network.SystemNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift, false), 23)
assert.Len(t, getPreflightChecks(false, network.SystemNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift, false, false), 23)
assert.Len(t, getPreflightChecks(true, network.SystemNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift, false, false), 23)

assert.Len(t, getPreflightChecks(false, network.UserNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift, false), 24)
assert.Len(t, getPreflightChecks(true, network.UserNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift, false), 24)
assert.Len(t, getPreflightChecks(false, network.UserNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift, false, false), 24)
assert.Len(t, getPreflightChecks(true, network.UserNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift, false, false), 24)

assert.Len(t, getPreflightChecks(false, network.SystemNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift, false, true), 25)
assert.Len(t, getPreflightChecks(true, network.SystemNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift, false, true), 25)

assert.Len(t, getPreflightChecks(false, network.UserNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift, false, true), 26)
assert.Len(t, getPreflightChecks(true, network.UserNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift, false, true), 26)
}