Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[azure] [fix] Fixed collecting network resources + added tests #1810

Merged
merged 8 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion plugins/azure/resoto_plugin_azure/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
AzureResource,
resources as base_resources,
)
from resoto_plugin_azure.resource.network import resources as network_resources
from resotolib.baseresources import Cloud, GraphRoot
from resotolib.core.actions import CoreFeedback
from resotolib.graph import Graph
Expand All @@ -27,7 +28,7 @@ def resource_with_params(clazz: Type[AzureResource], params: Set[str], includes_
return cp.issubset(params) and (not includes_all or params.issubset(cp))


all_resources: List[Type[AzureResource]] = base_resources + compute_resources
all_resources: List[Type[AzureResource]] = base_resources + compute_resources + network_resources
global_resources = [r for r in all_resources if resource_with_params(r, {"subscriptionId"})]
regional_resources = [r for r in all_resources if resource_with_params(r, {"subscriptionId", "location"}, True)]

Expand Down
2 changes: 1 addition & 1 deletion plugins/azure/resoto_plugin_azure/resource/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -2150,7 +2150,7 @@ class AzureVirtualMachineNetworkInterfaceConfiguration:

@define(eq=False, slots=False)
class AzureNetworkProfile:
kind: ClassVar[str] = "azure_network_profile"
kind: ClassVar[str] = "azure_virtual_machine_network_profile"
1101-1 marked this conversation as resolved.
Show resolved Hide resolved
mapping: ClassVar[Dict[str, Bender]] = {
"network_api_version": S("networkApiVersion"),
"network_interface_configurations": S("networkInterfaceConfigurations")
Expand Down
20 changes: 11 additions & 9 deletions plugins/azure/resoto_plugin_azure/resource/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from resoto_plugin_azure.azure_client import AzureApiSpec
from resoto_plugin_azure.resource.base import AzureResource, AzureSubResource, AzureSku
from resotolib.json_bender import Bender, S, Bend, ForallBend, K
from resotolib.json_bender import Bender, S, Bend, ForallBend, K, AsInt, StringToUnitNumber


@define(eq=False, slots=False)
Expand Down Expand Up @@ -1173,15 +1173,13 @@ class AzureAutoApprovedPrivateLinkService(AzureResource):
expect_array=True,
)
mapping: ClassVar[Dict[str, Bender]] = {
"id": K(None),
"id": S("privateLinkService"),
"tags": S("tags", default={}),
"name": K(None),
"ctime": K(None),
"mtime": K(None),
"atime": K(None),
"private_link_service": S("privateLinkService"),
}
private_link_service: Optional[str] = field(default=None, metadata={'description': 'The id of the private link service resource.'}) # fmt: skip


@define(eq=False, slots=False)
Expand Down Expand Up @@ -3242,7 +3240,7 @@ class AzureExpressRoutePort(AzureResource):
"ether_type": S("properties", "etherType"),
"identity": S("identity") >> Bend(AzureManagedServiceIdentity.mapping),
"links": S("properties", "links") >> ForallBend(AzureExpressRouteLink.mapping),
"mtu_string": S("properties", "mtu"), # TODO: check if this string is actually an int?
"mtu": S("properties", "mtu") >> AsInt(),
"peering_location": S("properties", "peeringLocation"),
"provisioned_bandwidth_in_gbps": S("properties", "provisionedBandwidthInGbps"),
"provisioning_state": S("properties", "provisioningState"),
Expand All @@ -3257,7 +3255,7 @@ class AzureExpressRoutePort(AzureResource):
ether_type: Optional[str] = field(default=None, metadata={"description": "Ether type of the physical port."})
identity: Optional[AzureManagedServiceIdentity] = field(default=None, metadata={'description': 'Identity for the resource.'}) # fmt: skip
links: Optional[List[AzureExpressRouteLink]] = field(default=None, metadata={'description': 'The set of physical links of the ExpressRoutePort resource.'}) # fmt: skip
mtu_string: Optional[str] = field(default=None, metadata={'description': 'Maximum transmission unit of the physical port pair(s).'}) # fmt: skip
mtu: Optional[int] = field(default=None, metadata={'description': 'Maximum transmission unit of the physical port pair(s).'}) # fmt: skip
peering_location: Optional[str] = field(default=None, metadata={'description': 'The name of the peering location that the ExpressRoutePort is mapped to physically.'}) # fmt: skip
provisioned_bandwidth_in_gbps: Optional[float] = field(default=None, metadata={'description': 'Aggregate Gbps of associated circuit bandwidths.'}) # fmt: skip
provisioning_state: Optional[str] = field(default=None, metadata={'description': 'The current provisioning state.'}) # fmt: skip
Expand Down Expand Up @@ -3491,7 +3489,7 @@ class AzureFirewallPolicy(AzureResource):
>> Bend(AzureFirewallPolicyIntrusionDetection.mapping),
"provisioning_state": S("properties", "provisioningState"),
"rule_collection_groups": S("properties") >> S("ruleCollectionGroups", default=[]) >> ForallBend(S("id")),
"size_string": S("properties", "size"), # TODO: check if this is actually an int?
"size_string": S("properties", "size") >> StringToUnitNumber("B"),
1101-1 marked this conversation as resolved.
Show resolved Hide resolved
"sku": S("properties", "sku", "tier"),
"snat": S("properties", "snat") >> Bend(AzureFirewallPolicySNAT.mapping),
"sql": S("properties", "sql", "allowSqlRedirect"),
Expand All @@ -3512,7 +3510,7 @@ class AzureFirewallPolicy(AzureResource):
intrusion_detection: Optional[AzureFirewallPolicyIntrusionDetection] = field(default=None, metadata={'description': 'Configuration for intrusion detection mode and rules.'}) # fmt: skip
provisioning_state: Optional[str] = field(default=None, metadata={'description': 'The current provisioning state.'}) # fmt: skip
rule_collection_groups: Optional[List[str]] = field(default=None, metadata={'description': 'List of references to FirewallPolicyRuleCollectionGroups.'}) # fmt: skip
size_string: Optional[str] = field(default=None, metadata={'description': 'A read-only string that represents the size of the FirewallPolicyPropertiesFormat in MB. (ex 0.5MB)'}) # fmt: skip
size_string: Optional[int] = field(default=None, metadata={'description': 'A read-only string that represents the size of the FirewallPolicyPropertiesFormat in MB. (ex 0.5MB)'}) # fmt: skip
1101-1 marked this conversation as resolved.
Show resolved Hide resolved
sku: Optional[str] = field(default=None, metadata={"description": "SKU of Firewall policy."})
snat: Optional[AzureFirewallPolicySNAT] = field(default=None, metadata={'description': 'The private IP addresses/IP ranges to which traffic will not be SNAT.'}) # fmt: skip
sql: Optional[bool] = field(default=None, metadata={"description": "SQL Settings in Firewall Policy."})
Expand Down Expand Up @@ -4448,14 +4446,18 @@ class AzureUsage(AzureResource):
mapping: ClassVar[Dict[str, Bender]] = {
"id": S("id"),
"tags": S("tags", default={}),
"name": S("name"),
"name": K(None),
"usage_name": S("name") >> Bend(AzureUsageName.mapping),
"ctime": K(None),
"mtime": K(None),
"atime": K(None),
aquamatthias marked this conversation as resolved.
Show resolved Hide resolved
"current_value": S("currentValue"),
"limit": S("limit"),
"unit": S("unit"),
}
usage_name: Optional[AzureUsageName] = field(
default=None, metadata={"description": "The name of the type of usage."}
)
current_value: Optional[int] = field(default=None, metadata={"description": "The current value of the usage."})
limit: Optional[int] = field(default=None, metadata={"description": "The limit of usage."})
unit: Optional[str] = field(default=None, metadata={"description": "An enum describing the unit of measurement."})
Expand Down
4 changes: 2 additions & 2 deletions plugins/azure/test/collector_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ def test_collect(
) -> None:
collector = AzureSubscriptionCollector(config, Cloud(id="azure"), azure_subscription, credentials, core_feedback)
collector.collect()
assert len(collector.graph.nodes) == 62
assert len(collector.graph.edges) == 80
assert len(collector.graph.nodes) == 454
assert len(collector.graph.edges) == 472
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
{
"value": [
{
"name": "Policy1",
"id": "/subscriptions/subid/resourceGroups/rg1/providers/Microsoft.Network/ApplicationGatewayWebApplicationFirewallPolicies/Policy1",
"type": "Microsoft.Network/applicationgatewaywebapplicationfirewallpolicies",
"tags": {
"key1": "value1",
"key2": "value2"
},
"location": "WestUs",
"properties": {
"resourceState": "Enabled",
"provisioningState": "Succeeded",
"policySettings": {
"state": "Enabled",
"mode": "Prevention",
"requestBodyEnforcement": true,
"maxRequestBodySizeInKb": 2000,
"requestBodyInspectLimitInKB": 2000,
"fileUploadEnforcement": true,
"fileUploadLimitInMb": 4000,
"requestBodyCheck": true,
"customBlockResponseStatusCode": 405,
"customBlockResponseBody": "SGVsbG8=",
"logScrubbing": {
"state": "Enabled",
"scrubbingRules": [
{
"state": "Enabled",
"matchVariable": "RequestArgNames",
"selectorMatchOperator": "Equals",
"selector": "test"
},
{
"state": "Enabled",
"matchVariable": "RequestIPAddress",
"selectorMatchOperator": "EqualsAny",
"selector": "*"
}
]
}
},
"customRules": [
{
"name": "Rule1",
"priority": 1,
"state": "Enabled",
"ruleType": "MatchRule",
"matchConditions": [
{
"matchVariables": [
{
"variableName": "RemoteAddr",
"selector": null
}
],
"operator": "IPMatch",
"negationConditon": false,
"matchValues": [
"192.168.1.0/24",
"10.0.0.0/24"
],
"transforms": []
}
],
"action": "Block"
},
{
"name": "Rule2",
"priority": 2,
"state": "Enabled",
"ruleType": "MatchRule",
"matchConditions": [
{
"matchVariables": [
{
"variableName": "RemoteAddr",
"selector": null
}
],
"operator": "IPMatch",
"negationConditon": false,
"matchValues": [
"192.168.1.0/24"
]
},
{
"matchVariables": [
{
"variableName": "RequestHeader",
"selector": "UserAgent"
}
],
"operator": "Contains",
"negationConditon": false,
"matchValues": [
"Windows"
]
}
],
"action": "Block"
},
{
"name": "RateLimitRule3",
"priority": 3,
"rateLimitDuration": "OneMin",
"rateLimitThreshold": 10,
"ruleType": "RateLimitRule",
"matchConditions": [
{
"matchVariables": [
{
"variableName": "RemoteAddr",
"selector": null
}
],
"operator": "IPMatch",
"negationConditon": true,
"matchValues": [
"192.168.1.0/24",
"10.0.0.0/24"
]
}
],
"groupByUserSession": [
{
"groupByVariables": [
{
"variableName": "ClientAddr"
}
]
}
],
"action": "Block"
}
],
"managedRules": {
"managedRuleSets": [
{
"ruleSetType": "OWASP",
"ruleSetVersion": "3.2"
}
]
}
}
}
]
}
52 changes: 52 additions & 0 deletions plugins/azure/test/files/network/ExpressRoutePorts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"value": [
{
"name": "portName",
"id": "/subscriptions/subid/resourceGroups/rg1/providers/Microsoft.Network/expressRoutePorts/portName",
"type": "Microsoft.Network/expressRoutePorts",
"location": "westus",
"properties": {
"provisioningState": "Succeeded",
"peeringLocation": "peeringLocationName",
"bandwidthInGbps": 100,
"provisionedBandwidthInGbps": 0,
"mtu": "1500",
"encapsulation": "QinQ",
"billingType": "UnlimitedData",
"etherType": "0x8100",
"allocationDate": "Friday, July 1, 2018",
"links": [
{
"id": "/subscriptions/subid/resourceGroups/rg1/providers/Microsoft.Network/expressRoutePorts/portName/links/link1",
"name": "link1",
"properties": {
"provisioningState": "Succeeded",
"routerName": "router1",
"interfaceName": "Ethernet 0/0",
"patchPanelId": "patchPanelId1",
"rackId": "rackId1",
"coloLocation": "coloLocation1",
"connectorType": "LC",
"adminState": "Disabled"
}
},
{
"id": "/subscriptions/subid/resourceGroups/rg1/providers/Microsoft.Network/expressRoutePorts/portName/links/link2",
"name": "link2",
"properties": {
"provisioningState": "Succeeded",
"routerName": "router2",
"interfaceName": "Ethernet 0/0",
"patchPanelId": "patchPanelId2",
"rackId": "rackId2",
"coloLocation": "coloLocation2",
"connectorType": "LC",
"adminState": "Disabled"
}
}
],
"circuits": []
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"value": [
{
"name": "locationName",
"id": "/subscriptions/subid/providers/Microsoft.Network/expressRoutePortsLocations/locationName",
"type": "Microsoft.Network/expressRoutePortsLocations",
"location": "westus",
"properties": {
"provisioningState": "Succeeded",
"address": "123 Main Street, City, State, Zip",
"contact": "[email protected]",
"availableBandwidths": []
}
}
]
}
32 changes: 32 additions & 0 deletions plugins/azure/test/files/network/IpAllocations.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"value": [
{
"name": "test-ipallocation1",
"id": "/subscriptions/subid/resourceGroups/rg1/providers/Microsoft.Network/IpAllocations/test-ipallocation1",
"type": "Microsoft.Network/IpAllocations",
"location": "centraluseuap",
"properties": {
"type": "Hypernet",
"prefix": "3.2.5.0/24",
"ipamAllocationId": "916d3b28-663f-448b-9abc-1bea9d5fed8f",
"allocationTags": {
"VNetID": "/subscriptions/subid/resourceGroups/rg1/providers/Microsoft.Network/virtualNetworks/HypernetVnet1"
}
}
},
{
"name": "test-ipallocation2",
"id": "/subscriptions/subid/resourceGroups/rg1/providers/Microsoft.Network/IpAllocations/test-ipallocation2",
"type": "Microsoft.Network/IpAllocations",
"location": "centraluseuap",
"properties": {
"type": "Hypernet",
"prefix": "3.2.6.0/24",
"ipamAllocationId": "57dc7256-2ff7-43f2-b9c8-85a70b5c6408",
"allocationTags": {
"VNetID": "/subscriptions/subid/resourceGroups/rg1/providers/Microsoft.Network/virtualNetworks/HypernetVnet2"
}
}
}
]
}
Loading
Loading