次の例は、特定のトラフィックをブロックするルールを作成する要求を示しています。 一致する条件では、プロパティ間で AND ロジックを使用します (ソースと宛先は一致する必要があります)。コレクション内の項目は OR ロジック (任意の 1 つのアドレスまたはポートが一致する可能性があります) を使用します。
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)