2026-02-02 16:50:30 +00:00
|
|
|
package osquery_utils
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
2026-02-16 21:43:59 +00:00
|
|
|
"log/slog"
|
2026-02-02 16:50:30 +00:00
|
|
|
|
|
|
|
|
"github.com/fleetdm/fleet/v4/server/fleet"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// IsDiskEncryptionEnabledForHost checks if disk encryption is enabled for the
|
|
|
|
|
// host team or globally if the host is not assigned to a team.
|
2026-02-16 21:43:59 +00:00
|
|
|
func IsDiskEncryptionEnabledForHost(ctx context.Context, logger *slog.Logger, ds fleet.Datastore, host *fleet.Host) bool {
|
2026-02-02 16:50:30 +00:00
|
|
|
// team
|
|
|
|
|
if host.TeamID != nil {
|
|
|
|
|
teamMDM, err := ds.TeamMDMConfig(ctx, *host.TeamID)
|
|
|
|
|
if err != nil {
|
2026-02-16 21:43:59 +00:00
|
|
|
logger.DebugContext(ctx, "failed to get team MDM config for disk encryption check",
|
2026-02-02 16:50:30 +00:00
|
|
|
"host_id", host.ID,
|
|
|
|
|
"team_id", *host.TeamID,
|
|
|
|
|
"err", err,
|
|
|
|
|
)
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
if teamMDM == nil {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
return teamMDM.EnableDiskEncryption
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// global
|
|
|
|
|
appConfig, err := ds.AppConfig(ctx)
|
|
|
|
|
if err != nil {
|
2026-02-16 21:43:59 +00:00
|
|
|
logger.DebugContext(ctx, "failed to get app config for disk encryption check",
|
2026-02-02 16:50:30 +00:00
|
|
|
"host_id", host.ID,
|
|
|
|
|
"err", err,
|
|
|
|
|
)
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
return appConfig.MDM.EnableDiskEncryption.Value
|
|
|
|
|
}
|