add base types and handlers for DDM (#17657)

This includes the base types and the request handlers to reduce the
chances of conflicts.
This commit is contained in:
Roberto Dip 2024-03-15 10:51:47 -03:00 committed by GitHub
parent dc87ac2271
commit d261762e83
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 97 additions and 2 deletions

View File

@ -532,3 +532,80 @@ type SCEPIdentityAssociation struct {
EnrollReference string `db:"enroll_reference"`
RenewCommandUUID string `db:"renew_command_uuid"`
}
// MDMAppleDeclarationType is the type for the supported declaration types.
type MDMAppleDeclarationType string
const (
// MDMAppleConfigurationDeclaration is the value for [configuration][1] declarations
//
// [1]: https://developer.apple.com/documentation/devicemanagement/declarations#3813088
MDMAppleDeclarativeConfiguration MDMAppleDeclarationType = "com.apple.configuration"
// MDMAppleActivationConfiguration is the value for [activation][1] declarations
//
// [1]: https://developer.apple.com/documentation/devicemanagement/declarations#3829708
MDMAppleDeclarativeActivation MDMAppleDeclarationType = "com.apple.activation"
)
// MDMAppleDeclaration represents a DDM JSON declaration.
type MDMAppleDeclaration struct {
// DeclarationUUID is the unique identifier of the declaration in
// Fleet. Since we use the same endpoints for declarations and profiles:
// - This is marshalled as profile_uuid
// - The value has a prefix (TODO: @jahzielv to determine and document this)
DeclarationUUID string `db:"declaration_uuid" json:"profile_uuid"`
// TeamID is the id of the team with which the declaration is associated. A nil team id
// represents a declaration that is not associated with any team.
TeamID *uint `db:"team_id" json:"team_id"`
// Identifier corresponds to the "Identifier" key of the associated declaration.
// Fleet requires that Identifier must be unique in combination with the Name and TeamID.
Identifier string `db:"identifier" json:"identifier"`
// Name corresponds to the file name of the associated JSON declaration payload.
// Fleet requires that Name must be unique in combination with the Identifier and TeamID.
Name string `db:"name" json:"name"`
// DeclarationType is the type of the declaration, at the moment we
// only support configurations and activations.
DeclarationType MDMAppleDeclarationType `db:"declaration_type"`
// Declaration is the raw JSON content of the declaration
Declaration json.RawMessage `db:"declaration" json:"-"`
// MD5Checksum is a checsum of the JSON contents
MD5Checksum string `db:"md5_checksum" json:"-"`
CreatedAt time.Time `db:"created_at" json:"created_at"`
UploadedAt time.Time `db:"uploaded_at" json:"uploaded_at"`
}
// MDMAppleHostDeclaration represents the state of a declaration on a host
type MDMAppleHostDeclaration struct {
// HostUUID is the uuid of the host affected by this declaration
HostUUID string `db:"host_uuid" json:"-"`
// DeclarationUUID is the unique identifier of the declaration in
// Fleet. Since we use the same endpoints for declarations and profiles:
// - This is marshalled as profile_uuid
// - The value has a prefix (TODO: @jahzielv to determine and document this)
DeclarationUUID string `db:"declaration_uuid" json:"profile_uuid"`
// Name corresponds to the file name of the associated JSON declaration payload.
Name string `db:"name" json:"name"`
// Identifier corresponds to the "Identifier" key of the associated declaration.
Identifier string `db:"identifier" json:"-"`
// Status represent the current state of the declaration, as known by the Fleet server.
Status *MDMDeliveryStatus `db:"status" json:"status"`
// Operation type represents the operation being performed.
OperationType MDMOperationType `db:"operation_type" json:"operation_type"`
// Detail contains any messages that must be surfaced to the user,
// either by the MDM protocol or the Fleet server.
Detail string `db:"detail" json:"detail"`
}

View File

@ -2354,8 +2354,26 @@ func (svc *MDMAppleCheckinAndCommandService) UserAuthenticate(*mdm.Request, *mdm
// This method is executed after the request has been handled by nanomdm.
//
// [1]: https://developer.apple.com/documentation/devicemanagement/declarative_management_checkin
func (svc *MDMAppleCheckinAndCommandService) DeclarativeManagement(*mdm.Request, *mdm.DeclarativeManagement) ([]byte, error) {
return nil, nil
func (svc *MDMAppleCheckinAndCommandService) DeclarativeManagement(r *mdm.Request, cmd *mdm.DeclarativeManagement) ([]byte, error) {
switch cmd.Endpoint {
case "tokens":
return nil, nil
case "declaration-items":
return nil, nil
case "status":
return nil, nil
default:
parts := strings.Split(cmd.Endpoint, "/")
if len(parts) != 3 {
return nil, ctxerr.New(r.Context, "unrecognized DDM endpoint")
}
declarationType := parts[1]
declarationIdentifier := parts[2]
fmt.Println(declarationType, declarationIdentifier)
return nil, nil
}
}
// CommandAndReportResults handles MDM [Commands and Queries][1].