Skip to content

Commit 986d069

Browse files
committed
Require server private key only when disk encryption enforcement is turned on, skip FileVault config when enabling disk encryption when macOS MDM is off
Also ensures disk encryption on a per-team basis works as expected. TODO: set up FileVault if Mac MDM gets enabled after encryption enforcement is enabled.
1 parent 1a716f5 commit 986d069

File tree

5 files changed

+59
-18
lines changed

5 files changed

+59
-18
lines changed

ee/server/service/teams.go

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,15 +1516,15 @@ func unmarshalWithGlobalDefaults(b *json.RawMessage) (fleet.Features, error) {
15161516
}
15171517

15181518
func (svc *Service) updateTeamMDMDiskEncryption(ctx context.Context, tm *fleet.Team, enable *bool) error {
1519-
var didUpdate, didUpdateMacOSDiskEncryption bool
1519+
var didUpdate bool
15201520
if enable != nil {
1521-
if svc.config.Server.PrivateKey == "" {
1522-
return ctxerr.New(ctx, "Missing required private key. Learn how to configure the private key here: https://fleetdm.com/learn-more-about/fleet-server-private-key")
1523-
}
15241521
if tm.Config.MDM.EnableDiskEncryption != *enable {
1522+
if *enable && svc.config.Server.PrivateKey == "" {
1523+
return ctxerr.New(ctx, "Missing required private key. Learn how to configure the private key here: https://fleetdm.com/learn-more-about/fleet-server-private-key")
1524+
}
1525+
15251526
tm.Config.MDM.EnableDiskEncryption = *enable
15261527
didUpdate = true
1527-
didUpdateMacOSDiskEncryption = true
15281528
}
15291529
}
15301530

@@ -1537,13 +1537,7 @@ func (svc *Service) updateTeamMDMDiskEncryption(ctx context.Context, tm *fleet.T
15371537
if err != nil {
15381538
return err
15391539
}
1540-
1541-
// macOS-specific stuff. For legacy reasons we check if apple is configured
1542-
// via `appCfg.MDM.EnabledAndConfigured`
1543-
//
1544-
// TODO: is there a missing bitlocker activity feed item? (see same TODO on
1545-
// other methods that deal with disk encryption)
1546-
if appCfg.MDM.EnabledAndConfigured && didUpdateMacOSDiskEncryption {
1540+
if appCfg.MDM.EnabledAndConfigured {
15471541
var act fleet.ActivityDetails
15481542
if tm.Config.MDM.EnableDiskEncryption {
15491543
act = fleet.ActivityTypeEnabledMacosDiskEncryption{TeamID: &tm.ID, TeamName: &tm.Name}

server/service/appconfig.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ func (svc *Service) ModifyAppConfig(ctx context.Context, p []byte, applyOpts fle
416416
// 1. To get the JSON value from the database
417417
// 2. To update fields with the incoming values
418418
if newAppConfig.MDM.EnableDiskEncryption.Valid {
419-
if svc.config.Server.PrivateKey == "" {
419+
if newAppConfig.MDM.EnableDiskEncryption.Value && svc.config.Server.PrivateKey == "" {
420420
return nil, ctxerr.New(ctx, "Missing required private key. Learn how to configure the private key here: https://fleetdm.com/learn-more-about/fleet-server-private-key")
421421
}
422422
appConfig.MDM.EnableDiskEncryption = newAppConfig.MDM.EnableDiskEncryption

server/service/apple_mdm.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2152,20 +2152,23 @@ func (svc *Service) updateAppConfigMDMDiskEncryption(ctx context.Context, enable
21522152
return err
21532153
}
21542154

2155-
var didUpdate, didUpdateMacOSDiskEncryption bool
2155+
var didUpdate bool
21562156
if enabled != nil {
21572157
if ac.MDM.EnableDiskEncryption.Value != *enabled {
2158+
if *enabled && svc.config.Server.PrivateKey == "" {
2159+
return ctxerr.New(ctx, "Missing required private key. Learn how to configure the private key here: https://fleetdm.com/learn-more-about/fleet-server-private-key")
2160+
}
2161+
21582162
ac.MDM.EnableDiskEncryption = optjson.SetBool(*enabled)
21592163
didUpdate = true
2160-
didUpdateMacOSDiskEncryption = ac.MDM.EnabledAndConfigured
21612164
}
21622165
}
21632166

21642167
if didUpdate {
21652168
if err := svc.ds.SaveAppConfig(ctx, ac); err != nil {
21662169
return err
21672170
}
2168-
if didUpdateMacOSDiskEncryption {
2171+
if ac.MDM.EnabledAndConfigured { // if macOS MDM is configured, set up FileVault escrow
21692172
var act fleet.ActivityDetails
21702173
if ac.MDM.EnableDiskEncryption.Value {
21712174
act = fleet.ActivityTypeEnabledMacosDiskEncryption{}

server/service/integration_enterprise_test.go

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2885,7 +2885,7 @@ func (s *integrationEnterpriseTestSuite) TestLinuxDiskEncryption() {
28852885
t := s.T()
28862886

28872887
// create a Linux host
2888-
hostLin, err := s.ds.NewHost(context.Background(), &fleet.Host{
2888+
noTeamHost, err := s.ds.NewHost(context.Background(), &fleet.Host{
28892889
DetailUpdatedAt: time.Now(),
28902890
LabelUpdatedAt: time.Now(),
28912891
PolicyUpdatedAt: time.Now(),
@@ -2900,14 +2900,35 @@ func (s *integrationEnterpriseTestSuite) TestLinuxDiskEncryption() {
29002900
OSVersion: "Ubuntu 22.04",
29012901
})
29022902
require.NoError(t, err)
2903+
team, err := s.ds.NewTeam(context.Background(), &fleet.Team{Name: "A team"})
2904+
require.NoError(t, err)
2905+
teamID := ptr.Uint(team.ID)
2906+
teamHost, err := s.ds.NewHost(context.Background(), &fleet.Host{
2907+
DetailUpdatedAt: time.Now(),
2908+
LabelUpdatedAt: time.Now(),
2909+
PolicyUpdatedAt: time.Now(),
2910+
SeenTime: time.Now(),
2911+
NodeKey: ptr.String(strings.ReplaceAll(t.Name(), "/", "_") + "2"),
2912+
OsqueryHostID: ptr.String(strings.ReplaceAll(t.Name(), "/", "_") + "2"),
2913+
UUID: t.Name() + "2",
2914+
Hostname: t.Name() + "foo2.local",
2915+
PrimaryIP: "192.168.1.2",
2916+
PrimaryMac: "30-65-EC-6F-C4-59",
2917+
Platform: "rhel",
2918+
OSVersion: "Fedora 38.0",
2919+
TeamID: teamID,
2920+
})
2921+
require.NoError(t, err)
2922+
2923+
// NO TEAM //
29032924

29042925
// config profiles endpoint should work but show all zeroes
29052926
var profileSummary getMDMProfilesSummaryResponse
29062927
s.DoJSON("GET", "/api/latest/fleet/configuration_profiles/summary", getMDMProfilesSummaryRequest{}, http.StatusOK, &profileSummary)
29072928
require.Equal(t, fleet.MDMProfilesSummary{}, profileSummary.MDMProfilesSummary)
29082929

29092930
// set encrypted for host
2910-
require.NoError(t, s.ds.SetOrUpdateHostDisksEncryption(context.Background(), hostLin.ID, true))
2931+
require.NoError(t, s.ds.SetOrUpdateHostDisksEncryption(context.Background(), noTeamHost.ID, true))
29112932

29122933
// should still show zeroes
29132934
s.DoJSON("GET", "/api/latest/fleet/configuration_profiles/summary", getMDMProfilesSummaryRequest{}, http.StatusOK, &profileSummary)
@@ -2926,6 +2947,28 @@ func (s *integrationEnterpriseTestSuite) TestLinuxDiskEncryption() {
29262947
s.DoJSON("GET", "/api/latest/fleet/disk_encryption", getMDMDiskEncryptionSummaryRequest{}, http.StatusOK, &summary)
29272948
// disk is encrypted but key hasn't been escrowed yet
29282949
require.Equal(t, fleet.MDMDiskEncryptionSummary{ActionRequired: fleet.MDMPlatformsCounts{Linux: 1}}, *summary.MDMDiskEncryptionSummary)
2950+
2951+
// TEAM //
2952+
s.DoJSON("GET", "/api/latest/fleet/configuration_profiles/summary", getMDMProfilesSummaryRequest{TeamID: teamID}, http.StatusOK, &profileSummary)
2953+
require.Equal(t, fleet.MDMProfilesSummary{}, profileSummary.MDMProfilesSummary)
2954+
2955+
// set encrypted for host
2956+
require.NoError(t, s.ds.SetOrUpdateHostDisksEncryption(context.Background(), teamHost.ID, true))
2957+
2958+
// should still show zeroes
2959+
s.DoJSON("GET", "/api/latest/fleet/configuration_profiles/summary", getMDMProfilesSummaryRequest{TeamID: teamID}, http.StatusOK, &profileSummary)
2960+
require.Equal(t, fleet.MDMProfilesSummary{}, profileSummary.MDMProfilesSummary)
2961+
2962+
// turn on disk encryption enforcement for team
2963+
s.Do("POST", "/api/latest/fleet/disk_encryption", updateDiskEncryptionRequest{TeamID: teamID, EnableDiskEncryption: true}, http.StatusNoContent)
2964+
2965+
// should show the Linux host as pending
2966+
s.DoJSON("GET", "/api/latest/fleet/configuration_profiles/summary", getMDMProfilesSummaryRequest{TeamID: teamID}, http.StatusOK, &profileSummary)
2967+
require.Equal(t, fleet.MDMProfilesSummary{Pending: 1}, profileSummary.MDMProfilesSummary)
2968+
2969+
// encryption summary should show host as action required
2970+
s.DoJSON("GET", "/api/latest/fleet/disk_encryption", getMDMDiskEncryptionSummaryRequest{TeamID: teamID}, http.StatusOK, &summary)
2971+
require.Equal(t, fleet.MDMDiskEncryptionSummary{ActionRequired: fleet.MDMPlatformsCounts{Linux: 1}}, *summary.MDMDiskEncryptionSummary)
29292972
}
29302973

29312974
func (s *integrationEnterpriseTestSuite) TestListDevicePolicies() {

server/service/mdm.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2613,6 +2613,7 @@ func (svc *Service) UploadMDMAppleAPNSCert(ctx context.Context, cert io.ReadSeek
26132613
}
26142614

26152615
appCfg.MDM.EnabledAndConfigured = true
2616+
// TODO for each team (or no-team) set up for disk encryption, enable FileVault
26162617

26172618
return svc.ds.SaveAppConfig(ctx, appCfg)
26182619
}

0 commit comments

Comments
 (0)