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

Apply minimum OS version enforcement to MDM SSO endpoint #23856

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 2 additions & 0 deletions changes/22361-os-update-ade-sso
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Fixed issue where minimum OS version enforcement was not being applied during Apple ADE if MDM
IdP integration was enabled.
3 changes: 3 additions & 0 deletions cmd/fleet/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,9 @@ the way that the Fleet server works.
"get_frontend",
service.ServeFrontend(config.Server.URLPrefix, config.Server.SandboxEnabled, httpLogger),
)

frontendHandler = service.WithMDMEnrollmentMiddleware(svc, httpLogger, frontendHandler, config.Server.URLPrefix)

apiHandler = service.MakeHandler(svc, config, httpLogger, limiterStore)

setupRequired, err := svc.SetupRequired(baseCtx)
Expand Down
8 changes: 7 additions & 1 deletion server/service/apple_mdm.go
Original file line number Diff line number Diff line change
Expand Up @@ -1526,7 +1526,13 @@ func (svc *Service) needsOSUpdateForDEPEnrollment(ctx context.Context, m fleet.M
return false, nil
}

return apple_mdm.IsLessThanVersion(m.OSVersion, settings.MinimumVersion.Value)
needsUpdate, err := apple_mdm.IsLessThanVersion(m.OSVersion, settings.MinimumVersion.Value)
if err != nil {
level.Info(svc.logger).Log("msg", "checking os updates settings, cannot compare versions", "serial", m.Serial, "current_version", m.OSVersion, "minimum_version", settings.MinimumVersion.Value)
return false, nil
}

return needsUpdate, nil
}

func (svc *Service) getAppleSoftwareUpdateRequiredForDEPEnrollment(m fleet.MDMAppleMachineInfo) (*fleet.MDMAppleSoftwareUpdateRequired, error) {
Expand Down
2 changes: 1 addition & 1 deletion server/service/apple_mdm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4093,7 +4093,7 @@ func TestCheckMDMAppleEnrollmentWithMinimumOSVersion(t *testing.T) {
SoftwareUpdateDeviceID: "J516sAP",
},
updateRequired: nil,
err: "invalid current version",
err: "", // no error, allow enrollment to proceed without software update
},
}

Expand Down
42 changes: 42 additions & 0 deletions server/service/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package service

import (
"context"
"encoding/json"
"errors"
"fmt"
"net/http"
Expand Down Expand Up @@ -1231,3 +1232,44 @@ func registerMDM(
mux.Handle(apple_mdm.MDMPath, mdmHandler)
return nil
}

func WithMDMEnrollmentMiddleware(svc fleet.Service, logger kitlog.Logger, next http.Handler, urlPrefix string) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/mdm/sso" {
next.ServeHTTP(w, r)
return
}

// if x-apple-aspen-deviceinfo custom header is present, we need to check for minimum os version
di := r.Header.Get("x-apple-aspen-deviceinfo")
if di != "" {
parsed, err := apple_mdm.ParseDeviceinfo(di, false) // FIXME: use verify=true when we have better parsing for various Apple certs (https://github.com/fleetdm/fleet/issues/20879)
if err != nil {
// just log the error and continue to next
level.Error(logger).Log("msg", "parsing x-apple-aspen-deviceinfo", "err", err)
next.ServeHTTP(w, r)
return
}

sur, err := svc.CheckMDMAppleEnrollmentWithMinimumOSVersion(context.Background(), parsed)
if err != nil {
// just log the error and continue to next
level.Error(logger).Log("msg", "checking minimum os version for mdm", "err", err)
next.ServeHTTP(w, r)
return
}

if sur != nil {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusForbidden)
if err := json.NewEncoder(w).Encode(sur); err != nil {
level.Error(logger).Log("msg", "failed to encode software update required", "err", err)
http.Redirect(w, r, r.URL.String()+"?error=true", http.StatusSeeOther)
}
return
}
}

next.ServeHTTP(w, r)
}
}
Loading
Loading