Skip to content

Commit

Permalink
⭐️ Adding conditional Access - Named location part
Browse files Browse the repository at this point in the history
Signed-off-by: Hossein Rouhani <h_rouhani@hotmail.com>
  • Loading branch information
HRouhani committed Sep 5, 2024
1 parent 80e078c commit 4339ce3
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
41 changes: 41 additions & 0 deletions providers/ms365/resources/conditional-access.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (c) Mondoo, Inc.
// SPDX-License-Identifier: BUSL-1.1

package resources

import (
"context"
"log"

"github.com/microsoftgraph/msgraph-sdk-go/models"
"go.mondoo.com/cnquery/v11/providers/ms365/connection"
)

func (a *mqlMicrosoftConditionalAccess) namedLocations() (string, error) {
conn := a.MqlRuntime.Connection.(*connection.Ms365Connection)
graphClient, err := conn.GraphClient()
if err != nil {
return "", err
}

// Make a request to get named locations
ctx := context.Background()
namedLocations, err := graphClient.Identity().ConditionalAccess().NamedLocations().Get(ctx, nil)
if err != nil {
return "", transformError(err)
}

// Check if any of the named locations exist and return the first one
for _, location := range namedLocations.GetValue() {
// Use type assertion to check for IP named locations
if ipLocation, ok := location.(*models.IpNamedLocation); ok {
displayName := ipLocation.GetDisplayName()
if displayName != nil {
return *displayName, nil
}
}
}

log.Println("No named locations are defined.")
return "", nil
}
6 changes: 6 additions & 0 deletions providers/ms365/resources/ms365.lr
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ microsoft.tenant @defaults("name") {
subscriptions() []dict
}

// Microsoft Conditional Access Policies
private microsoft.conditionalAccess {
// Return the name of the first named location
namedLocations() string
}

// Microsoft Entra ID user
private microsoft.user @defaults("id displayName userPrincipalName") {
// User Object ID
Expand Down
7 changes: 7 additions & 0 deletions providers/ms365/resources/ms365.lr.manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ resources:
microsoft:
fields:
applications: {}
conditionalAccess:
min_mondoo_version: 9.0.0
domains: {}
enterpriseApplications:
min_mondoo_version: latest
Expand Down Expand Up @@ -118,6 +120,11 @@ resources:
value: {}
is_private: true
min_mondoo_version: 9.0.0
microsoft.conditionalAccess:
fields:
namedLocations: {}
is_private: true
min_mondoo_version: 9.0.0
microsoft.devicemanagement:
fields:
deviceCompliancePolicies: {}
Expand Down

0 comments on commit 4339ce3

Please sign in to comment.