Namespace: microsoft.graph.networkaccess
Important
APIs under the /beta version in Microsoft Graph are subject to change. Use of these APIs in production applications is not supported. To determine whether an API is available in v1.0, use the Version selector.
Create a new cloudFirewallRule object in a cloudFirewallPolicy.
This API is available in the following national cloud deployments.
| Global service |
US Government L4 |
US Government L5 (DOD) |
China operated by 21Vianet |
| ✅ |
❌ |
❌ |
❌ |
Permissions
Choose the permission or permissions marked as least privileged for this API. Use a higher privileged permission or permissions only if your app requires it. For details about delegated and application permissions, see Permission types. To learn more about these permissions, see the permissions reference.
| Permission type |
Least privileged permissions |
Higher privileged permissions |
| Delegated (work or school account) |
NetworkAccess.ReadWrite.All |
Not available. |
| Delegated (personal Microsoft account) |
Not supported. |
Not supported. |
| Application |
NetworkAccess.ReadWrite.All |
Not available. |
Important
For delegated access using work or school accounts, the signed-in user must be assigned a supported Microsoft Entra role or a custom role that grants the permissions required for this operation. This operation supports the following built-in roles, which provide only the least privilege necessary:
- Global Secure Access Administrator
- Security Administrator
HTTP request
POST /networkAccess/cloudFirewallPolicies/{cloudFirewallPolicyId}/policyRules
Request body
In the request body, supply a JSON representation of the cloudFirewallRule object.
You can specify the following properties when creating a cloudFirewallRule.
Response
If successful, this method returns a 201 Created response code and a cloudFirewallRule object in the response body.
Examples
Request
The following example shows a request that creates a rule to block specific traffic. The matching conditions use AND logic between properties (sources AND destinations must match), while items within collections use OR logic (any one address or port can match).
POST https://graph.microsoft.com/beta/networkAccess/cloudFirewallPolicies/80b58b7d-572f-4457-8944-c804fcf3b694/policyRules
Content-Type: application/json
{
"@odata.type": "#microsoft.graph.networkaccess.cloudFirewallRule",
"name": "Block outbound to risky destinations",
"description": "Block traffic to specific IPs on common ports",
"priority": 100,
"action": "block",
"settings": {
"status": "enabled"
},
"matchingConditions": {
"sources": {
"addresses": [
{
"@odata.type": "#microsoft.graph.networkaccess.cloudFirewallSourceIpAddress",
"values": ["192.168.1.1", "192.168.0.0/16", "172.16.0.0-172.16.255.255"]
}
],
"ports": ["80", "443", "445-447"]
},
"destinations": {
"addresses": [
{
"@odata.type": "#microsoft.graph.networkaccess.cloudFirewallDestinationIpAddress",
"values": ["10.0.0.1"]
}
],
"ports": ["80", "443", "445-447"],
"protocols": "tcp"
}
}
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Beta.Models.Networkaccess;
var requestBody = new CloudFirewallRule
{
OdataType = "#microsoft.graph.networkaccess.cloudFirewallRule",
Name = "Block outbound to risky destinations",
Description = "Block traffic to specific IPs on common ports",
Priority = 100L,
Action = CloudFirewallAction.Block,
Settings = new CloudFirewallRuleSettings
{
Status = SecurityRuleStatus.Enabled,
},
MatchingConditions = new CloudFirewallMatchingConditions
{
Sources = new CloudFirewallSourceMatching
{
Addresses = new List<CloudFirewallSourceAddress>
{
new CloudFirewallSourceIpAddress
{
OdataType = "#microsoft.graph.networkaccess.cloudFirewallSourceIpAddress",
Values = new List<string>
{
"192.168.1.1",
"192.168.0.0/16",
"172.16.0.0-172.16.255.255",
},
},
},
Ports = new List<string>
{
"80",
"443",
"445-447",
},
},
Destinations = new CloudFirewallDestinationMatching
{
Addresses = new List<CloudFirewallDestinationAddress>
{
new CloudFirewallDestinationIpAddress
{
OdataType = "#microsoft.graph.networkaccess.cloudFirewallDestinationIpAddress",
Values = new List<string>
{
"10.0.0.1",
},
},
},
Ports = new List<string>
{
"80",
"443",
"445-447",
},
Protocols = CloudFirewallProtocol.Tcp,
},
},
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.NetworkAccess.CloudFirewallPolicies["{cloudFirewallPolicy-id}"].PolicyRules.PostAsync(requestBody);
// Code snippets are only available for the latest major version. Current major version is $v0.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
graphmodelsnetworkaccess "github.com/microsoftgraph/msgraph-beta-sdk-go/models/networkaccess"
//other-imports
)
requestBody := graphmodelsnetworkaccess.NewPolicyRule()
name := "Block outbound to risky destinations"
requestBody.SetName(&name)
description := "Block traffic to specific IPs on common ports"
requestBody.SetDescription(&description)
priority := int64(100)
requestBody.SetPriority(&priority)
action := graphmodels.BLOCK_CLOUDFIREWALLACTION
requestBody.SetAction(&action)
settings := graphmodelsnetworkaccess.NewCloudFirewallRuleSettings()
status := graphmodels.ENABLED_SECURITYRULESTATUS
settings.SetStatus(&status)
requestBody.SetSettings(settings)
matchingConditions := graphmodelsnetworkaccess.NewCloudFirewallMatchingConditions()
sources := graphmodelsnetworkaccess.NewCloudFirewallSourceMatching()
cloudFirewallSourceAddress := graphmodelsnetworkaccess.NewCloudFirewallSourceIpAddress()
values := []string {
"192.168.1.1",
"192.168.0.0/16",
"172.16.0.0-172.16.255.255",
}
cloudFirewallSourceAddress.SetValues(values)
addresses := []graphmodelsnetworkaccess.CloudFirewallSourceAddressable {
cloudFirewallSourceAddress,
}
sources.SetAddresses(addresses)
ports := []string {
"80",
"443",
"445-447",
}
sources.SetPorts(ports)
matchingConditions.SetSources(sources)
destinations := graphmodelsnetworkaccess.NewCloudFirewallDestinationMatching()
cloudFirewallDestinationAddress := graphmodelsnetworkaccess.NewCloudFirewallDestinationIpAddress()
values := []string {
"10.0.0.1",
}
cloudFirewallDestinationAddress.SetValues(values)
addresses := []graphmodelsnetworkaccess.CloudFirewallDestinationAddressable {
cloudFirewallDestinationAddress,
}
destinations.SetAddresses(addresses)
ports := []string {
"80",
"443",
"445-447",
}
destinations.SetPorts(ports)
protocols := graphmodels.TCP_CLOUDFIREWALLPROTOCOL
destinations.SetProtocols(&protocols)
matchingConditions.SetDestinations(destinations)
requestBody.SetMatchingConditions(matchingConditions)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
policyRules, err := graphClient.NetworkAccess().CloudFirewallPolicies().ByCloudFirewallPolicyId("cloudFirewallPolicy-id").PolicyRules().Post(context.Background(), requestBody, nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
com.microsoft.graph.beta.models.networkaccess.CloudFirewallRule policyRule = new com.microsoft.graph.beta.models.networkaccess.CloudFirewallRule();
policyRule.setOdataType("#microsoft.graph.networkaccess.cloudFirewallRule");
policyRule.setName("Block outbound to risky destinations");
policyRule.setDescription("Block traffic to specific IPs on common ports");
policyRule.setPriority(100L);
policyRule.setAction(com.microsoft.graph.beta.models.networkaccess.CloudFirewallAction.Block);
com.microsoft.graph.beta.models.networkaccess.CloudFirewallRuleSettings settings = new com.microsoft.graph.beta.models.networkaccess.CloudFirewallRuleSettings();
settings.setStatus(com.microsoft.graph.beta.models.networkaccess.SecurityRuleStatus.Enabled);
policyRule.setSettings(settings);
com.microsoft.graph.beta.models.networkaccess.CloudFirewallMatchingConditions matchingConditions = new com.microsoft.graph.beta.models.networkaccess.CloudFirewallMatchingConditions();
com.microsoft.graph.beta.models.networkaccess.CloudFirewallSourceMatching sources = new com.microsoft.graph.beta.models.networkaccess.CloudFirewallSourceMatching();
LinkedList<com.microsoft.graph.beta.models.networkaccess.CloudFirewallSourceAddress> addresses = new LinkedList<com.microsoft.graph.beta.models.networkaccess.CloudFirewallSourceAddress>();
com.microsoft.graph.beta.models.networkaccess.CloudFirewallSourceIpAddress cloudFirewallSourceAddress = new com.microsoft.graph.beta.models.networkaccess.CloudFirewallSourceIpAddress();
cloudFirewallSourceAddress.setOdataType("#microsoft.graph.networkaccess.cloudFirewallSourceIpAddress");
LinkedList<String> values = new LinkedList<String>();
values.add("192.168.1.1");
values.add("192.168.0.0/16");
values.add("172.16.0.0-172.16.255.255");
cloudFirewallSourceAddress.setValues(values);
addresses.add(cloudFirewallSourceAddress);
sources.setAddresses(addresses);
LinkedList<String> ports = new LinkedList<String>();
ports.add("80");
ports.add("443");
ports.add("445-447");
sources.setPorts(ports);
matchingConditions.setSources(sources);
com.microsoft.graph.beta.models.networkaccess.CloudFirewallDestinationMatching destinations = new com.microsoft.graph.beta.models.networkaccess.CloudFirewallDestinationMatching();
LinkedList<com.microsoft.graph.beta.models.networkaccess.CloudFirewallDestinationAddress> addresses1 = new LinkedList<com.microsoft.graph.beta.models.networkaccess.CloudFirewallDestinationAddress>();
com.microsoft.graph.beta.models.networkaccess.CloudFirewallDestinationIpAddress cloudFirewallDestinationAddress = new com.microsoft.graph.beta.models.networkaccess.CloudFirewallDestinationIpAddress();
cloudFirewallDestinationAddress.setOdataType("#microsoft.graph.networkaccess.cloudFirewallDestinationIpAddress");
LinkedList<String> values1 = new LinkedList<String>();
values1.add("10.0.0.1");
cloudFirewallDestinationAddress.setValues(values1);
addresses1.add(cloudFirewallDestinationAddress);
destinations.setAddresses(addresses1);
LinkedList<String> ports1 = new LinkedList<String>();
ports1.add("80");
ports1.add("443");
ports1.add("445-447");
destinations.setPorts(ports1);
destinations.setProtocols(EnumSet.of(com.microsoft.graph.beta.models.networkaccess.CloudFirewallProtocol.Tcp));
matchingConditions.setDestinations(destinations);
policyRule.setMatchingConditions(matchingConditions);
com.microsoft.graph.models.networkaccess.PolicyRule result = graphClient.networkAccess().cloudFirewallPolicies().byCloudFirewallPolicyId("{cloudFirewallPolicy-id}").policyRules().post(policyRule);
const options = {
authProvider,
};
const client = Client.init(options);
const policyRule = {
'@odata.type': '#microsoft.graph.networkaccess.cloudFirewallRule',
name: 'Block outbound to risky destinations',
description: 'Block traffic to specific IPs on common ports',
priority: 100,
action: 'block',
settings: {
status: 'enabled'
},
matchingConditions: {
sources: {
addresses: [
{
'@odata.type': '#microsoft.graph.networkaccess.cloudFirewallSourceIpAddress',
values: ['192.168.1.1', '192.168.0.0/16', '172.16.0.0-172.16.255.255']
}
],
ports: ['80', '443', '445-447']
},
destinations: {
addresses: [
{
'@odata.type': '#microsoft.graph.networkaccess.cloudFirewallDestinationIpAddress',
values: ['10.0.0.1']
}
],
ports: ['80', '443', '445-447'],
protocols: 'tcp'
}
}
};
await client.api('/networkAccess/cloudFirewallPolicies/80b58b7d-572f-4457-8944-c804fcf3b694/policyRules')
.version('beta')
.post(policyRule);
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Models\Networkaccess\CloudFirewallRule;
use Microsoft\Graph\Beta\Generated\Models\Networkaccess\CloudFirewallAction;
use Microsoft\Graph\Beta\Generated\Models\Networkaccess\CloudFirewallRuleSettings;
use Microsoft\Graph\Beta\Generated\Models\Networkaccess\SecurityRuleStatus;
use Microsoft\Graph\Beta\Generated\Models\Networkaccess\CloudFirewallMatchingConditions;
use Microsoft\Graph\Beta\Generated\Models\Networkaccess\CloudFirewallSourceMatching;
use Microsoft\Graph\Beta\Generated\Models\Networkaccess\CloudFirewallSourceAddress;
use Microsoft\Graph\Beta\Generated\Models\Networkaccess\CloudFirewallSourceIpAddress;
use Microsoft\Graph\Beta\Generated\Models\Networkaccess\CloudFirewallDestinationMatching;
use Microsoft\Graph\Beta\Generated\Models\Networkaccess\CloudFirewallDestinationAddress;
use Microsoft\Graph\Beta\Generated\Models\Networkaccess\CloudFirewallDestinationIpAddress;
use Microsoft\Graph\Beta\Generated\Models\Networkaccess\CloudFirewallProtocol;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new CloudFirewallRule();
$requestBody->setOdataType('#microsoft.graph.networkaccess.cloudFirewallRule');
$requestBody->setName('Block outbound to risky destinations');
$requestBody->setDescription('Block traffic to specific IPs on common ports');
$requestBody->setPriority(100);
$requestBody->setAction(new CloudFirewallAction('block'));
$settings = new CloudFirewallRuleSettings();
$settings->setStatus(new SecurityRuleStatus('enabled'));
$requestBody->setSettings($settings);
$matchingConditions = new CloudFirewallMatchingConditions();
$matchingConditionsSources = new CloudFirewallSourceMatching();
$addressesCloudFirewallSourceAddress1 = new CloudFirewallSourceIpAddress();
$addressesCloudFirewallSourceAddress1->setOdataType('#microsoft.graph.networkaccess.cloudFirewallSourceIpAddress');
$addressesCloudFirewallSourceAddress1->setValues(['192.168.1.1', '192.168.0.0/16', '172.16.0.0-172.16.255.255', ]);
$addressesArray []= $addressesCloudFirewallSourceAddress1;
$matchingConditionsSources->setAddresses($addressesArray);
$matchingConditionsSources->setPorts(['80', '443', '445-447', ]);
$matchingConditions->setSources($matchingConditionsSources);
$matchingConditionsDestinations = new CloudFirewallDestinationMatching();
$addressesCloudFirewallDestinationAddress1 = new CloudFirewallDestinationIpAddress();
$addressesCloudFirewallDestinationAddress1->setOdataType('#microsoft.graph.networkaccess.cloudFirewallDestinationIpAddress');
$addressesCloudFirewallDestinationAddress1->setValues(['10.0.0.1', ]);
$addressesArray []= $addressesCloudFirewallDestinationAddress1;
$matchingConditionsDestinations->setAddresses($addressesArray);
$matchingConditionsDestinations->setPorts(['80', '443', '445-447', ]);
$matchingConditionsDestinations->setProtocols(new CloudFirewallProtocol('tcp'));
$matchingConditions->setDestinations($matchingConditionsDestinations);
$requestBody->setMatchingConditions($matchingConditions);
$result = $graphServiceClient->networkAccess()->cloudFirewallPolicies()->byCloudFirewallPolicyId('cloudFirewallPolicy-id')->policyRules()->post($requestBody)->wait();
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph_beta import GraphServiceClient
from msgraph_beta.generated.models.networkaccess.cloud_firewall_rule import CloudFirewallRule
from msgraph_beta.generated.models.cloud_firewall_action import CloudFirewallAction
from msgraph_beta.generated.models.networkaccess.cloud_firewall_rule_settings import CloudFirewallRuleSettings
from msgraph_beta.generated.models.security_rule_status import SecurityRuleStatus
from msgraph_beta.generated.models.networkaccess.cloud_firewall_matching_conditions import CloudFirewallMatchingConditions
from msgraph_beta.generated.models.networkaccess.cloud_firewall_source_matching import CloudFirewallSourceMatching
from msgraph_beta.generated.models.networkaccess.cloud_firewall_source_address import CloudFirewallSourceAddress
from msgraph_beta.generated.models.networkaccess.cloud_firewall_source_ip_address import CloudFirewallSourceIpAddress
from msgraph_beta.generated.models.networkaccess.cloud_firewall_destination_matching import CloudFirewallDestinationMatching
from msgraph_beta.generated.models.networkaccess.cloud_firewall_destination_address import CloudFirewallDestinationAddress
from msgraph_beta.generated.models.networkaccess.cloud_firewall_destination_ip_address import CloudFirewallDestinationIpAddress
from msgraph_beta.generated.models.cloud_firewall_protocol import CloudFirewallProtocol
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = CloudFirewallRule(
odata_type = "#microsoft.graph.networkaccess.cloudFirewallRule",
name = "Block outbound to risky destinations",
description = "Block traffic to specific IPs on common ports",
priority = 100,
action = CloudFirewallAction.Block,
settings = CloudFirewallRuleSettings(
status = SecurityRuleStatus.Enabled,
),
matching_conditions = CloudFirewallMatchingConditions(
sources = CloudFirewallSourceMatching(
addresses = [
CloudFirewallSourceIpAddress(
odata_type = "#microsoft.graph.networkaccess.cloudFirewallSourceIpAddress",
values = [
"192.168.1.1",
"192.168.0.0/16",
"172.16.0.0-172.16.255.255",
],
),
],
ports = [
"80",
"443",
"445-447",
],
),
destinations = CloudFirewallDestinationMatching(
addresses = [
CloudFirewallDestinationIpAddress(
odata_type = "#microsoft.graph.networkaccess.cloudFirewallDestinationIpAddress",
values = [
"10.0.0.1",
],
),
],
ports = [
"80",
"443",
"445-447",
],
protocols = CloudFirewallProtocol.Tcp,
),
),
)
result = await graph_client.network_access.cloud_firewall_policies.by_cloud_firewall_policy_id('cloudFirewallPolicy-id').policy_rules.post(request_body)
Response
The following example shows the response.
Note: The response object shown here might be shortened for readability.
HTTP/1.1 201 Created
Content-Type: application/json
{
"@odata.type": "#microsoft.graph.networkaccess.cloudFirewallRule",
"id": "406ebb24-e229-4011-8240-e11bbaa4f49d",
"name": "Block outbound to risky destinations",
"description": "Block traffic to specific IPs on common ports",
"priority": 100,
"action": "block",
"settings": {
"status": "enabled"
},
"matchingConditions": {
"sources": {
"addresses": [
{
"@odata.type": "#microsoft.graph.networkaccess.cloudFirewallSourceIpAddress",
"values": ["192.168.1.1", "192.168.0.0/16", "172.16.0.0-172.16.255.255"]
}
],
"ports": ["80", "443", "445-447"]
},
"destinations": {
"addresses": [
{
"@odata.type": "#microsoft.graph.networkaccess.cloudFirewallDestinationIpAddress",
"values": ["10.0.0.1"]
}
],
"ports": ["80", "443", "445-447"],
"protocols": "tcp"
}
}
}