Add service discovery API endpoint (#31089)

relates to #31057 

adds an endpoint to expose the fleet handled service discovery endpoint.

> NOTE: test will be done in a follow up PR

- [x] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files)
for more information.
This commit is contained in:
Gabriel Hernandez
2025-07-23 12:11:32 +01:00
committed by GitHub
parent c71787d35d
commit 4d0518137e
5 changed files with 29 additions and 0 deletions
+1
View File
@@ -1206,6 +1206,7 @@ the way that the Fleet server works.
mdmCheckinAndCommandService,
ddmService,
commander,
appCfg.ServerSettings.ServerURL,
); err != nil {
initFatal(err, "setup mdm apple services")
}
+2
View File
@@ -36,6 +36,8 @@ const (
SCEPPath = "/mdm/apple/scep"
// MDMPath is Fleet's HTTP path for the core MDM service.
MDMPath = "/mdm/apple/mdm"
// MDMServiceDiscoveryPath is Fleet's HTTP path for the MDM service discovery service.
ServiceDiscoveryPath = "/mdm/apple/service_discovery"
// EnrollPath is the HTTP path that serves the mobile profile to devices when enrolling.
EnrollPath = "/api/mdm/apple/enroll"
+25
View File
@@ -1130,6 +1130,7 @@ func RegisterAppleMDMProtocolServices(
checkinAndCommandService nanomdm_service.CheckinAndCommandService,
ddmService nanomdm_service.DeclarativeManagement,
profileService nanomdm_service.ProfileService,
serverURLPrefix string,
) error {
if err := registerSCEP(mux, scepConfig, scepStorage, mdmStorage, logger); err != nil {
return fmt.Errorf("scep: %w", err)
@@ -1137,6 +1138,30 @@ func RegisterAppleMDMProtocolServices(
if err := registerMDM(mux, mdmStorage, checkinAndCommandService, ddmService, profileService, logger); err != nil {
return fmt.Errorf("mdm: %w", err)
}
if err := registerMDMServiceDiscovery(mux, logger, serverURLPrefix); err != nil {
return fmt.Errorf("service discovery: %w", err)
}
return nil
}
func registerMDMServiceDiscovery(
mux *http.ServeMux,
logger kitlog.Logger,
serverURLPrefix string,
) error {
serviceDiscoveryLogger := kitlog.With(logger, "component", "mdm-apple-service-discovery")
fullMDMEnrollmentURL := fmt.Sprintf("%s%s", serverURLPrefix, apple_mdm.AccountDrivenEnrollPath)
serviceDiscoveryHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
serviceDiscoveryLogger.Log("msg", "serving MDM service discovery response", "url", fullMDMEnrollmentURL)
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
_, err := fmt.Fprintf(w, `{"Servers":[{"Version": "mdm-byod", "BaseURL": "%s"}]}`, fullMDMEnrollmentURL)
if err != nil {
serviceDiscoveryLogger.Log("err", "error writing service discovery response", "err", err)
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
}
})
mux.Handle(apple_mdm.ServiceDiscoveryPath, serviceDiscoveryHandler)
return nil
}
+1
View File
@@ -429,6 +429,7 @@ func RunServerForTestsWithServiceWithDS(t *testing.T, ctx context.Context, ds fl
logger: logger,
},
commander,
"https://test-url.com",
)
require.NoError(t, err)
}