Skip to content

Commit

Permalink
Drop global scripts enabled gate from software uninstalls, script-bas…
Browse files Browse the repository at this point in the history
…ed lock/unlock/wipe

TODO:

* Fix tests
* Write scripts to DB as eligible for skipping script disabled, read from DB when scripts disabled
  • Loading branch information
iansltx committed Dec 16, 2024
1 parent 3c0b39c commit d2cba3f
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 51 deletions.
10 changes: 0 additions & 10 deletions cmd/fleetctl/mdm.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,16 +265,6 @@ func mdmWipeCommand() *cli.Command {
return err
}

config, err := client.GetAppConfig()
if err != nil {
return err
}

// linux hosts need scripts to be enabled in the org settings to wipe.
if host.Platform == "linux" && config.ServerSettings.ScriptsDisabled {
return errors.New("Can't wipe host because running scripts is disabled in organization settings.")
}

if err := client.MDMWipeHost(host.ID); err != nil {
return fmt.Errorf("Failed to wipe host: %w", err)
}
Expand Down
30 changes: 2 additions & 28 deletions ee/server/service/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,6 @@ func (svc *Service) LockHost(ctx context.Context, hostID uint, viewPIN bool) (un
return "", ctxerr.Wrap(ctx, err, "check windows MDM enabled")
}
}
// on windows and linux, a script is used to lock the host so scripts must
// be enabled
appCfg, err := svc.ds.AppConfig(ctx)
if err != nil {
return "", ctxerr.Wrap(ctx, err, "get app config")
}
if appCfg.ServerSettings.ScriptsDisabled {
return "", ctxerr.Wrap(
ctx,
fleet.NewInvalidArgumentError("host_id", "Can't lock host because running scripts is disabled in organization settings."),
)
}
hostOrbitInfo, err := svc.ds.GetHostOrbitInfo(ctx, host.ID)
switch {
case err != nil:
Expand Down Expand Up @@ -182,7 +170,7 @@ func (svc *Service) UnlockHost(ctx context.Context, hostID uint) (string, error)

case "windows", "linux":
// on windows and linux, a script is used to lock the host so scripts must
// be enabled
// be enabled on the host
if host.FleetPlatform() == "windows" {
if err := svc.VerifyMDMWindowsConfigured(ctx); err != nil {
if errors.Is(err, fleet.ErrMDMNotConfigured) {
Expand All @@ -191,13 +179,6 @@ func (svc *Service) UnlockHost(ctx context.Context, hostID uint) (string, error)
return "", ctxerr.Wrap(ctx, err, "check windows MDM enabled")
}
}
appCfg, err := svc.ds.AppConfig(ctx)
if err != nil {
return "", ctxerr.Wrap(ctx, err, "get app config")
}
if appCfg.ServerSettings.ScriptsDisabled {
return "", ctxerr.Wrap(ctx, fleet.NewInvalidArgumentError("host_id", "Can't unlock host because running scripts is disabled in organization settings."))
}
hostOrbitInfo, err := svc.ds.GetHostOrbitInfo(ctx, host.ID)
switch {
case err != nil:
Expand Down Expand Up @@ -286,14 +267,7 @@ func (svc *Service) WipeHost(ctx context.Context, hostID uint) error {
requireMDM = true

case "linux":
// on linux, a script is used to wipe the host so scripts must be enabled
appCfg, err := svc.ds.AppConfig(ctx)
if err != nil {
return ctxerr.Wrap(ctx, err, "get app config")
}
if appCfg.ServerSettings.ScriptsDisabled {
return ctxerr.Wrap(ctx, fleet.NewInvalidArgumentError("host_id", "Can't wipe host because running scripts is disabled in organization settings."))
}
// on linux, a script is used to wipe the host so scripts must be enabled on the host
hostOrbitInfo, err := svc.ds.GetHostOrbitInfo(ctx, host.ID)
switch {
case err != nil:
Expand Down
12 changes: 0 additions & 12 deletions ee/server/service/software_installers.go
Original file line number Diff line number Diff line change
Expand Up @@ -836,18 +836,6 @@ func (svc *Service) installSoftwareTitleUsingInstaller(ctx context.Context, host
}

func (svc *Service) UninstallSoftwareTitle(ctx context.Context, hostID uint, softwareTitleID uint) error {
// First check if scripts are disabled globally. If so, no need for further processing.
cfg, err := svc.ds.AppConfig(ctx)
if err != nil {
svc.authz.SkipAuthorization(ctx)
return err
}

if cfg.ServerSettings.ScriptsDisabled {
svc.authz.SkipAuthorization(ctx)
return fleet.NewUserMessageError(errors.New(fleet.RunScriptScriptsDisabledGloballyErrMsg), http.StatusForbidden)
}

// we need to use ds.Host because ds.HostLite doesn't return the orbit node key
host, err := svc.ds.Host(ctx, hostID)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion server/service/orbit.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ func (svc *Service) GetOrbitConfig(ctx context.Context) (fleet.OrbitConfig, erro
}

// load the pending script executions for that host
if !appConfig.ServerSettings.ScriptsDisabled {
if !appConfig.ServerSettings.ScriptsDisabled { // TODO filter to only "special" scripts rather than skipping entirely when scripts disabled
pending, err := svc.ds.ListPendingHostScriptExecutions(ctx, host.ID)
if err != nil {
return fleet.OrbitConfig{}, err
Expand Down

0 comments on commit d2cba3f

Please sign in to comment.