Skip to content

Commit

Permalink
Improved to include the trusted
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 19, 2024
1 parent e2cf4b3 commit 7f0e524
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 9 deletions.
27 changes: 20 additions & 7 deletions providers/ms365/resources/conditional-access.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"log"

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

Expand All @@ -18,29 +19,41 @@ func (a *mqlMicrosoftConditionalAccess) namedLocations() ([]interface{}, error)
return nil, err
}

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

// Collect all named location names
var locationNames []interface{} // Changed to interface{} to match the expected return type
var locationDetails []interface{}
for _, location := range namedLocations.GetValue() {
// Use type assertion to check for IP named locations
if ipLocation, ok := location.(*models.IpNamedLocation); ok {
displayName := ipLocation.GetDisplayName()
isTrusted := ipLocation.GetIsTrusted()

if displayName != nil {
locationNames = append(locationNames, *displayName)
trusted := false
if isTrusted != nil {
trusted = *isTrusted
}

locationInfo, err := CreateResource(a.MqlRuntime, "microsoft.conditionalAccess.ipNamedLocation",
map[string]*llx.RawData{
"name": llx.StringDataPtr(displayName),
"trusted": llx.BoolData(trusted),
})
if err != nil {
return nil, err
}
locationDetails = append(locationDetails, locationInfo)
}
}
}

if len(locationNames) == 0 {
if len(locationDetails) == 0 {
log.Println("No named locations are defined.")
return nil, nil
}

return locationNames, nil
return locationDetails, nil
}
10 changes: 9 additions & 1 deletion providers/ms365/resources/ms365.lr
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,15 @@ microsoft.tenant @defaults("name") {
// Microsoft Conditional Access Policies
microsoft.conditionalAccess {
// IP named location
namedLocations() []string
namedLocations() []microsoft.conditionalAccess.ipNamedLocation
}

// Microsoft Conditional Access IP named location
microsoft.conditionalAccess.ipNamedLocation @defaults("name trusted") {
// Named location name
name string
// Whether the location is marked as trusted
trusted bool
}

// Microsoft Entra ID user
Expand Down
83 changes: 82 additions & 1 deletion providers/ms365/resources/ms365.lr.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions providers/ms365/resources/ms365.lr.manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,19 @@ resources:
min_mondoo_version: 9.0.0
microsoft.conditionalAccess:
fields:
name: {}
namedLocations: {}
trusted: {}
min_mondoo_version: 9.0.0
microsoft.conditionalAccess.ipNamedLocation:
fields:
name: {}
trusted: {}
min_mondoo_version: 9.0.0
microsoft.conditionalAccess.namedLocation:
fields:
name: {}
trusted: {}
min_mondoo_version: 9.0.0
microsoft.devicemanagement:
fields:
Expand Down

0 comments on commit 7f0e524

Please sign in to comment.