diff --git a/providers/ms365/resources/conditional-access.go b/providers/ms365/resources/conditional-access.go new file mode 100644 index 0000000000..7f2481b074 --- /dev/null +++ b/providers/ms365/resources/conditional-access.go @@ -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 +} diff --git a/providers/ms365/resources/ms365.lr b/providers/ms365/resources/ms365.lr index 395f75d446..74e14f8390 100644 --- a/providers/ms365/resources/ms365.lr +++ b/providers/ms365/resources/ms365.lr @@ -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 diff --git a/providers/ms365/resources/ms365.lr.manifest.yaml b/providers/ms365/resources/ms365.lr.manifest.yaml index 87d39b4c2c..c3bb1da015 100755 --- a/providers/ms365/resources/ms365.lr.manifest.yaml +++ b/providers/ms365/resources/ms365.lr.manifest.yaml @@ -5,6 +5,8 @@ resources: microsoft: fields: applications: {} + conditionalAccess: + min_mondoo_version: 9.0.0 domains: {} enterpriseApplications: min_mondoo_version: latest @@ -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: {}