mirror of
https://github.com/fleetdm/fleet
synced 2026-05-23 08:58:41 +00:00
**Related issue:** Resolves #35357 # Checklist for submitter If some of the following don't apply, delete the relevant line. - [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. - [x] Input data is properly validated, `SELECT *` is avoided, SQL injection is prevented (using placeholders for values in statements) ## Testing - [x] Added/updated automated tests - [ ] QA'd all new/changed functionality manually
38 lines
1.3 KiB
Go
38 lines
1.3 KiB
Go
package mdm
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/fleetdm/fleet/v4/server/contexts/ctxerr"
|
|
"github.com/fleetdm/fleet/v4/server/fleet"
|
|
)
|
|
|
|
// We take in the AndroidDatastore here, so it can also be called from the android package until https://github.com/fleetdm/fleet/issues/31218 is done
|
|
func RequiresEnrollOTAAuthentication(ctx context.Context, ds fleet.AndroidDatastore, enrollSecret string, noTeamIdPEnabled bool) (bool, error) {
|
|
secret, err := ds.VerifyEnrollSecret(ctx, enrollSecret)
|
|
if err != nil && !fleet.IsNotFound(err) {
|
|
return false, ctxerr.Wrap(ctx, err, "verify enroll secret")
|
|
}
|
|
|
|
if secret == nil {
|
|
// enroll secret is invalid, check if any team has IdP enabled for setup
|
|
// experience and if so require authentication before going through (we
|
|
// enforce the failure due to the enroll secret being invalid only when the
|
|
// enrollment profile is installed).
|
|
ids, err := ds.TeamIDsWithSetupExperienceIdPEnabled(ctx)
|
|
if err != nil {
|
|
return false, ctxerr.Wrap(ctx, err, "get team IDs with setup experience IdP enabled")
|
|
}
|
|
return len(ids) > 0, nil
|
|
}
|
|
|
|
if secret.TeamID == nil { // enroll in "no team"
|
|
return noTeamIdPEnabled, nil
|
|
}
|
|
|
|
tm, err := ds.TeamLite(ctx, *secret.TeamID)
|
|
if err != nil {
|
|
return false, ctxerr.Wrap(ctx, err, "get team for settings")
|
|
}
|
|
return tm.Config.MDM.MacOSSetup.EnableEndUserAuthentication, nil
|
|
}
|